use of com.python.pydev.refactoring.refactorer.search.copied.FileMatch in project Pydev by fabioz.
the class FindOccurrencesSearchQuery method run.
@Override
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
try {
monitor.beginTask("Searching...", 100);
req.pushMonitor(monitor);
FindOccurrencesSearchResult searchResult = (FindOccurrencesSearchResult) getSearchResult();
Map<Tuple<String, File>, HashSet<ASTEntry>> occurrences;
try {
req.pushMonitor(new SubProgressMonitor(monitor, 80));
occurrences = pyRefactoring.findAllOccurrences(req);
} finally {
req.popMonitor().done();
}
if (occurrences == null) {
return Status.OK_STATUS;
}
int length = req.qualifier.length();
HashSet<Integer> foundOffsets = new HashSet<Integer>();
try {
req.pushMonitor(new SubProgressMonitor(monitor, 20));
Set<Entry<Tuple<String, File>, HashSet<ASTEntry>>> entrySet = occurrences.entrySet();
req.getMonitor().beginTask("Resolving occurrences...", entrySet.size());
for (Map.Entry<Tuple<String, File>, HashSet<ASTEntry>> o : entrySet) {
foundOffsets.clear();
IFile workspaceFile = null;
try {
IProject project = null;
IPythonNature nature = req.nature;
if (nature != null) {
project = nature.getProject();
}
workspaceFile = FindWorkspaceFiles.getWorkspaceFile(o.getKey().o2, project);
if (workspaceFile == null) {
Log.logInfo(StringUtils.format("Ignoring: %s. " + "Unable to resolve to a file in the Eclipse workspace.", o.getKey().o2));
continue;
}
} catch (IllegalStateException e) {
// this can happen on tests (but if not on tests, we want to re-throw it
String message = e.getMessage();
if (message == null || !message.equals("Workspace is closed.")) {
throw e;
}
// otherwise, let's just keep going in the test...
continue;
}
IDocument doc = FileUtilsFileBuffer.getDocFromResource(workspaceFile);
req.getMonitor().setTaskName("Resolving occurrences... " + workspaceFile);
for (ASTEntry entry : o.getValue()) {
int offset = AbstractRenameRefactorProcess.getOffset(doc, entry);
if (!foundOffsets.contains(offset)) {
foundOffsets.add(offset);
if (DebugFlags.DEBUG_FIND_REFERENCES) {
System.out.println("Adding match:" + workspaceFile);
}
PySelection ps = new PySelection(doc, offset);
int lineNumber = ps.getLineOfOffset();
String lineContents = ps.getLine(lineNumber);
int lineStartOffset = ps.getLineOffset(lineNumber);
LineElement element = new LineElement(workspaceFile, lineNumber, lineStartOffset, lineContents, offset - lineStartOffset);
searchResult.addMatch(new FileMatch(workspaceFile, offset, length, element));
}
}
}
} finally {
req.popMonitor().done();
}
} catch (CoreException e) {
Log.log(e);
} finally {
req.popMonitor().done();
}
return Status.OK_STATUS;
}
Aggregations