mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
Bug 141653 - Iimproved support for qualified named during binding resolution. Fixed Open Declaration to look for definitions as well as declarations (the PDOM keeps these separate where the DOM does not).
This commit is contained in:
parent
9e9b4fe3cd
commit
622a3c2e97
2 changed files with 70 additions and 15 deletions
|
@ -159,8 +159,11 @@ public class PDOMCPPLinkage extends PDOMLinkage {
|
|||
|
||||
private static final class FindBinding extends PDOMNamedNode.NodeFinder {
|
||||
PDOMBinding pdomBinding;
|
||||
final int desiredType;
|
||||
final int[] desiredType;
|
||||
public FindBinding(PDOM pdom, char[] name, int desiredType) {
|
||||
this(pdom, name, new int[] { desiredType });
|
||||
}
|
||||
public FindBinding(PDOM pdom, char[] name, int[] desiredType) {
|
||||
super(pdom, name);
|
||||
this.desiredType = desiredType;
|
||||
}
|
||||
|
@ -171,13 +174,16 @@ public class PDOMCPPLinkage extends PDOMLinkage {
|
|||
if (!tBinding.hasName(name))
|
||||
// no more bindings with our desired name
|
||||
return false;
|
||||
if (tBinding.getNodeType() != desiredType)
|
||||
// wrong type, try again
|
||||
return true;
|
||||
int nodeType = tBinding.getNodeType();
|
||||
for (int i = 0; i < desiredType.length; ++i)
|
||||
if (nodeType == desiredType[i]) {
|
||||
// got it
|
||||
pdomBinding = tBinding;
|
||||
return false;
|
||||
}
|
||||
|
||||
// got it
|
||||
pdomBinding = tBinding;
|
||||
return false;
|
||||
// wrong type, try again
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -231,8 +237,18 @@ public class PDOMCPPLinkage extends PDOMLinkage {
|
|||
return lastName != null ? resolveBinding(lastName) : null;
|
||||
}
|
||||
IASTNode parent = name.getParent();
|
||||
if (parent instanceof ICPPASTQualifiedName)
|
||||
parent = parent.getParent();
|
||||
if (parent instanceof ICPPASTQualifiedName) {
|
||||
ICPPASTQualifiedName qualName = (ICPPASTQualifiedName)parent;
|
||||
IASTName lastName = qualName.getLastName();
|
||||
if (name != lastName) {
|
||||
return resolveInQualifiedName(name);
|
||||
} else {
|
||||
// Drop down to the rest of the resolution procedure
|
||||
// with the parent of the qualified name
|
||||
parent = parent.getParent();
|
||||
}
|
||||
}
|
||||
|
||||
if (parent instanceof IASTIdExpression) {
|
||||
// reference
|
||||
IASTNode eParent = parent.getParent();
|
||||
|
@ -261,6 +277,34 @@ public class PDOMCPPLinkage extends PDOMLinkage {
|
|||
return null;
|
||||
}
|
||||
|
||||
private PDOMBinding resolveInQualifiedName(IASTName name) throws CoreException {
|
||||
ICPPASTQualifiedName qualName = (ICPPASTQualifiedName)name.getParent();
|
||||
|
||||
// Must be a namespace or a class
|
||||
IASTName[] names = qualName.getNames();
|
||||
IASTName nsName = null;
|
||||
for (int i = 0; i < names.length; ++i) {
|
||||
if (names[i] == name)
|
||||
break;
|
||||
else
|
||||
nsName = names[i];
|
||||
}
|
||||
if (nsName == names[names.length - 1])
|
||||
// didn't find our name here, weird...
|
||||
return null;
|
||||
|
||||
if (nsName == null) {
|
||||
// we are at the root
|
||||
FindBinding visitor = new FindBinding(pdom, name.toCharArray(),
|
||||
new int[] { CPPNAMESPACE, CPPCLASSTYPE });
|
||||
getIndex().accept(visitor);
|
||||
return visitor.pdomBinding;
|
||||
} else {
|
||||
// TODO we are in another namespace
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void findBindings(String pattern, List bindings) throws CoreException {
|
||||
MatchBinding visitor = new MatchBinding(pdom, pattern, bindings);
|
||||
getIndex().accept(visitor);
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
|
||||
package org.eclipse.cdt.internal.ui.search.actions;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.IPDOM;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
|
@ -43,7 +45,7 @@ public class OpenDeclarationsAction extends SelectionParseAction {
|
|||
|
||||
private class Runner extends Job {
|
||||
Runner() {
|
||||
super(CEditorMessages.getString("OpenDeclarations.label")); //$NON-NLS-1$
|
||||
super(CEditorMessages.getString("OpenDeclarations.dialog.title")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
|
@ -54,8 +56,12 @@ public class OpenDeclarationsAction extends SelectionParseAction {
|
|||
IWorkingCopy workingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(fEditor.getEditorInput());
|
||||
if (workingCopy == null)
|
||||
return Status.CANCEL_STATUS;
|
||||
|
||||
IASTTranslationUnit ast = workingCopy.getLanguage().getASTTranslationUnit(workingCopy, ILanguage.AST_SKIP_ALL_HEADERS | ILanguage.AST_USE_INDEX);
|
||||
|
||||
int style = 0;
|
||||
IPDOM pdom = CCorePlugin.getPDOMManager().getPDOM(workingCopy.getCProject());
|
||||
if (!pdom.isEmpty())
|
||||
style |= ILanguage.AST_SKIP_ALL_HEADERS | ILanguage.AST_USE_INDEX;
|
||||
IASTTranslationUnit ast = workingCopy.getLanguage().getASTTranslationUnit(workingCopy, style);
|
||||
IASTName[] selectedNames = workingCopy.getLanguage().getSelectedNames(ast, selectionStart, selectionLength);
|
||||
|
||||
if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected
|
||||
|
@ -75,17 +81,22 @@ public class OpenDeclarationsAction extends SelectionParseAction {
|
|||
};
|
||||
});
|
||||
} else if (binding instanceof PDOMBinding) {
|
||||
final IASTName name = ((PDOMBinding)binding).getFirstDeclaration();
|
||||
if (name != null)
|
||||
PDOMBinding pdomBinding = (PDOMBinding)binding;
|
||||
IASTName name = pdomBinding.getFirstDefinition();
|
||||
if (name == null)
|
||||
name = pdomBinding.getFirstDeclaration();
|
||||
if (name != null) {
|
||||
final IASTName dname = name;
|
||||
Display.getDefault().asyncExec(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
open(name);
|
||||
open(dname);
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue