use of org.eclipse.jdt.ui.search.ElementQuerySpecification 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.jdt.ui.search.ElementQuerySpecification in project che by eclipse.
the class SearchTestHelper method runMethodRefQuery.
static JavaSearchQuery runMethodRefQuery(String TypeName, String methodName, String[] parameterTypes) throws JavaModelException {
IMethod method = getMethod(TypeName, methodName, parameterTypes);
JavaSearchQuery query = new JavaSearchQuery(new ElementQuerySpecification(method, IJavaSearchConstants.REFERENCES, JavaSearchScopeFactory.getInstance().createWorkspaceScope(true), "workspace scope"));
NewSearchUI.runQueryInForeground(null, query);
return query;
}
use of org.eclipse.jdt.ui.search.ElementQuerySpecification in project xtext-eclipse by eclipse.
the class QueryParticipant method search.
@Override
public void search(ISearchRequestor requestor, QuerySpecification query, IProgressMonitor monitor) throws CoreException {
if (!isHandled(query)) {
return;
}
if (monitor == null) {
monitor = new NullProgressMonitor();
}
try {
if (query instanceof ElementQuerySpecification) {
ElementQuerySpecification elementQuery = (ElementQuerySpecification) query;
IJavaElement element = elementQuery.getElement();
final URI uri = typeURIHelper.getFullURI(element);
if (uri != null)
createSearchHelper(requestor).search(uri, monitor);
}
} finally {
monitor.done();
}
}
use of org.eclipse.jdt.ui.search.ElementQuerySpecification in project xtext-eclipse by eclipse.
the class JdtReferenceFinder method createQuery.
@SuppressWarnings("all")
protected QuerySpecification createQuery(IJavaElement element) throws JavaModelException, InterruptedException {
JavaSearchScopeFactory factory = JavaSearchScopeFactory.getInstance();
boolean isInsideJRE = factory.isInsideJRE(element);
IJavaSearchScope scope = factory.createWorkspaceScope(isInsideJRE);
String description = factory.getWorkspaceScopeDescription(isInsideJRE);
return new ElementQuerySpecification(element, IJavaSearchConstants.REFERENCES, scope, description);
}
use of org.eclipse.jdt.ui.search.ElementQuerySpecification in project che by eclipse.
the class SearchTestHelper method runTypeRefQuery.
static JavaSearchQuery runTypeRefQuery(String typeName) throws JavaModelException {
IType type = getType(typeName);
JavaSearchQuery query = new JavaSearchQuery(new ElementQuerySpecification(type, IJavaSearchConstants.REFERENCES, JavaSearchScopeFactory.getInstance().createWorkspaceScope(true), "workspace scope"));
NewSearchUI.runQueryInForeground(null, query);
return query;
}
Aggregations