[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] FIXED 43128- Search: cannot find declarations of local variables
|
FIXED 43128- Search: cannot find declarations
of local variables
This patch fixes the last bug reported
in 43128. So that the names with bindings that are local are only
searched in the local scope via the DOM AST.
i.e. Ctrl+G on 'x' below should
only find the local variable via the DOM AST and not both variables
via
the Index
// example code:
int
main(int argc, char **argv) {
int x = argc; // select "x"->right click->All Declarations->Workspace
}
int
foo() {
int x;
}
Devin Steffler
IBM's Eclipse CDT
Ottawa (Palladium), Ontario, Canada
Index: src/org/eclipse/cdt/internal/ui/search/DOMQuery.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/DOMQuery.java,v
retrieving revision 1.1
diff -u -r1.1 DOMQuery.java
--- src/org/eclipse/cdt/internal/ui/search/DOMQuery.java 27 Apr 2005 17:43:28 -0000 1.1
+++ src/org/eclipse/cdt/internal/ui/search/DOMQuery.java 11 May 2005 18:29:05 -0000
@@ -16,6 +16,7 @@
import org.eclipse.cdt.core.browser.PathUtil;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.DOMException;
+import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
@@ -27,8 +28,11 @@
import org.eclipse.cdt.core.dom.ast.IField;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
+import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.IVariable;
+import org.eclipse.cdt.core.dom.ast.c.ICFunctionScope;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
@@ -40,9 +44,7 @@
import org.eclipse.cdt.core.search.ICSearchResultCollector;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.IMatch;
-import org.eclipse.cdt.internal.ui.search.CSearchQuery;
-import org.eclipse.cdt.internal.ui.search.CSearchResult;
-import org.eclipse.cdt.internal.ui.search.NewSearchResultCollector;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
@@ -88,8 +90,12 @@
NewSearchResultCollector collector = new NewSearchResultCollector(textResult, mainSearchPM);
collector.aboutToStart();
- Set matches = DOMSearchUtil.getMatchesFromSearchEngine(scope, searchName, limitTo);
- if (matches != null && matches.size() > 0) {
+ // fix for 43128
+ Set matches=null;
+ if (!isLocal())
+ matches = DOMSearchUtil.getMatchesFromSearchEngine(scope, searchName, limitTo);
+
+ if (matches != null && matches.size() > 0) {
Iterator itr = matches.iterator();
while(itr.hasNext()) {
Object next = itr.next();
@@ -139,6 +145,24 @@
return new Status(IStatus.OK, CUIPlugin.getPluginId(), 0, BLANK_STRING, null); //$NON-NLS-1$
}
+ private boolean isLocal() {
+ IBinding binding = searchName.resolveBinding();
+ if (searchName instanceof CPPASTName) {
+ try {
+ if (binding instanceof ICPPBinding && !((ICPPBinding)binding).isGloballyQualified())
+ return true;
+ } catch (DOMException e) {}
+ } else {
+ try {
+ IScope nameScope = binding.getScope();
+ if (nameScope instanceof ICFunctionScope || nameScope.getPhysicalNode() instanceof IASTCompoundStatement)
+ return true;
+ } catch (DOMException e1) {}
+ }
+
+ return false; // otherwise it's not local
+ }
+
/**
* This method creates an IMatch corresponding to an IASTNode found at a specific
* fileResource (an IResource if external or an IPath if internal), the start/end offsets