use of org.eclipse.jdt.core.search.SearchEngine in project quarkus-ls by redhat-developer.
the class JavaTypesSearch method collectClassesAndInterfaces.
private void collectClassesAndInterfaces(IProgressMonitor monitor, List<JavaTypeInfo> javaTypes) throws JavaModelException {
// Collect classes and interfaces according to the type name
SearchEngine engine = new SearchEngine();
//
engine.searchAllTypeNames(//
packageName == null ? null : packageName.toCharArray(), //
SearchPattern.R_EXACT_MATCH, //
typeName.toCharArray(), //
SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE, //
IJavaSearchConstants.CLASS_AND_INTERFACE, //
scope, new TypeNameMatchRequestor() {
@Override
public void acceptTypeNameMatch(TypeNameMatch match) {
IType type = (IType) match.getType();
String typeSignature = AbstractTypeResolver.resolveJavaTypeSignature(type);
JavaTypeInfo classInfo = new JavaTypeInfo();
classInfo.setSignature(typeSignature);
javaTypes.add(classInfo);
try {
classInfo.setKind(type.isInterface() ? JavaTypeKind.Interface : JavaTypeKind.Class);
} catch (JavaModelException e) {
LOGGER.log(Level.SEVERE, "Error while collecting Java Types for '" + packageName + " package and Java type '" + typeName + "'.", e);
}
}
}, //
IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, monitor);
}
use of org.eclipse.jdt.core.search.SearchEngine in project quarkus-ls by redhat-developer.
the class TemplateDataSupport method search.
private static void search(IMember fieldOrMethod, TemplateDataVisitor visitor, IProgressMonitor monitor) throws CoreException {
boolean searchInJavaProject = isSearchInJavaProject(fieldOrMethod);
SearchEngine engine = new SearchEngine();
SearchPattern pattern = SearchPattern.createPattern(fieldOrMethod, IJavaSearchConstants.REFERENCES);
int searchScope = IJavaSearchScope.SOURCES;
IJavaSearchScope scope = SearchEngine.createJavaSearchScope(true, new IJavaElement[] { searchInJavaProject ? fieldOrMethod.getJavaProject() : fieldOrMethod.getCompilationUnit() }, searchScope);
engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, new SearchRequestor() {
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
Object o = match.getElement();
if (o instanceof IMethod) {
IMethod method = (IMethod) o;
visitor.setMethod(method);
// Get the AST of the method declaration where template field of CheckedTemplate
// method is referenced.
CompilationUnit cu = getASTRoot(method.getCompilationUnit());
ASTNode methodDeclarationAST = new NodeFinder(cu, method.getSourceRange().getOffset(), method.getSourceRange().getLength()).getCoveringNode();
// Visit the body of the method declaration to collect method invocation of
// temlate.data(param-name, param-type);
methodDeclarationAST.accept(visitor);
}
}
}, monitor);
}
use of org.eclipse.jdt.core.search.SearchEngine in project teavm by konsoletyper.
the class ClassSelectionDialog method findTypes.
private IType[] findTypes(String patternText, IProgressMonitor progressMonitor) {
IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaProject[] { javaProject }, IJavaSearchScope.SOURCES | IJavaSearchScope.REFERENCED_PROJECTS | IJavaSearchScope.SYSTEM_LIBRARIES | IJavaSearchScope.APPLICATION_LIBRARIES);
SearchPattern pattern = createSearchPattern(patternText);
SearchParticipant[] participants = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() };
ClassCollector collector = new ClassCollector();
try {
new SearchEngine().search(pattern, participants, scope, collector, progressMonitor);
} catch (CoreException e) {
logError(e);
return new IType[0];
}
IType[] foundTypes = collector.getTypes().toArray(new IType[collector.getTypes().size()]);
return foundTypes;
}
use of org.eclipse.jdt.core.search.SearchEngine in project che by eclipse.
the class AddImportsOperation method findAllTypes.
/*
* Finds a type by the simple name.
*/
private TypeNameMatch[] findAllTypes(String simpleTypeName, IJavaSearchScope searchScope, SimpleName nameNode, IProgressMonitor monitor) throws JavaModelException {
boolean is50OrHigher = JavaModelUtil.is50OrHigher(fCompilationUnit.getJavaProject());
int typeKinds = SimilarElementsRequestor.ALL_TYPES;
if (nameNode != null) {
typeKinds = ASTResolving.getPossibleTypeKinds(nameNode, is50OrHigher);
}
ArrayList<TypeNameMatch> typeInfos = new ArrayList<TypeNameMatch>();
TypeNameMatchCollector requestor = new TypeNameMatchCollector(typeInfos);
int matchMode = SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE;
new SearchEngine().searchAllTypeNames(null, matchMode, simpleTypeName.toCharArray(), matchMode, getSearchForConstant(typeKinds), searchScope, requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, monitor);
ArrayList<TypeNameMatch> typeRefsFound = new ArrayList<TypeNameMatch>(typeInfos.size());
for (int i = 0, len = typeInfos.size(); i < len; i++) {
TypeNameMatch curr = typeInfos.get(i);
if (curr.getPackageName().length() > 0) {
// do not suggest imports from the default package
if (isOfKind(curr, typeKinds, is50OrHigher) && isVisible(curr)) {
typeRefsFound.add(curr);
}
}
}
return typeRefsFound.toArray(new TypeNameMatch[typeRefsFound.size()]);
}
use of org.eclipse.jdt.core.search.SearchEngine in project che by eclipse.
the class RenameMethodProcessor method batchFindNewOccurrences.
//Lower memory footprint than batchFindNewOccurrences. Not used because it is too slow.
//Final solution is maybe to do searches in chunks of ~ 50 CUs.
// private SearchResultGroup[] findNewOccurrences(IMethod[] newMethods, ICompilationUnit[] newDeclarationWCs, IProgressMonitor pm) throws CoreException {
// pm.beginTask("", fOccurrences.length * 2); //$NON-NLS-1$
//
// SearchPattern refsPattern= RefactoringSearchEngine.createOrPattern(newMethods, IJavaSearchConstants.REFERENCES);
// SearchParticipant[] searchParticipants= SearchUtils.getDefaultSearchParticipants();
// IJavaSearchScope scope= RefactoringScopeFactory.create(newMethods);
// MethodOccurenceCollector requestor= new MethodOccurenceCollector(getNewElementName());
// SearchEngine searchEngine= new SearchEngine(fWorkingCopyOwner);
//
// //TODO: should process only references
// for (int j= 0; j < fOccurrences.length; j++) { //should be getReferences()
// //cut memory peak by holding only one reference CU at a time in memory
// ICompilationUnit originalCu= fOccurrences[j].getCompilationUnit();
// ICompilationUnit newWc= null;
// try {
// ICompilationUnit wc= RenameAnalyzeUtil.findWorkingCopyForCu(newDeclarationWCs, originalCu);
// if (wc == null) {
// newWc= RenameAnalyzeUtil.createNewWorkingCopy(originalCu, fChangeManager, fWorkingCopyOwner,
// new SubProgressMonitor(pm, 1));
// }
// searchEngine.search(refsPattern, searchParticipants, scope, requestor, new SubProgressMonitor(pm, 1));
// } finally {
// if (newWc != null)
// newWc.discardWorkingCopy();
// }
// }
// SearchResultGroup[] newResults= RefactoringSearchEngine.groupByResource(requestor.getResults());
// pm.done();
// return newResults;
// }
private SearchResultGroup[] batchFindNewOccurrences(IMethod[] wcNewMethods, final IMethod[] wcOldMethods, ICompilationUnit[] newDeclarationWCs, IProgressMonitor pm, RefactoringStatus status) throws CoreException {
//$NON-NLS-1$
pm.beginTask("", 2);
SearchPattern refsPattern = RefactoringSearchEngine.createOrPattern(wcNewMethods, IJavaSearchConstants.REFERENCES);
SearchParticipant[] searchParticipants = SearchUtils.getDefaultSearchParticipants();
IJavaSearchScope scope = RefactoringScopeFactory.create(wcNewMethods);
MethodOccurenceCollector requestor;
if (getDelegateUpdating()) {
// There will be two new matches inside the delegate(s) (the invocation
// and the javadoc) which are OK and must not be reported.
// Note that except these ocurrences, the delegate bodies are empty
// (as they were created this way).
requestor = new MethodOccurenceCollector(getNewElementName()) {
@Override
public void acceptSearchMatch(ICompilationUnit unit, SearchMatch match) throws CoreException {
for (int i = 0; i < wcOldMethods.length; i++) if (wcOldMethods[i].equals(match.getElement()))
return;
super.acceptSearchMatch(unit, match);
}
};
} else
requestor = new MethodOccurenceCollector(getNewElementName());
SearchEngine searchEngine = new SearchEngine(fWorkingCopyOwner);
ArrayList<ICompilationUnit> needWCs = new ArrayList<ICompilationUnit>();
HashSet<ICompilationUnit> declaringCUs = new HashSet<ICompilationUnit>(newDeclarationWCs.length);
for (int i = 0; i < newDeclarationWCs.length; i++) declaringCUs.add(newDeclarationWCs[i].getPrimary());
for (int i = 0; i < fOccurrences.length; i++) {
ICompilationUnit cu = fOccurrences[i].getCompilationUnit();
if (!declaringCUs.contains(cu))
needWCs.add(cu);
}
ICompilationUnit[] otherWCs = null;
try {
otherWCs = RenameAnalyzeUtil.createNewWorkingCopies(needWCs.toArray(new ICompilationUnit[needWCs.size()]), fChangeManager, fWorkingCopyOwner, new SubProgressMonitor(pm, 1));
searchEngine.search(refsPattern, searchParticipants, scope, requestor, new SubProgressMonitor(pm, 1));
} finally {
pm.done();
if (otherWCs != null) {
for (int i = 0; i < otherWCs.length; i++) {
otherWCs[i].discardWorkingCopy();
}
}
}
SearchResultGroup[] newResults = RefactoringSearchEngine.groupByCu(requestor.getResults(), status);
return newResults;
}
Aggregations