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

Search Refactoring for bugs

50983 - OrPattern not visible
51250 - search engine throws runtime exception OperationCanceledException
This commit is contained in:
Andrew Niefer 2004-02-16 20:46:12 +00:00
parent a693c52f25
commit c1a246da20
20 changed files with 1789 additions and 1766 deletions

View file

@ -1,3 +1,6 @@
2004-02-13 Andrew Niefer
updated tests using search to handle InterruptedExcpetion
2004-02-12 Andrew Niefer
UnCommented CompleteParseASTTest.testBug47628
Added CompleteParseASTTest.testBug47636

View file

@ -651,7 +651,10 @@ import org.eclipse.core.runtime.Platform;
}
protected void search(IWorkspace workspace, ICSearchPattern pattern, ICSearchScope scope, ICSearchResultCollector collector) {
try {
searchEngine.search( workspace, pattern, scope, collector, false );
} catch (InterruptedException e) {
}
}
/*

View file

@ -122,7 +122,11 @@ public class BaseSearchTest extends TestCase implements ICSearchConstants {
}
protected void search(IWorkspace workspace, ICSearchPattern pattern, ICSearchScope scope, ICSearchResultCollector collector) {
try {
searchEngine.search( workspace, pattern, scope, collector, false );
} catch (InterruptedException e) {
}
}
}

View file

@ -19,10 +19,10 @@ import java.util.Set;
import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.core.search.ICSearchPattern;
import org.eclipse.cdt.core.search.IMatch;
import org.eclipse.cdt.core.search.OrPattern;
import org.eclipse.cdt.core.search.SearchEngine;
import org.eclipse.cdt.internal.core.CharOperation;
import org.eclipse.cdt.internal.core.search.matching.ClassDeclarationPattern;
import org.eclipse.cdt.internal.core.search.matching.OrPattern;
/**

View file

@ -22,13 +22,13 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.search.BasicSearchMatch;
import org.eclipse.cdt.core.search.ICSearchPattern;
import org.eclipse.cdt.core.search.IMatch;
import org.eclipse.cdt.core.search.OrPattern;
import org.eclipse.cdt.core.search.SearchEngine;
import org.eclipse.cdt.internal.core.CharOperation;
import org.eclipse.cdt.internal.core.search.AcceptMatchOperation;
import org.eclipse.cdt.internal.core.search.matching.FieldDeclarationPattern;
import org.eclipse.cdt.internal.core.search.matching.MatchLocator;
import org.eclipse.cdt.internal.core.search.matching.NamespaceDeclarationPattern;
import org.eclipse.cdt.internal.core.search.matching.OrPattern;
import org.eclipse.cdt.testplugin.CTestPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
@ -327,7 +327,10 @@ public class OtherPatternTests extends BaseSearchTest {
ArrayList matchesList = new ArrayList();
MatchLocator matchLocator = new MatchLocator( pattern, resultCollector, scope, monitor );
try {
matchLocator.locateMatches( new String [] { path }, workspace, null, matchesList);
} catch (InterruptedException e1) {
}
AcceptMatchOperation acceptMatchOp = new AcceptMatchOperation(resultCollector, matchesList);
try {

View file

@ -1,3 +1,9 @@
2004-02-16 Andrew Niefer
fixed a couple of warnings
moved OrPattern from org.eclipse.cdt.internal.core.search.matching to org.eclipse.cdt.core.search
changed SearchEngine.search & MatchLocator.locateMatches to throw InterruptedException when cancelled
updates calls to search to handle InterruptedException
2004-02-13 Bogdan Gheorghe
- Added error handling to MatchLocator.locateMatches to handle possible
parser failures.

View file

@ -59,8 +59,6 @@ public class BasicSearchMatch implements IMatch, Comparable {
}
BasicSearchMatch match = (BasicSearchMatch)obj;
IPath path = getLocation();
if( startOffset != match.getStartOffset() || endOffset != match.getEndOffset() )
return false;

View file

@ -11,18 +11,17 @@
/*
* Created on Aug 6, 2003
*/
package org.eclipse.cdt.internal.core.search.matching;
package org.eclipse.cdt.core.search;
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.cdt.internal.core.search.matching.CSearchPattern;
import org.eclipse.core.runtime.IProgressMonitor;

View file

@ -36,7 +36,6 @@ import org.eclipse.core.resources.IWorkspace;
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;
import org.eclipse.core.runtime.SubProgressMonitor;
@ -109,7 +108,6 @@ public class SearchEngine implements ICSearchConstants{
*/
public static ICSearchScope createCFileSearchScope(IFile sourceFile, ArrayList elements) {
CSearchScope scope = new CSearchScope();
HashSet visitedProjects = new HashSet(2);
if (sourceFile != null){
//Add the source file and project
@ -155,7 +153,7 @@ public class SearchEngine implements ICSearchConstants{
* @param _scope
* @param _collector
*/
public void search(IWorkspace workspace, ICSearchPattern pattern, ICSearchScope scope, ICSearchResultCollector collector, boolean excludeLocalDeclarations) {
public void search(IWorkspace workspace, ICSearchPattern pattern, ICSearchScope scope, ICSearchResultCollector collector, boolean excludeLocalDeclarations) throws InterruptedException {
if( VERBOSE ) {
System.out.println("Searching for " + pattern + " in " + scope); //$NON-NLS-1$//$NON-NLS-2$
}
@ -199,7 +197,7 @@ public class SearchEngine implements ICSearchConstants{
matchLocator.setShouldExcludeLocalDeclarations( excludeLocalDeclarations );
if( progressMonitor != null && progressMonitor.isCanceled() )
throw new OperationCanceledException();
throw new InterruptedException();
//TODO: BOG Filter Working Copies...
matchLocator.locateMatches( pathCollector.getPaths(), workspace, this.workingCopies, matches);

View file

@ -45,6 +45,7 @@ import org.eclipse.cdt.core.parser.ast.IASTFunction;
import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
import org.eclipse.cdt.core.search.*;
import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.core.search.ICSearchPattern;
import org.eclipse.cdt.core.search.ICSearchScope;

View file

@ -189,7 +189,6 @@ public class FieldDeclarationPattern extends CSearchPattern {
private char [][] decodedQualifications;
private char [] simpleName;
private char [] decodedSimpleName;
private char decodedType;
private SearchFor searchFor;
}

View file

@ -41,7 +41,6 @@ public class IncludePattern extends CSearchPattern {
*/
protected void decodeIndexEntry(IEntryResult entryResult) {
char[] word = entryResult.getWord();
int size = word.length;
int firstSlash = CharOperation.indexOf( SEPARATOR, word, 0 );

View file

@ -86,7 +86,6 @@ public class MacroDeclarationPattern extends CSearchPattern {
*/
protected void decodeIndexEntry(IEntryResult entryResult) {
char[] word = entryResult.getWord();
int size = word.length;
int firstSlash = CharOperation.indexOf( SEPARATOR, word, 0 );

View file

@ -89,7 +89,6 @@ 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;
@ -335,7 +334,7 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants
}
public void locateMatches( String [] paths, IWorkspace workspace, IWorkingCopy[] workingCopies,ArrayList matches ){
public void locateMatches( String [] paths, IWorkspace workspace, IWorkingCopy[] workingCopies,ArrayList matches ) throws InterruptedException{
matchStorage = matches;
workspaceRoot = (workspace != null) ? workspace.getRoot() : null;
@ -368,7 +367,7 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants
for( int i = 0; i < length; i++ ){
if( progressMonitor != null ) {
if( progressMonitor.isCanceled() ){
throw new OperationCanceledException();
throw new InterruptedException();
} else {
progressMonitor.worked( 1 );
}
@ -482,7 +481,7 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants
if( node instanceof IASTReference ){
IASTReference reference = (IASTReference) node;
offset = reference.getOffset();
end = offset + reference.getName().length();;
end = offset + reference.getName().length();
if (VERBOSE)
MatchLocator.verbose("Report Match: " + reference.getName());
} else if( node instanceof IASTOffsetableNamedElement ){
@ -491,7 +490,7 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants
: offsetableElement.getStartingOffset();
end = offsetableElement.getNameEndOffset();
if( end == 0 ){
end = offset + offsetableElement.getName().length();;
end = offset + offsetableElement.getName().length();
}
if (VERBOSE)

View file

@ -1,3 +1,6 @@
2004-02-13 Andrew Niefer
Updated calls to search to handle InterruptedException
2004-02-16 Alain Magloire
Use ITextEditor instead of CEditor.

View file

@ -16,8 +16,8 @@ import org.eclipse.cdt.core.search.BasicSearchResultCollector;
import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.IMatch;
import org.eclipse.cdt.core.search.OrPattern;
import org.eclipse.cdt.core.search.SearchEngine;
import org.eclipse.cdt.internal.core.search.matching.OrPattern;
import org.eclipse.cdt.internal.ui.dialogs.ElementListSelectionDialog;
import org.eclipse.cdt.internal.ui.util.EditorUtility;
import org.eclipse.cdt.ui.CSearchResultLabelProvider;
@ -132,7 +132,8 @@ public class OpenDeclarationsAction extends Action implements IUpdate {
final ArrayList elementsFound = new ArrayList();
IRunnableWithProgress runnable = new IRunnableWithProgress() {
IRunnableWithProgress runnable = new IRunnableWithProgress()
{
public void run(IProgressMonitor monitor) {
BasicSearchResultCollector resultCollector = new BasicSearchResultCollector(monitor);
IWorkingCopyManager fManager = CUIPlugin.getDefault().getWorkingCopyManager();
@ -152,7 +153,10 @@ public class OpenDeclarationsAction extends Action implements IUpdate {
orPattern.addPattern(SearchEngine.createSearchPattern( selectedText, ICSearchConstants.NAMESPACE, ICSearchConstants.DECLARATIONS, true ));
orPattern.addPattern(SearchEngine.createSearchPattern( selectedText, ICSearchConstants.MACRO, ICSearchConstants.DECLARATIONS, true ));
orPattern.addPattern(SearchEngine.createSearchPattern( selectedText, ICSearchConstants.TYPEDEF, ICSearchConstants.DECLARATIONS, true ));
try {
searchEngine.search(CUIPlugin.getWorkspace(), orPattern, scope, resultCollector, true);
} catch (InterruptedException e) {
}
elementsFound.addAll(resultCollector.getSearchResults());
}
};

View file

@ -12,8 +12,8 @@ package org.eclipse.cdt.internal.ui.opentype;
import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.OrPattern;
import org.eclipse.cdt.core.search.SearchEngine;
import org.eclipse.cdt.internal.core.search.matching.OrPattern;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;

View file

@ -20,16 +20,14 @@ import java.util.List;
import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.core.search.ICSearchPattern;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.OrPattern;
import org.eclipse.cdt.core.search.SearchEngine;
import org.eclipse.cdt.internal.core.search.matching.OrPattern;
import org.eclipse.cdt.internal.ui.CPluginImages;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.actions.WorkspaceModifyOperation;
/**
* @author aniefer
@ -78,9 +76,10 @@ public class CSearchOperation implements IRunnableWithProgress,ICSearchConstants
pattern = SearchEngine.createSearchPattern( _stringPattern, (SearchFor)iter.next(), _limitTo, _caseSensitive );
}
try {
engine.search( _workspace, pattern, _scope, _collector, false );
} catch (InterruptedException e) {
}
}
/**

View file

@ -20,8 +20,8 @@ import org.eclipse.cdt.core.search.BasicSearchMatch;
import org.eclipse.cdt.core.search.BasicSearchResultCollector;
import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.OrPattern;
import org.eclipse.cdt.core.search.SearchEngine;
import org.eclipse.cdt.internal.core.search.matching.OrPattern;
import org.eclipse.cdt.internal.corext.template.ContextType;
import org.eclipse.cdt.internal.corext.template.ContextTypeRegistry;
import org.eclipse.cdt.internal.corext.template.ITemplateEditor;
@ -546,7 +546,10 @@ public class CCompletionProcessor implements IContentAssistProcessor {
orPattern.addPattern(SearchEngine.createSearchPattern(
searchPrefix, ICSearchConstants.FUNCTION, ICSearchConstants.DECLARATIONS, false ));
}
try {
searchEngine.search(CUIPlugin.getWorkspace(), orPattern, scope, searchResultCollector, true);
} catch (InterruptedException e) {
}
elementsFound.addAll(searchResultCollector.getSearchResults());
sendResultsToCollector(elementsFound.iterator(), offset, length, prefix );

View file

@ -449,7 +449,10 @@ public class NewClassWizardPage extends WizardPage implements Listener {
elements[0] = cProject;
ICSearchScope scope = SearchEngine.createCSearchScope(elements, true);
try {
searchEngine.search(CUIPlugin.getWorkspace(), pattern, scope, resultCollector, false);
} catch (InterruptedException e) {
}
elementsFound.addAll(resultCollector.getSearchResults());
}