mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Patch for Dave Daoust - cleans up some name references in the search tests
This commit is contained in:
parent
4b511c67ae
commit
0bca2b33c3
6 changed files with 39 additions and 29 deletions
|
@ -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;
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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(){
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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;
|
||||
|
@ -48,16 +48,16 @@ public class OtherPatternTests extends BaseSearchTest {
|
|||
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(){
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue