1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-30 04:15:35 +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:
Doug Schaefer 2006-05-26 15:59:59 +00:00
parent 9e9b4fe3cd
commit 622a3c2e97
2 changed files with 70 additions and 15 deletions

View file

@ -159,8 +159,11 @@ public class PDOMCPPLinkage extends PDOMLinkage {
private static final class FindBinding extends PDOMNamedNode.NodeFinder { private static final class FindBinding extends PDOMNamedNode.NodeFinder {
PDOMBinding pdomBinding; PDOMBinding pdomBinding;
final int desiredType; final int[] desiredType;
public FindBinding(PDOM pdom, char[] name, 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); super(pdom, name);
this.desiredType = desiredType; this.desiredType = desiredType;
} }
@ -171,13 +174,16 @@ public class PDOMCPPLinkage extends PDOMLinkage {
if (!tBinding.hasName(name)) if (!tBinding.hasName(name))
// no more bindings with our desired name // no more bindings with our desired name
return false; return false;
if (tBinding.getNodeType() != desiredType) int nodeType = tBinding.getNodeType();
// wrong type, try again for (int i = 0; i < desiredType.length; ++i)
return true; if (nodeType == desiredType[i]) {
// got it
pdomBinding = tBinding;
return false;
}
// got it // wrong type, try again
pdomBinding = tBinding; return true;
return false;
} }
} }
@ -231,8 +237,18 @@ public class PDOMCPPLinkage extends PDOMLinkage {
return lastName != null ? resolveBinding(lastName) : null; return lastName != null ? resolveBinding(lastName) : null;
} }
IASTNode parent = name.getParent(); IASTNode parent = name.getParent();
if (parent instanceof ICPPASTQualifiedName) if (parent instanceof ICPPASTQualifiedName) {
parent = parent.getParent(); 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) { if (parent instanceof IASTIdExpression) {
// reference // reference
IASTNode eParent = parent.getParent(); IASTNode eParent = parent.getParent();
@ -261,6 +277,34 @@ public class PDOMCPPLinkage extends PDOMLinkage {
return null; 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 { public void findBindings(String pattern, List bindings) throws CoreException {
MatchBinding visitor = new MatchBinding(pdom, pattern, bindings); MatchBinding visitor = new MatchBinding(pdom, pattern, bindings);
getIndex().accept(visitor); getIndex().accept(visitor);

View file

@ -11,6 +11,8 @@
package org.eclipse.cdt.internal.ui.search.actions; 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.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
@ -43,7 +45,7 @@ public class OpenDeclarationsAction extends SelectionParseAction {
private class Runner extends Job { private class Runner extends Job {
Runner() { Runner() {
super(CEditorMessages.getString("OpenDeclarations.label")); //$NON-NLS-1$ super(CEditorMessages.getString("OpenDeclarations.dialog.title")); //$NON-NLS-1$
} }
protected IStatus run(IProgressMonitor monitor) { protected IStatus run(IProgressMonitor monitor) {
@ -54,8 +56,12 @@ public class OpenDeclarationsAction extends SelectionParseAction {
IWorkingCopy workingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(fEditor.getEditorInput()); IWorkingCopy workingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(fEditor.getEditorInput());
if (workingCopy == null) if (workingCopy == null)
return Status.CANCEL_STATUS; 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); IASTName[] selectedNames = workingCopy.getLanguage().getSelectedNames(ast, selectionStart, selectionLength);
if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected 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) { } else if (binding instanceof PDOMBinding) {
final IASTName name = ((PDOMBinding)binding).getFirstDeclaration(); PDOMBinding pdomBinding = (PDOMBinding)binding;
if (name != null) IASTName name = pdomBinding.getFirstDefinition();
if (name == null)
name = pdomBinding.getFirstDeclaration();
if (name != null) {
final IASTName dname = name;
Display.getDefault().asyncExec(new Runnable() { Display.getDefault().asyncExec(new Runnable() {
public void run() { public void run() {
try { try {
open(name); open(dname);
} catch (CoreException e) { } catch (CoreException e) {
CUIPlugin.getDefault().log(e); CUIPlugin.getDefault().log(e);
} }
} }
}); });
}
} }
} }
} }