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 e4b4e68afaf..0f2c51ad34e 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 @@ -23,6 +23,7 @@ import org.eclipse.cdt.core.search.SearchEngine; import org.eclipse.cdt.internal.core.search.CharOperation; import org.eclipse.cdt.internal.core.search.matching.ClassDeclarationPattern; import org.eclipse.cdt.internal.core.search.matching.MatchLocator; +import org.eclipse.cdt.internal.core.search.matching.OrPattern; /** @@ -246,4 +247,14 @@ public class ClassDeclarationPatternTests extends BaseSearchTest implements ICSe assertEquals( matches.size(), 2 ); } + public void testAllOccurences(){ + ICSearchPattern pattern = SearchEngine.createSearchPattern( "A", TYPE, ALL_OCCURRENCES, true ); + assertTrue( pattern instanceof OrPattern ); + + search( workspace, pattern, scope, resultCollector ); + + Set matches = resultCollector.getSearchResults(); + + assertEquals( matches.size(), 6 ); + } } 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 73b444efa82..23ff878c236 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,6 +21,7 @@ import org.eclipse.cdt.core.search.SearchEngine; import org.eclipse.cdt.internal.core.search.CharOperation; import org.eclipse.cdt.internal.core.search.matching.FieldDeclarationPattern; import org.eclipse.cdt.internal.core.search.matching.NamespaceDeclarationPattern; +import org.eclipse.cdt.internal.core.search.matching.OrPattern; import org.eclipse.cdt.internal.core.search.matching.VariableDeclarationPattern; /** @@ -145,5 +146,27 @@ public class OtherPatternTests extends BaseSearchTest { IMatch match = (IMatch) matches.iterator().next(); assertTrue( match.getParentName().equals( "" ) ); } + + public void testOrPattern(){ + OrPattern orPattern = new OrPattern(); + orPattern.addPattern( SearchEngine.createSearchPattern( "::NS::B::e", ENUM, REFERENCES, true ) ); + orPattern.addPattern( SearchEngine.createSearchPattern( "Hea*", CLASS, DECLARATIONS, true ) ); + + search( workspace, orPattern, scope, resultCollector ); + + Set matches = resultCollector.getSearchResults(); + + assertEquals( matches.size(), 3 ); + + orPattern = new OrPattern(); + orPattern.addPattern( SearchEngine.createSearchPattern( "b?", VAR, DECLARATIONS, true ) ); + orPattern.addPattern( SearchEngine.createSearchPattern( "a*Struct", FIELD, DECLARATIONS, true ) ); + orPattern.addPattern( SearchEngine.createSearchPattern( "::NS::NS2", NAMESPACE, REFERENCES, true ) ); + orPattern.addPattern( SearchEngine.createSearchPattern( "A::B::f( A )", METHOD, DECLARATIONS, true ) ); + + search( workspace, orPattern, scope, resultCollector ); + matches = resultCollector.getSearchResults(); + assertEquals( matches.size(), 6 ); + } } diff --git a/core/org.eclipse.cdt.core/search/ChangeLog b/core/org.eclipse.cdt.core/search/ChangeLog index f9e006af455..b163170197d 100644 --- a/core/org.eclipse.cdt.core/search/ChangeLog +++ b/core/org.eclipse.cdt.core/search/ChangeLog @@ -1,3 +1,8 @@ +2003-08-06 Andrew Niefer + - Create OrPattern which matches for search if any of its constituent patterns matches + - modified MatchLocator to support the OrPattern + - searching for All occurences now uses the OrPattern + 2003-08-01 Andrew Niefer - Modified BasicSearchResultCollector to only accept matches it has not already seen - fixed bug in finding a resource when entering includes diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/ICSearchPattern.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/ICSearchPattern.java index feed4d13f89..8dc2edc2acc 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/ICSearchPattern.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/ICSearchPattern.java @@ -32,7 +32,8 @@ public interface ICSearchPattern extends ICSearchConstants{ * @param node * @return */ - int matchLevel( ISourceElementCallbackDelegate node ); + int matchLevel( ISourceElementCallbackDelegate node, LimitTo limit ); - LimitTo getLimitTo(); + LimitTo getLimitTo(); + boolean canAccept( LimitTo limit ); } 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 f319aa554a8..c3feac12c04 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 @@ -57,13 +57,17 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte _caseSensitive = caseSensitive; _limitTo = limitTo; } - + + public CSearchPattern() { + super(); + } + public LimitTo getLimitTo(){ return _limitTo; } - public CSearchPattern() { - super(); + public boolean canAccept(LimitTo limit) { + return ( limit == getLimitTo() ); } public static CSearchPattern createPattern( String patternString, SearchFor searchFor, LimitTo limitTo, int matchMode, boolean caseSensitive ){ @@ -97,6 +101,13 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte * @return */ private static CSearchPattern createNamespacePattern(String patternString, LimitTo limitTo, int matchMode, boolean caseSensitive) { + if( limitTo == ALL_OCCURRENCES ){ + OrPattern orPattern = new OrPattern(); + orPattern.addPattern( createNamespacePattern( patternString, DECLARATIONS, matchMode, caseSensitive ) ); + orPattern.addPattern( createNamespacePattern( patternString, REFERENCES, matchMode, caseSensitive ) ); + return orPattern; + } + IScanner scanner = ParserFactory.createScanner( new StringReader( patternString ), "TEXT", new ScannerInfo(), ParserMode.QUICK_PARSE, null ); LinkedList list = scanForNames( scanner, null ); @@ -114,6 +125,14 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte * @return */ private static CSearchPattern createFunctionPattern(String patternString, LimitTo limitTo, int matchMode, boolean caseSensitive) { + if( limitTo == ALL_OCCURRENCES ){ + OrPattern orPattern = new OrPattern(); + orPattern.addPattern( createFunctionPattern( patternString, DECLARATIONS, matchMode, caseSensitive ) ); + orPattern.addPattern( createFunctionPattern( patternString, REFERENCES, matchMode, caseSensitive ) ); + orPattern.addPattern( createFunctionPattern( patternString, DEFINITIONS, matchMode, caseSensitive ) ); + return orPattern; + } + int index = patternString.indexOf( '(' ); String paramString = ( index == -1 ) ? "" : patternString.substring( index ); @@ -139,6 +158,12 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte * @return */ private static CSearchPattern createVariablePattern(String patternString, LimitTo limitTo, int matchMode, boolean caseSensitive) { + if( limitTo == ALL_OCCURRENCES ){ + OrPattern orPattern = new OrPattern(); + orPattern.addPattern( createVariablePattern( patternString, DECLARATIONS, matchMode, caseSensitive ) ); + orPattern.addPattern( createVariablePattern( patternString, REFERENCES, matchMode, caseSensitive ) ); + return orPattern; + } return new VariableDeclarationPattern( patternString.toCharArray(), matchMode, limitTo, caseSensitive ); } @@ -150,6 +175,13 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte * @return */ private static CSearchPattern createFieldPattern(String patternString, LimitTo limitTo, int matchMode, boolean caseSensitive) { + if( limitTo == ALL_OCCURRENCES ){ + OrPattern orPattern = new OrPattern(); + orPattern.addPattern( createFieldPattern( patternString, DECLARATIONS, matchMode, caseSensitive ) ); + orPattern.addPattern( createFieldPattern( patternString, REFERENCES, matchMode, caseSensitive ) ); + return orPattern; + } + IScanner scanner = ParserFactory.createScanner( new StringReader( patternString ), "TEXT", new ScannerInfo(), ParserMode.QUICK_PARSE, null ); LinkedList list = scanForNames( scanner, null ); @@ -167,7 +199,15 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte * @return */ private static CSearchPattern createMethodPattern(String patternString, LimitTo limitTo, int matchMode, boolean caseSensitive) { - + + if( limitTo == ALL_OCCURRENCES ){ + OrPattern orPattern = new OrPattern(); + orPattern.addPattern( createMethodPattern( patternString, DECLARATIONS, matchMode, caseSensitive ) ); + orPattern.addPattern( createMethodPattern( patternString, REFERENCES, matchMode, caseSensitive ) ); + orPattern.addPattern( createMethodPattern( patternString, DEFINITIONS, matchMode, caseSensitive ) ); + return orPattern; + } + int index = patternString.indexOf( '(' ); String paramString = ( index == -1 ) ? "" : patternString.substring( index ); String nameString = ( index == -1 ) ? patternString : patternString.substring( 0, index ); @@ -197,6 +237,14 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte * @return */ private static CSearchPattern createClassPattern(String patternString, SearchFor searchFor, LimitTo limitTo, int matchMode, boolean caseSensitive) { + + if( limitTo == ALL_OCCURRENCES ){ + OrPattern orPattern = new OrPattern(); + orPattern.addPattern( createClassPattern( patternString, searchFor, DECLARATIONS, matchMode, caseSensitive ) ); + orPattern.addPattern( createClassPattern( patternString, searchFor, REFERENCES, matchMode, caseSensitive ) ); + return orPattern; + } + IScanner scanner = ParserFactory.createScanner( new StringReader( patternString ), "TEXT", new ScannerInfo(), ParserMode.QUICK_PARSE, null ); IToken token = null; diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/ClassDeclarationPattern.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/ClassDeclarationPattern.java index 286da32e0f5..3a38f03192c 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/ClassDeclarationPattern.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/ClassDeclarationPattern.java @@ -57,10 +57,13 @@ public class ClassDeclarationPattern extends CSearchPattern { classKind = kind; } - public int matchLevel( ISourceElementCallbackDelegate node ){ + public int matchLevel( ISourceElementCallbackDelegate node, LimitTo limit ){ if( !( node instanceof IASTClassSpecifier ) && !( node instanceof IASTEnumerationSpecifier ) ) return IMPOSSIBLE_MATCH; + + if( ! canAccept( limit ) ) + return IMPOSSIBLE_MATCH; String nodeName = ((IASTOffsetableNamedElement)node).getName(); @@ -205,5 +208,4 @@ public class ClassDeclarationPattern extends CSearchPattern { return true; } - } diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FieldDeclarationPattern.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FieldDeclarationPattern.java index 0d02a79cf81..3b215a37257 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FieldDeclarationPattern.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FieldDeclarationPattern.java @@ -48,12 +48,12 @@ public class FieldDeclarationPattern extends VariableDeclarationPattern { } - public int matchLevel(ISourceElementCallbackDelegate node) { + public int matchLevel(ISourceElementCallbackDelegate node, LimitTo limit ) { if( !(node instanceof IASTField) ){ return IMPOSSIBLE_MATCH; } - if( super.matchLevel( node ) == IMPOSSIBLE_MATCH ){ + if( super.matchLevel( node, limit ) == IMPOSSIBLE_MATCH ){ return IMPOSSIBLE_MATCH; } diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FunctionDeclarationPattern.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FunctionDeclarationPattern.java index 44ca4ce31b3..88fa2829f7f 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FunctionDeclarationPattern.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FunctionDeclarationPattern.java @@ -55,8 +55,8 @@ public class FunctionDeclarationPattern extends CSearchPattern { /* (non-Javadoc) * @see org.eclipse.cdt.core.search.ICSearchPattern#matchLevel(org.eclipse.cdt.core.parser.ast.IASTOffsetableElement) */ - public int matchLevel(ISourceElementCallbackDelegate node) { - if( !( node instanceof IASTFunction ) ) + public int matchLevel(ISourceElementCallbackDelegate node, LimitTo limit ) { + if( !( node instanceof IASTFunction ) || !canAccept( limit ) ) return IMPOSSIBLE_MATCH; IASTFunction function = (IASTFunction) node; diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java index e834da4c190..dcfb004dd90 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java @@ -97,7 +97,6 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants } public void acceptProblem(IProblem problem) { } - public void acceptMacro(IASTMacro macro) { } public void acceptUsingDirective(IASTUsingDirective usageDirective) { } public void acceptUsingDeclaration(IASTUsingDeclaration usageDeclaration) { } public void acceptASMDefinition(IASTASMDefinition asmDefinition) { } @@ -116,65 +115,69 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants public void exitTemplateExplicitInstantiation(IASTTemplateInstantiation instantiation) { } public void exitLinkageSpecification(IASTLinkageSpecification linkageSpec) { } + public void acceptMacro(IASTMacro macro){ + check( DECLARATIONS, macro ); + } + public void acceptVariable(IASTVariable variable){ - check( DECLARATIONS, VariableDeclarationPattern.class, variable ); + check( DECLARATIONS, variable ); } public void acceptField(IASTField field){ - check( DECLARATIONS, FieldDeclarationPattern.class, field ); + check( DECLARATIONS, field ); } public void acceptEnumerationSpecifier(IASTEnumerationSpecifier enumeration){ - check( DECLARATIONS, ClassDeclarationPattern.class, enumeration ); + check( DECLARATIONS, enumeration ); Iterator iter = enumeration.getEnumerators(); while( iter.hasNext() ){ - check ( DECLARATIONS, FieldDeclarationPattern.class, (ISourceElementCallbackDelegate) iter.next() ); + check ( DECLARATIONS, (ISourceElementCallbackDelegate) iter.next() ); } } public void acceptFunctionDeclaration(IASTFunction function){ - check( DECLARATIONS, FunctionDeclarationPattern.class, function ); + check( DECLARATIONS, function ); } public void acceptMethodDeclaration(IASTMethod method){ - check( DECLARATIONS, MethodDeclarationPattern.class, method ); + check( DECLARATIONS, method ); } public void acceptClassReference(IASTClassReference reference) { - check( REFERENCES, ClassDeclarationPattern.class, reference ); + check( REFERENCES, reference ); } public void acceptNamespaceReference( IASTNamespaceReference reference ){ - check( REFERENCES, NamespaceDeclarationPattern.class, reference ); + check( REFERENCES, reference ); } public void acceptVariableReference( IASTVariableReference reference ){ - check( REFERENCES, VariableDeclarationPattern.class, reference ); + check( REFERENCES, reference ); } public void acceptFieldReference( IASTFieldReference reference ){ - check( REFERENCES, FieldDeclarationPattern.class, reference ); + check( REFERENCES, reference ); } public void acceptEnumerationReference( IASTEnumerationReference reference ){ - check( REFERENCES, ClassDeclarationPattern.class, reference ); + check( REFERENCES, reference ); } public void acceptFunctionReference( IASTFunctionReference reference ){ - check( REFERENCES, FunctionDeclarationPattern.class, reference ); + check( REFERENCES, reference ); } public void acceptMethodReference( IASTMethodReference reference ){ - check( REFERENCES, MethodDeclarationPattern.class, reference ); + check( REFERENCES, reference ); } public void enterFunctionBody(IASTFunction function){ - check( DEFINITIONS, FunctionDeclarationPattern.class, function ); + check( DEFINITIONS, function ); pushScope( function ); } public void enterMethodBody(IASTMethod method) { - check( DEFINITIONS, MethodDeclarationPattern.class, method ); + check( DEFINITIONS, method ); pushScope( method ); } @@ -183,12 +186,12 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants } public void enterNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) { - check( DECLARATIONS, NamespaceDeclarationPattern.class, namespaceDefinition ); + check( DECLARATIONS, namespaceDefinition ); pushScope( namespaceDefinition ); } public void enterClassSpecifier(IASTClassSpecifier classSpecification) { - check( DECLARATIONS, ClassDeclarationPattern.class, classSpecification ); + check( DECLARATIONS, classSpecification ); pushScope( classSpecification ); } @@ -366,23 +369,21 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants } } - private void check( LimitTo limit, Class patternClass, ISourceElementCallbackDelegate node ){ - if( searchPattern.getLimitTo() != limit && searchPattern.getLimitTo() != ALL_OCCURRENCES ) + private void check( LimitTo limit, ISourceElementCallbackDelegate node ){ + if( !searchPattern.canAccept( limit ) ) return; - if( searchPattern.getClass() == patternClass ){ - int level = ICSearchPattern.IMPOSSIBLE_MATCH; - - if( node instanceof IASTReference ){ - level = searchPattern.matchLevel( ((IASTReference)node).getReferencedElement() ); - } else { - level = searchPattern.matchLevel( node ); - } - - if( level != ICSearchPattern.IMPOSSIBLE_MATCH ) - { - report( node, level ); - } + int level = ICSearchPattern.IMPOSSIBLE_MATCH; + + if( node instanceof IASTReference ){ + level = searchPattern.matchLevel( ((IASTReference)node).getReferencedElement(), limit ); + } else { + level = searchPattern.matchLevel( node, limit ); + } + + if( level != ICSearchPattern.IMPOSSIBLE_MATCH ) + { + report( node, level ); } } 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 d33d93af16e..cdbcd5f0d19 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 @@ -45,12 +45,12 @@ public class MethodDeclarationPattern extends FunctionDeclarationPattern { } - public int matchLevel(ISourceElementCallbackDelegate node) { - if( !(node instanceof IASTMethod) ){ + public int matchLevel(ISourceElementCallbackDelegate node, LimitTo limit ) { + if( !(node instanceof IASTMethod) || !canAccept( limit ) ){ return IMPOSSIBLE_MATCH; } - if( super.matchLevel( node ) == IMPOSSIBLE_MATCH ){ + if( super.matchLevel( node, limit ) == IMPOSSIBLE_MATCH ){ return IMPOSSIBLE_MATCH; } diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/NamespaceDeclarationPattern.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/NamespaceDeclarationPattern.java index e16130443b0..9eb162d9b4f 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/NamespaceDeclarationPattern.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/NamespaceDeclarationPattern.java @@ -51,8 +51,8 @@ public class NamespaceDeclarationPattern extends CSearchPattern { /* (non-Javadoc) * @see org.eclipse.cdt.core.search.ICSearchPattern#matchLevel(org.eclipse.cdt.core.parser.ast.IASTOffsetableElement) */ - public int matchLevel(ISourceElementCallbackDelegate node) { - if( !( node instanceof IASTNamespaceDefinition ) ) + public int matchLevel(ISourceElementCallbackDelegate node, LimitTo limit ) { + if( !( node instanceof IASTNamespaceDefinition ) || !canAccept( limit ) ) return IMPOSSIBLE_MATCH; IASTNamespaceDefinition namespace = (IASTNamespaceDefinition)node; diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/OrPattern.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/OrPattern.java new file mode 100644 index 00000000000..5a35d8b60c1 --- /dev/null +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/OrPattern.java @@ -0,0 +1,118 @@ +/******************************************************************************* + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Corp. - Rational Software - initial implementation + ******************************************************************************/ +/* + * Created on Aug 6, 2003 + */ +package org.eclipse.cdt.internal.core.search.matching; + +import java.io.IOException; +import java.util.Iterator; +import java.util.LinkedList; + +import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; +import org.eclipse.cdt.core.search.ICSearchPattern; +import org.eclipse.cdt.core.search.ICSearchScope; +import org.eclipse.cdt.internal.core.index.IEntryResult; +import org.eclipse.cdt.internal.core.index.impl.IndexInput; +import org.eclipse.cdt.internal.core.search.IIndexSearchRequestor; +import org.eclipse.core.runtime.IProgressMonitor; + + +/** + * @author aniefer + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class OrPattern extends CSearchPattern { + + public OrPattern(){ + super(); + patterns = new LinkedList(); + } + + /** + * @param pattern + */ + public void addPattern( ICSearchPattern pattern) { + if( pattern != null ) + patterns.add( pattern ); + } + + public int matchLevel(ISourceElementCallbackDelegate node, LimitTo limit ) { + Iterator iter = patterns.iterator(); + int size = patterns.size(); + + int result = IMPOSSIBLE_MATCH; + + for( int i = 0; i < size; i++ ){ + ICSearchPattern pattern = (ICSearchPattern) iter.next(); + result = pattern.matchLevel( node, limit ); + if( result != IMPOSSIBLE_MATCH ) + break; + } + + return result; + } + + public boolean canAccept(LimitTo limit) { + if( limit == ALL_OCCURRENCES ){ + return true; + } + + Iterator iter = patterns.iterator(); + int size = patterns.size(); + + for( int i = 0; i < size; i++ ){ + ICSearchPattern pattern = (ICSearchPattern) iter.next(); + if( pattern.canAccept( limit ) ) + return true; + } + + return false; + } + + public void findIndexMatches(IndexInput input, IIndexSearchRequestor requestor, int detailLevel, IProgressMonitor progressMonitor, ICSearchScope scope) throws IOException { + Iterator iter = patterns.iterator(); + int size = patterns.size(); + + for( int i = 0; i < size; i++ ){ + CSearchPattern pattern = (CSearchPattern) iter.next(); + pattern.findIndexMatches( input, requestor, detailLevel, progressMonitor, scope ); + } + } + + public void feedIndexRequestor( IIndexSearchRequestor requestor, int detailLevel, int[] references, IndexInput input, ICSearchScope scope ) + throws IOException { + //never called for OrPattern + } + + protected void resetIndexInfo() { + //never called for OrPattern + } + + protected void decodeIndexEntry(IEntryResult entryResult) { + //never called for OrPattern + } + + public char[] indexEntryPrefix() { + //never called for OrPattern + return null; + } + + protected boolean matchIndexEntry() { + //never called for OrPattern + return false; + } + + private LinkedList patterns; + +} diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/VariableDeclarationPattern.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/VariableDeclarationPattern.java index 76826448a2d..131a321d163 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/VariableDeclarationPattern.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/VariableDeclarationPattern.java @@ -49,8 +49,8 @@ public class VariableDeclarationPattern extends CSearchPattern { /* (non-Javadoc) * @see org.eclipse.cdt.core.search.ICSearchPattern#matchLevel(org.eclipse.cdt.core.parser.ast.IASTOffsetableElement) */ - public int matchLevel(ISourceElementCallbackDelegate node) { - if( !(node instanceof IASTVariable) ){ + public int matchLevel(ISourceElementCallbackDelegate node, LimitTo limit ) { + if( !(node instanceof IASTVariable) || !canAccept( limit ) ){ return IMPOSSIBLE_MATCH; }