From 0bca2b33c34108727a2de5145f749012057601ce Mon Sep 17 00:00:00 2001 From: Bogdan Gheorghe Date: Mon, 25 Apr 2005 18:53:48 +0000 Subject: [PATCH] Patch for Dave Daoust - cleans up some name references in the search tests --- .../core/tests/SelectionRegressionTest.java | 1 - .../cdt/core/search/tests/BaseSearchTest.java | 9 ++++++ .../tests/ClassDeclarationPatternTests.java | 9 +++--- .../tests/FunctionMethodPatternTests.java | 15 +++++----- .../core/search/tests/OtherPatternTests.java | 28 +++++++++---------- .../core/index/cindexstorage/Index.java | 6 ++-- 6 files changed, 39 insertions(+), 29 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/SelectionRegressionTest.java b/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/SelectionRegressionTest.java index 94993e12576..3f1d7aa433d 100644 --- a/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/SelectionRegressionTest.java +++ b/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/SelectionRegressionTest.java @@ -20,7 +20,6 @@ import java.io.Writer; import junit.framework.Test; import junit.framework.TestSuite; -import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.NullLogService; diff --git a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/BaseSearchTest.java b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/BaseSearchTest.java index 070e026dc89..9794d4a3b77 100644 --- a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/BaseSearchTest.java +++ b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/BaseSearchTest.java @@ -28,6 +28,7 @@ import org.eclipse.cdt.core.search.SearchEngine; import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.CTestPlugin; import org.eclipse.cdt.core.testplugin.FileManager; +import org.eclipse.cdt.internal.core.index.cindexstorage.Index; import org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; @@ -133,6 +134,14 @@ public class BaseSearchTest extends TestCase implements ICSearchConstants { } + protected char[] getSearchPattern(int meta_kind, int kind, int ref, String name) { + return Index.encodeEntry(meta_kind, kind, ref, name); + } + + public void assertEquals(char [] first, char [] second) { + assertEquals( new String(first), new String(second)); + } + protected void search(IWorkspace workspace, ICSearchPattern pattern, ICSearchScope scope, ICSearchResultCollector collector) { try { searchEngine.search( workspace, pattern, scope, collector, false ); diff --git a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/ClassDeclarationPatternTests.java b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/ClassDeclarationPatternTests.java index 103d59afe77..ad43a037673 100644 --- a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/ClassDeclarationPatternTests.java +++ b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/ClassDeclarationPatternTests.java @@ -22,6 +22,7 @@ import org.eclipse.cdt.core.search.IMatch; import org.eclipse.cdt.core.search.OrPattern; import org.eclipse.cdt.core.search.SearchEngine; import org.eclipse.cdt.internal.core.CharOperation; +import org.eclipse.cdt.internal.core.index.IIndex; import org.eclipse.cdt.internal.core.search.matching.ClassDeclarationPattern; @@ -157,16 +158,16 @@ public class ClassDeclarationPatternTests extends BaseSearchTest implements ICSe assertTrue( pattern instanceof ClassDeclarationPattern ); ClassDeclarationPattern clsPattern = (ClassDeclarationPattern)pattern; - assertEquals( CharOperation.compareWith( "typeDecl/S/c/".toCharArray(), clsPattern.indexEntryPrefix() ), 0); + assertEquals( getSearchPattern(IIndex.TYPE, IIndex.TYPE_STRUCT, IIndex.DECLARATION, "c/"), clsPattern.indexEntryPrefix()); clsPattern = (ClassDeclarationPattern) SearchEngine.createSearchPattern( "class ::*::A::B::c", TYPE, DECLARATIONS, true ); - assertEquals( CharOperation.compareWith( "typeDecl/C/c/B/A/".toCharArray(), clsPattern.indexEntryPrefix() ), 0); + assertEquals( getSearchPattern(IIndex.TYPE, IIndex.TYPE_CLASS, IIndex.DECLARATION, "c/B/A/"), clsPattern.indexEntryPrefix()); clsPattern = (ClassDeclarationPattern) SearchEngine.createSearchPattern( "enum ::RT*::c", TYPE, REFERENCES, true ); - assertEquals( CharOperation.compareWith( "typeRef/E/c/RT".toCharArray(), clsPattern.indexEntryPrefix() ), 0); + assertEquals( getSearchPattern(IIndex.TYPE, IIndex.TYPE_ENUM, IIndex.REFERENCE,"c/RT"), clsPattern.indexEntryPrefix()); clsPattern = (ClassDeclarationPattern) SearchEngine.createSearchPattern( "union A::B::c", TYPE, REFERENCES, false ); - assertEquals( CharOperation.compareWith( "typeRef/U/".toCharArray(), clsPattern.indexEntryPrefix() ), 0); + assertEquals( getSearchPattern(IIndex.TYPE, IIndex.TYPE_UNION, IIndex.REFERENCE, ""), clsPattern.indexEntryPrefix()); } public void testGloballyQualifiedItem(){ 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 0b5f29ab7cc..e6e3713efc1 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 @@ -19,6 +19,7 @@ import org.eclipse.cdt.core.search.ICSearchPattern; import org.eclipse.cdt.core.search.IMatch; import org.eclipse.cdt.core.search.SearchEngine; import org.eclipse.cdt.internal.core.CharOperation; +import org.eclipse.cdt.internal.core.index.IIndex; import org.eclipse.cdt.internal.core.search.matching.MethodDeclarationPattern; /** @@ -41,13 +42,13 @@ public class FunctionMethodPatternTests extends BaseSearchTest { ICSearchPattern pattern = SearchEngine.createSearchPattern( "c()", FUNCTION, DECLARATIONS, true ); //$NON-NLS-1$ MethodDeclarationPattern functionPattern = (MethodDeclarationPattern)pattern; - assertEquals( CharOperation.compareWith( "functionDecl/c".toCharArray(), functionPattern.indexEntryPrefix() ), 0); //$NON-NLS-1$ + assertEquals( getSearchPattern(IIndex.FUNCTION, IIndex.ANY, IIndex.DECLARATION, "c"), functionPattern.indexEntryPrefix() ); //$NON-NLS-1$ functionPattern = (MethodDeclarationPattern) SearchEngine.createSearchPattern( "rt*()", FUNCTION, DECLARATIONS, true ); //$NON-NLS-1$ - assertEquals( CharOperation.compareWith( "functionDecl/rt".toCharArray(), functionPattern.indexEntryPrefix() ), 0); //$NON-NLS-1$ + assertEquals( getSearchPattern(IIndex.FUNCTION, IIndex.ANY, IIndex.DECLARATION, "rt"), functionPattern.indexEntryPrefix()); //$NON-NLS-1$ functionPattern = (MethodDeclarationPattern) SearchEngine.createSearchPattern( "Ac", FUNCTION, REFERENCES, false ); //$NON-NLS-1$ - assertEquals( CharOperation.compareWith( "functionRef/".toCharArray(), functionPattern.indexEntryPrefix() ), 0); //$NON-NLS-1$ + assertEquals( getSearchPattern(IIndex.FUNCTION, IIndex.ANY, IIndex.REFERENCE, ""), functionPattern.indexEntryPrefix()); //$NON-NLS-1$ } public void testMethodIndexPrefix(){ @@ -55,16 +56,16 @@ public class FunctionMethodPatternTests extends BaseSearchTest { assertTrue( pattern instanceof MethodDeclarationPattern ); MethodDeclarationPattern methodPattern = (MethodDeclarationPattern)pattern; - assertEquals( CharOperation.compareWith( "methodDecl/c/B/A".toCharArray(), methodPattern.indexEntryPrefix() ), 0); //$NON-NLS-1$ + assertEquals( getSearchPattern(IIndex.METHOD, IIndex.ANY, IIndex.DECLARATION, "c/B/A"), methodPattern.indexEntryPrefix()); //$NON-NLS-1$ methodPattern = (MethodDeclarationPattern) SearchEngine.createSearchPattern( "::*::A::B::c", METHOD, DECLARATIONS, true ); //$NON-NLS-1$ - assertEquals( CharOperation.compareWith( "methodDecl/c/B/A/".toCharArray(), methodPattern.indexEntryPrefix() ), 0); //$NON-NLS-1$ + assertEquals( getSearchPattern(IIndex.METHOD, IIndex.ANY, IIndex.DECLARATION, "c/B/A/"), methodPattern.indexEntryPrefix()); //$NON-NLS-1$ methodPattern = (MethodDeclarationPattern) SearchEngine.createSearchPattern( "::RT*::c", METHOD, REFERENCES, true ); //$NON-NLS-1$ - assertEquals( CharOperation.compareWith( "methodRef/c/RT".toCharArray(), methodPattern.indexEntryPrefix() ), 0); //$NON-NLS-1$ + assertEquals( getSearchPattern(IIndex.METHOD, IIndex.ANY, IIndex.REFERENCE, "c/RT"), methodPattern.indexEntryPrefix()); //$NON-NLS-1$ methodPattern = (MethodDeclarationPattern) SearchEngine.createSearchPattern( "A::B::c", METHOD, REFERENCES, false ); //$NON-NLS-1$ - assertEquals( CharOperation.compareWith( "methodRef/".toCharArray(), methodPattern.indexEntryPrefix() ), 0); //$NON-NLS-1$ + assertEquals( getSearchPattern(IIndex.METHOD, IIndex.ANY, IIndex.REFERENCE, ""), methodPattern.indexEntryPrefix()); //$NON-NLS-1$ } public void testMethodDeclaration() { diff --git a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/OtherPatternTests.java b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/OtherPatternTests.java index 95e89cf7712..04d8b439d6c 100644 --- a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/OtherPatternTests.java +++ b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/OtherPatternTests.java @@ -21,7 +21,7 @@ import org.eclipse.cdt.core.search.ICSearchPattern; import org.eclipse.cdt.core.search.IMatch; import org.eclipse.cdt.core.search.SearchEngine; import org.eclipse.cdt.core.testplugin.CTestPlugin; -import org.eclipse.cdt.internal.core.CharOperation; +import org.eclipse.cdt.internal.core.index.IIndex; import org.eclipse.cdt.internal.core.search.matching.FieldDeclarationPattern; import org.eclipse.cdt.internal.core.search.matching.MatchLocator; import org.eclipse.cdt.internal.core.search.matching.NamespaceDeclarationPattern; @@ -42,22 +42,22 @@ public class OtherPatternTests extends BaseSearchTest { super(name); // TODO Auto-generated constructor stub } - + public void testNamespaceIndexPrefix(){ ICSearchPattern pattern = SearchEngine.createSearchPattern( "A::B::c", NAMESPACE, DECLARATIONS, true ); //$NON-NLS-1$ assertTrue( pattern instanceof NamespaceDeclarationPattern ); NamespaceDeclarationPattern nsPattern = (NamespaceDeclarationPattern)pattern; - assertEquals( CharOperation.compareWith( "namespaceDecl/c/B/A".toCharArray(), nsPattern.indexEntryPrefix() ), 0); //$NON-NLS-1$ + assertEquals( getSearchPattern(IIndex.NAMESPACE, IIndex.ANY, IIndex.DECLARATION, "c/B/A"), nsPattern.indexEntryPrefix() ); //$NON-NLS-1$ nsPattern = (NamespaceDeclarationPattern) SearchEngine.createSearchPattern( "::*::A::B::c", NAMESPACE, DECLARATIONS, true ); //$NON-NLS-1$ - assertEquals( CharOperation.compareWith( "namespaceDecl/c/B/A/".toCharArray(), nsPattern.indexEntryPrefix() ), 0); //$NON-NLS-1$ + assertEquals( getSearchPattern(IIndex.NAMESPACE, IIndex.ANY, IIndex.DECLARATION, "c/B/A/"), nsPattern.indexEntryPrefix() ); //$NON-NLS-1$ nsPattern = (NamespaceDeclarationPattern) SearchEngine.createSearchPattern( "::RT*::c", NAMESPACE, REFERENCES, true ); //$NON-NLS-1$ - assertEquals( CharOperation.compareWith( "namespaceRef/c/RT".toCharArray(), nsPattern.indexEntryPrefix() ), 0); //$NON-NLS-1$ + assertEquals( getSearchPattern(IIndex.NAMESPACE, IIndex.ANY, IIndex.REFERENCE, "c/RT"), nsPattern.indexEntryPrefix() ); //$NON-NLS-1$ nsPattern = (NamespaceDeclarationPattern) SearchEngine.createSearchPattern( "A::B::c", NAMESPACE, REFERENCES, false ); //$NON-NLS-1$ - assertEquals( CharOperation.compareWith( "namespaceRef/".toCharArray(), nsPattern.indexEntryPrefix() ), 0); //$NON-NLS-1$ + assertEquals( getSearchPattern(IIndex.NAMESPACE, IIndex.ANY, IIndex.REFERENCE, ""), nsPattern.indexEntryPrefix() ); //$NON-NLS-1$ } public void testVariableIndexPrefix(){ @@ -65,16 +65,16 @@ public class OtherPatternTests extends BaseSearchTest { assertTrue( pattern instanceof FieldDeclarationPattern ); FieldDeclarationPattern variablePattern = (FieldDeclarationPattern)pattern; - assertEquals( CharOperation.compareWith( "typeDecl/V/c".toCharArray(), variablePattern.indexEntryPrefix() ), 0); //$NON-NLS-1$ + assertEquals( getSearchPattern(IIndex.TYPE, IIndex.TYPE_VAR, IIndex.DECLARATION, "c"), variablePattern.indexEntryPrefix() ); //$NON-NLS-1$ variablePattern = (FieldDeclarationPattern) SearchEngine.createSearchPattern( "rt*", VAR, DECLARATIONS, true ); //$NON-NLS-1$ - assertEquals( CharOperation.compareWith( "typeDecl/V/rt".toCharArray(), variablePattern.indexEntryPrefix() ), 0); //$NON-NLS-1$ + assertEquals( getSearchPattern(IIndex.TYPE, IIndex.TYPE_VAR, IIndex.DECLARATION, "rt"), variablePattern.indexEntryPrefix() ); //$NON-NLS-1$ variablePattern = (FieldDeclarationPattern) SearchEngine.createSearchPattern( "Ac", VAR, REFERENCES, false ); //$NON-NLS-1$ - assertEquals( CharOperation.compareWith( "typeRef/V/".toCharArray(), variablePattern.indexEntryPrefix() ), 0); //$NON-NLS-1$ + assertEquals( getSearchPattern(IIndex.TYPE, IIndex.TYPE_VAR, IIndex.REFERENCE, ""), variablePattern.indexEntryPrefix() ); //$NON-NLS-1$ variablePattern = (FieldDeclarationPattern) SearchEngine.createSearchPattern( "A?c", VAR, REFERENCES, true ); //$NON-NLS-1$ - assertEquals( CharOperation.compareWith( "typeRef/V/A".toCharArray(), variablePattern.indexEntryPrefix() ), 0); //$NON-NLS-1$ + assertEquals( getSearchPattern(IIndex.TYPE, IIndex.TYPE_VAR, IIndex.REFERENCE, "A"), variablePattern.indexEntryPrefix() ); //$NON-NLS-1$ } public void testFieldIndexPrefix(){ @@ -82,16 +82,16 @@ public class OtherPatternTests extends BaseSearchTest { assertTrue( pattern instanceof FieldDeclarationPattern ); FieldDeclarationPattern fieldPattern = (FieldDeclarationPattern)pattern; - assertEquals( CharOperation.compareWith( "fieldDecl/c/B/A".toCharArray(), fieldPattern.indexEntryPrefix() ), 0); //$NON-NLS-1$ + assertEquals( getSearchPattern(IIndex.FIELD, IIndex.ANY, IIndex.DECLARATION, "c/B/A"), fieldPattern.indexEntryPrefix() ); //$NON-NLS-1$ fieldPattern = (FieldDeclarationPattern) SearchEngine.createSearchPattern( "::*::A::B::c", FIELD, DECLARATIONS, true ); //$NON-NLS-1$ - assertEquals( CharOperation.compareWith( "fieldDecl/c/B/A/".toCharArray(), fieldPattern.indexEntryPrefix() ), 0); //$NON-NLS-1$ + assertEquals( getSearchPattern(IIndex.FIELD, IIndex.ANY, IIndex.DECLARATION, "c/B/A/"), fieldPattern.indexEntryPrefix() ); //$NON-NLS-1$ fieldPattern = (FieldDeclarationPattern) SearchEngine.createSearchPattern( "::RT*::c", FIELD, REFERENCES, true ); //$NON-NLS-1$ - assertEquals( CharOperation.compareWith( "fieldRef/c/RT".toCharArray(), fieldPattern.indexEntryPrefix() ), 0); //$NON-NLS-1$ + assertEquals( getSearchPattern(IIndex.FIELD, IIndex.ANY, IIndex.REFERENCE, "c/RT"), fieldPattern.indexEntryPrefix() ); //$NON-NLS-1$ fieldPattern = (FieldDeclarationPattern) SearchEngine.createSearchPattern( "A::B::c", FIELD, REFERENCES, false ); //$NON-NLS-1$ - assertEquals( CharOperation.compareWith( "fieldRef/".toCharArray(), fieldPattern.indexEntryPrefix() ), 0); //$NON-NLS-1$ + assertEquals( getSearchPattern(IIndex.FIELD, IIndex.ANY, IIndex.REFERENCE, ""), fieldPattern.indexEntryPrefix() ); //$NON-NLS-1$ } public void testNamespaceDeclaration(){ diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/Index.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/Index.java index a631939bca9..56377123ab8 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/Index.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/Index.java @@ -762,12 +762,12 @@ public class Index implements IIndex, ICIndexStorageConstants, ICSearchConstants StringBuffer buff = new StringBuffer(); buff.append(encodings[meta_kind]); buff.append(encodingTypes[ref]); - if(kind != 0) + if(kind != 0) { buff.append(typeConstants[kind]); - if (name.length() != 0) { buff.append( SEPARATOR ); - buff.append ( name ); } + buff.append ( name ); + return buff.toString().toCharArray(); }