use of org.eclipse.search.ui.text.Match in project webtools.sourceediting by eclipse.
the class JsSearchRequestor method addSearchMatch.
protected void addSearchMatch(IDocument jspDocument, IFile jspFile, int jspStart, int jspEnd, String jspText) {
if (!jspFile.exists()) {
return;
}
int lineNumber = -1;
try {
lineNumber = jspDocument.getLineOfOffset(jspStart);
} catch (BadLocationException e) {
// $NON-NLS-1$
Logger.logException("offset: " + Integer.toString(jspStart), e);
}
createSearchMarker(jspFile, jspStart, jspEnd, lineNumber);
if (this.fJavaRequestor != null) {
Match match = new Match(jspFile, jspStart, jspEnd - jspStart);
this.fJavaRequestor.reportMatch(match);
}
}
use of org.eclipse.search.ui.text.Match in project titan.EclipsePlug-ins by eclipse.
the class SearchLabelProvider method getText.
@Override
public String getText(final Object element) {
if (element instanceof IResource) {
return WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider().getText(element);
}
if (element instanceof Match) {
Match match = (Match) element;
IFile logFile = (IFile) match.getElement();
RandomAccessFile file = null;
String result = "";
try {
// TODO: This should be cached in some way
File indexFile = LogFileCacheHandler.getLogRecordIndexFileForLogFile(logFile);
LogRecordIndex[] indexes = LogFileCacheHandler.readLogRecordIndexFile(indexFile, match.getOffset(), 1);
file = new RandomAccessFile(new File(logFile.getLocationURI()), "r");
int length = indexes[0].getRecordLength() > MAX_TEXT_LENGTH ? MAX_TEXT_LENGTH : indexes[0].getRecordLength();
byte[] record = new byte[length];
file.seek(indexes[0].getFileOffset());
file.read(record);
result = new String(record);
} catch (FileNotFoundException e) {
ErrorReporter.logExceptionStackTrace(e);
// $NON-NLS-1$
TitanLogExceptionHandler.handleException(new TechnicalException(logFile.getName() + ": File not found " + e.getMessage()));
return logFile.getName() + ": File not found";
} catch (IOException e) {
ErrorReporter.logExceptionStackTrace(e);
// $NON-NLS-1$
TitanLogExceptionHandler.handleException(new TechnicalException("Error while reading the log file." + e.getMessage()));
return "Error while reading the log file.";
} finally {
IOUtils.closeQuietly(file);
}
return result;
}
return "Unexpected element";
}
use of org.eclipse.search.ui.text.Match in project erlide_eclipse by erlang.
the class ErlSearchQuery method addMatches.
private void addMatches(final List<ModuleLineFunctionArityRef> chunk) {
final List<Match> l = Lists.newArrayListWithCapacity(chunk.size());
final List<ErlangSearchElement> resultAdded = Lists.newArrayListWithCapacity(chunk.size());
for (final ModuleLineFunctionArityRef ref : chunk) {
final Match m = SearchUtil.createMatch(ref, pathToModuleMap);
l.add(m);
resultAdded.add((ErlangSearchElement) m.getElement());
}
fSearchResult = (ErlangSearchResult) getSearchResult();
final List<ErlangSearchElement> result = fSearchResult.getResult();
result.addAll(resultAdded);
fSearchResult.setResult(result);
fSearchResult.addMatches(l.toArray(new Match[l.size()]));
}
use of org.eclipse.search.ui.text.Match in project erlide_eclipse by erlang.
the class ErlangSearchResult method removeMatches.
@Override
public void removeMatches(final Match[] matches) {
for (final Match match : matches) {
final Object element = match.getElement();
final int matchCount = getMatchCount(element);
if (matchCount == 1 || matchCount == countMatches(element, matches)) {
removeElement(element);
}
}
super.removeMatches(matches);
}
use of org.eclipse.search.ui.text.Match in project erlide_eclipse by erlang.
the class ErlangSearchResult method computeContainedMatches.
@Override
public Match[] computeContainedMatches(final AbstractTextSearchResult aResult, final IFile file) {
final ErlangSearchResult esr = (ErlangSearchResult) aResult;
final List<Match> l = new ArrayList<>();
final List<ErlangSearchElement> eses = esr.getResult();
final String name = file.getName();
if (eses == null) {
// || !ErlideUtil.hasModuleExtension(name)) {
return ErlangSearchResult.NO_MATCHES;
}
for (final ErlangSearchElement ese : eses) {
final String moduleName = new Path(ese.getModuleName()).lastSegment();
if (moduleName.equals(name)) {
final Match[] matches = getMatches(ese);
Collections.addAll(l, matches);
}
}
return l.toArray(new Match[l.size()]);
}
Aggregations