mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
bug 61044 - report matches after each compilation unit
This commit is contained in:
parent
c5dabe7b00
commit
9f21cf4d4a
6 changed files with 54 additions and 81 deletions
|
@ -13,24 +13,20 @@
|
|||
*/
|
||||
package org.eclipse.cdt.core.search.tests;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
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.testplugin.CTestPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
|
||||
/**
|
||||
|
@ -338,24 +334,15 @@ public class OtherPatternTests extends BaseSearchTest {
|
|||
|
||||
resultCollector.aboutToStart();
|
||||
|
||||
ArrayList matchesList = new ArrayList();
|
||||
MatchLocator matchLocator = new MatchLocator( pattern, resultCollector, scope);
|
||||
matchLocator.setProgressMonitor(monitor);
|
||||
|
||||
try {
|
||||
matchLocator.locateMatches( new String [] { path }, workspace, null, matchesList);
|
||||
matchLocator.locateMatches( new String [] { path }, workspace, null );
|
||||
} catch (InterruptedException e1) {
|
||||
}
|
||||
|
||||
AcceptMatchOperation acceptMatchOp = new AcceptMatchOperation(resultCollector, matchesList);
|
||||
try {
|
||||
CCorePlugin.getWorkspace().run(acceptMatchOp,null);
|
||||
} catch (CoreException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
//
|
||||
//resultCollector.done();
|
||||
resultCollector.done();
|
||||
|
||||
Set matches = resultCollector.getSearchResults();
|
||||
assertEquals( matches.size(), 4 );
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
2004-05-17 Andrew Niefer
|
||||
bug 61044 - report search matches at the end of each compilation unit
|
||||
|
||||
2004-05-14 Bogdan Gheorghe
|
||||
bug 60491
|
||||
Added working copy filtering to search engine
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
*/
|
||||
package org.eclipse.cdt.core.search;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
|
@ -23,7 +22,7 @@ public interface IMatchLocator
|
|||
ISourceElementRequestor,
|
||||
ICSearchConstants {
|
||||
|
||||
public void locateMatches( String [] paths, IWorkspace workspace, IWorkingCopy[] workingCopies,ArrayList matches ) throws InterruptedException;
|
||||
public void locateMatches( String [] paths, IWorkspace workspace, IWorkingCopy[] workingCopies ) throws InterruptedException;
|
||||
|
||||
public void setProgressMonitor(IProgressMonitor progressMonitor);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ import org.eclipse.cdt.core.model.ICProject;
|
|||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.internal.core.Util;
|
||||
import org.eclipse.cdt.internal.core.model.CModelManager;
|
||||
import org.eclipse.cdt.internal.core.search.AcceptMatchOperation;
|
||||
import org.eclipse.cdt.internal.core.search.CSearchScope;
|
||||
import org.eclipse.cdt.internal.core.search.CWorkspaceScope;
|
||||
import org.eclipse.cdt.internal.core.search.PathCollector;
|
||||
|
@ -33,7 +32,6 @@ import org.eclipse.cdt.internal.core.search.matching.CSearchPattern;
|
|||
import org.eclipse.cdt.internal.core.search.matching.MatchLocator;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
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.Path;
|
||||
|
@ -172,54 +170,48 @@ public class SearchEngine implements ICSearchConstants{
|
|||
|
||||
/* search is starting */
|
||||
collector.aboutToStart();
|
||||
ArrayList matches = new ArrayList();
|
||||
try{
|
||||
//initialize progress monitor
|
||||
IProgressMonitor progressMonitor = collector.getProgressMonitor();
|
||||
if( progressMonitor != null ){
|
||||
progressMonitor.beginTask( Util.bind("engine.searching"), 100 ); //$NON_NLS-1$ //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/* index search */
|
||||
PathCollector pathCollector = new PathCollector();
|
||||
|
||||
CModelManager modelManager = CModelManager.getDefault();
|
||||
IndexManager indexManager = modelManager.getIndexManager();
|
||||
|
||||
SubProgressMonitor subMonitor = (progressMonitor == null ) ? null : new SubProgressMonitor( progressMonitor, 5 );
|
||||
|
||||
indexManager.performConcurrentJob(
|
||||
new PatternSearchJob(
|
||||
(CSearchPattern) pattern,
|
||||
scope,
|
||||
pathCollector,
|
||||
indexManager
|
||||
),
|
||||
ICSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
|
||||
subMonitor,
|
||||
null );
|
||||
|
||||
subMonitor = (progressMonitor == null ) ? null : new SubProgressMonitor( progressMonitor, 95 );
|
||||
|
||||
matchLocator.setProgressMonitor(subMonitor);
|
||||
|
||||
if( progressMonitor != null && progressMonitor.isCanceled() )
|
||||
throw new InterruptedException();
|
||||
|
||||
//indexer might have had a # files left to index subtask, replace that with searching again
|
||||
if( progressMonitor != null )
|
||||
progressMonitor.subTask( Util.bind( "engine.searching" ) );
|
||||
|
||||
String[] indexerPaths = pathCollector.getPaths();
|
||||
pathCollector = null; // release
|
||||
|
||||
matchLocator.locateMatches( indexerPaths, workspace, filterWorkingCopies(this.workingCopies, scope), matches);
|
||||
} finally {
|
||||
AcceptMatchOperation acceptMatchOp = new AcceptMatchOperation(collector, matches);
|
||||
try {
|
||||
CCorePlugin.getWorkspace().run(acceptMatchOp,null);
|
||||
} catch (CoreException e) {}
|
||||
|
||||
//initialize progress monitor
|
||||
IProgressMonitor progressMonitor = collector.getProgressMonitor();
|
||||
if( progressMonitor != null ){
|
||||
progressMonitor.beginTask( Util.bind("engine.searching"), 100 ); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/* index search */
|
||||
PathCollector pathCollector = new PathCollector();
|
||||
|
||||
CModelManager modelManager = CModelManager.getDefault();
|
||||
IndexManager indexManager = modelManager.getIndexManager();
|
||||
|
||||
SubProgressMonitor subMonitor = (progressMonitor == null ) ? null : new SubProgressMonitor( progressMonitor, 5 );
|
||||
|
||||
indexManager.performConcurrentJob(
|
||||
new PatternSearchJob(
|
||||
(CSearchPattern) pattern,
|
||||
scope,
|
||||
pathCollector,
|
||||
indexManager
|
||||
),
|
||||
ICSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
|
||||
subMonitor,
|
||||
null );
|
||||
|
||||
subMonitor = (progressMonitor == null ) ? null : new SubProgressMonitor( progressMonitor, 95 );
|
||||
|
||||
matchLocator.setProgressMonitor(subMonitor);
|
||||
|
||||
if( progressMonitor != null && progressMonitor.isCanceled() )
|
||||
throw new InterruptedException();
|
||||
|
||||
//indexer might have had a # files left to index subtask, replace that with searching again
|
||||
if( progressMonitor != null )
|
||||
progressMonitor.subTask( Util.bind( "engine.searching" ) ); //$NON-NLS-1$
|
||||
|
||||
String[] indexerPaths = pathCollector.getPaths();
|
||||
pathCollector = null; // release
|
||||
|
||||
matchLocator.locateMatches( indexerPaths, workspace, filterWorkingCopies(this.workingCopies, scope));
|
||||
collector.done();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -42,7 +42,6 @@ public class AcceptMatchOperation implements IWorkspaceRunnable {
|
|||
IMatch match = (IMatch) i.next();
|
||||
collector.acceptMatch(match);
|
||||
}
|
||||
collector.done();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -341,12 +341,12 @@ public class MatchLocator implements IMatchLocator{
|
|||
}
|
||||
|
||||
|
||||
public void locateMatches( String [] paths, IWorkspace workspace, IWorkingCopy[] workingCopies,ArrayList matches ) throws InterruptedException{
|
||||
public void locateMatches( String [] paths, IWorkspace workspace, IWorkingCopy[] workingCopies ) throws InterruptedException{
|
||||
|
||||
if (!(paths.length > 0))
|
||||
return;
|
||||
|
||||
matchStorage = matches;
|
||||
matchStorage = new ArrayList();
|
||||
workspaceRoot = (workspace != null) ? workspace.getRoot() : null;
|
||||
|
||||
HashMap wcPaths = new HashMap();
|
||||
|
@ -449,7 +449,7 @@ public class MatchLocator implements IMatchLocator{
|
|||
|
||||
ParserLanguage language = null;
|
||||
if( project != null ){
|
||||
language = CoreModel.getDefault().hasCCNature( project ) ? ParserLanguage.CPP : ParserLanguage.C;
|
||||
language = CoreModel.hasCCNature( project ) ? ParserLanguage.CPP : ParserLanguage.C;
|
||||
} else {
|
||||
//TODO no project, what language do we use?
|
||||
language = ParserLanguage.CPP;
|
||||
|
@ -485,17 +485,10 @@ public class MatchLocator implements IMatchLocator{
|
|||
}
|
||||
}
|
||||
|
||||
Iterator j = matches.iterator();
|
||||
while (j.hasNext()){
|
||||
IMatch match = (IMatch) j.next();
|
||||
try {
|
||||
resultCollector.acceptMatch(match);
|
||||
} catch (CoreException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
resultCollector.done();
|
||||
AcceptMatchOperation acceptMatchOp = new AcceptMatchOperation( resultCollector, matchStorage );
|
||||
try {
|
||||
CCorePlugin.getWorkspace().run(acceptMatchOp,null);
|
||||
} catch (CoreException e) {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue