Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Niefer2004-05-26 14:24:15 -0400
committerAndrew Niefer2004-05-26 14:24:15 -0400
commite2aba75dbbabe4882dc32d4d1fc217c2532d86a1 (patch)
tree3f41fac7e73e499836886687077190ebd1b5c47d
parentbea9188980f06bff33723999a3fc8e6c7653fc75 (diff)
downloadorg.eclipse.cdt-e2aba75dbbabe4882dc32d4d1fc217c2532d86a1.tar.gz
org.eclipse.cdt-e2aba75dbbabe4882dc32d4d1fc217c2532d86a1.tar.xz
org.eclipse.cdt-e2aba75dbbabe4882dc32d4d1fc217c2532d86a1.zip
- Move cdt.internal.core.parser.util.ASTUtil to cdt.core.parser.ast
- Modify search to use ASTUtil for building function parameter strings - Modify selection search to use parameter info in search (bug 63966)
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java2
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTUtil.java (renamed from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/util/ASTUtil.java)14
-rw-r--r--core/org.eclipse.cdt.core/search/ChangeLog4
-rw-r--r--core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/BasicSearchResultCollector.java63
-rw-r--r--core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java77
-rw-r--r--core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MethodDeclarationPattern.java22
-rw-r--r--core/org.eclipse.cdt.ui/ChangeLog5
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindAction.java33
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CompletionEngine.java2
9 files changed, 71 insertions, 151 deletions
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java
index e3722815c2..a607bfd728 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java
@@ -37,6 +37,7 @@ import org.eclipse.cdt.core.parser.ParserUtil;
import org.eclipse.cdt.core.parser.ScannerInfo;
import org.eclipse.cdt.core.parser.ast.ASTClassKind;
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
+import org.eclipse.cdt.core.parser.ast.ASTUtil;
import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier;
@@ -63,7 +64,6 @@ import org.eclipse.cdt.core.parser.ast.IASTVariable;
import org.eclipse.cdt.internal.core.parser.ParserException;
import org.eclipse.cdt.internal.core.parser.QuickParseCallback;
import org.eclipse.cdt.internal.core.parser.StructuralParseCallback;
-import org.eclipse.cdt.internal.core.parser.util.ASTUtil;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/util/ASTUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTUtil.java
index 17916a9614..158658afad 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/util/ASTUtil.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTUtil.java
@@ -8,24 +8,12 @@
* Contributors:
* Rational Software - initial implementation
******************************************************************************/
-package org.eclipse.cdt.internal.core.parser.util;
+package org.eclipse.cdt.core.parser.ast;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import org.eclipse.cdt.core.parser.ast.ASTClassKind;
-import org.eclipse.cdt.core.parser.ast.ASTPointerOperator;
-import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration;
-import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier;
-import org.eclipse.cdt.core.parser.ast.IASTExpression;
-import org.eclipse.cdt.core.parser.ast.IASTFunction;
-import org.eclipse.cdt.core.parser.ast.IASTInitializerClause;
-import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration;
-import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier;
-import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
-import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter;
-import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
/**
* This is a utility class to help convert AST elements to Strings.
diff --git a/core/org.eclipse.cdt.core/search/ChangeLog b/core/org.eclipse.cdt.core/search/ChangeLog
index f3d725a490..cf63825bf2 100644
--- a/core/org.eclipse.cdt.core/search/ChangeLog
+++ b/core/org.eclipse.cdt.core/search/ChangeLog
@@ -1,3 +1,7 @@
+2004-05-26 Andrew Niefer
+ Modified search to use ASTUtil.getFunctionParameterTypes to get the strings to search for
+ functions with specific parameters.
+
2004-05-21 Andrw Niefer
fix bug 63478
diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/BasicSearchResultCollector.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/BasicSearchResultCollector.java
index 1f981591b1..ef7417fe31 100644
--- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/BasicSearchResultCollector.java
+++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/BasicSearchResultCollector.java
@@ -14,14 +14,13 @@
package org.eclipse.cdt.core.search;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.Set;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.core.parser.ast.ASTClassKind;
-import org.eclipse.cdt.core.parser.ast.ASTPointerOperator;
+import org.eclipse.cdt.core.parser.ast.ASTUtil;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier;
@@ -33,14 +32,10 @@ import org.eclipse.cdt.core.parser.ast.IASTMethod;
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
import org.eclipse.cdt.core.parser.ast.IASTOffsetableElement;
import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement;
-import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement;
import org.eclipse.cdt.core.parser.ast.IASTReference;
-import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier;
-import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTVariable;
-import org.eclipse.cdt.internal.core.parser.util.ASTUtil;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
@@ -144,57 +139,15 @@ public class BasicSearchResultCollector implements ICSearchResultCollector {
return ""; //$NON-NLS-1$
String paramString = "("; //$NON-NLS-1$
-
- Iterator iter = function.getParameters();
- boolean first = true;
- while( iter.hasNext() ){
- IASTParameterDeclaration param = (IASTParameterDeclaration) iter.next();
-
- if( !first ) paramString += ", "; //$NON-NLS-1$
-
- IASTTypeSpecifier typeSpec = param.getTypeSpecifier();
- if( param.isConst() )
- paramString += "const "; //$NON-NLS-1$
-
- if( typeSpec instanceof IASTSimpleTypeSpecifier ){
- paramString += ((IASTSimpleTypeSpecifier)typeSpec).getTypename();
- } else if( typeSpec instanceof IASTOffsetableNamedElement ){
- paramString += ((IASTOffsetableNamedElement)typeSpec).getName();
- } else if( typeSpec instanceof IASTElaboratedTypeSpecifier ){
- ASTClassKind kind = ((IASTElaboratedTypeSpecifier)typeSpec).getClassKind();
- if( kind == ASTClassKind.CLASS ){
- paramString += "class "; //$NON-NLS-1$
- } else if( kind == ASTClassKind.STRUCT ){
- paramString += "struct "; //$NON-NLS-1$
- } else if( kind == ASTClassKind.ENUM ){
- paramString += "enum "; //$NON-NLS-1$
- } else if( kind == ASTClassKind.UNION ){
- paramString += "union "; //$NON-NLS-1$
- }
- paramString += ((IASTElaboratedTypeSpecifier)typeSpec).getName();
- }
-
- Iterator ptrs = param.getPointerOperators();
- if( ptrs.hasNext() ) paramString += " "; //$NON-NLS-1$
-
- while( ptrs.hasNext() ){
- ASTPointerOperator ptr = (ASTPointerOperator)ptrs.next();
- if( ptr == ASTPointerOperator.POINTER )
- paramString += "*"; //$NON-NLS-1$
- else if( ptr == ASTPointerOperator.REFERENCE )
- paramString += "&"; //$NON-NLS-1$
- else if( ptr == ASTPointerOperator.CONST_POINTER )
- paramString += " const * "; //$NON-NLS-1$
- else if( ptr == ASTPointerOperator.VOLATILE_POINTER )
- paramString += " volatile * "; //$NON-NLS-1$
-
- ptr = ASTPointerOperator.POINTER;
- }
-
- first = false;
- }
+ String [] paramTypes = ASTUtil.getFunctionParameterTypes( function );
+ for( int i = 0; i < paramTypes.length; i++ ){
+ if( i != 0 )
+ paramString += ", ";
+ paramString += paramTypes[i];
+ }
+
paramString += ")"; //$NON-NLS-1$
return paramString;
}
diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java
index 2b10908c47..e204ada50f 100644
--- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java
+++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java
@@ -37,6 +37,7 @@ import org.eclipse.cdt.core.parser.ScannerInfo;
import org.eclipse.cdt.core.parser.ast.ASTClassKind;
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
import org.eclipse.cdt.core.parser.ast.ASTPointerOperator;
+import org.eclipse.cdt.core.parser.ast.ASTUtil;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
@@ -511,81 +512,21 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
IASTFunction function = (IASTFunction) decl;
- Iterator parameters = function.getParameters();
- char [] param = null;
- while( parameters.hasNext() ){
- param = getParamString( (IASTParameterDeclaration)parameters.next() );
- list.add( param );
- }
-
- if (param == null){
+ String [] paramTypes = ASTUtil.getFunctionParameterTypes(function);
+ if( paramTypes.length == 0 )
+ {
//This means that no params have been added (i.e. empty brackets - void case)
- param = "void ".toCharArray(); //$NON-NLS-1$
- list.add (param);
+ list.add ("void".toCharArray() ); //$NON-NLS-1$
+ } else {
+ for( int i = 0; i < paramTypes.length; i++ ){
+ list.add( paramTypes[i].toCharArray() );
+ }
}
}
return list;
}
- static public char [] getParamString( IASTParameterDeclaration param ){
- if( param == null ) return null;
-
- String signature = ""; //$NON-NLS-1$
-
- IASTTypeSpecifier typeSpec = param.getTypeSpecifier();
- if( typeSpec instanceof IASTSimpleTypeSpecifier ){
- IASTSimpleTypeSpecifier simple = (IASTSimpleTypeSpecifier)typeSpec;
- signature += simple.getTypename();
- } else if( typeSpec instanceof IASTElaboratedTypeSpecifier ){
- IASTElaboratedTypeSpecifier elaborated = (IASTElaboratedTypeSpecifier)typeSpec;
- if( elaborated.getClassKind() == ASTClassKind.CLASS ){
- signature += "class "; //$NON-NLS-1$
- } else if( elaborated.getClassKind() == ASTClassKind.ENUM ) {
- signature += "enum "; //$NON-NLS-1$
- } else if( elaborated.getClassKind() == ASTClassKind.STRUCT ) {
- signature += "struct "; //$NON-NLS-1$
- } else if( elaborated.getClassKind() == ASTClassKind.UNION ) {
- signature += "union"; //$NON-NLS-1$
- }
-
- signature += elaborated.getName();
- } else if( typeSpec instanceof IASTClassSpecifier ){
- IASTClassSpecifier classSpec = (IASTClassSpecifier)typeSpec;
- signature += classSpec.getName();
- } else if( typeSpec instanceof IASTEnumerationSpecifier ){
- IASTEnumerationSpecifier enumSpec = (IASTEnumerationSpecifier)typeSpec;
- signature += enumSpec.getName();
- }
-
- signature += " "; //$NON-NLS-1$
-
- if( param.isConst() ) signature += "const "; //$NON-NLS-1$
- if( param.isVolatile() ) signature += "volatile "; //$NON-NLS-1$
-
- Iterator ptrs = param.getPointerOperators();
- while( ptrs.hasNext() ){
- ASTPointerOperator ptrOp = (ASTPointerOperator) ptrs.next();
- if( ptrOp == ASTPointerOperator.POINTER ){
- signature += " * "; //$NON-NLS-1$
- } else if( ptrOp == ASTPointerOperator.REFERENCE ){
- signature += " & "; //$NON-NLS-1$
- } else if( ptrOp == ASTPointerOperator.CONST_POINTER ){
- signature += " const * "; //$NON-NLS-1$
- } else if( ptrOp == ASTPointerOperator.VOLATILE_POINTER ){
- signature += " volatile * "; //$NON-NLS-1$
- }
- }
-
- Iterator arrayModifiers = param.getArrayModifiers();
- while( arrayModifiers.hasNext() ){
- arrayModifiers.next();
- signature += " [] "; //$NON-NLS-1$
- }
-
- return signature.toCharArray();
- }
-
static private LinkedList scanForNames( IScanner scanner, IToken unusedToken ){
LinkedList list = new LinkedList();
diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MethodDeclarationPattern.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MethodDeclarationPattern.java
index e75ce85412..a464fa7e54 100644
--- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MethodDeclarationPattern.java
+++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MethodDeclarationPattern.java
@@ -17,6 +17,7 @@ import java.io.IOException;
import java.util.Iterator;
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
+import org.eclipse.cdt.core.parser.ast.ASTUtil;
import org.eclipse.cdt.core.parser.ast.IASTFunction;
import org.eclipse.cdt.core.parser.ast.IASTMethod;
import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration;
@@ -99,32 +100,29 @@ public class MethodDeclarationPattern extends CSearchPattern {
//parameters
if( parameterNames != null && parameterNames.length > 0 && parameterNames[0].length > 0 ){
-
- Iterator params = function.getParameters();
-
- if (!params.hasNext() && CharOperation.equals(parameterNames[0], "void ".toCharArray())){ //$NON-NLS-1$
- //All empty lists have transformed to void, this function has no parms
+ String [] paramTypes = ASTUtil.getFunctionParameterTypes(function);
+
+ if ( paramTypes.length == 0 && CharOperation.equals(parameterNames[0], "void".toCharArray())){ //$NON-NLS-1$
+ //All empty lists have transformed to void, this function has no parms
return ACCURATE_MATCH;
}
+ if( parameterNames.length != paramTypes.length )
+ return IMPOSSIBLE_MATCH;
+
for( int i = 0; i < parameterNames.length; i++ ){
//if this function doesn't have this many parameters, it is not a match.
//or if this function has a parameter, but parameterNames only has null.
- if( !params.hasNext() || parameterNames[ i ] == null )
+ if( parameterNames[ i ] == null )
return IMPOSSIBLE_MATCH;
- IASTParameterDeclaration parameter = (IASTParameterDeclaration) params.next();
- char[] param = CSearchPattern.getParamString( parameter );
+ char[] param = paramTypes[ i ].toCharArray();
//no wildcards in parameters strings
if( !CharOperation.equals( parameterNames[i], param, _caseSensitive ) )
return IMPOSSIBLE_MATCH;
}
-
- //if this function still has more parameters, it is not a match
- if( params.hasNext() )
- return IMPOSSIBLE_MATCH;
}
return ACCURATE_MATCH;
diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog
index 798c1b0465..351e3cb10e 100644
--- a/core/org.eclipse.cdt.ui/ChangeLog
+++ b/core/org.eclipse.cdt.ui/ChangeLog
@@ -1,3 +1,8 @@
+2004-05-26 Andrew Niefer
+ Selection search: if searching on a function, use ASTUtil.getFunctionParameterTypes to create a
+ search pattern to find functions with the same parameters. Also, for AST nodes that have a
+ qualified name, use that to search. (bug 63966)
+
2004-05-26 Alain Magloire
CUIPlugin.startup() cleanup. The method
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindAction.java
index 464737ffd2..b05626535f 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindAction.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindAction.java
@@ -34,8 +34,11 @@ import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ParserUtil;
import org.eclipse.cdt.core.parser.ScannerInfo;
+import org.eclipse.cdt.core.parser.ast.ASTUtil;
+import org.eclipse.cdt.core.parser.ast.IASTFunction;
import org.eclipse.cdt.core.parser.ast.IASTNode;
import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement;
+import org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.ICSearchConstants.LimitTo;
import org.eclipse.cdt.core.search.ICSearchConstants.SearchFor;
@@ -140,6 +143,34 @@ public abstract class FindAction extends Action {
}
+ protected CSearchQuery createSearchQuery( IASTOffsetableNamedElement node ){
+ String pattern = null;
+
+ if( node instanceof IASTQualifiedNameElement ){
+ String [] qualNames = ((IASTQualifiedNameElement)node).getFullyQualifiedName();
+ pattern = "::" + qualNames[0]; //$NON-NLS-1$
+ for( int i = 1; i < qualNames.length; i++ ){
+ pattern += "::"; //$NON-NLS-1$
+ pattern += qualNames[i];
+ }
+ } else {
+ pattern = node.getName();
+ }
+
+ if( node instanceof IASTFunction ){
+ pattern += '(';
+ String[] parameterTypes = ASTUtil.getFunctionParameterTypes((IASTFunction) node);
+ for( int i = 0; i < parameterTypes.length; i++ ){
+ if( i != 0 )
+ pattern += ", "; //$NON-NLS-1$
+ pattern += parameterTypes[i];
+ }
+ pattern += ')';
+ }
+
+ return createSearchQuery( pattern, CSearchUtil.getSearchForFromNode(node) );
+ }
+
protected ISelection getSelection(){
ISelection sel = null;
if (fSite != null){
@@ -205,7 +236,7 @@ public abstract class FindAction extends Action {
return;
}
- CSearchQuery job = createSearchQuery(selectedText.getText(), CSearchUtil.getSearchForFromNode(node));
+ CSearchQuery job = createSearchQuery(node);
NewSearchUI.activateSearchResultView();
NewSearchUI.runQuery(job);
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CompletionEngine.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CompletionEngine.java
index bdeae2cc62..3d4b25560f 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CompletionEngine.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CompletionEngine.java
@@ -39,6 +39,7 @@ import org.eclipse.cdt.core.parser.ParserUtil;
import org.eclipse.cdt.core.parser.ScannerInfo;
import org.eclipse.cdt.core.parser.ast.ASTClassKind;
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
+import org.eclipse.cdt.core.parser.ast.ASTUtil;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTCodeScope;
import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
@@ -60,7 +61,6 @@ import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
import org.eclipse.cdt.core.parser.ast.IASTNode.ILookupResult;
import org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind;
import org.eclipse.cdt.internal.core.CharOperation;
-import org.eclipse.cdt.internal.core.parser.util.ASTUtil;
import org.eclipse.cdt.internal.ui.CUIMessages;
import org.eclipse.cdt.internal.ui.util.IDebugLogConstants;
import org.eclipse.cdt.internal.ui.util.Util;

Back to the top