use of org.eclipse.jdt.core.search.SearchEngine in project liferay-ide by liferay.
the class JSPMarkerResolutionGenerator method _findTypes.
private List<IType> _findTypes(IJavaProject javaProject, String typeName) {
List<IType> retval = Collections.emptyList();
try {
IType type = javaProject.findType(typeName);
if (type != null) {
TypeInProjectRequestor requestor = new TypeInProjectRequestor();
IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(javaProject, type, true, false, null);
SearchPattern search = SearchPattern.createPattern("*", IJavaSearchConstants.CLASS, IJavaSearchConstants.DECLARATIONS, 0);
new SearchEngine().search(search, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, new NullProgressMonitor());
retval = requestor.getResults();
}
} catch (Exception e) {
}
return retval;
}
use of org.eclipse.jdt.core.search.SearchEngine in project liferay-ide by liferay.
the class HierarchyTypeClassNameExtractor method doExtractClassNames.
@Override
protected String[] doExtractClassNames(Node node, IFile file, String pathForClass, String findByAttrName, boolean findByParentNode, String xpathFactoryProviderId, NamespaceInfos namespaceInfo) throws XPathExpressionException {
String[] retval = null;
IJavaProject project = JavaCore.create(file.getProject());
try {
IType type = project.findType(_typeName);
if (type != null) {
TypeNameRequestor requestor = new TypeNameRequestor();
IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(project, type, true, false, null);
SearchPattern search = SearchPattern.createPattern("*", IJavaSearchConstants.CLASS, IJavaSearchConstants.DECLARATIONS, 0);
new SearchEngine().search(search, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, new NullProgressMonitor());
retval = requestor.getResults().toArray(new String[0]);
}
} catch (Exception e) {
}
return retval;
}
use of org.eclipse.jdt.core.search.SearchEngine in project ch.hsr.ifs.cdttesting by IFS-HSR.
the class JumpToMostSpecificClassHandler method findType.
protected final IType findType(final IJavaProject project, String className) {
final IType[] result = { null };
final String dottedName = className.replace('$', '.');
try {
PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
if (project != null) {
result[0] = internalFindType(project, dottedName, new HashSet<IJavaProject>(), monitor);
}
if (result[0] == null) {
int lastDot = dottedName.lastIndexOf('.');
TypeNameMatchRequestor nameMatchRequestor = new TypeNameMatchRequestor() {
@Override
public void acceptTypeNameMatch(TypeNameMatch match) {
result[0] = match.getType();
}
};
new SearchEngine().searchAllTypeNames(lastDot >= 0 ? dottedName.substring(0, lastDot).toCharArray() : null, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE, (lastDot >= 0 ? dottedName.substring(lastDot + 1) : dottedName).toCharArray(), SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE, IJavaSearchConstants.TYPE, SearchEngine.createWorkspaceScope(), nameMatchRequestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, monitor);
}
} catch (JavaModelException e) {
throw new InvocationTargetException(e);
}
}
});
} catch (InvocationTargetException e) {
JUnitPlugin.log(e);
} catch (InterruptedException e) {
// user cancelled
}
return result[0];
}
use of org.eclipse.jdt.core.search.SearchEngine in project xtext-eclipse by eclipse.
the class JavaTypeQuickfixes method getImportedTypesScope.
protected IScope getImportedTypesScope(EObject model, final String misspelled, final IScope actualScope, IJavaSearchScope scope) {
if (scope == null) {
return IScope.NULLSCOPE;
}
try {
final Set<String> visiblePackages = importsConfiguration.getImplicitlyImportedPackages((XtextResource) model.eResource());
final Set<String> importedTypes = Sets.newHashSet();
final Set<String> seen = Sets.newHashSet();
XImportSection importSection = importsConfiguration.getImportSection((XtextResource) model.eResource());
if (importSection != null) {
parseImportSection(importSection, new IAcceptor<String>() {
@Override
public void accept(String t) {
visiblePackages.add(t);
}
}, new IAcceptor<String>() {
@Override
public void accept(String t) {
importedTypes.add(t);
}
});
}
SearchEngine searchEngine = new SearchEngine();
final List<IEObjectDescription> validProposals = Lists.newArrayList();
for (String importedType : importedTypes) {
if (validProposals.size() <= 5 && seen.add(importedType)) {
int dot = importedType.lastIndexOf('.');
if (dot != -1) {
importedType = importedType.substring(dot + 1);
}
if (isSimilarTypeName(misspelled, importedType)) {
QualifiedName qualifiedName = qualifiedNameConverter.toQualifiedName(importedType);
for (IEObjectDescription element : actualScope.getElements(qualifiedName)) {
validProposals.add(new AliasedEObjectDescription(qualifiedName, element));
break;
}
}
}
}
try {
for (String visiblePackage : visiblePackages) {
if (validProposals.size() <= 5) {
searchEngine.searchAllTypeNames(visiblePackage.toCharArray(), SearchPattern.R_EXACT_MATCH, null, SearchPattern.R_EXACT_MATCH, IJavaSearchConstants.TYPE, scope, new TypeNameRequestor() {
@Override
public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) {
StringBuilder typeNameBuilder = new StringBuilder(simpleTypeName.length);
for (char[] enclosingType : enclosingTypeNames) {
typeNameBuilder.append(enclosingType);
typeNameBuilder.append('.');
}
typeNameBuilder.append(simpleTypeName);
String typeName = typeNameBuilder.toString();
if (isSimilarTypeName(misspelled, typeName)) {
String fqNameAsString = getQualifiedTypeName(packageName, enclosingTypeNames, simpleTypeName);
if (seen.add(fqNameAsString)) {
QualifiedName qualifiedName = qualifiedNameConverter.toQualifiedName(typeName);
for (IEObjectDescription element : actualScope.getElements(qualifiedName)) {
validProposals.add(new AliasedEObjectDescription(qualifiedName, element));
break;
}
}
}
}
}, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, new NullProgressMonitor() {
@Override
public boolean isCanceled() {
return validProposals.size() > 5;
}
});
}
}
} catch (OperationCanceledException exc) {
// enough proposals
}
return new SimpleScope(validProposals);
} catch (JavaModelException jme) {
return IScope.NULLSCOPE;
}
}
use of org.eclipse.jdt.core.search.SearchEngine in project egradle by de-jcup.
the class JDTDataAccess method scanForJavaType.
/**
* Scan for package names
*
* @param type
* @param scope
* @param packageNames - can be <code>null</code>
* @return list with java types
*/
public List<String> scanForJavaType(String type, IJavaSearchScope scope, String... packageNames) {
SearchEngine engine = new SearchEngine();
List<String> foundList = new ArrayList<>();
try {
// int packageFlags=0;
// String packPattern = "org.gradle.api";
// String typePattern = "Project";
// int matchRule;
// int elementKind;
// IJavaSearchScope searchScope;
// TypeNameRequestor requestor;
// IProgressMonitor progressMonitor;
// engine.searchAllTypeNames((packPattern == null) ? null :
// packPattern.toCharArray(),
// packageFlags,
// typePattern.toCharArray(), matchRule,
// IJavaElement.TYPE, searchScope, requestor, 3,
// progressMonitor);
List<char[]> groovyAutomaticImports = new ArrayList<>();
if ("BigDecimal".equals(type) || "BigInteger".equals(type)) {
addImport(groovyAutomaticImports, "java.math");
} else {
addImport(groovyAutomaticImports, "java.lang");
addImport(groovyAutomaticImports, "java.util");
addImport(groovyAutomaticImports, "java.net");
addImport(groovyAutomaticImports, "java.io");
if (packageNames != null && packageNames.length > 0) {
for (String packageName : packageNames) {
if (packageName != null && !packageName.isEmpty()) {
addImport(groovyAutomaticImports, packageName);
}
}
}
}
char[][] qualifications = new char[groovyAutomaticImports.size()][];
for (int i = 0; i < groovyAutomaticImports.size(); i++) {
qualifications[i] = groovyAutomaticImports.get(i);
}
char[][] typeNames = new char[1][];
typeNames[0] = type.toCharArray();
TypeNameRequestor nameRequestor = new TypeNameRequestor() {
@Override
public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) {
String simpleName = new String(simpleTypeName);
String simplePackageName = new String(packageName);
foundList.add(simplePackageName + "." + simpleName);
}
};
int policiy = IJavaSearchConstants.FORCE_IMMEDIATE_SEARCH;
IProgressMonitor progressMonitor = new NullProgressMonitor();
engine.searchAllTypeNames(qualifications, typeNames, scope, nameRequestor, policiy, progressMonitor);
} catch (JavaModelException e) {
EditorUtil.INSTANCE.logError("Was not able to search all type names", e);
}
return foundList;
}
Aggregations