[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] Search: invoke parser and initial tests
|
cdt.core:
- Modified ICSearchConstants to use
classes (SearchFor & LimitTo) instead of int for constants
- Modified MatchLocator to actually
invoke the parser to do the search
cdt.core.tests:
-
Added new source Folder search
-
Added search/ClassDeclarationPatternTests::testMatchSimpleDeclaration
-
Added search/ClassDeclarationPatternTests::testMatchNamespaceNestedDeclaration
-
Added new resource folder search & containing file classDecl.cpp
-
Added new failures package ord.eclipse.cdt.core.search.failedTests
-
Added new failing test PatternsFailedTests::testBug39652
*
Note that both the ClassDeclarationPatternTests and PatternsFailedTests
must be run as Plugin Tests *
cdt.ui:
-
Updated Search classes to reflect changes to ICSearchConstants.
-Andrew
Index: search/ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/search/ChangeLog,v
retrieving revision 1.2
diff -u -r1.2 ChangeLog
--- search/ChangeLog 28 Jun 2003 19:56:54 -0000 1.2
+++ search/ChangeLog 4 Jul 2003 15:55:57 -0000
@@ -1,3 +1,8 @@
+2003-07-04 Andrew Niefer
+ * Modified ICSearchConstants to use new nested classes SearchFor and LimitTo instead of int
+ for stronger type safety
+ * Updated MatchLocator to invoke parser to do actual search.
+
2003-06-27 Andrew Niefer
Modified:
search/org.eclipse.cdt.core.search.matching/MatchLocator.java
Index: search/org/eclipse/cdt/core/search/ICSearchConstants.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/ICSearchConstants.java,v
retrieving revision 1.2
diff -u -r1.2 ICSearchConstants.java
--- search/org/eclipse/cdt/core/search/ICSearchConstants.java 27 Jun 2003 14:31:27 -0000 1.2
+++ search/org/eclipse/cdt/core/search/ICSearchConstants.java 4 Jul 2003 15:55:57 -0000
@@ -33,64 +33,65 @@
* The nature of searched element or the nature
* of match in unknown.
*/
- int UNKNOWN = -1;
+ public static final SearchFor UNKNOWN_SEARCH_FOR = new SearchFor( -1 );
+ public static final LimitTo UNKNOWN_LIMIT_TO = new LimitTo( -1 );
/* Nature of searched element */
/**
* The searched element is a type.
*/
- int TYPE= 0;
+ public static final SearchFor TYPE = new SearchFor( 0 );
/**
* The searched element is a function.
*/
- int FUNCTION= 1;
+ public static final SearchFor FUNCTION = new SearchFor( 1 );
/**
* The searched element is a namespace.
*/
- int NAMESPACE= 2;
+ public static final SearchFor NAMESPACE = new SearchFor( 2 );
/**
* The searched element is a constructor.
*/
- int CONSTRUCTOR= 3;
+ public static final SearchFor CONSTRUCTOR = new SearchFor( 3 );
/**
* The searched element is a member.
*/
- int MEMBER= 4;
+ public static final SearchFor MEMBER = new SearchFor( 4 );
/**
* The searched element is a variable.
* More selective than using TYPE
*/
- int VAR= 5;
+ public static final SearchFor VAR = new SearchFor( 5 );
/**
* The searched element is a class.
* More selective than using TYPE
*/
- int CLASS= 6;
+ public static final SearchFor CLASS = new SearchFor( 6 );
/**
* The searched element is a struct.
* More selective than using TYPE
*/
- int STRUCT= 7;
+ public static final SearchFor STRUCT = new SearchFor( 7 );
/**
* The searched element is a enum.
* More selective than using TYPE
*/
- int ENUM= 8;
+ public static final SearchFor ENUM = new SearchFor( 8 );
/**
* The searched element is a union.
* More selective than using TYPE
*/
- int UNION= 9;
+ public static final SearchFor UNION = new SearchFor( 9 );
/* Nature of match */
@@ -100,7 +101,7 @@
* Can be used in conjunction with any of the nature of searched elements
* so as to better narrow down the search.
*/
- int DECLARATIONS= 0;
+ public static final LimitTo DECLARATIONS = new LimitTo( 0 );
/**
* The search result is a type that implements an interface.
@@ -109,7 +110,7 @@
* rather exclusively search for classes implementing an interface, or interfaces
* extending an interface.
*/
- int DEFINITIONS= 1;
+ public static final LimitTo DEFINITIONS = new LimitTo( 1 );
/**
* The search result is a reference.
@@ -118,7 +119,7 @@
* References can contain implementers since they are more generic kind
* of matches.
*/
- int REFERENCES= 2;
+ public static final LimitTo REFERENCES = new LimitTo( 2 );
/**
* The search result is a declaration, a reference, or an implementer
@@ -126,7 +127,7 @@
* Can be used in conjunction with any of the nature of searched elements
* so as to better narrow down the search.
*/
- int ALL_OCCURRENCES= 3;
+ public static final LimitTo ALL_OCCURRENCES = new LimitTo( 3 );
/* Syntactic match modes */
@@ -180,4 +181,19 @@
int WAIT_UNTIL_READY_TO_SEARCH = IJob.WaitUntilReady;
+ public class SearchFor{
+ private SearchFor( int value )
+ {
+ this.value = value;
+ }
+ private final int value;
+ }
+
+ public class LimitTo {
+ private LimitTo( int value )
+ {
+ this.value = value;
+ }
+ private final int value;
+ }
}
Index: search/org/eclipse/cdt/core/search/ICSearchResultCollector.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/ICSearchResultCollector.java,v
retrieving revision 1.2
diff -u -r1.2 ICSearchResultCollector.java
--- search/org/eclipse/cdt/core/search/ICSearchResultCollector.java 28 Jun 2003 19:56:54 -0000 1.2
+++ search/org/eclipse/cdt/core/search/ICSearchResultCollector.java 4 Jul 2003 15:55:57 -0000
@@ -16,6 +16,7 @@
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
/**
@@ -74,5 +75,17 @@
* @return a progress monitor or null if no progress monitor is provided
*/
public IProgressMonitor getProgressMonitor();
+ /**
+ * @param currentPath
+ * @param start
+ * @param end
+ * @param object
+ * @param accuracyLevel
+ */
+ public void accept(IPath currentPath,
+ int start,
+ int end,
+ ICElement enclosingElement,
+ int accuracyLevel) throws CoreException;
}
Index: search/org/eclipse/cdt/core/search/SearchEngine.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/SearchEngine.java,v
retrieving revision 1.2
diff -u -r1.2 SearchEngine.java
--- search/org/eclipse/cdt/core/search/SearchEngine.java 28 Jun 2003 19:56:54 -0000 1.2
+++ search/org/eclipse/cdt/core/search/SearchEngine.java 4 Jul 2003 15:55:57 -0000
@@ -31,7 +31,7 @@
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
-public class SearchEngine {
+public class SearchEngine implements ICSearchConstants{
private boolean VERBOSE = false;
@@ -60,7 +60,7 @@
return null;
}
- public static ICSearchPattern createSearchPattern( String stringPattern, int searchFor, int limitTo, boolean isCaseSensitive){
+ public static ICSearchPattern createSearchPattern( String stringPattern, SearchFor searchFor, LimitTo limitTo, boolean isCaseSensitive){
int mode;
if( stringPattern.indexOf( '*' ) != -1 || stringPattern.indexOf( '?' ) != -1 ){
@@ -127,7 +127,7 @@
* @param _scope
* @param _collector
*/
- public void search(IWorkspace workspace, ICElement elementPattern, int limitTo, ICSearchScope scope, ICSearchResultCollector collector) {
+ public void search(IWorkspace workspace, ICElement elementPattern, LimitTo limitTo, ICSearchScope scope, ICSearchResultCollector collector) {
// TODO Auto-generated method stub
}
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.3
diff -u -r1.3 CSearchPattern.java
--- search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java 28 Jun 2003 19:56:54 -0000 1.3
+++ search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java 4 Jul 2003 15:55:57 -0000
@@ -22,6 +22,7 @@
import org.eclipse.cdt.core.parser.ParserFactory;
import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ScannerException;
+import org.eclipse.cdt.core.parser.ast.ClassKind;
import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.core.search.ICSearchPattern;
import org.eclipse.cdt.internal.core.search.CharOperation;
@@ -56,26 +57,23 @@
// TODO Auto-generated constructor stub
}
- public static CSearchPattern createPattern( String patternString, int searchFor, int limitTo, int matchMode, boolean caseSensitive ){
+ public static CSearchPattern createPattern( String patternString, SearchFor searchFor, LimitTo limitTo, int matchMode, boolean caseSensitive ){
if( patternString == null || patternString.length() == 0 ){
return null;
}
CSearchPattern pattern = null;
- switch( searchFor ){
- case ICSearchConstants.TYPE:
- pattern = createClassPattern( patternString, limitTo, matchMode, caseSensitive );
- break;
- //case ICSearchConstants.METHOD:
+ if( searchFor == TYPE || searchFor == CLASS || searchFor == STRUCT || searchFor == ENUM || searchFor == UNION ){
+ pattern = createClassPattern( patternString, searchFor, limitTo, matchMode, caseSensitive );
+ } else if ( searchFor == MEMBER ){
// pattern = createMethodPattern( patternString, limitTo, matchMode, caseSensitive );
- // break;
- case ICSearchConstants.CONSTRUCTOR:
- pattern = createConstructorPattern( patternString, limitTo, matchMode, caseSensitive );
- break;
+ } else if ( searchFor == CONSTRUCTOR ){
+ pattern = createConstructorPattern( patternString, limitTo, matchMode, caseSensitive );
+ }
//case ICSearchConstants.FIELD:
// pattern = createFieldPattern( patternString, limitTo, matchMode, caseSensitive );
// break;
- }
+
return pattern;
}
@@ -87,7 +85,7 @@
* @param caseSensitive
* @return
*/
- private static CSearchPattern createFieldPattern(String patternString, int limitTo, int matchMode, boolean caseSensitive) {
+ private static CSearchPattern createFieldPattern(String patternString, LimitTo limitTo, int matchMode, boolean caseSensitive) {
// TODO Auto-generated method stub
return null;
}
@@ -99,7 +97,7 @@
* @param caseSensitive
* @return
*/
- private static CSearchPattern createMethodPattern(String patternString, int limitTo, int matchMode, boolean caseSensitive) {
+ private static CSearchPattern createMethodPattern(String patternString, LimitTo limitTo, int matchMode, boolean caseSensitive) {
// TODO Auto-generated method stub
return null;
}
@@ -111,7 +109,7 @@
* @param caseSensitive
* @return
*/
- private static CSearchPattern createConstructorPattern(String patternString, int limitTo, int matchMode, boolean caseSensitive) {
+ private static CSearchPattern createConstructorPattern(String patternString, LimitTo limitTo, int matchMode, boolean caseSensitive) {
// TODO Auto-generated method stub
return null;
}
@@ -123,7 +121,7 @@
* @param caseSensitive
* @return
*/
- private static CSearchPattern createClassPattern(String patternString, int limitTo, int matchMode, boolean caseSensitive) {
+ private static CSearchPattern createClassPattern(String patternString, SearchFor searchFor, LimitTo limitTo, int matchMode, boolean caseSensitive) {
IScanner scanner = ParserFactory.createScanner( new StringReader( patternString ), "TEXT", null, null, ParserMode.QUICK_PARSE );
LinkedList list = new LinkedList();
@@ -147,9 +145,20 @@
} catch (EndOfFile e) {
} catch (ScannerException e) {
}
-
- char [][] qualifications = new char[1][];
- return new ClassDeclarationPattern( name.toCharArray(), (char[][])list.toArray( qualifications ), null, matchMode, caseSensitive );
+
+ ClassKind kind = null;
+ if( searchFor == CLASS ){
+ kind = ClassKind.CLASS;
+ } else if( searchFor == STRUCT ) {
+ kind = ClassKind.STRUCT;
+ } else if ( searchFor == ENUM ) {
+ kind = ClassKind.ENUM;
+ } else if ( searchFor == UNION ) {
+ kind = ClassKind.UNION;
+ }
+
+ char [][] qualifications = new char[0][];
+ return new ClassDeclarationPattern( name.toCharArray(), (char[][])list.toArray( qualifications ), kind, matchMode, caseSensitive );
}
protected boolean matchesName( char[] pattern, char[] name ){
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.2
diff -u -r1.2 ClassDeclarationPattern.java
--- search/org/eclipse/cdt/internal/core/search/matching/ClassDeclarationPattern.java 28 Jun 2003 19:56:54 -0000 1.2
+++ search/org/eclipse/cdt/internal/core/search/matching/ClassDeclarationPattern.java 4 Jul 2003 15:55:57 -0000
@@ -58,22 +58,34 @@
//check containing scopes
String [] qualifications = clsSpec.getFullyQualifiedName();
- int size = containingTypes.length;
- if( qualifications.length < size )
- return IMPOSSIBLE_MATCH;
+ if( qualifications != null ){
- for( int i = 0; i < containingTypes.length; i++ ){
- if( !matchesName( containingTypes[i], qualifications[i].toCharArray() ) ){
+ int size = containingTypes.length;
+ if( qualifications.length < size )
return IMPOSSIBLE_MATCH;
+
+ for( int i = 0; i < containingTypes.length; i++ ){
+ if( !matchesName( containingTypes[i], qualifications[i].toCharArray() ) ){
+ return IMPOSSIBLE_MATCH;
+ }
}
+ } else if( containingTypes.length > 0 ) {
+ return IMPOSSIBLE_MATCH;
}
//check type
- if( classKind != clsSpec.getClassKind() ){
+ if( classKind != null && classKind != clsSpec.getClassKind() ){
return IMPOSSIBLE_MATCH;
}
return ACCURATE_MATCH;
+ }
+
+ public char [] getName() {
+ return simpleName;
+ }
+ public char[] [] getContainingTypes () {
+ return containingTypes;
}
private char[] simpleName;
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.3
diff -u -r1.3 MatchLocator.java
--- search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java 28 Jun 2003 19:56:54 -0000 1.3
+++ search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java 4 Jul 2003 15:55:57 -0000
@@ -13,21 +13,33 @@
*/
package org.eclipse.cdt.internal.core.search.matching;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.Arrays;
+import java.util.HashMap;
import java.util.LinkedList;
+import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.IProblem;
+import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
+import org.eclipse.cdt.core.parser.ParserFactory;
+import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ast.*;
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.internal.core.model.IWorkingCopy;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Path;
@@ -88,15 +100,36 @@
String includePath = inclusion.getFullFileName();
IPath path = new Path( includePath );
- IResource resource = workspaceRoot.findMember( path, true );
- if( resource != null ){
- resourceStack.addFirst( currentResource );
- currentResource = resource;
+ IResource resource = null;
+
+ if( workspaceRoot != null ){
+ resource = workspaceRoot.findMember( path, true );
+ if( resource == null ){
+ IFile file = workspaceRoot.getFile( path );
+ try{
+ file.createLink( path, 0, null );
+ } catch ( CoreException e ){
+ file = null;
+ }
+ resource = file;
+ }
}
+
+ resourceStack.addFirst( ( currentResource != null ) ? (Object)currentResource : (Object)currentPath );
+
+ currentResource = resource;
+ currentPath = ( resource == null ) ? path : null;
}
public void exitInclusion(IASTInclusion inclusion) {
- currentResource = (IResource) resourceStack.removeFirst();
+ Object obj = resourceStack.removeFirst();
+ if( obj instanceof IResource ){
+ currentResource = (IResource)obj;
+ currentPath = null;
+ } else {
+ currentPath = (IPath) obj;
+ currentResource = null;
+ }
}
public void enterClassSpecifier(IASTClassSpecifier classSpecification) {
@@ -109,16 +142,100 @@
}
public void locateMatches( String [] paths, IWorkspace workspace, IWorkingCopy[] workingCopies ){
- workspaceRoot = workspace.getRoot();
+ workspaceRoot = (workspace != null) ? workspace.getRoot() : null;
+
+ HashMap wcPaths = new HashMap();
+ int wcLength = (workingCopies == null) ? 0 : workingCopies.length;
+ if( wcLength > 0 ){
+ String [] newPaths = new String[ wcLength ];
+
+ for( int i = 0; i < wcLength; i++ ){
+ IWorkingCopy workingCopy = workingCopies[ i ];
+ String path = workingCopy.getOriginalElement().getPath().toString();
+ wcPaths.put( path, workingCopy );
+ newPaths[ i ] = path;
+ }
+
+ int len = paths.length;
+ String [] tempArray = new String[ len + wcLength ];
+ System.arraycopy( paths, 0, tempArray, 0, len );
+ System.arraycopy( newPaths, 0, tempArray, len, wcLength );
+ paths = tempArray;
+ }
+
+ Arrays.sort( paths );
+
+ int length = paths.length;
+ if( progressMonitor != null ){
+ progressMonitor.beginTask( "", length );
+ }
+
+ for( int i = 0; i < length; i++ ){
+ if( progressMonitor != null && progressMonitor.isCanceled() ){
+ throw new OperationCanceledException();
+ }
+
+ String pathString = paths[ i ];
+
+ //skip duplicates
+ if( i > 0 && pathString.equals( paths[ i - 1 ] ) ) continue;
+
+ Reader reader = null;
+ if( workspaceRoot != null ){
+ IWorkingCopy workingCopy = (IWorkingCopy)wcPaths.get( pathString );
+
+ if( workingCopy != null ){
+ currentResource = workingCopy.getOriginalElement().getResource();
+ } else {
+ currentResource = workspaceRoot.findMember( pathString, true );
+ }
+
+ try{
+ if( currentResource == null ){
+ IPath path = new Path( pathString );
+ IFile file = workspaceRoot.getFile( path );
+ file.createLink( path, 0, null );
+ }
+ if( currentResource != null && currentResource instanceof IFile ){
+ IFile file = (IFile) currentResource;
+ reader = new InputStreamReader( file.getContents() );
+ } else continue;
+ } catch ( CoreException e ){
+ continue;
+ }
+ } else {
+ IPath path = new Path( pathString );
+ try {
+ currentPath = path;
+ reader = new FileReader( path.toFile() );
+ } catch (FileNotFoundException e) {
+ continue;
+ }
+ }
+
+ IScanner scanner = ParserFactory.createScanner( reader, pathString, null, null, ParserMode.QUICK_PARSE );
+ IParser parser = ParserFactory.createParser( scanner, null, ParserMode.QUICK_PARSE );
+ parser.setRequestor( this );
+
+ parser.parse();
+ }
}
- protected void report( IASTOffsetableElement node, int accuracyLevel ){
+ protected void report( IASTOffsetableNamedElement node, int accuracyLevel ){
try {
- resultCollector.accept( currentResource,
- node.getElementStartingOffset(),
- node.getElementEndingOffset(),
- null,
- accuracyLevel );
+ if( currentResource != null ){
+ resultCollector.accept( currentResource,
+ node.getElementNameOffset(),
+ node.getElementNameOffset() + node.getName().length(),
+ null,
+ accuracyLevel );
+ } else if( currentPath != null ){
+ resultCollector.accept( currentPath,
+ node.getElementStartingOffset(),
+ node.getElementEndingOffset(),
+ null,
+ accuracyLevel );
+ }
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -128,8 +245,9 @@
private ICSearchPattern searchPattern;
private ICSearchResultCollector resultCollector;
private IProgressMonitor progressMonitor;
- private IResource currentResource;
+ private IResource currentResource = null;
+ private IPath currentPath = null;
private ICSearchScope searchScope;
- private LinkedList resourceStack;
+ private LinkedList resourceStack = new LinkedList();
private IWorkspaceRoot workspaceRoot;
}
Index: .classpath
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/.classpath,v
retrieving revision 1.3
diff -u -r1.3 .classpath
--- .classpath 27 Jun 2003 14:31:34 -0000 1.3
+++ .classpath 4 Jul 2003 16:04:53 -0000
@@ -21,5 +21,6 @@
<classpathentry kind="src" path="/org.junit"/>
<classpathentry kind="src" path="/org.eclipse.core.boot"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="src" path="search"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/ChangeLog,v
retrieving revision 1.13
diff -u -r1.13 ChangeLog
--- ChangeLog 4 Jul 2003 03:03:01 -0000 1.13
+++ ChangeLog 4 Jul 2003 16:04:53 -0000
@@ -1,3 +1,13 @@
+2003-07-04 Andrew Niefer
+ Added new source Folder search
+ Added search/ClassDeclarationPatternTests::testMatchSimpleDeclaration
+ Added search/ClassDeclarationPatternTests::testMatchNamespaceNestedDeclaration
+ Added new resource folder search & containing file classDecl.cpp
+ Added new failures package ord.eclipse.cdt.core.search.failedTests
+ Added new failing test PatternsFailedTests::testBug39652
+
+ * Note that ClassDeclarationPatternTests and PatternsFailedTests both must be run as plugin tests
+
2003-07-03 Bogdan Gheorghe
Added IndexManagerTest::testAddNewFileToIndex()
Added IndexManagerTest::testRemoveProjectFromIndex()
Attachment:
core.tests.zip
Description: Zip archive
Index: src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties,v
retrieving revision 1.2
diff -u -r1.2 CSearchMessages.properties
--- src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties 28 Jun 2003 19:56:52 -0000 1.2
+++ src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties 4 Jul 2003 15:52:57 -0000
@@ -57,11 +57,9 @@
CSearchPage.limitTo.label= Limit To
CSearchPage.limitTo.declarations= Dec&larations
-CSearchPage.limitTo.implementors= &Implementors
+CSearchPage.limitTo.definitions= &Definitions
CSearchPage.limitTo.references= &References
CSearchPage.limitTo.allOccurrences= All &Occurrences
-CSearchPage.limitTo.readReferences= Read A&ccess
-CSearchPage.limitTo.writeReferences= Writ&e Access
CSearchPage.expression.label= Se&arch string (* = any string, ? = any character):
CSearchPage.expression.caseSensitive= Case sens&itive
Index: src/org/eclipse/cdt/internal/ui/search/CSearchOperation.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchOperation.java,v
retrieving revision 1.2
diff -u -r1.2 CSearchOperation.java
--- src/org/eclipse/cdt/internal/ui/search/CSearchOperation.java 28 Jun 2003 19:56:52 -0000 1.2
+++ src/org/eclipse/cdt/internal/ui/search/CSearchOperation.java 4 Jul 2003 15:52:57 -0000
@@ -33,21 +33,21 @@
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
-public class CSearchOperation extends WorkspaceModifyOperation {
+public class CSearchOperation extends WorkspaceModifyOperation implements ICSearchConstants{
- public CSearchOperation(IWorkspace workspace, ICElement element, int limitTo, ICSearchScope scope, String scopeDescription, CSearchResultCollector collector) {
+ public CSearchOperation(IWorkspace workspace, ICElement element, LimitTo limitTo, ICSearchScope scope, String scopeDescription, CSearchResultCollector collector) {
this( workspace, limitTo, scope, scopeDescription, collector );
_elementPattern = element;
}
- public CSearchOperation(IWorkspace workspace, String pattern, boolean caseSensitive, int searchFor, int limitTo, ICSearchScope scope, String scopeDescription, CSearchResultCollector collector) {
+ public CSearchOperation(IWorkspace workspace, String pattern, boolean caseSensitive, SearchFor searchFor, LimitTo limitTo, ICSearchScope scope, String scopeDescription, CSearchResultCollector collector) {
this( workspace, limitTo, scope, scopeDescription, collector );
_stringPattern = pattern;
_caseSensitive = caseSensitive;
_searchFor = searchFor;
}
- public CSearchOperation(IWorkspace workspace, int limitTo, ICSearchScope scope, String scopeDescription, CSearchResultCollector collector ){
+ public CSearchOperation(IWorkspace workspace, LimitTo limitTo, ICSearchScope scope, String scopeDescription, CSearchResultCollector collector ){
_workspace = workspace;
_limitTo = limitTo;
_scope = scope;
@@ -87,13 +87,13 @@
}
String [] args = new String [] { desc, _scopeDescription };
- switch( _limitTo ){
- case ICSearchConstants.DECLARATIONS :
- return CSearchMessages.getFormattedString( "CSearchOperation.singularDeclarationsPostfix", args ); //$NON_NLS-1$
- case ICSearchConstants.REFERENCES :
- return CSearchMessages.getFormattedString( "CSearchOperation.singularReferencesPostfix", args ); //$NON_NLS-1$
- default:
- return CSearchMessages.getFormattedString( "CSearchOperation.singularOccurencesPostfix", args ); //$NON_NLS-1$
+
+ if( _limitTo == DECLARATIONS ){
+ return CSearchMessages.getFormattedString( "CSearchOperation.singularDeclarationsPostfix", args ); //$NON_NLS-1$
+ } else if( _limitTo == REFERENCES ){
+ return CSearchMessages.getFormattedString( "CSearchOperation.singularReferencesPostfix", args ); //$NON_NLS-1$
+ } else {
+ return CSearchMessages.getFormattedString( "CSearchOperation.singularOccurencesPostfix", args ); //$NON_NLS-1$
}
}
@@ -110,13 +110,12 @@
}
String [] args = new String [] { desc, "{0}", _scopeDescription };
- switch( _limitTo ){
- case ICSearchConstants.DECLARATIONS :
- return CSearchMessages.getFormattedString( "CSearchOperation.pluralDeclarationsPostfix", args ); //$NON_NLS-1$
- case ICSearchConstants.REFERENCES :
- return CSearchMessages.getFormattedString( "CSearchOperation.pluralReferencesPostfix", args ); //$NON_NLS-1$
- default:
- return CSearchMessages.getFormattedString( "CSearchOperation.pluralOccurencesPostfix", args ); //$NON_NLS-1$
+ if( _limitTo == DECLARATIONS ){
+ return CSearchMessages.getFormattedString( "CSearchOperation.pluralDeclarationsPostfix", args ); //$NON_NLS-1$
+ } else if ( _limitTo == REFERENCES ){
+ return CSearchMessages.getFormattedString( "CSearchOperation.pluralReferencesPostfix", args ); //$NON_NLS-1$
+ } else {
+ return CSearchMessages.getFormattedString( "CSearchOperation.pluralOccurencesPostfix", args ); //$NON_NLS-1$
}
}
@@ -138,8 +137,8 @@
private String _stringPattern;
private String _scopeDescription;
private boolean _caseSensitive;
- private int _limitTo;
- private int _searchFor;
+ private LimitTo _limitTo;
+ private SearchFor _searchFor;
}
Index: src/org/eclipse/cdt/internal/ui/search/CSearchPage.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchPage.java,v
retrieving revision 1.3
diff -u -r1.3 CSearchPage.java
--- src/org/eclipse/cdt/internal/ui/search/CSearchPage.java 28 Jun 2003 19:56:52 -0000 1.3
+++ src/org/eclipse/cdt/internal/ui/search/CSearchPage.java 4 Jul 2003 15:52:57 -0000
@@ -18,12 +18,14 @@
import java.io.StringReader;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.SearchEngine;
+//import org.eclipse.cdt.core.search.SearchFor;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.runtime.IAdaptable;
@@ -229,21 +231,7 @@
int index = fgPreviousSearchPatterns.size() - 1 - fPattern.getSelectionIndex();
fInitialData = (SearchPatternData) fgPreviousSearchPatterns.get( index );
- for (int i = 0; i < fSearchFor.length; i++)
- fSearchFor[i].setSelection(false);
-
- for (int i = 0; i < fLimitTo.length; i++)
- fLimitTo[i].setSelection(false);
-
- fSearchFor[ fInitialData.searchFor ].setSelection( true );
- setLimitTo( fInitialData.searchFor );
- fLimitTo[ fInitialData.limitTo ].setSelection( true );
-
- fPattern.setText( fInitialData.pattern );
- fIsCaseSensitive = fInitialData.isCaseSensitive;
- fCElement = fInitialData.cElement;
- fCaseSensitive.setEnabled( fCElement == null );
- fCaseSensitive.setSelection( fInitialData.isCaseSensitive );
+ updateSelections();
if( fInitialData.workingSets != null )
getContainer().setSelectedWorkingSets( fInitialData.workingSets );
@@ -272,43 +260,35 @@
return result;
}
- private int getLimitTo() {
+ private LimitTo getLimitTo() {
for (int i= 0; i < fLimitTo.length; i++) {
if (fLimitTo[i].getSelection())
- return i;
+ return fLimitToValues[ i ];
}
- return -1;
+ return null;
}
- private void setLimitTo(int searchFor) {
- fLimitTo[ DECLARATIONS ].setEnabled( true );
- //fLimitTo[ IMPLEMENTORS ].setEnabled( false);
- fLimitTo[ REFERENCES ].setEnabled( true );
- fLimitTo[ ALL_OCCURRENCES ].setEnabled( true );
- //fLimitTo[ READ_ACCESSES ].setEnabled( false);
- //fLimitTo[ WRITE_ACCESSES ].setEnabled( false);
-
-// if (!(searchFor == TYPE || searchFor == INTERFACE) && fLimitTo[IMPLEMENTORS].getSelection()) {
-// fLimitTo[ IMPLEMENTORS ].setSelection(false);
-// fLimitTo[ REFERENCES ].setSelection(true);
-// }
-//
-// if (!(searchFor == FIELD) && (getLimitTo() == READ_ACCESSES || getLimitTo() == WRITE_ACCESSES)) {
-// fLimitTo[ getLimitTo()].setSelection(false);
-// fLimitTo[ REFERENCES ].setSelection(true);
-// }
-//
-// switch (searchFor) {
-// case TYPE:
-// case INTERFACE:
-// fLimitTo[ IMPLEMENTORS ].setEnabled(true);
-// break;
-// case FIELD:
-// fLimitTo[ READ_ACCESSES ].setEnabled(true);
-// fLimitTo[ WRITE_ACCESSES ].setEnabled(true);
-// break;
-// default :
-// break;
-// }
+
+ private void setLimitTo( SearchFor searchFor ) {
+ HashSet set = new HashSet();
+
+ if( searchFor == TYPE ){
+ set.add( DECLARATIONS );
+ set.add( REFERENCES );
+ } else if ( searchFor == FUNCTION || searchFor == CONSTRUCTOR ) {
+ set.add( DECLARATIONS );
+ set.add( DEFINITIONS );
+ //set.add( REFERENCES );
+ } else if( searchFor == NAMESPACE ) {
+ set.add( DECLARATIONS );
+ set.add( REFERENCES );
+ } else if( searchFor == MEMBER ) {
+ set.add( DECLARATIONS );
+ set.add( REFERENCES );
+ }
+ set.add( ALL_OCCURRENCES );
+
+ for( int i = 0; i < fLimitTo.length; i++ )
+ fLimitTo[ i ].setEnabled( set.contains( fLimitToValues[ i ] ) );
}
private Control createSearchFor(Composite parent) {
@@ -334,13 +314,13 @@
return result;
}
- private int getSearchFor() {
+ private SearchFor getSearchFor() {
for (int i= 0; i < fSearchFor.length; i++) {
- if (fSearchFor[i].getSelection())
- return i;
+ if( fSearchFor[i].getSelection() )
+ return fSearchForValues[ i ];
}
Assert.isTrue(false, "shouldNeverHappen"); //$NON-NLS-1$
- return -1;
+ return null;
}
public void setContainer(ISearchPageContainer container) {
@@ -399,17 +379,28 @@
private void initSelections() {
fStructuredSelection = asStructuredSelection();
fInitialData = tryStructuredSelection( fStructuredSelection );
+ updateSelections();
+ }
+
+ private void updateSelections(){
if (fInitialData == null)
fInitialData = trySimpleTextSelection( getContainer().getSelection() );
if (fInitialData == null)
fInitialData = getDefaultInitValues();
fCElement = fInitialData.cElement;
+ fIsCaseSensitive = fInitialData.isCaseSensitive;
fCaseSensitive.setSelection( fInitialData.isCaseSensitive );
fCaseSensitive.setEnabled( fInitialData.cElement == null );
- fSearchFor[ fInitialData.searchFor ].setSelection( true );
+
+ for (int i = 0; i < fSearchFor.length; i++)
+ fSearchFor[i].setSelection( fSearchForValues[i] == fInitialData.searchFor );
+
setLimitTo( fInitialData.searchFor );
- fLimitTo[ fInitialData.limitTo ].setSelection( true );
+
+ for (int i = 0; i < fLimitTo.length; i++)
+ fLimitTo[i].setSelection( fLimitToValues[i] == fInitialData.limitTo );
+
fPattern.setText( fInitialData.pattern );
}
@@ -456,13 +447,13 @@
} catch (IOException ex) {
text= ""; //$NON-NLS-1$
}
- result= new SearchPatternData(TYPE, REFERENCES, fIsCaseSensitive, text, null);
+ result= new SearchPatternData( TYPE, REFERENCES, fIsCaseSensitive, text, null);
}
return result;
}
private SearchPatternData getDefaultInitValues() {
- return new SearchPatternData(TYPE, REFERENCES, fIsCaseSensitive, "", null); //$NON-NLS-1$
+ return new SearchPatternData( TYPE, REFERENCES, fIsCaseSensitive, "", null); //$NON-NLS-1$
}
private String[] getPreviousSearchPatterns() {
@@ -494,8 +485,8 @@
if( element == null )
return null;
- int searchFor = UNKNOWN;
- int limitTo = UNKNOWN;
+ SearchFor searchFor = UNKNOWN_SEARCH_FOR;
+ LimitTo limitTo = UNKNOWN_LIMIT_TO;
String pattern = null;
switch( element.getElementType() ) {
@@ -506,7 +497,7 @@
break;*/
}
- if( searchFor != UNKNOWN && limitTo != UNKNOWN && pattern != null )
+ if( searchFor != UNKNOWN_SEARCH_FOR && limitTo != UNKNOWN_LIMIT_TO && pattern != null )
return new SearchPatternData( searchFor, limitTo, true, pattern, element );
return null;
@@ -546,19 +537,19 @@
}
private static class SearchPatternData {
- int searchFor;
- int limitTo;
+ SearchFor searchFor;
+ LimitTo limitTo;
String pattern;
boolean isCaseSensitive;
ICElement cElement;
int scope;
IWorkingSet[] workingSets;
- public SearchPatternData(int s, int l, boolean i, String p, ICElement element) {
+ public SearchPatternData(SearchFor s, LimitTo l, boolean i, String p, ICElement element) {
this(s, l, p, i, element, ISearchPageContainer.WORKSPACE_SCOPE, null);
}
- public SearchPatternData(int s, int l, String p, boolean i, ICElement element, int scope, IWorkingSet[] workingSets) {
+ public SearchPatternData(SearchFor s, LimitTo l, String p, boolean i, ICElement element, int scope, IWorkingSet[] workingSets) {
searchFor= s;
limitTo= l;
pattern= p;
@@ -573,9 +564,10 @@
private final static String PAGE_NAME= "CSearchPage"; //$NON-NLS-1$
private final static String STORE_CASE_SENSITIVE= PAGE_NAME + "CASE_SENSITIVE"; //$NON-NLS-1$
- private static List fgPreviousSearchPatterns= new ArrayList(20);
+ private static List fgPreviousSearchPatterns = new ArrayList(20);
private Button[] fSearchFor;
+ private SearchFor[] fSearchForValues = { TYPE, FUNCTION, NAMESPACE, CONSTRUCTOR, MEMBER };
private String[] fSearchForText= {
CSearchMessages.getString("CSearchPage.searchFor.type"), //$NON-NLS-1$
CSearchMessages.getString("CSearchPage.searchFor.method"), //$NON-NLS-1$
@@ -584,13 +576,14 @@
CSearchMessages.getString("CSearchPage.searchFor.field")}; //$NON-NLS-1$
private Button[] fLimitTo;
+ private LimitTo[] fLimitToValues = { DECLARATIONS, DEFINITIONS, REFERENCES, ALL_OCCURRENCES };
private String[] fLimitToText= {
CSearchMessages.getString("CSearchPage.limitTo.declarations"), //$NON-NLS-1$
- CSearchMessages.getString("CSearchPage.limitTo.implementors"), //$NON-NLS-1$
+ CSearchMessages.getString("CSearchPage.limitTo.definitions"), //$NON-NLS-1$
CSearchMessages.getString("CSearchPage.limitTo.references"), //$NON-NLS-1$
- CSearchMessages.getString("CSearchPage.limitTo.allOccurrences"), //$NON-NLS-1$
- CSearchMessages.getString("CSearchPage.limitTo.readReferences"), //$NON-NLS-1$
- CSearchMessages.getString("CSearchPage.limitTo.writeReferences")}; //$NON-NLS-1$
+ CSearchMessages.getString("CSearchPage.limitTo.allOccurrences") }; //$NON-NLS-1$
+ //CSearchMessages.getString("CSearchPage.limitTo.readReferences"), //$NON-NLS-1$
+ //CSearchMessages.getString("CSearchPage.limitTo.writeReferences")}; //$NON-NLS-1$
private SearchPatternData fInitialData;
private IStructuredSelection fStructuredSelection;
Index: src/org/eclipse/cdt/internal/ui/search/CSearchResultCollector.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResultCollector.java,v
retrieving revision 1.2
diff -u -r1.2 CSearchResultCollector.java
--- src/org/eclipse/cdt/internal/ui/search/CSearchResultCollector.java 28 Jun 2003 19:56:52 -0000 1.2
+++ src/org/eclipse/cdt/internal/ui/search/CSearchResultCollector.java 4 Jul 2003 15:52:57 -0000
@@ -15,12 +15,15 @@
import java.text.MessageFormat;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.search.ICSearchResultCollector;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.search.ui.IActionGroupFactory;
import org.eclipse.search.ui.ISearchResultView;
@@ -34,7 +37,6 @@
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class CSearchResultCollector implements ICSearchResultCollector {
-
/**
*
*/
@@ -94,6 +96,21 @@
_matchCount++;
}
+ public void accept(
+ IPath path,
+ int start,
+ int end,
+ ICElement enclosingElement,
+ int accuracy)
+ throws CoreException
+ {
+ if( _matches == null ){
+ _matches = new HashSet();
+ }
+
+ _matches.add( new Match( path.toString(), start, end ) );
+ }
+
/* (non-Javadoc)
* @see org.eclipse.cdt.core.search.ICSearchResultCollector#done()
*/
@@ -132,20 +149,38 @@
_operation = operation;
}
+ public Set getMatches(){
+ return _matches;
+ }
+
private class ActionGroupFactory implements IActionGroupFactory {
public ActionGroup createActionGroup( ISearchResultView part ){
return new CSearchViewActionGroup( part );
}
}
+ public static class Match {
+ public Match( String path, int start, int end ){
+ this.path = path;
+ this.start = start;
+ this.end = end;
+ }
+
+ public String path;
+ public int start;
+ public int end;
+ }
+
private static final String SEARCHING = CSearchMessages.getString("CSearchResultCollector.searching"); //$NON-NLS-1$
private static final String MATCH = CSearchMessages.getString("CSearchResultCollector.match"); //$NON-NLS-1$
private static final String MATCHES = CSearchMessages.getString("CSearchResultCollector.matches"); //$NON-NLS-1$
private static final String DONE = CSearchMessages.getString("CSearchResultCollector.done"); //$NON-NLS-1$
-
+
+
private IProgressMonitor _monitor;
private CSearchOperation _operation;
private ISearchResultView _view;
private int _matchCount;
+ private Set _matches;
}