Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVladimir Hirsl2005-06-16 15:55:34 -0400
committerVladimir Hirsl2005-06-16 15:55:34 -0400
commit51203a09e78bc926c258c0791db24d3ff13a4f16 (patch)
tree82bcaebe419f41afd2da58f1701b0a2c2a115499
parent652898366bda10dbd4f0631a884ad4aee5ca2b16 (diff)
downloadorg.eclipse.cdt-51203a09e78bc926c258c0791db24d3ff13a4f16.tar.gz
org.eclipse.cdt-51203a09e78bc926c258c0791db24d3ff13a4f16.tar.xz
org.eclipse.cdt-51203a09e78bc926c258c0791db24d3ff13a4f16.zip
Fix for PR 99433: [Search] Return parms not part of qualification matching. Function/methos parameters are now used as a part of search pattern.
-rw-r--r--core/org.eclipse.cdt.core.tests/ChangeLog9
-rw-r--r--core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/DOMSourceIndexerTests.java2
-rw-r--r--core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/DependencyTests.java6
-rw-r--r--core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/SearchRegressionTests.java37
-rw-r--r--core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/FunctionMethodPatternTests.java19
-rw-r--r--core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/SearchTestSuite.java2
-rw-r--r--core/org.eclipse.cdt.core/ChangeLog16
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/ctagsindexer/CTagEntry.java6
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/CGenerateIndexVisitor.java2
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/CPPGenerateIndexVisitor.java4
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/IndexEncoderUtil.java4
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/IndexVisitorUtil.java36
-rw-r--r--core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/BasicSearchMatch.java13
-rw-r--r--core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/DOMSearchUtil.java42
-rw-r--r--core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java603
-rw-r--r--core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MethodDeclarationPattern.java52
16 files changed, 437 insertions, 416 deletions
diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog
index cbff95fad6..a384c5f762 100644
--- a/core/org.eclipse.cdt.core.tests/ChangeLog
+++ b/core/org.eclipse.cdt.core.tests/ChangeLog
@@ -1,3 +1,12 @@
+2005-06-16 Vladimir Hirsl
+ Updated search related tests to reflect function parameters in search pattern.
+
+ * indexer/org/eclipse/cdt/core/indexer/tests/DependencyTests.java
+ * indexer/org/eclipse/cdt/core/indexer/tests/DOMSourceIndexerTests.java
+ * regression/org/eclipse/cdt/core/tests/SearchRegressionTests.java
+ * search/org/eclipse/cdt/core/search/tests/FunctionMethodPatternTests.java
+ * search/org/eclipse/cdt/core/search/tests/SearchTestSuite.java
+
2005-06-08 Alain Magloire
Remove the ResolverModelTest
- misc/org/eclipse/cdt/core/filetype/tests/ResolverTeste.java
diff --git a/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/DOMSourceIndexerTests.java b/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/DOMSourceIndexerTests.java
index 5aa8e0607f..955529be0f 100644
--- a/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/DOMSourceIndexerTests.java
+++ b/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/DOMSourceIndexerTests.java
@@ -176,7 +176,7 @@ public class DOMSourceIndexerTests extends TestCase implements IIndexChangeListe
suite.addTest(new FailingTest(new DOMSourceIndexerTests("testIndexContents"))); //$NON-NLS-1$
suite.addTest(new DOMSourceIndexerTests("testMacros")); //$NON-NLS-1$
suite.addTest(new FailingTest(new DOMSourceIndexerTests("testRefs"))); //$NON-NLS-1$
- suite.addTest(new FailingTest(new DOMSourceIndexerTests("testExactDeclarations"))); //$NON-NLS-1$
+ suite.addTest(new DOMSourceIndexerTests("testExactDeclarations")); //$NON-NLS-1$
suite.addTest(new FailingTest(new DOMSourceIndexerTests("testRemoveFileFromIndex"))); //$NON-NLS-1$
suite.addTest(new DOMSourceIndexerTests("testRemoveProjectFromIndex")); //$NON-NLS-1$
suite.addTest(new DOMSourceIndexerTests("testIndexShutdown")); //$NON-NLS-1$
diff --git a/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/DependencyTests.java b/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/DependencyTests.java
index 760690eac8..57afb7a832 100644
--- a/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/DependencyTests.java
+++ b/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/DependencyTests.java
@@ -82,9 +82,9 @@ import org.eclipse.core.runtime.Platform;
//suite.addTest(new DependencyTests("testDepTable"));
suite.addTest(new DependencyTests("testDepSourceChangeTree"));
suite.addTest(new DependencyTests("testDepHeaderChangeTree"));
- suite.addTest(new FailingTest(new DependencyTests("testDepHeaderChangeReindex")));
- suite.addTest(new FailingTest(new DependencyTests("testDepSourceChangeTable")));
- suite.addTest(new FailingTest(new DependencyTests("testDepHeaderChangeTable")));
+ suite.addTest(new DependencyTests("testDepHeaderChangeReindex"));
+ suite.addTest(new DependencyTests("testDepSourceChangeTable"));
+ suite.addTest(new DependencyTests("testDepHeaderChangeTable"));
suite.addTest(new DependencyTests("testUpdateDependancyNPE"));
return suite;
}
diff --git a/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/SearchRegressionTests.java b/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/SearchRegressionTests.java
index 217894bef1..e19adf2c29 100644
--- a/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/SearchRegressionTests.java
+++ b/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/SearchRegressionTests.java
@@ -122,6 +122,7 @@ public class SearchRegressionTests extends BaseTestFramework implements ICSearch
protected Set search( ICSearchPattern pattern ) {
try {
+ resultCollector.aboutToStart();
searchEngine.search( workspace, pattern, scope, resultCollector, false );
} catch (InterruptedException e) {
//boo
@@ -198,29 +199,28 @@ public class SearchRegressionTests extends BaseTestFramework implements ICSearch
suite.addTest( new SearchRegressionTests("testClassStructDeclaration") ); //$NON-NLS-1$
suite.addTest( new SearchRegressionTests("testClassStructReference") ); //$NON-NLS-1$
- //Fix up for DOM Indexer
- suite.addTest( new FailingTest(new SearchRegressionTests("testNamespaceDeclaration"))); //$NON-NLS-1$
- //Fix up for DOM Indexer
- suite.addTest( new FailingTest(new SearchRegressionTests("testNamespaceDefinition"))); //$NON-NLS-1$
+ suite.addTest(new SearchRegressionTests("testNamespaceDeclaration")); //$NON-NLS-1$
+ suite.addTest( new SearchRegressionTests("testNamespaceDefinition")); //$NON-NLS-1$
suite.addTest( new SearchRegressionTests("testNamespaceReference")); //$NON-NLS-1$
suite.addTest( new SearchRegressionTests("testMethodDeclaration")); //$NON-NLS-1$
- //Fix up for DOM Indexer
- suite.addTest( new FailingTest(new SearchRegressionTests("testMethodDefinition"))); //$NON-NLS-1$
+ suite.addTest(new SearchRegressionTests("testMethodDefinition")); //$NON-NLS-1$
suite.addTest( new SearchRegressionTests("testMethodReference") ); //$NON-NLS-1$
suite.addTest( new SearchRegressionTests("testMethodReferenceOperator") ); //$NON-NLS-1$
suite.addTest( new FailingTest( new SearchRegressionTests("testMethodReferenceImplicitOperator"), 80117 ) ); //defect80117 //$NON-NLS-1$
- suite.addTest(new SearchRegressionTests("testMethodReferenceInitializer")); //$NON-NLS-1$
- suite.addTest(new SearchRegressionTests("testMethodReferenceInline")); //$NON-NLS-1$
- suite.addTest( new SearchRegressionTests("testMethodReferenceWithCctor") ); //$NON-NLS-1$
- suite.addTest( new SearchRegressionTests("testConstructorReferenceArg")); //$NON-NLS-1$
- suite.addTest(new SearchRegressionTests("testConstructorReferenceAlone")); //$NON-NLS-1$
+ suite.addTest(new SearchRegressionTests("testMethodReferenceInitializer")); //defect76169 //$NON-NLS-1$
+ //fails because inline def refers to a member not declared yet
+ suite.addTest(new SearchRegressionTests("testMethodReferenceInline")); //defect79425//$NON-NLS-1$
+ //method call with constructor call not found
+ suite.addTest( new SearchRegressionTests("testMethodReferenceWithCctor") ); //defect79789//$NON-NLS-1$
+ //constructor call in function argument not found
+ suite.addTest( new SearchRegressionTests("testConstructorReferenceArg")); //defect79785 //$NON-NLS-1$
+ //constructor call by itself not found
+ suite.addTest(new SearchRegressionTests("testConstructorReferenceAlone")); //defect79792 //$NON-NLS-1$
suite.addTest( new SearchRegressionTests("testDestructorReference") ); //defect79792 //$NON-NLS-1$
- //Fixup for DOM Indexer
- suite.addTest( new FailingTest(new SearchRegressionTests("testFunctionDeclaration"))); //$NON-NLS-1$
- //Fixup for DOM Indexer
- suite.addTest( new FailingTest(new SearchRegressionTests("testFunctionDefinition"))); //$NON-NLS-1$
+ suite.addTest(new SearchRegressionTests("testFunctionDeclaration")); //$NON-NLS-1$
+ suite.addTest( new SearchRegressionTests("testFunctionDefinition")); //$NON-NLS-1$
suite.addTest( new SearchRegressionTests("testFunctionReference") ); //$NON-NLS-1$
suite.addTest( new SearchRegressionTests("testFieldDeclaration") ); //$NON-NLS-1$
@@ -245,7 +245,7 @@ public class SearchRegressionTests extends BaseTestFramework implements ICSearch
suite.addTest( new FailingTest(new SearchRegressionTests("testUnionReference"))); //$NON-NLS-1$
suite.addTest( new FailingTest(new SearchRegressionTests("testEnumerationDeclaration"))); //$NON-NLS-1$
- suite.addTest( new FailingTest(new SearchRegressionTests("testEnumerationReference"))); //$NON-NLS-1$
+ suite.addTest(new SearchRegressionTests("testEnumerationReference")); //$NON-NLS-1$
//search doesn't distinguish between global and local symbols
suite.addTest( new FailingTest( new SearchRegressionTests("testEnumerationReferenceGlobal"), 79811 ) ); //defect79811 //$NON-NLS-1$
@@ -541,7 +541,7 @@ public class SearchRegressionTests extends BaseTestFramework implements ICSearch
public void testMethodDefinition() throws Exception {
Writer writer = new StringWriter();
writer.write("class N { \n" ); //$NON-NLS-1$
- writer.write(" N& operator ||(const N &rhs){} \n" ); //$NON-NLS-1$
+ writer.write(" N& operator ||(const N &rhs){return *this;}\n" ); //$NON-NLS-1$
writer.write(" N& operator|(const N &rhs); \n" ); //$NON-NLS-1$
writer.write(" int m; \n" ); //$NON-NLS-1$
writer.write("}; \n" ); //$NON-NLS-1$
@@ -575,7 +575,8 @@ public class SearchRegressionTests extends BaseTestFramework implements ICSearch
String code = writer.toString();
IFile cpp = importFile( "MethodDefinition.cpp", code ); //$NON-NLS-1$
//vp1 operator, constructor, destructor, inline, static, const, explicit constructor
- ICElement[] list = {cproject.findElement(new Path("MethodDefinition.cpp"))}; //$NON-NLS-1$
+ ICElement[] list = new ICElement[1];//{cproject.findElement(new Path("MethodDefinition.cpp"))}; //$NON-NLS-1$
+ list[0] = cproject;
ICSearchPattern pattern=SearchEngine.createSearchPattern("*", METHOD, DEFINITIONS, true); //$NON-NLS-1$
Set matches = search(pattern, list);
assertMatch( matches, cpp, code.indexOf( "operator|/*def1*/" ) ); //$NON-NLS-1$
diff --git a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/FunctionMethodPatternTests.java b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/FunctionMethodPatternTests.java
index 3a61117a57..80a3ea89af 100644
--- a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/FunctionMethodPatternTests.java
+++ b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/FunctionMethodPatternTests.java
@@ -114,7 +114,7 @@ public class FunctionMethodPatternTests extends BaseSearchTest {
Set matches = resultCollector.getSearchResults();
assertEquals( 2, matches.size());
- pattern = SearchEngine.createSearchPattern( "turn(void)", METHOD, DECLARATIONS, true ); //$NON-NLS-1$
+ pattern = SearchEngine.createSearchPattern( "turn(void)", METHOD, DECLARATIONS_DEFINITIONS, true ); //$NON-NLS-1$
search( workspace, pattern, scope, resultCollector );
matches = resultCollector.getSearchResults();
@@ -129,7 +129,7 @@ public class FunctionMethodPatternTests extends BaseSearchTest {
}
public void testOperators_bug43063_bug42979(){
- ICSearchPattern pattern = SearchEngine.createSearchPattern( "operator \\*", METHOD, DECLARATIONS, true ); //$NON-NLS-1$
+ ICSearchPattern pattern = SearchEngine.createSearchPattern( "operator \\*", METHOD, DECLARATIONS_DEFINITIONS, true ); //$NON-NLS-1$
search( workspace, pattern, scope, resultCollector );
Set matches = resultCollector.getSearchResults();
@@ -158,10 +158,15 @@ public class FunctionMethodPatternTests extends BaseSearchTest {
assertTrue( ((IOffsetLocatable)match1.getLocatable()).getNameStartOffset() != ((IOffsetLocatable)match2.getLocatable()).getNameStartOffset() );
- pattern = SearchEngine.createSearchPattern( "operator *", METHOD, DECLARATIONS, true ); //$NON-NLS-1$
+ pattern = SearchEngine.createSearchPattern( "operator *", METHOD, DECLARATIONS, true ); //$NON-NLS-1$
+ search( workspace, pattern, scope, resultCollector );
+ matches = resultCollector.getSearchResults();
+ assertEquals( matches.size(), 5 );
+
+ pattern = SearchEngine.createSearchPattern( "operator *", METHOD, DECLARATIONS_DEFINITIONS, true ); //$NON-NLS-1$
search( workspace, pattern, scope, resultCollector );
matches = resultCollector.getSearchResults();
- assertEquals( matches.size(), 6 ); //3 in classDecl.cpp
+ assertEquals( matches.size(), 8 ); //2 in classDecl.cpp
pattern = SearchEngine.createSearchPattern( "operator ->\\*", METHOD, DECLARATIONS, true ); //$NON-NLS-1$
assertTrue( pattern instanceof MethodDeclarationPattern );
@@ -214,13 +219,13 @@ public class FunctionMethodPatternTests extends BaseSearchTest {
}
public void testConstructorDestructor(){
- ICSearchPattern pattern = SearchEngine.createSearchPattern( "A", METHOD, DECLARATIONS, true ); //$NON-NLS-1$
+ ICSearchPattern pattern = SearchEngine.createSearchPattern( "A", METHOD, DECLARATIONS_DEFINITIONS, true ); //$NON-NLS-1$
search( workspace, pattern, scope, resultCollector );
Set matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 1 );
- pattern = SearchEngine.createSearchPattern( "~A", METHOD, DECLARATIONS, true ); //$NON-NLS-1$
+ pattern = SearchEngine.createSearchPattern( "~A", METHOD, DECLARATIONS_DEFINITIONS, true ); //$NON-NLS-1$
search( workspace, pattern, scope, resultCollector );
matches = resultCollector.getSearchResults();
@@ -228,7 +233,7 @@ public class FunctionMethodPatternTests extends BaseSearchTest {
}
public void testLookupForDefinition(){
- ICSearchPattern pattern = SearchEngine.createSearchPattern( "turn", METHOD, DECLARATIONS, true ); //$NON-NLS-1$
+ ICSearchPattern pattern = SearchEngine.createSearchPattern( "turn", METHOD, DECLARATIONS_DEFINITIONS, true ); //$NON-NLS-1$
search( workspace, pattern, scope, resultCollector );
Set matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 3 );
diff --git a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/SearchTestSuite.java b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/SearchTestSuite.java
index 5abb3766fd..bcb00fa223 100644
--- a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/SearchTestSuite.java
+++ b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/SearchTestSuite.java
@@ -26,7 +26,7 @@ public class SearchTestSuite extends TestCase {
TestSuite suite= new TestSuite(SearchTestSuite.class.getName());
suite.addTestSuite(ClassDeclarationPatternTests.class);
- //suite.addTestSuite(FunctionMethodPatternTests.class);
+ suite.addTestSuite(FunctionMethodPatternTests.class);
suite.addTestSuite(OtherPatternTests.class);
suite.addTestSuite(ParseTestOnSearchFiles.class);
return suite;
diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog
index 494e2c118c..81e36218f4 100644
--- a/core/org.eclipse.cdt.core/ChangeLog
+++ b/core/org.eclipse.cdt.core/ChangeLog
@@ -1,3 +1,19 @@
+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.
+ Note: return parameters are NOT used as a part of search pattern. The PR title
+ is somewhat missleading.
+
+ * index/org/eclipse/cdt/internal/core/index/ctagsindexer/CTagEntry.java
+ * index/org/eclipse/cdt/internal/core/index/domsourceindexer/CGenerateIndexVisitor.java
+ * index/org/eclipse/cdt/internal/core/index/domsourceindexer/CPPGenerateIndexVisitor.java
+ * index/org/eclipse/cdt/internal/core/index/domsourceindexer/IndexEncoderUtil.java
+ * index/org/eclipse/cdt/internal/core/index/domsourceindexer/IndexVisitorUtil.java
+ * search/org/eclipse/cdt/core/search/BasicSearchMatch.java
+ * search/org/eclipse/cdt/core/search/DOMSearchUtil.java
+ * search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java
+ * search/org/eclipse/cdt/internal/core/search/matching/MethodDeclarationPattern.java
+
2005-06-14 David Inglis
Support for older cygpaths - bug # 94702
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/ctagsindexer/CTagEntry.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/ctagsindexer/CTagEntry.java
index f9f7e7e927..f720266b66 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/ctagsindexer/CTagEntry.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/ctagsindexer/CTagEntry.java
@@ -216,11 +216,7 @@ class CTagEntry{
private char[][] getFunctionSignature() {
String signature = (String) tagExtensionField.get(CTagsConsoleParser.SIGNATURE);
- LinkedList list = CSearchPattern.scanForParameters(signature);
- char [][] parameters = new char [0][];
- parameters = (char[][])list.toArray( parameters );
-
- return parameters;
+ return CSearchPattern.scanForParameters(signature);
}
private int getModifiers() {
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/CGenerateIndexVisitor.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/CGenerateIndexVisitor.java
index d458ca5963..042275d453 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/CGenerateIndexVisitor.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/CGenerateIndexVisitor.java
@@ -244,7 +244,7 @@ public class CGenerateIndexVisitor extends CASTVisitor {
}
FunctionEntry indexEntry = new FunctionEntry(IIndex.FUNCTION, entryKind, qualifiedName, modifiers, fileNumber);
indexEntry.setNameOffset(fileLoc.getNodeOffset(), fileLoc.getNodeLength(), IIndex.OFFSET);
- indexEntry.setSignature(IndexVisitorUtil.getParameters((IFunction) binding));
+ indexEntry.setSignature(IndexVisitorUtil.getParameters(name));
indexEntry.setReturnType(IndexVisitorUtil.getReturnType((IFunction) binding));
indexEntry.serialize(indexer.getOutput());
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/CPPGenerateIndexVisitor.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/CPPGenerateIndexVisitor.java
index c6d7592f3b..32c543d863 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/CPPGenerateIndexVisitor.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/CPPGenerateIndexVisitor.java
@@ -297,7 +297,7 @@ public class CPPGenerateIndexVisitor extends CPPASTVisitor {
}
FunctionEntry indexEntry = new FunctionEntry(IIndex.METHOD, entryKind, qualifiedName, modifiers, fileNumber);
indexEntry.setNameOffset(fileLoc.getNodeOffset(), fileLoc.getNodeLength(), IIndex.OFFSET);
- indexEntry.setSignature(IndexVisitorUtil.getParameters((IFunction) binding));
+ indexEntry.setSignature(IndexVisitorUtil.getParameters(name));
indexEntry.setReturnType(IndexVisitorUtil.getReturnType((IFunction) binding));
serialize(indexEntry);
@@ -313,7 +313,7 @@ public class CPPGenerateIndexVisitor extends CPPASTVisitor {
}
FunctionEntry indexEntry = new FunctionEntry(IIndex.FUNCTION, entryKind, qualifiedName, modifiers, fileNumber);
indexEntry.setNameOffset(fileLoc.getNodeOffset(), fileLoc.getNodeLength(), IIndex.OFFSET);
- indexEntry.setSignature(IndexVisitorUtil.getParameters((IFunction) binding));
+ indexEntry.setSignature(IndexVisitorUtil.getParameters(name));
indexEntry.setReturnType(IndexVisitorUtil.getReturnType((IFunction) binding));
serialize(indexEntry);
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/IndexEncoderUtil.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/IndexEncoderUtil.java
index fa65a40336..e88966822d 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/IndexEncoderUtil.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/IndexEncoderUtil.java
@@ -39,14 +39,14 @@ public class IndexEncoderUtil {
String filePath = ""; //$NON-NLS-1$
if (tempFile != null){
//File is local to workspace
- filePath = tempFile.getFullPath().toOSString();
+ filePath = tempFile.getFullPath().toString();
}
else {
//File is external to workspace
filePath = fileName;
}
- if (!filePath.equals(indexer.getResourceFile().getFullPath().toOSString())) {
+ if (!filePath.equals(indexer.getResourceFile().getFullPath().toString())) {
//We are not in the file that has triggered the index. Thus, we need to find the
//file number for the current file (if it has one). If the current file does not
//have a file number, we need to add it to the index.
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 115706d1f5..791020685c 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
@@ -10,12 +10,11 @@
***********************************************************************/
package org.eclipse.cdt.internal.core.index.domsourceindexer;
-import java.util.ArrayList;
-import java.util.List;
-
+import org.eclipse.cdt.core.dom.ast.ASTSignatureUtil;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
@@ -180,32 +179,31 @@ public class IndexVisitorUtil {
}
/**
- * @param function
+ * @param functionName
* @return
*/
- static char[][] getParameters(IFunction function) {
- List parameterList = new ArrayList();
- try {
- IFunctionType functionType = function.getType();
- IType[] parameterTypes = functionType.getParameterTypes();
- for (int i = 0; i < parameterTypes.length; i++) {
- IType parameterType = parameterTypes[i];
- parameterList.add(ASTTypeUtil.getType(parameterType).toCharArray());
+ public static char[][] getParameters(IASTName functionName) {
+ IASTNode parent = functionName.getParent();
+ if (parent instanceof IASTDeclarator) {
+ IASTDeclarator declarator = (IASTDeclarator) parent;
+ String[] parameters = ASTSignatureUtil.getParameterSignatureArray(declarator);
+ if (parameters.length == 0) {
+ return new char[][] { "void".toCharArray() }; //$NON-NLS-1$
}
- if (parameterList.isEmpty()) {
- parameterList.add("void".toCharArray()); //$NON-NLS-1$
+ char[][] rv = new char[parameters.length][];
+ for (int k = 0; k < parameters.length; k++) {
+ rv[k] = parameters[k].toCharArray();
}
+ return rv;
}
- catch (DOMException e) {
- }
- return (char[][]) parameterList.toArray(new char[parameterList.size()][]);
+ return new char[0][];
}
-
+
/**
* @param function
* @return
*/
- static char[] getReturnType(IFunction function) {
+ public static char[] getReturnType(IFunction function) {
try {
IFunctionType functionType = function.getType();
IType returnType = functionType.getReturnType();
diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/BasicSearchMatch.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/BasicSearchMatch.java
index b7dc2c287f..8b77fb387e 100644
--- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/BasicSearchMatch.java
+++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/BasicSearchMatch.java
@@ -28,6 +28,7 @@ public class BasicSearchMatch implements IMatch, Comparable {
String parentName = null;
String[] qualifiedName;
+ String[] parameters;
String returnType;
IResource resource = null;
@@ -194,7 +195,11 @@ public class BasicSearchMatch implements IMatch, Comparable {
return parentName;
}
- public String getReturnType() {
+ public String[] getParameters() {
+ return parameters;
+ }
+
+ public String getReturnType() {
return returnType;
}
@@ -266,7 +271,11 @@ public class BasicSearchMatch implements IMatch, Comparable {
parentName = string;
}
- /**
+ public void setParameters(String[] params) {
+ parameters = params;
+ }
+
+ /**
* @param string
*/
public void setReturnType(String string) {
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 8c5d5d2477..fcef59a282 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
@@ -102,49 +102,15 @@ public class DOMSearchUtil {
// build the SearchFor/pattern based on the IBinding
SearchFor searchFor = createSearchFor(binding);
- if (binding instanceof IFunction) {
- searchFor = ICSearchConstants.FUNCTION;
- } else if (binding instanceof ICPPNamespace || binding instanceof ICPPNamespaceAlias) {
- searchFor = ICSearchConstants.NAMESPACE;
- } else if (binding instanceof ICPPField) {
- searchFor = ICSearchConstants.FIELD;
- } else if (binding instanceof IEnumerator) {
- searchFor = ICSearchConstants.ENUMTOR;
- } else if (binding instanceof ICPPMethod) {
- searchFor = ICSearchConstants.METHOD;
- } else if (binding instanceof IMacroBinding) {
- searchFor = ICSearchConstants.MACRO;
- } else if (binding instanceof ITypedef) {
- searchFor = ICSearchConstants.TYPEDEF;
- } else if (binding instanceof IVariable) {
- searchFor = ICSearchConstants.VAR;
- } else if (binding instanceof ICPPClassType) {
- searchFor = ICSearchConstants.CLASS;
- } else if (binding instanceof ICompositeType) {
- try {
- switch(((ICompositeType)binding).getKey()) {
- case ICompositeType.k_struct:
- searchFor = ICSearchConstants.CLASS_STRUCT;
- break;
- case ICompositeType.k_union:
- searchFor = ICSearchConstants.UNION;
- break;
- }
- } catch (DOMException e) {
- searchFor = ICSearchConstants.UNKNOWN_SEARCH_FOR;
- }
- } else if (binding instanceof IEnumeration) {
- searchFor = ICSearchConstants.ENUM;
- } else {
- searchFor = ICSearchConstants.UNKNOWN_SEARCH_FOR;
- }
return CSearchPattern.createPattern(DOMSearchUtil.getSearchPattern(searchName), searchFor, limitTo, ICSearchConstants.EXACT_MATCH, caseSensitive);
}
private static SearchFor createSearchFor( IBinding binding ) {
SearchFor searchFor = null;
- if (binding instanceof IFunction) {
+ if (binding instanceof ICPPMethod) {
+ searchFor = ICSearchConstants.METHOD;
+ } else if (binding instanceof IFunction) {
searchFor = ICSearchConstants.FUNCTION;
} else if (binding instanceof ICPPNamespace || binding instanceof ICPPNamespaceAlias) {
searchFor = ICSearchConstants.NAMESPACE;
@@ -152,8 +118,6 @@ public class DOMSearchUtil {
searchFor = ICSearchConstants.FIELD;
} else if (binding instanceof IEnumerator) {
searchFor = ICSearchConstants.ENUMTOR;
- } else if (binding instanceof ICPPMethod) {
- searchFor = ICSearchConstants.METHOD;
} else if (binding instanceof IMacroBinding) {
searchFor = ICSearchConstants.MACRO;
} else if (binding instanceof ITypedef) {
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 85158166b8..25a33db700 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
@@ -14,16 +14,20 @@
package org.eclipse.cdt.internal.core.search.matching;
import java.io.IOException;
-import java.util.Iterator;
-import java.util.LinkedList;
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.cdt.core.dom.ast.ASTSignatureUtil;
+import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.EndOfFileException;
-import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.IParserLogService;
import org.eclipse.cdt.core.parser.IProblem;
-import org.eclipse.cdt.core.parser.IQuickParseCallback;
import org.eclipse.cdt.core.parser.IScanner;
+import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.NullLogService;
import org.eclipse.cdt.core.parser.NullSourceElementRequestor;
@@ -31,22 +35,29 @@ import org.eclipse.cdt.core.parser.ParserFactory;
import org.eclipse.cdt.core.parser.ParserFactoryError;
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.ASTNotImplementedException;
-import org.eclipse.cdt.core.parser.ast.ASTUtil;
-import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
-import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
-import org.eclipse.cdt.core.parser.ast.IASTFunction;
import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.core.search.ICSearchPattern;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.OrPattern;
import org.eclipse.cdt.internal.core.CharOperation;
+import org.eclipse.cdt.internal.core.dom.parser.ISourceCodeParser;
+import org.eclipse.cdt.internal.core.dom.parser.c.ANSICParserExtensionConfiguration;
+import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser;
+import org.eclipse.cdt.internal.core.dom.parser.c.ICParserExtensionConfiguration;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.ANSICPPParserExtensionConfiguration;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPParserExtensionConfiguration;
import org.eclipse.cdt.internal.core.index.IEntryResult;
import org.eclipse.cdt.internal.core.index.IIndex;
import org.eclipse.cdt.internal.core.index.cindexstorage.io.BlocksIndexInput;
import org.eclipse.cdt.internal.core.index.cindexstorage.io.IndexInput;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner;
+import org.eclipse.cdt.internal.core.parser.scanner2.FileCodeReaderFactory;
+import org.eclipse.cdt.internal.core.parser.scanner2.GCCScannerExtensionConfiguration;
+import org.eclipse.cdt.internal.core.parser.scanner2.GPPScannerExtensionConfiguration;
+import org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration;
import org.eclipse.cdt.internal.core.search.IIndexSearchRequestor;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
@@ -182,28 +193,13 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
return orPattern;
}
- char [] patternArray = patternString.toCharArray();
+ char[][] names = scanForNames( patternString );
- IScanner scanner = null;
- Requestor callback = new Requestor( ParserMode.COMPLETE_PARSE );
- try {
- scanner =
- ParserFactory.createScanner(
- new CodeReader(patternArray),
- new ScannerInfo(),
- ParserMode.QUICK_PARSE,
- ParserLanguage.CPP,
- callback,
- nullLog, null);
- } catch (ParserFactoryError e) {
-
- }
- LinkedList list = scanForNames( scanner, callback, null, patternArray );
-
- char [] name = (char []) list.removeLast();
- char [][] qualifications = new char [0][];
+ char[] name = names[names.length - 1];
+ char[][] qualifications = new char [names.length - 1][];
+ System.arraycopy(names, 0, qualifications, 0, qualifications.length);
- return new NamespaceDeclarationPattern( name, (char[][]) list.toArray( qualifications ), matchMode, limitTo, caseSensitive );
+ return new NamespaceDeclarationPattern( name, qualifications , matchMode, limitTo, caseSensitive );
}
// /**
@@ -261,26 +257,14 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
orPattern.addPattern( createFieldPattern( patternString, searchFor, DEFINITIONS, matchMode, caseSensitive ) );
return orPattern;
}
- char [] patternArray = patternString.toCharArray();
- Requestor callback = new Requestor( ParserMode.COMPLETE_PARSE );
- IScanner scanner=null;
- try {
- scanner =
- ParserFactory.createScanner(
- new CodeReader(patternArray),
- new ScannerInfo(),
- ParserMode.QUICK_PARSE,
- ParserLanguage.CPP,
- callback, nullLog, null);
- } catch (ParserFactoryError e) {
- }
- LinkedList list = scanForNames( scanner, callback, null, patternArray );
+ char[][] names = scanForNames( patternString );
- char [] name = (char []) list.removeLast();
- char [][] qualifications = new char[0][];
+ char[] name = names[names.length - 1];
+ char[][] qualifications = new char[names.length - 1][];
+ System.arraycopy(names, 0, qualifications, 0, qualifications.length);
- return new FieldDeclarationPattern( name, (char[][]) list.toArray( qualifications ), matchMode, searchFor, limitTo, caseSensitive );
+ return new FieldDeclarationPattern( name, qualifications, matchMode, searchFor, limitTo, caseSensitive );
}
/**
@@ -309,34 +293,23 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
int index = patternString.indexOf( '(' );
String paramString = ( index == -1 ) ? "" : patternString.substring( index ); //$NON-NLS-1$
String nameString = ( index == -1 ) ? patternString : patternString.substring( 0, index );
- char [] nameArray = nameString.toCharArray();
- IScanner scanner=null;
- Requestor callback = new Requestor( ParserMode.COMPLETE_PARSE );
- try {
- scanner =
- ParserFactory.createScanner(
- new CodeReader(nameArray),
- new ScannerInfo(),
- ParserMode.QUICK_PARSE,
- ParserLanguage.CPP,
- callback, nullLog, null);
- } catch (ParserFactoryError e) {
- }
- LinkedList names = scanForNames( scanner, callback, null, nameArray );
-
- LinkedList params = scanForParameters( paramString );
+ char[][] names = scanForNames( nameString );
+
+ char[][] parameters = scanForParameters( paramString );
+
+ // TODO implement
+ //LinkedList returnType = scanForReturnType();
- char [] name = (char [])names.removeLast();
- char [][] qualifications = new char[0][];
- qualifications = (char[][])names.toArray( qualifications );
- char [][] parameters = new char [0][];
- parameters = (char[][])params.toArray( parameters );
+ char[] name = names[names.length - 1];
+ char[][] qualifications = new char[names.length - 1][];
+ System.arraycopy(names, 0, qualifications, 0, qualifications.length);
+ char[] returnType = new char[0];
- return new MethodDeclarationPattern( name, qualifications, parameters, matchMode, searchFor, limitTo, caseSensitive );
+ return new MethodDeclarationPattern( name, qualifications, parameters, returnType, matchMode, searchFor, limitTo, caseSensitive );
}
- private static final IParserLogService nullLog = new NullLogService();
+ private static final IParserLogService nullLog = new NullLogService();
/**
* @param patternString
* @param limitTo
@@ -367,269 +340,209 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
orPattern.addPattern( createClassPattern( patternString, STRUCT, limitTo, matchMode, caseSensitive ) );
return orPattern;
}
-
- char [] patternArray = patternString.toCharArray();
-
- IScanner scanner =null;
- Requestor callback = new Requestor( ParserMode.COMPLETE_PARSE );
- try {
- scanner =
- ParserFactory.createScanner(
- new CodeReader(patternArray),
- new ScannerInfo(),
- ParserMode.QUICK_PARSE,
- ParserLanguage.CPP,
- callback, nullLog, null );
- } catch (ParserFactoryError e1) {
- }
-
- IToken token = null;
-
- try {
- token = scanner.nextToken();
- } catch (EndOfFileException e) {
- }
-
- if( token != null ){
- boolean nullifyToken = true;
- if( token.getType() == IToken.t_class ){
- searchFor = CLASS;
- } else if ( token.getType() == IToken.t_struct ){
- searchFor = STRUCT;
- } else if ( token.getType() == IToken.t_union ){
- searchFor = UNION;
- } else if ( token.getType() == IToken.t_enum ){
- searchFor = ENUM;
- } else if ( token.getType() == IToken.t_typedef ){
- searchFor = TYPEDEF;
- } else {
- nullifyToken = false;
- }
- if( nullifyToken ){
- patternArray = CharOperation.subarray( patternArray, token.getLength() + 1, -1 );
- token = null;
- }
- }
-
- LinkedList list = scanForNames( scanner, callback, token, patternArray );
-
- char[] name = (char [])list.removeLast();
- char [][] qualifications = new char[0][];
-
- return new ClassDeclarationPattern( name, (char[][])list.toArray( qualifications ), searchFor, limitTo, matchMode, caseSensitive);
+
+ String[] tokens = patternString.split("\\s+"); //$NON-NLS-1$
+ if (tokens.length > 0) {
+ boolean removeFirst = true;
+ if (tokens[0].equals("class")) { //$NON-NLS-1$
+ searchFor = CLASS;
+ }
+ else if (tokens[0].equals("struct")) { //$NON-NLS-1$
+ searchFor = STRUCT;
+ }
+ else if (tokens[0].equals("union")) { //$NON-NLS-1$
+ searchFor = UNION;
+ }
+ else if (tokens[0].equals("enum")) { //$NON-NLS-1$
+ searchFor = ENUM;
+ }
+ else if (tokens[0].equals("typedef")) { //$NON-NLS-1$
+ searchFor = TYPEDEF;
+ }
+ else {
+ removeFirst = false;
+ }
+ if (removeFirst) {
+ patternString = patternString.substring(tokens[0].length()).trim();
+ }
+ }
+ char[][] names = scanForNames( patternString ); // return type as first element of the array
+
+ char[] name = names[names.length - 1];
+ char[][] qualifications = new char[names.length - 1][];
+ System.arraycopy(names, 0, qualifications, 0, qualifications.length);
+
+ return new ClassDeclarationPattern( name, qualifications, searchFor, limitTo, matchMode, caseSensitive);
}
private static CSearchPattern createDerivedPattern(String patternString, SearchFor searchFor, LimitTo limitTo, int matchMode, boolean caseSensitive) {
- char [] patternArray = patternString.toCharArray();
-
- IScanner scanner =null;
- Requestor callback = new Requestor( ParserMode.COMPLETE_PARSE );
- try {
- scanner =
- ParserFactory.createScanner(
- new CodeReader(patternArray),
- new ScannerInfo(),
- ParserMode.QUICK_PARSE,
- ParserLanguage.CPP,
- callback, nullLog, null);
- } catch (ParserFactoryError e1) {
- }
-
searchFor = DERIVED;
- LinkedList list = scanForNames( scanner, callback, null, patternArray );
-
- char[] name = (char [])list.removeLast();
- char [][] qualifications = new char[0][];
-
- return new DerivedTypesPattern( name, (char[][])list.toArray( qualifications ), searchFor, limitTo, matchMode, caseSensitive );
+ char[][] names = scanForNames( patternString );
+
+ char[] name = names[names.length - 1];
+ char[][] qualifications = new char[names.length - 1][];
+ System.arraycopy(names, 0, qualifications, 0, qualifications.length);
+
+ return new DerivedTypesPattern( name, qualifications, searchFor, limitTo, matchMode, caseSensitive );
}
private static CSearchPattern createFriendPattern(String patternString, SearchFor searchFor, LimitTo limitTo, int matchMode, boolean caseSensitive) {
-
- char [] patternArray = patternString.toCharArray();
- IScanner scanner =null;
- Requestor callback = new Requestor( ParserMode.COMPLETE_PARSE );
- try {
- scanner =
- ParserFactory.createScanner(
- new CodeReader(patternArray),
- new ScannerInfo(),
- ParserMode.QUICK_PARSE,
- ParserLanguage.CPP,
- callback, nullLog, null);
- } catch (ParserFactoryError e1) {
- }
-
searchFor = FRIEND;
- LinkedList list = scanForNames( scanner, callback, null, patternArray );
-
- char[] name = (char [])list.removeLast();
- char [][] qualifications = new char[0][];
-
- return new FriendPattern( name, (char[][])list.toArray( qualifications ), searchFor, limitTo, matchMode, caseSensitive );
+ char[][] names = scanForNames( patternString );
+
+ char[] name = names[names.length - 1];
+ char[][] qualifications = new char[names.length - 1][];
+ System.arraycopy(names, 0, qualifications, 0, qualifications.length);
+
+ return new FriendPattern( name, qualifications, searchFor, limitTo, matchMode, caseSensitive );
}
- /**
+
+ /**
+ * @param nameString
+ * @return
+ */
+ private static char[][] scanForNames(String nameString) {
+ final List nameList = new ArrayList();
+
+ if (nameString != null && nameString.length() > 0) {
+
+ Requestor callback = new Requestor( ParserMode.COMPLETE_PARSE );
+ IScanner scanner = createScanner(nameString, callback);
+ if (scanner != null) {
+
+ String name = new String(""); //$NON-NLS-1$
+ char[] pattern = nameString.toCharArray();
+ int idx = 0;
+
+ try {
+ IToken token = scanner.nextToken();
+ IToken prev = null;
+
+ boolean encounteredWild = false;
+ boolean lastTokenWasOperator = false;
+
+ while( true ){
+ switch( token.getType() ){
+ case IToken.tCOLONCOLON :
+ nameList.add( name.toCharArray() );
+ name = new String(""); //$NON-NLS-1$
+ lastTokenWasOperator = false;
+ idx += token.getLength();
+ while( idx < pattern.length && CharOperation.isWhitespace( pattern[idx] ) ){ idx++; }
+ break;
+
+ case IToken.t_operator :
+ name += token.getImage();
+ name += ' ';
+ lastTokenWasOperator = true;
+ idx += token.getLength();
+ while( idx < pattern.length && CharOperation.isWhitespace( pattern[idx] ) ){ idx++; }
+ break;
+
+ default:
+ if( token.getType() == IToken.tSTAR ||
+ token.getType() == IToken.tQUESTION ) {
+ if( idx > 0 && idx < pattern.length && CharOperation.isWhitespace( pattern[ idx - 1 ] ) && !lastTokenWasOperator )
+ name += ' ';
+ encounteredWild = true;
+ }
+ else if( !encounteredWild && !lastTokenWasOperator && name.length() > 0 &&
+ prev.getType() != IToken.tIDENTIFIER &&
+ prev.getType() != IToken.tLT &&
+ prev.getType() != IToken.tCOMPL &&
+ prev.getType() != IToken.tARROW &&
+ prev.getType() != IToken.tLBRACKET &&
+ token.getType() != IToken.tRBRACKET &&
+ token.getType()!= IToken.tGT
+ ){
+ name += ' ';
+ } else {
+ encounteredWild = false;
+ }
+
+ name += token.getImage();
+
+ if( encounteredWild && idx < pattern.length - 1 && CharOperation.isWhitespace( pattern[ idx + 1 ] ) )
+ {
+ name += ' ';
+ }
+ idx += token.getLength();
+ while( idx < pattern.length && CharOperation.isWhitespace( pattern[idx] ) ){ idx++; }
+
+ lastTokenWasOperator = false;
+ break;
+ }
+ prev = token;
+
+ token = null;
+ while( token == null ){
+ token = scanner.nextToken();
+ if( callback.badCharacterOffset != -1 && token.getOffset() > callback.badCharacterOffset ){
+ //TODO : This may not be \\, it could be another bad character
+ if( !encounteredWild && !lastTokenWasOperator && prev.getType() != IToken.tARROW ) name += " "; //$NON-NLS-1$
+ name += "\\"; //$NON-NLS-1$
+ idx++;
+ encounteredWild = true;
+ lastTokenWasOperator = false;
+ prev = null;
+ callback.badCharacterOffset = -1;
+ }
+ }
+ }
+ } catch (EndOfFileException e) {
+ nameList.add( name.toCharArray() );
+ }
+ }
+ }
+ return (char[][]) nameList.toArray(new char [nameList.size()] []);
+ }
+
+
+ /**
* @param scanner
* @param object
* @return
*/
- public static LinkedList scanForParameters( String paramString ) {
- LinkedList list = new LinkedList();
-
+ public static char[][] scanForParameters( String paramString ) {
+ char[][] rv = new char[0][];
+
if( paramString == null || paramString.equals("") ) //$NON-NLS-1$
- return list;
+ return rv;
String functionString = "void f " + paramString + ";"; //$NON-NLS-1$ //$NON-NLS-2$
- IScanner scanner=null;
- IQuickParseCallback callback = ParserFactory.createQuickParseCallback();
- try {
- scanner =
- ParserFactory.createScanner(
- new CodeReader(functionString.toCharArray()),
- new ScannerInfo(),
- ParserMode.QUICK_PARSE,
- ParserLanguage.CPP,
- callback,new NullLogService(), null);
- } catch (ParserFactoryError e1) {
- }
-
- IParser parser=null;
- try {
- parser =
- ParserFactory.createParser(
- scanner,
- callback,
- ParserMode.QUICK_PARSE,
- ParserLanguage.CPP, ParserUtil.getParserLogService());
- } catch (ParserFactoryError e2) {
- }
-
- if( parser.parse() ){
- IASTCompilationUnit compUnit = callback.getCompilationUnit();
- Iterator declarations = null;
- try {
- declarations = compUnit.getDeclarations();
- } catch (ASTNotImplementedException e) {
- }
-
- if( declarations == null || ! declarations.hasNext() )
- return null;
-
- IASTDeclaration decl = (IASTDeclaration) declarations.next();
- if( !(decl instanceof IASTFunction) ){
- //if the user puts something not so good in the brackets, we might not get a function back
- return list;
- }
-
- IASTFunction function = (IASTFunction) decl;
-
- String [] paramTypes = ASTUtil.getFunctionParameterTypes(function);
- if( paramTypes.length == 0 )
- {
- //This means that no params have been added (i.e. empty brackets - void case)
- list.add ("void".toCharArray() ); //$NON-NLS-1$
- } else {
- for( int i = 0; i < paramTypes.length; i++ ){
- list.add( paramTypes[i].toCharArray() );
- }
- }
- }
-
- return list;
+ try {
+ IASTTranslationUnit tu = parse(functionString);
+ if (tu != null) {
+ IASTDeclaration[] decls = tu.getDeclarations();
+ for (int i = 0; i < decls.length; i++) {
+ IASTDeclaration decl = decls[i];
+ if (decl instanceof IASTSimpleDeclaration) {
+ IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) decl;
+ IASTDeclarator[] declarators = simpleDecl.getDeclarators();
+ for (int j = 0; j < declarators.length; j++) {
+ String[] parameters = ASTSignatureUtil.getParameterSignatureArray(declarators[j]);
+ rv = new char[parameters.length][];
+ for (int k = 0; k < parameters.length; k++) {
+ rv[k] = parameters[k].toCharArray();
+ }
+ // take first set of parameters only
+ break;
+ }
+ }
+ // take first declaration only
+ break;
+ }
+ }
+ }
+ catch (ParserException e) {
+ }
+
+ return rv;
}
- static private LinkedList scanForNames( IScanner scanner, Requestor callback, IToken unusedToken, char[] pattern ){
- LinkedList list = new LinkedList();
-
- String name = new String(""); //$NON-NLS-1$
- int idx = 0;
-
- try {
- IToken token = ( unusedToken != null ) ? unusedToken : scanner.nextToken();
- IToken prev = null;
-
- boolean encounteredWild = false;
- boolean lastTokenWasOperator = false;
-
- while( true ){
- switch( token.getType() ){
- case IToken.tCOLONCOLON :
- list.addLast( name.toCharArray() );
- name = new String(""); //$NON-NLS-1$
- lastTokenWasOperator = false;
- idx += token.getLength();
- while( idx < pattern.length && CharOperation.isWhitespace( pattern[idx] ) ){ idx++; }
- break;
-
- case IToken.t_operator :
- name += token.getImage();
- name += ' ';
- lastTokenWasOperator = true;
- idx += token.getLength();
- while( idx < pattern.length && CharOperation.isWhitespace( pattern[idx] ) ){ idx++; }
- break;
-
- default:
- if( token.getType() == IToken.tSTAR ||
- token.getType() == IToken.tQUESTION
- )
- {
- if( idx > 0 && idx < pattern.length && CharOperation.isWhitespace( pattern[ idx - 1 ] ) && !lastTokenWasOperator )
- name += ' ';
- encounteredWild = true;
- } else if( !encounteredWild && !lastTokenWasOperator && name.length() > 0 &&
- prev.getType() != IToken.tIDENTIFIER &&
- prev.getType() != IToken.tLT &&
- prev.getType() != IToken.tCOMPL &&
- prev.getType() != IToken.tARROW &&
- prev.getType() != IToken.tLBRACKET &&
- token.getType() != IToken.tRBRACKET &&
- token.getType()!= IToken.tGT
- ){
- name += ' ';
- } else {
- encounteredWild = false;
- }
-
- name += token.getImage();
-
- if( encounteredWild && idx < pattern.length - 1 && CharOperation.isWhitespace( pattern[ idx + 1 ] ) )
- {
- name += ' ';
- }
- idx += token.getLength();
- while( idx < pattern.length && CharOperation.isWhitespace( pattern[idx] ) ){ idx++; }
-
- lastTokenWasOperator = false;
- break;
- }
- prev = token;
-
- token = null;
- while( token == null ){
- token = scanner.nextToken();
- if( callback.badCharacterOffset != -1 && token.getOffset() > callback.badCharacterOffset ){
- //TODO : This may not be \\, it could be another bad character
- if( !encounteredWild && !lastTokenWasOperator && prev.getType() != IToken.tARROW ) name += " "; //$NON-NLS-1$
- name += "\\"; //$NON-NLS-1$
- idx++;
- encounteredWild = true;
- lastTokenWasOperator = false;
- prev = null;
- callback.badCharacterOffset = -1;
- }
- }
- }
- } catch (EndOfFileException e) {
- list.addLast( name.toCharArray() );
- }
-
- return list;
- }
-
protected boolean matchesName( char[] pattern, char[] name ){
if( pattern == null ){
return true; //treat null as "*"
@@ -756,4 +669,70 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
protected int _matchMode;
protected boolean _caseSensitive;
protected LimitTo _limitTo;
+
+
+ protected static IASTTranslationUnit parse( String code ) throws ParserException {
+ return parse(code, ParserLanguage.CPP);
+ }
+
+ /**
+ * @param string
+ * @param c
+ * @return
+ * @throws ParserException
+ */
+ protected static IASTTranslationUnit parse( String code, ParserLanguage lang ) throws ParserException {
+ IParserLogService NULL_LOG = new NullLogService();
+ CodeReader codeReader = new CodeReader(code .toCharArray());
+ ScannerInfo scannerInfo = new ScannerInfo();
+ IScannerExtensionConfiguration configuration = null;
+ if( lang == ParserLanguage.C )
+ configuration = new GCCScannerExtensionConfiguration();
+ else
+ configuration = new GPPScannerExtensionConfiguration();
+ IScanner scanner = new DOMScanner( codeReader, scannerInfo, ParserMode.COMPLETE_PARSE, lang, NULL_LOG, configuration, FileCodeReaderFactory.getInstance() );
+
+ ISourceCodeParser parser2 = null;
+ if( lang == ParserLanguage.CPP )
+ {
+ ICPPParserExtensionConfiguration config = new ANSICPPParserExtensionConfiguration();
+ parser2 = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, config );
+ }
+ else {
+ ICParserExtensionConfiguration config = new ANSICParserExtensionConfiguration();
+ parser2 = new GNUCSourceParser( scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, config );
+ }
+
+ IASTTranslationUnit tu = parser2.parse();
+
+ if( parser2.encounteredError())
+ throw new ParserException( "FAILURE"); //$NON-NLS-1$
+
+ return tu;
+ }
+
+ protected static IScanner createScanner( String code, ISourceElementRequestor callback ) {
+ return createScanner(code, callback, ParserLanguage.CPP);
+ }
+
+ /**
+ * @param code
+ * @param callback
+ * @param lang
+ * @return
+ */
+ protected static IScanner createScanner( String code, ISourceElementRequestor callback, ParserLanguage lang ) {
+ IScanner scanner = null;
+ try {
+ scanner = ParserFactory.createScanner(
+ new CodeReader(code.toCharArray()),
+ new ScannerInfo(),
+ ParserMode.QUICK_PARSE,
+ lang, callback, nullLog, null);
+ }
+ catch (ParserFactoryError e) {
+ }
+ return scanner;
+ }
+
}
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 8f8d8346a0..d4b9f48e6e 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
@@ -52,18 +52,21 @@ public class MethodDeclarationPattern extends CSearchPattern {
private char[][] parameterNames;
private char[] simpleName;
private char[][] qualifications;
-
+ private char[] returnTypes;
+
private char[] decodedSimpleName;
private char[][] decodedQualifications;
private char[][] decodedParameters;
+ private char[] decodedReturnTypes;
- public MethodDeclarationPattern(char[] name, char[][] qual, char [][] params, int matchMode, SearchFor search, LimitTo limitTo, boolean caseSensitive) {
+ public MethodDeclarationPattern(char[] name, char[][] qual, char [][] params, char[] returnTypes, int matchMode, SearchFor search, LimitTo limitTo, boolean caseSensitive) {
//super( name, params, matchMode, limitTo, caseSensitive );
super( matchMode, caseSensitive, limitTo );
qualifications = qual;
simpleName = name;
parameterNames = params;
+ this.returnTypes = returnTypes;
searchFor = search;
}
@@ -167,6 +170,28 @@ public class MethodDeclarationPattern extends CSearchPattern {
}
}
+ //Check for return type
+ boolean returnTypeExists=false;
+ int returnStart=0;
+ int returnEnd=0;
+ if (end != 0 &&
+ end<missmatch.length){
+ //Make sure that we have a parameter string and that there is still something left
+ //to be decoded
+
+ for (int j=end; j<missmatch.length; j++){
+ if (missmatch[j].equals("R(")){ //$NON-NLS-1$
+ returnStart=j;
+ returnTypeExists=true;
+ }
+
+ if (missmatch[j].equals(")R")){ //$NON-NLS-1$
+ returnEnd=j;
+ break;
+ }
+ }
+ }
+
if (parmsExist){
this.decodedParameters = new char[end - (start + 1)][];
@@ -174,9 +199,9 @@ public class MethodDeclarationPattern extends CSearchPattern {
for (int i=start+1; i<end; i++){
decodedParameters[counter++]=missmatch[i].toCharArray();
}
- this.decodedQualifications = new char[missmatch.length - (end + 1)][];
+ this.decodedQualifications = new char[missmatch.length - (returnEnd + 1)][];
counter=0;
- for (int i = end + 1; i < missmatch.length; i++)
+ for (int i = returnEnd + 1; i < missmatch.length; i++)
this.decodedQualifications[counter++] = missmatch[i].toCharArray();
} else {
this.decodedParameters = new char[0][];
@@ -185,6 +210,9 @@ public class MethodDeclarationPattern extends CSearchPattern {
this.decodedQualifications[i] = missmatch[i].toCharArray();
}
+ if (returnTypeExists){
+ this.returnTypes = missmatch[returnStart + 1].toCharArray();
+ }
}
}
@@ -205,9 +233,25 @@ public class MethodDeclarationPattern extends CSearchPattern {
return false;
}
+ if (!matchReturnType(returnTypes, decodedReturnTypes)){
+ return false;
+ }
return true;
}
+ /**
+ * @param returnTypes
+ * @param decodedReturnTypes
+ * @return
+ */
+ private boolean matchReturnType(char[] returnTypes, char[] decodedReturnTypes) {
+ if( returnTypes == null || decodedReturnTypes == null ){
+ return true; //treat null as "*"
+ }
+
+ return CharOperation.equals( returnTypes, decodedReturnTypes, true);
+ }
+
private boolean matchParameters(char[][] parameterNames2, char[][] decodedParameters2) {
if (parameterNames2.length == 0)

Back to the top