Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVladimir Hirsl2005-06-17 04:19:28 +0000
committerVladimir Hirsl2005-06-17 04:19:28 +0000
commit7ab54e4dad4bb7c4bf5c2ed6057a2eac8435f38c (patch)
tree8d4cfad82154b7c6031dc3fb513f27fe9f56e70d
parente2daf28d350eec7c17520160e2a1995bc6b90b7d (diff)
downloadorg.eclipse.cdt-7ab54e4dad4bb7c4bf5c2ed6057a2eac8435f38c.tar.gz
org.eclipse.cdt-7ab54e4dad4bb7c4bf5c2ed6057a2eac8435f38c.tar.xz
org.eclipse.cdt-7ab54e4dad4bb7c4bf5c2ed6057a2eac8435f38c.zip
Fix for 95174: [Search Engine][DOM AST Indexer] does not find definition of a method.
-rw-r--r--core/org.eclipse.cdt.core/ChangeLog7
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/EntryResult.java10
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/IndexVisitorUtil.java4
-rw-r--r--core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/DOMSearchUtil.java118
4 files changed, 84 insertions, 55 deletions
diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog
index 81e36218f4f..c5a148c8162 100644
--- a/core/org.eclipse.cdt.core/ChangeLog
+++ b/core/org.eclipse.cdt.core/ChangeLog
@@ -1,3 +1,10 @@
+2005-06-17 Vladimir Hirsl
+ Fix for 95174: [Search Engine][DOM AST Indexer] does not find definition of a method
+
+ * index/org/eclipse/cdt/internal/core/index/cindexstorage/EntryResult.java
+ * index/org/eclipse/cdt/internal/core/index/domsourceindexer/IndexVisitorUtil.java
+ * search/org/eclipse/cdt/core/search/DOMSearchUtil.java
+
2005-06-16 Vladimir Hirsl
Fix for PR 99433: [Search] Return parms not part of qualification matching
Function/methos parameters are now used as a part of search pattern.
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/EntryResult.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/EntryResult.java
index 06a0e938a04..c6cb5f5a92d 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/EntryResult.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/EntryResult.java
@@ -206,7 +206,10 @@ public String getDisplayString() {
int finishParam = longname.indexOf("/("); //$NON-NLS-1$
String functionName;
- String arguments = longname.substring(startParam + 2, finishParam);
+ String arguments = ""; //$NON-NLS-1$
+ if (startParam + 2 < finishParam) {
+ arguments = longname.substring(startParam + 2, finishParam);
+ }
// TODO: flip arguments
arguments = arguments.replace('/',',');
@@ -219,7 +222,10 @@ public String getDisplayString() {
return functionName + arguments ;
}
else {
- String returnType = longname.substring(startReturn + 3, finishReturn);
+ String returnType = "";
+ if (startReturn + 3 < finishReturn) {
+ returnType = longname.substring(startReturn + 3, finishReturn);
+ }
functionName = longname.substring(0, startReturn -1);
return functionName + arguments + ':' + returnType;
}
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/IndexVisitorUtil.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/IndexVisitorUtil.java
index 791020685c1..190d30f7dfb 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/IndexVisitorUtil.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/IndexVisitorUtil.java
@@ -26,6 +26,7 @@ import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember;
@@ -184,6 +185,9 @@ public class IndexVisitorUtil {
*/
public static char[][] getParameters(IASTName functionName) {
IASTNode parent = functionName.getParent();
+ if (parent instanceof ICPPASTQualifiedName) {
+ parent = parent.getParent();
+ }
if (parent instanceof IASTDeclarator) {
IASTDeclarator declarator = (IASTDeclarator) parent;
String[] parameters = ASTSignatureUtil.getParameterSignatureArray(declarator);
diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/DOMSearchUtil.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/DOMSearchUtil.java
index fcef59a2828..5f6a3830218 100644
--- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/DOMSearchUtil.java
+++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/DOMSearchUtil.java
@@ -19,9 +19,9 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICLogConstants;
import org.eclipse.cdt.core.dom.CDOM;
import org.eclipse.cdt.core.dom.IASTServiceProvider;
-import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.DOMException;
+import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
@@ -30,15 +30,14 @@ import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IEnumeration;
import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IFunction;
-import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
-import org.eclipse.cdt.core.dom.ast.IType;
+import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.c.CASTVisitor;
-import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding;
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
@@ -53,6 +52,7 @@ import org.eclipse.cdt.core.search.ICSearchConstants.LimitTo;
import org.eclipse.cdt.core.search.ICSearchConstants.SearchFor;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTQualifiedName;
+import org.eclipse.cdt.internal.core.index.domsourceindexer.IndexVisitorUtil;
import org.eclipse.cdt.internal.core.search.matching.CSearchPattern;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@@ -443,60 +443,72 @@ public class DOMSearchUtil {
*/
public static String getSearchPattern(IASTName name) {
StringBuffer buffer = new StringBuffer();
- buffer.append("::"); //$NON-NLS-1$
-
- String[] namespaces = null;
-
- IASTNode parent = name.getParent();
- while(!(parent instanceof IASTTranslationUnit) && parent != null) {
- if (parent instanceof ICPPASTNamespaceDefinition) {
- namespaces = (String[])ArrayUtil.append(String.class, namespaces, ((ICPPASTNamespaceDefinition)parent).getName().toString());
- }
- parent = parent.getParent();
- }
-
- if (namespaces != null && namespaces.length > 0) {
- for( int i=namespaces.length-1; i>=0; i-- ) {
- if (namespaces[i] != null) {
- buffer.append(namespaces[i]);
- buffer.append("::"); //$NON-NLS-1$
- }
- }
- }
-
- if (name instanceof CPPASTName && name.getParent() instanceof CPPASTQualifiedName) {
- IASTName[] names = ((CPPASTQualifiedName)name.getParent()).getNames();
- for(int i=0; i<names.length; i++) {
- if (i != 0) buffer.append("::"); //$NON-NLS-1$
- buffer.append(names[i].toString());
+ // first option - use binding to get qualified name
+ IBinding binding = name.resolveBinding();
+ if (! (binding instanceof IProblemBinding)) {
+ if (binding instanceof ICPPBinding) {
+ ICPPBinding cppBinding = (ICPPBinding) binding;
+ try {
+ String[] qualifiedName = cppBinding.getQualifiedName();
+ for (int i = 0; i < qualifiedName.length; i++) {
+ if (i != 0) {
+ buffer.append("::"); //$NON-NLS-1$
+ }
+ buffer.append(qualifiedName[i]);
+ }
+ } catch (DOMException e) {
+ buffer.append(name.toString());
+ }
}
- } else {
- buffer.append(name.toString());
}
-
- if( name.resolveBinding() instanceof IFunction ){
- try {
- IBinding binding = name.resolveBinding();
- IFunctionType type = ((IFunction)binding).getType();
-
- buffer.append("("); //$NON-NLS-1$
- if (binding instanceof ICExternalBinding) {
- buffer.append("..."); //$NON-NLS-1$
- } else {
- IType[] parms = type.getParameterTypes();
- for( int i = 0; i < parms.length; i++ ){
- if( i != 0 )
- buffer.append(", "); //$NON-NLS-1$
- buffer.append(ASTTypeUtil.getType(parms[i]));
- }
+ // second option - traverse the tree
+ else {
+ String[] namespaces = null;
+
+ IASTNode parent = name.getParent();
+ while(!(parent instanceof IASTTranslationUnit) && parent != null) {
+ if (parent instanceof ICPPASTNamespaceDefinition) {
+ namespaces = (String[])ArrayUtil.append(String.class, namespaces,
+ ((ICPPASTNamespaceDefinition)parent).getName().toString());
+ }
+ parent = parent.getParent();
+ }
+
+ if (namespaces != null && namespaces.length > 0) {
+ for( int i=namespaces.length-1; i>=0; i-- ) {
+ if (namespaces[i] != null) {
+ buffer.append(namespaces[i]);
+ buffer.append("::"); //$NON-NLS-1$
+ }
+ }
+ }
+
+ if (name instanceof CPPASTName && name.getParent() instanceof CPPASTQualifiedName) {
+ IASTName[] names = ((CPPASTQualifiedName)name.getParent()).getNames();
+ for(int i=0; i<names.length; i++) {
+ if (i != 0) buffer.append("::"); //$NON-NLS-1$
+ buffer.append(names[i].toString());
}
- buffer.append(")"); //$NON-NLS-1$
- } catch (DOMException e) {
- buffer = new StringBuffer();
+ } else {
buffer.append(name.toString());
}
- }
-
+
+ }
+ // if function, get parameters
+ if (binding instanceof IFunction ||
+ (binding instanceof IProblemBinding &&
+ name.getParent() instanceof IASTFunctionDeclarator)) {
+ char[][] parameters = IndexVisitorUtil.getParameters(name);
+ buffer.append("("); //$NON-NLS-1$
+ for (int i = 0; i < parameters.length; i++) {
+ if (i != 0) {
+ buffer.append(", "); //$NON-NLS-1$
+ }
+ buffer.append(parameters[i]);
+ }
+ buffer.append(")"); //$NON-NLS-1$
+ }
+
return buffer.toString();
}
}

Back to the top