Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Search: OrPattern

core:
- created new search pattern OrPattern, which returns a match if any of 
its constituent pattens return a match.

To use it, do something like:
OrPattern orPattern = new OrPattern();
orPattern.addPattern( SearchEngine.createSearchPattern( "::NS::B::e", 
ENUM, REFERENCES, true ) );
orPattern.addPattern( SearchEngine.createSearchPattern( "Hea*", CLASS, 
DECLARATIONS, true ) );

Searching for all occurences of something now uses the OrPattern. ie, 
SearchEngine.createSearchPattern( "A", TYPE, ALL_OCCURENCES, true );
is the same as
OrPattern orPattern = new OrPattern();
orPattern.addPattern( SearchEngine.createSearchPattern( "f", FUNCTION, 
DECLARATIONS, true ) );
orPattern.addPattern( SearchEngine.createSearchPattern( "f", FUNCTION, 
REFERENCES, true ) );
orPattern.addPattern( SearchEngine.createSearchPattern( "f", FUNCTION, 
DEFINITIONS, true ) );

For large projects this is much more efficient than the old method of 
finding all occurences

core.tests:
- added ClassDeclarationPatternTests.testAllOccurences
- added OtherPatternTests.testOrPattern

-Andrew

Index: search/ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/search/ChangeLog,v
retrieving revision 1.12
diff -u -r1.12 ChangeLog
--- search/ChangeLog	1 Aug 2003 19:26:50 -0000	1.12
+++ search/ChangeLog	6 Aug 2003 21:16:51 -0000
@@ -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
Index: search/org/eclipse/cdt/core/search/ICSearchPattern.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/ICSearchPattern.java,v
retrieving revision 1.4
diff -u -r1.4 ICSearchPattern.java
--- search/org/eclipse/cdt/core/search/ICSearchPattern.java	24 Jul 2003 14:20:16 -0000	1.4
+++ search/org/eclipse/cdt/core/search/ICSearchPattern.java	6 Aug 2003 21:16:51 -0000
@@ -32,7 +32,8 @@
 	 * @param node
 	 * @return
 	 */
-	int matchLevel( ISourceElementCallbackDelegate node );
+	int matchLevel( ISourceElementCallbackDelegate node, LimitTo limit );
 	
-	LimitTo   getLimitTo();
+	LimitTo getLimitTo();
+	boolean	canAccept( LimitTo limit );
 }
Index: search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java,v
retrieving revision 1.12
diff -u -r1.12 CSearchPattern.java
--- search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java	29 Jul 2003 12:40:17 -0000	1.12
+++ search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java	6 Aug 2003 21:16:51 -0000
@@ -57,13 +57,17 @@
 		_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 @@
 	 * @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 @@
 	 * @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 @@
 	 * @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 @@
 	 * @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 @@
 	 * @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 @@
 	 * @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;
Index: search/org/eclipse/cdt/internal/core/search/matching/ClassDeclarationPattern.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/ClassDeclarationPattern.java,v
retrieving revision 1.9
diff -u -r1.9 ClassDeclarationPattern.java
--- search/org/eclipse/cdt/internal/core/search/matching/ClassDeclarationPattern.java	29 Jul 2003 12:40:17 -0000	1.9
+++ search/org/eclipse/cdt/internal/core/search/matching/ClassDeclarationPattern.java	6 Aug 2003 21:16:51 -0000
@@ -57,10 +57,13 @@
 		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 @@
 		
 		return true;
 	}
-	
 }
Index: search/org/eclipse/cdt/internal/core/search/matching/FieldDeclarationPattern.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FieldDeclarationPattern.java,v
retrieving revision 1.5
diff -u -r1.5 FieldDeclarationPattern.java
--- search/org/eclipse/cdt/internal/core/search/matching/FieldDeclarationPattern.java	29 Jul 2003 12:40:17 -0000	1.5
+++ search/org/eclipse/cdt/internal/core/search/matching/FieldDeclarationPattern.java	6 Aug 2003 21:16:51 -0000
@@ -48,12 +48,12 @@
 	}
 
 
-	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;
 		}
 		
Index: search/org/eclipse/cdt/internal/core/search/matching/FunctionDeclarationPattern.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FunctionDeclarationPattern.java,v
retrieving revision 1.7
diff -u -r1.7 FunctionDeclarationPattern.java
--- search/org/eclipse/cdt/internal/core/search/matching/FunctionDeclarationPattern.java	29 Jul 2003 12:40:17 -0000	1.7
+++ search/org/eclipse/cdt/internal/core/search/matching/FunctionDeclarationPattern.java	6 Aug 2003 21:16:51 -0000
@@ -55,8 +55,8 @@
 	/* (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;
Index: search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java,v
retrieving revision 1.16
diff -u -r1.16 MatchLocator.java
--- search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java	1 Aug 2003 19:26:50 -0000	1.16
+++ search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java	6 Aug 2003 21:16:51 -0000
@@ -97,7 +97,6 @@
 	}
 
 	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 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 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 @@
 		}
 	}
 
-	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 );
 		}
 	}
 	
Index: search/org/eclipse/cdt/internal/core/search/matching/MethodDeclarationPattern.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MethodDeclarationPattern.java,v
retrieving revision 1.5
diff -u -r1.5 MethodDeclarationPattern.java
--- search/org/eclipse/cdt/internal/core/search/matching/MethodDeclarationPattern.java	29 Jul 2003 12:40:17 -0000	1.5
+++ search/org/eclipse/cdt/internal/core/search/matching/MethodDeclarationPattern.java	6 Aug 2003 21:16:51 -0000
@@ -45,12 +45,12 @@
 	}
 
 
-	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;
 		}
 		
Index: search/org/eclipse/cdt/internal/core/search/matching/NamespaceDeclarationPattern.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/NamespaceDeclarationPattern.java,v
retrieving revision 1.5
diff -u -r1.5 NamespaceDeclarationPattern.java
--- search/org/eclipse/cdt/internal/core/search/matching/NamespaceDeclarationPattern.java	29 Jul 2003 12:40:17 -0000	1.5
+++ search/org/eclipse/cdt/internal/core/search/matching/NamespaceDeclarationPattern.java	6 Aug 2003 21:16:51 -0000
@@ -51,8 +51,8 @@
 	/* (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;
Index: search/org/eclipse/cdt/internal/core/search/matching/OrPattern.java
===================================================================
RCS file: search/org/eclipse/cdt/internal/core/search/matching/OrPattern.java
diff -N search/org/eclipse/cdt/internal/core/search/matching/OrPattern.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ search/org/eclipse/cdt/internal/core/search/matching/OrPattern.java	6 Aug 2003 21:16:51 -0000
@@ -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;
+
+}
Index: search/org/eclipse/cdt/internal/core/search/matching/VariableDeclarationPattern.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/VariableDeclarationPattern.java,v
retrieving revision 1.5
diff -u -r1.5 VariableDeclarationPattern.java
--- search/org/eclipse/cdt/internal/core/search/matching/VariableDeclarationPattern.java	29 Jul 2003 12:40:17 -0000	1.5
+++ search/org/eclipse/cdt/internal/core/search/matching/VariableDeclarationPattern.java	6 Aug 2003 21:16:51 -0000
@@ -49,8 +49,8 @@
 	/* (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;
 		}
 		
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/ChangeLog,v
retrieving revision 1.50
diff -u -r1.50 ChangeLog
--- ChangeLog	1 Aug 2003 19:26:55 -0000	1.50
+++ ChangeLog	6 Aug 2003 20:57:29 -0000
@@ -1,3 +1,7 @@
+2003-08-06 Andrew Niefer
+	Added ClassDeclarationPatternTests.testAllOccurences
+	Added OtherPatternTests.testOrPattern
+
 2003-08-01 Andrew Niefer
 	Added resources/search/header.h
 	Added ClassDeclarationPatternTests.testHeadersVisitedTwice()
Index: search/org/eclipse/cdt/core/search/tests/ClassDeclarationPatternTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/ClassDeclarationPatternTests.java,v
retrieving revision 1.9
diff -u -r1.9 ClassDeclarationPatternTests.java
--- search/org/eclipse/cdt/core/search/tests/ClassDeclarationPatternTests.java	1 Aug 2003 19:26:55 -0000	1.9
+++ search/org/eclipse/cdt/core/search/tests/ClassDeclarationPatternTests.java	6 Aug 2003 20:57:29 -0000
@@ -23,6 +23,7 @@
 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 @@
 		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 );
+	}
 }
Index: search/org/eclipse/cdt/core/search/tests/OtherPatternTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/OtherPatternTests.java,v
retrieving revision 1.4
diff -u -r1.4 OtherPatternTests.java
--- search/org/eclipse/cdt/core/search/tests/OtherPatternTests.java	1 Aug 2003 19:26:55 -0000	1.4
+++ search/org/eclipse/cdt/core/search/tests/OtherPatternTests.java	6 Aug 2003 20:57:29 -0000
@@ -21,6 +21,7 @@
 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;
 
 /**
@@ -144,6 +145,28 @@
 		
 		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 );
 	}
 
 }

Back to the top