use of org.eclipse.search.ui.text.Match in project che by eclipse.
the class SearchManager method performFindUsageSearch.
private FindUsagesResponse performFindUsageSearch(IJavaElement element) throws JavaModelException, BadLocationException {
JavaSearchScopeFactory factory = JavaSearchScopeFactory.getInstance();
boolean isInsideJRE = factory.isInsideJRE(element);
JavaSearchQuery query = new JavaSearchQuery(new ElementQuerySpecification(element, IJavaSearchConstants.REFERENCES, factory.createWorkspaceScope(isInsideJRE), "workspace scope"));
NewSearchUI.runQueryInForeground(null, query);
ISearchResult result = query.getSearchResult();
JavaSearchResult javaResult = ((JavaSearchResult) result);
FindUsagesResponse response = DtoFactory.newDto(FindUsagesResponse.class);
Map<String, List<org.eclipse.che.ide.ext.java.shared.dto.search.Match>> mapMaches = new HashMap<>();
JavaElementToDtoConverter converter = new JavaElementToDtoConverter(javaResult);
for (Object o : javaResult.getElements()) {
IJavaElement javaElement = (IJavaElement) o;
IDocument document = null;
if (javaElement instanceof IMember) {
IMember member = ((IMember) javaElement);
if (member.isBinary()) {
if (member.getClassFile().getSource() != null) {
document = new Document(member.getClassFile().getSource());
}
} else {
document = getDocument(member.getCompilationUnit());
}
} else if (javaElement instanceof IPackageDeclaration) {
ICompilationUnit ancestor = (ICompilationUnit) (javaElement).getAncestor(IJavaElement.COMPILATION_UNIT);
document = getDocument(ancestor);
}
converter.addElementToProjectHierarchy(javaElement);
Match[] matches = javaResult.getMatches(o);
List<org.eclipse.che.ide.ext.java.shared.dto.search.Match> matchList = new ArrayList<>();
for (Match match : matches) {
org.eclipse.che.ide.ext.java.shared.dto.search.Match dtoMatch = DtoFactory.newDto(org.eclipse.che.ide.ext.java.shared.dto.search.Match.class);
if (document != null) {
IRegion lineInformation = document.getLineInformationOfOffset(match.getOffset());
int offsetInLine = match.getOffset() - lineInformation.getOffset();
Region matchInLine = DtoFactory.newDto(Region.class).withOffset(offsetInLine).withLength(match.getLength());
dtoMatch.setMatchInLine(matchInLine);
dtoMatch.setMatchLineNumber(document.getLineOfOffset(match.getOffset()));
dtoMatch.setMatchedLine(document.get(lineInformation.getOffset(), lineInformation.getLength()));
}
dtoMatch.setFileMatchRegion(DtoFactory.newDto(Region.class).withOffset(match.getOffset()).withLength(match.getLength()));
matchList.add(dtoMatch);
}
mapMaches.put(javaElement.getHandleIdentifier(), matchList);
}
List<JavaProject> projects = converter.getProjects();
response.setProjects(projects);
response.setMatches(mapMaches);
response.setSearchElementLabel(JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT));
return response;
}
use of org.eclipse.search.ui.text.Match in project che by eclipse.
the class AbstractJavaSearchResult method computeContainedMatches.
private Match[] computeContainedMatches(IAdaptable adaptable) {
IJavaElement javaElement = (IJavaElement) adaptable.getAdapter(IJavaElement.class);
Set<Match> matches = new HashSet<Match>();
if (javaElement != null) {
collectMatches(matches, javaElement);
}
IFile file = (IFile) adaptable.getAdapter(IFile.class);
if (file != null) {
collectMatches(matches, file);
}
if (!matches.isEmpty()) {
return matches.toArray(new Match[matches.size()]);
}
return NO_MATCHES;
}
use of org.eclipse.search.ui.text.Match in project eclipse.platform.text by eclipse.
the class RemoveMatchAction method run.
@Override
public void run() {
Match match = fPage.getCurrentMatch();
AbstractTextSearchResult result = fPage.getInput();
if (match != null && result != null)
result.removeMatch(match);
}
use of org.eclipse.search.ui.text.Match in project eclipse.platform.text by eclipse.
the class AnnotationHighlighter method handleContentReplaced.
@Override
protected void handleContentReplaced(IFileBuffer buffer) {
if (!(buffer instanceof ITextFileBuffer))
return;
ITextFileBuffer textBuffer = (ITextFileBuffer) buffer;
if (fDocument != null && fDocument.equals(textBuffer.getDocument())) {
Set<Match> allMatches = fMatchesToAnnotations.keySet();
Match[] matchesCopy = allMatches.toArray(new Match[allMatches.size()]);
removeAll();
addHighlights(matchesCopy);
}
}
use of org.eclipse.search.ui.text.Match in project eclipse.platform.text by eclipse.
the class EditorAccessHighlighter method addHighlights.
@Override
public void addHighlights(Match[] matches) {
Map<IAnnotationModel, HashMap<Annotation, Position>> mapsByAnnotationModel = new HashMap<>();
for (Match match : matches) {
int offset = match.getOffset();
int length = match.getLength();
if (offset >= 0 && length >= 0) {
try {
Position position = createPosition(match);
if (position != null) {
Map<Annotation, Position> map = getMap(mapsByAnnotationModel, match);
if (map != null) {
Annotation annotation = match.isFiltered() ? new Annotation(SearchPlugin.FILTERED_SEARCH_ANNOTATION_TYPE, true, null) : new Annotation(SearchPlugin.SEARCH_ANNOTATION_TYPE, true, null);
fMatchesToAnnotations.put(match, annotation);
map.put(annotation, position);
}
}
} catch (BadLocationException e) {
SearchPlugin.log(new Status(IStatus.ERROR, SearchPlugin.getID(), 0, SearchMessages.EditorAccessHighlighter_error_badLocation, e));
}
}
}
for (Entry<IAnnotationModel, HashMap<Annotation, Position>> entry : mapsByAnnotationModel.entrySet()) {
addAnnotations(entry.getKey(), entry.getValue());
}
}
Aggregations