1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Refactored search engine to take an IMatchLocator; added friends to the index: removed derived from search page

This commit is contained in:
Bogdan Gheorghe 2004-05-06 18:33:01 +00:00
parent 43ec78a634
commit c29caac4d0
14 changed files with 242 additions and 20 deletions

View file

@ -339,7 +339,9 @@ public class OtherPatternTests extends BaseSearchTest {
resultCollector.aboutToStart();
ArrayList matchesList = new ArrayList();
MatchLocator matchLocator = new MatchLocator( pattern, resultCollector, scope, monitor );
MatchLocator matchLocator = new MatchLocator( pattern, resultCollector, scope);
matchLocator.setProgressMonitor(monitor);
try {
matchLocator.locateMatches( new String [] { path }, workspace, null, matchesList);
} catch (InterruptedException e1) {

View file

@ -1,3 +1,8 @@
2004-05-06 Bogdan Gheorghe
Modified AbstractIndexer to encode friends, add friends constant to IIndexConstants,
modified SourceIndexerRequestor to add class specifier on exit instead of enter in order
to be able to encode friends.
2004-05-05 Bogdan Gheorghe
Added code to load and store index enablement setting from a project's descriptor

View file

@ -18,6 +18,7 @@ import org.eclipse.cdt.core.parser.ast.ASTClassKind;
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
import org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTEnumerator;
@ -48,6 +49,7 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe
final static int VAR = 5;
final static int TYPEDEF = 6;
final static int DERIVED = 7;
final static int FRIEND = 8;
public static boolean VERBOSE = false;
@ -64,9 +66,9 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe
if (classSpecification.getClassKind().equals(ASTClassKind.CLASS))
{
//Get base clauses
Iterator i = classSpecification.getBaseClauses();
while (i.hasNext()){
IASTBaseSpecifier baseSpec = (IASTBaseSpecifier) i.next();
Iterator baseClauses = classSpecification.getBaseClauses();
while (baseClauses.hasNext()){
IASTBaseSpecifier baseSpec = (IASTBaseSpecifier) baseClauses.next();
try {
IASTTypeSpecifier typeSpec = baseSpec.getParentClassSpecifier();
if (typeSpec instanceof IASTClassSpecifier){
@ -77,6 +79,24 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe
} catch (ASTNotImplementedException e) {}
}
//Get friends
Iterator friends = classSpecification.getFriends();
while (friends.hasNext()){
Object decl = friends.next();
if (decl instanceof IASTClassSpecifier){
IASTClassSpecifier friendClassSpec = (IASTClassSpecifier) decl;
String[] baseFullyQualifiedName = friendClassSpec.getFullyQualifiedName();
this.output.addRef(encodeTypeEntry(baseFullyQualifiedName,FRIEND,ICSearchConstants.DECLARATIONS));
}
else if (decl instanceof IASTFunction){
}
else if (decl instanceof IASTMethod){
//
}
}
this.output.addRef(encodeTypeEntry(classSpecification.getFullyQualifiedName(),CLASS, ICSearchConstants.DECLARATIONS));
}
else if (classSpecification.getClassKind().equals(ASTClassKind.STRUCT))
@ -315,6 +335,11 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe
case(DERIVED):
result[pos++]= DERIVED_SUFFIX;
break;
case(FRIEND):
result[pos++]=FRIEND_SUFFIX;
break;
}
result[pos++] = SEPARATOR;
//Encode in the following manner
@ -428,6 +453,8 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe
classType = TYPEDEF_SUFFIX;
} else if ( searchFor == ICSearchConstants.DERIVED){
classType = DERIVED_SUFFIX;
} else if ( searchFor == ICSearchConstants.FRIEND){
classType = FRIEND_SUFFIX;
} else {
//could be TYPE or CLASS_STRUCT, best we can do for these is the prefix
return prefix;

View file

@ -104,6 +104,7 @@ public interface IIndexConstants {
char UNION_SUFFIX = 'U';
char TYPEDEF_SUFFIX = 'T';
char DERIVED_SUFFIX = 'D';
char FRIEND_SUFFIX = 'F';
char TYPE_SUFFIX = 0;
char SEPARATOR= '/';

View file

@ -258,7 +258,6 @@ public class SourceIndexerRequestor implements ISourceElementRequestor, IIndexCo
// TODO Auto-generated method stub
//System.out.println("New class spec: " + classSpecification.getName());
indexer.addClassSpecifier(classSpecification);
//System.out.println("enterClassSpecifier");
}
@ -383,6 +382,7 @@ public class SourceIndexerRequestor implements ISourceElementRequestor, IIndexCo
*/
public void exitClassSpecifier(IASTClassSpecifier classSpecification) {
// TODO Auto-generated method stub
indexer.addClassSpecifier(classSpecification);
//System.out.println("exitClassSpecifier");
}

View file

@ -1,3 +1,10 @@
2004-05-06 Bogdan Gheorghe
Added friend to ICSearchConstants
Created IMatchLocator to allow search users to pass in their own match locators
Modified CSearchPattern to create friend search pattern
Added Friend pattern
Modified MatchLocator to check for class specifiers upon class exit
2004-04-19 Andrew Niefer
speed up BasicSearchMatch.compareTo and .hashCode by reducing number of string objects created.

View file

@ -105,6 +105,8 @@ public interface ICSearchConstants {
public static final SearchFor ENUMTOR = new SearchFor( 15 );
public static final SearchFor FRIEND = new SearchFor( 16 );
/* Nature of match */
/**

View file

@ -0,0 +1,29 @@
/*
* Created on Apr 29, 2004
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package org.eclipse.cdt.core.search;
import java.util.ArrayList;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.runtime.IProgressMonitor;
/**
* @author bgheorgh
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public interface IMatchLocator
extends
ISourceElementRequestor,
ICSearchConstants {
public void locateMatches( String [] paths, IWorkspace workspace, IWorkingCopy[] workingCopies,ArrayList matches ) throws InterruptedException;
public void setProgressMonitor(IProgressMonitor progressMonitor);
}

View file

@ -147,13 +147,21 @@ public class SearchEngine implements ICSearchConstants{
return CSearchPattern.createPattern( stringPattern, searchFor, limitTo, mode, isCaseSensitive );
}
public void search(IWorkspace workspace, ICSearchPattern pattern, ICSearchScope scope, ICSearchResultCollector collector, boolean excludeLocalDeclarations) throws InterruptedException {
MatchLocator matchLocator = new MatchLocator(pattern,collector,scope);
matchLocator.setShouldExcludeLocalDeclarations(excludeLocalDeclarations);
search(workspace, pattern, scope, collector, excludeLocalDeclarations, matchLocator);
}
/**
* @param _workspace
* @param pattern
* @param _scope
* @param _collector
*/
public void search(IWorkspace workspace, ICSearchPattern pattern, ICSearchScope scope, ICSearchResultCollector collector, boolean excludeLocalDeclarations) throws InterruptedException {
public void search(IWorkspace workspace, ICSearchPattern pattern, ICSearchScope scope, ICSearchResultCollector collector, boolean excludeLocalDeclarations, IMatchLocator matchLocator) throws InterruptedException {
if( VERBOSE ) {
System.out.println("Searching for " + pattern + " in " + scope); //$NON-NLS-1$//$NON-NLS-2$
}
@ -192,9 +200,8 @@ public class SearchEngine implements ICSearchConstants{
null );
subMonitor = (progressMonitor == null ) ? null : new SubProgressMonitor( progressMonitor, 95 );
MatchLocator matchLocator = new MatchLocator( pattern, collector, scope, subMonitor );
matchLocator.setShouldExcludeLocalDeclarations( excludeLocalDeclarations );
matchLocator.setProgressMonitor(subMonitor);
if( progressMonitor != null && progressMonitor.isCanceled() )
throw new InterruptedException();

View file

@ -114,12 +114,15 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
CSearchPattern pattern = null;
if( searchFor == TYPE || searchFor == CLASS || searchFor == STRUCT ||
searchFor == ENUM || searchFor == UNION || searchFor == CLASS_STRUCT ||
searchFor == TYPEDEF )
searchFor == TYPEDEF )
{
pattern = createClassPattern( patternString, searchFor, limitTo, matchMode, caseSensitive );
} else if ( searchFor == DERIVED){
pattern = createDerivedPattern(patternString, searchFor, limitTo, matchMode, caseSensitive );
} else if ( searchFor == METHOD || searchFor == FUNCTION ){
} else if ( searchFor == FRIEND){
pattern = createFriendPattern(patternString, searchFor, limitTo, matchMode, caseSensitive );
}
else if ( searchFor == METHOD || searchFor == FUNCTION ){
pattern = createMethodPattern( patternString, searchFor, limitTo, matchMode, caseSensitive );
} else if ( searchFor == FIELD || searchFor == VAR || searchFor == ENUMTOR){
pattern = createFieldPattern( patternString, searchFor, limitTo, matchMode, caseSensitive );
@ -424,6 +427,32 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
return new DerivedTypesPattern( name, (char[][])list.toArray( qualifications ), searchFor, limitTo, matchMode, caseSensitive );
}
private static CSearchPattern createFriendPattern(String patternString, SearchFor searchFor, LimitTo limitTo, int matchMode, boolean caseSensitive) {
IScanner scanner =null;
try {
scanner =
ParserFactory.createScanner(
new StringReader(patternString),
"TEXT", //$NON-NLS-1$
new ScannerInfo(),
ParserMode.QUICK_PARSE,
ParserLanguage.CPP,
callback, nullLog, null);
} catch (ParserFactoryError e1) {
}
searchFor = FRIEND;
LinkedList list = scanForNames( scanner, null );
char[] name = (char [])list.removeLast();
char [][] qualifications = new char[0][];
return new FriendPattern( name, (char[][])list.toArray( qualifications ), searchFor, limitTo, matchMode, caseSensitive );
}
/**
* @param scanner
* @param object

View file

@ -0,0 +1,105 @@
/*
* Created on May 5, 2004
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package org.eclipse.cdt.internal.core.search.matching;
import java.util.Iterator;
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
import org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
import org.eclipse.cdt.internal.core.search.indexing.AbstractIndexer;
/**
* @author bgheorgh
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class FriendPattern extends ClassDeclarationPattern {
/**
* @param name
* @param containers
* @param searchFor
* @param limit
* @param mode
* @param caseSensitive
*/
public FriendPattern(char[] name, char[][] containers, SearchFor searchFor, LimitTo limit, int mode, boolean caseSensitive) {
super(name, containers, searchFor, limit, mode, caseSensitive);
}
public char[] indexEntryPrefix() {
return AbstractIndexer.bestTypePrefix(
searchFor,
getLimitTo(),
simpleName,
qualifications,
_matchMode,
_caseSensitive
);
}
protected boolean matchIndexEntry() {
if( decodedType != FRIEND_SUFFIX ){
return false;
}
return super.matchIndexEntry();
}
public int matchLevel( ISourceElementCallbackDelegate node, LimitTo limit ){
if (!( node instanceof IASTClassSpecifier )) {
return IMPOSSIBLE_MATCH;
}
if( ! canAccept( limit ) )
return IMPOSSIBLE_MATCH;
IASTClassSpecifier tempNode = (IASTClassSpecifier) node;
Iterator i = tempNode.getFriends();
boolean matchFlag=false;
while (i.hasNext()){
Object friend = i.next();
if (friend instanceof IASTClassSpecifier)
{
IASTClassSpecifier classSpec = (IASTClassSpecifier) friend;
String[] baseFullyQualifiedName = classSpec.getFullyQualifiedName();
//check name, if simpleName == null, its treated the same as "*"
if( simpleName != null && !matchesName( simpleName, classSpec.getName().toCharArray() ) ){
continue;
}
char [][] qualName = new char [ baseFullyQualifiedName.length - 1 ][];
for( int j = 0; j < baseFullyQualifiedName.length - 1; j++ ){
qualName[j] = baseFullyQualifiedName[j].toCharArray();
}
//check containing scopes
if( !matchQualifications( qualifications, qualName ) ){
continue;
}
matchFlag = true;
break;
}
}
if (matchFlag)
return ACCURATE_MATCH;
return IMPOSSIBLE_MATCH;
}
}

View file

@ -23,7 +23,6 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.IWorkingCopy;
@ -34,15 +33,16 @@ import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
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.IASTASMDefinition;
import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTClassReference;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTCodeScope;
@ -72,17 +72,18 @@ import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation;
import org.eclipse.cdt.core.parser.ast.IASTTemplateParameterReference;
import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization;
import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTTypedefReference;
import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTUsingDirective;
import org.eclipse.cdt.core.parser.ast.IASTVariable;
import org.eclipse.cdt.core.parser.ast.IASTVariableReference;
import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.core.search.ICSearchPattern;
import org.eclipse.cdt.core.search.ICSearchResultCollector;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.IMatch;
import org.eclipse.cdt.core.search.IMatchLocator;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@ -100,7 +101,7 @@ import org.eclipse.core.runtime.Path;
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class MatchLocator implements ISourceElementRequestor, ICSearchConstants {
public class MatchLocator implements IMatchLocator{
ArrayList matchStorage;
@ -109,12 +110,11 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants
/**
*
*/
public MatchLocator( ICSearchPattern pattern, ICSearchResultCollector collector, ICSearchScope scope, IProgressMonitor monitor) {
public MatchLocator( ICSearchPattern pattern, ICSearchResultCollector collector, ICSearchScope scope) {
super();
searchPattern = pattern;
resultCollector = collector;
searchScope = scope;
progressMonitor = monitor;
searchScope = scope;
}
public boolean acceptProblem(IProblem problem) { return DefaultProblemHandler.ruleOnProblem(problem, ParserMode.COMPLETE_PARSE ); }
@ -293,6 +293,7 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants
}
public void exitClassSpecifier(IASTClassSpecifier classSpecification) {
check(DECLARATIONS, classSpecification);
popScope();
}
@ -633,4 +634,11 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants
// TODO Auto-generated method stub
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.search.IMatchLocator#setProgressMonitor(org.eclipse.core.runtime.IProgressMonitor)
*/
public void setProgressMonitor(IProgressMonitor progressMonitor) {
this.progressMonitor = progressMonitor;
}
}

View file

@ -39,6 +39,7 @@ CSearchPage.searchFor.union= U&nion
CSearchPage.searchFor.enum= &Enumeration
CSearchPage.searchFor.enumr = Enume&rator
CSearchPage.searchFor.derived = &Derived
CSearchPage.searchFor.friend = &Friend
CSearchPage.searchFor.any= An&y Element
CSearchPage.searchFor.classStruct= &Class / Struct

View file

@ -627,7 +627,7 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons
private static List fgPreviousSearchPatterns = new ArrayList(20);
private Button[] fSearchFor;
private SearchFor[] fSearchForValues = { CLASS_STRUCT, FUNCTION, VAR, UNION, METHOD, FIELD, ENUM, ENUMTOR, NAMESPACE, DERIVED, UNKNOWN_SEARCH_FOR };
private SearchFor[] fSearchForValues = { CLASS_STRUCT, FUNCTION, VAR, UNION, METHOD, FIELD, ENUM, ENUMTOR, NAMESPACE, UNKNOWN_SEARCH_FOR };
private String[] fSearchForText= {
CSearchMessages.getString("CSearchPage.searchFor.classStruct"), //$NON-NLS-1$
@ -639,7 +639,6 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons
CSearchMessages.getString("CSearchPage.searchFor.enum"), //$NON-NLS-1$
CSearchMessages.getString("CSearchPage.searchFor.enumr"), //$NON-NLS-1$
CSearchMessages.getString("CSearchPage.searchFor.namespace"), //$NON-NLS-1$
CSearchMessages.getString("CSearchPage.searchFor.derived"), //$NON-NLS-1$
CSearchMessages.getString("CSearchPage.searchFor.any") }; //$NON-NLS-1$