use of org.eclipse.jdt.core.search.TypeNameMatch in project che by eclipse.
the class ImportOrganizeTest method createQuery.
protected IChooseImportQuery createQuery(final String name, final String[] choices, final int[] nEntries) {
return new IChooseImportQuery() {
public TypeNameMatch[] chooseImports(TypeNameMatch[][] openChoices, ISourceRange[] ranges) {
assertTrue(name + "-query-nchoices1", choices.length == openChoices.length);
assertTrue(name + "-query-nchoices2", nEntries.length == openChoices.length);
for (int i = 0; i < nEntries.length; i++) {
assertTrue(name + "-query-cnt" + i, openChoices[i].length == nEntries[i]);
}
TypeNameMatch[] res = new TypeNameMatch[openChoices.length];
for (int i = 0; i < openChoices.length; i++) {
TypeNameMatch[] selection = openChoices[i];
assertNotNull(name + "-query-setset" + i, selection);
assertTrue(name + "-query-setlen" + i, selection.length > 0);
TypeNameMatch found = null;
for (int k = 0; k < selection.length; k++) {
if (selection[k].getFullyQualifiedName().equals(choices[i])) {
found = selection[k];
}
}
assertNotNull(name + "-query-notfound" + i, found);
res[i] = found;
}
return res;
}
};
}
use of org.eclipse.jdt.core.search.TypeNameMatch in project AutoRefactor by JnRouvignac.
the class ReplaceQualifiedNamesBySimpleNamesRefactoring method importTypesFromPackage.
private void importTypesFromPackage(final String pkgName, ASTNode node) {
final TypeNameMatchRequestor importTypeCollector = new TypeNameMatchRequestor() {
@Override
public void acceptTypeNameMatch(TypeNameMatch typeNameMatch) {
final boolean isTopLevelType = typeNameMatch.getType().getDeclaringType() == null;
if (isTopLevelType) {
if (!pkgName.equals(typeNameMatch.getPackageName())) {
// sanity check failed
throw new IllegalStateException("Expected package '" + typeNameMatch.getPackageName() + "' to be equal to '" + pkgName + "'");
}
QName qname = QName.valueOf(typeNameMatch.getFullyQualifiedName());
types.addName(FQN.fromImport(qname, true));
}
}
};
try {
final SearchEngine searchEngine = new SearchEngine();
searchEngine.searchAllTypeNames(// search in this package
pkgName.toCharArray(), // search in this package
R_EXACT_MATCH, // do not filter by type name
null, // do not filter by type name
R_EXACT_MATCH, // look for all java types (class, interfaces, enums, etc.)
TYPE, // search everywhere
createWorkspaceScope(), importTypeCollector, // wait in case the indexer is indexing
WAIT_UNTIL_READY_TO_SEARCH, ctx.getProgressMonitor());
} catch (JavaModelException e) {
throw new UnhandledException(node, e);
}
}
use of org.eclipse.jdt.core.search.TypeNameMatch in project bndtools by bndtools.
the class SuperInterfaceSelectionDialog method addSelectedInterfaces.
/*
* Adds selected interfaces to the list.
*/
private void addSelectedInterfaces() {
StructuredSelection selection = getSelectedItems();
if (selection == null)
return;
for (Iterator<?> iter = selection.iterator(); iter.hasNext(); ) {
Object obj = iter.next();
if (obj instanceof TypeNameMatch) {
accessedHistoryItem(obj);
TypeNameMatch type = (TypeNameMatch) obj;
String qualifiedName = getNameWithTypeParameters(type.getType());
String message;
if (fTypeWizardPage.addSuperInterface(qualifiedName)) {
message = Messages.format(NewWizardMessages.SuperInterfaceSelectionDialog_interfaceadded_info, BasicElementLabels.getJavaElementName(qualifiedName));
} else {
message = Messages.format(NewWizardMessages.SuperInterfaceSelectionDialog_interfacealreadyadded_info, BasicElementLabels.getJavaElementName(qualifiedName));
}
updateStatus(new StatusInfo(IStatus.INFO, message));
}
}
}
use of org.eclipse.jdt.core.search.TypeNameMatch in project sts4 by spring-projects.
the class OpenFullyQualifiedNameInEditor method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
String fqName = event.getParameter(FQ_NAME);
String projectName = event.getParameter(PROJECT_NAME);
String packageName = "";
String typeName = fqName;
int idx = fqName.lastIndexOf('.');
if (idx >= 0) {
packageName = fqName.substring(0, idx);
typeName = idx < fqName.length() - 1 ? fqName.substring(idx + 1) : "";
}
if (!typeName.isEmpty()) {
SearchEngine engine = new SearchEngine((WorkingCopyOwner) null);
List<TypeNameMatch> matches = new ArrayList<>();
String searchedTypeName = getSearchedTypeName(typeName);
final boolean isInnerType = searchedTypeName != typeName;
TypeNameMatchRequestor requestor = new TypeNameMatchRequestor() {
@Override
public void acceptTypeNameMatch(TypeNameMatch match) {
if (isInnerType) {
if (match.getFullyQualifiedName().equals(fqName.replace("$", "."))) {
matches.add(match);
}
} else {
matches.add(match);
}
}
};
try {
IJavaSearchScope searchScope = createSearchScope(projectName);
engine.searchAllTypeNames(packageName.toCharArray(), SearchPattern.R_EXACT_MATCH, searchedTypeName.toCharArray(), SearchPattern.R_EXACT_MATCH, IJavaSearchConstants.TYPE, searchScope, requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, new NullProgressMonitor());
if (matches.isEmpty()) {
BootLanguageServerPlugin.getDefault().getLog().log(new Status(IStatus.WARNING, BootLanguageServerPlugin.ID, "Cannot find type: " + fqName));
} else {
if (matches.size() > 1) {
BootLanguageServerPlugin.getDefault().getLog().log(new Status(IStatus.WARNING, BootLanguageServerPlugin.ID, "More than one type is defined for: " + fqName));
}
try {
IType type = matches.get(0).getType();
IEditorPart editorPart = JavaUI.openInEditor(type);
JavaUI.revealInEditor(editorPart, (IJavaElement) type);
} catch (JavaModelException ex) {
// $NON-NLS-1$
throw new ExecutionException("Error opening java element in editor", ex);
} catch (PartInitException ex) {
// $NON-NLS-1$
throw new ExecutionException("Error opening java element in editor", ex);
}
}
} catch (JavaModelException e) {
BootLanguageServerPlugin.getDefault().getLog().log(e.getStatus());
}
}
return null;
}
use of org.eclipse.jdt.core.search.TypeNameMatch in project AutoRefactor by JnRouvignac.
the class ObsoleteSimpleNameRatherThanQualifiedNameCleanUp method importTypesFromPackage.
private void importTypesFromPackage(final String pkgName, final ASTNode visited) {
TypeNameMatchRequestor importTypeCollector = new TypeNameMatchRequestor() {
@Override
public void acceptTypeNameMatch(final TypeNameMatch typeNameMatch) {
boolean isTopLevelType = typeNameMatch.getType().getDeclaringType() == null;
if (isTopLevelType) {
if (!pkgName.equals(typeNameMatch.getPackageName())) {
// Sanity check failed
throw new IllegalStateException(// $NON-NLS-1$
"Expected package '" + typeNameMatch.getPackageName() + "' to be equal to '" + pkgName + // $NON-NLS-1$ //$NON-NLS-2$
"'");
}
QName qname = QName.valueOf(typeNameMatch.getFullyQualifiedName());
types.addName(FQN.fromImport(qname, true));
}
}
};
try {
SearchEngine searchEngine = new SearchEngine();
// search in this package
searchEngine.searchAllTypeNames(// search in this package
pkgName.toCharArray(), // search in this package
SearchPattern.R_EXACT_MATCH, // do not filter by type name
null, // do not filter by type name
SearchPattern.R_EXACT_MATCH, // look for all java types (class, interfaces, enums, etc.)
IBinding.TYPE, // search everywhere
SearchEngine.createWorkspaceScope(), // wait in case the indexer is indexing
importTypeCollector, // wait in case the indexer is indexing
IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, cuRewrite.getProgressMonitor());
} catch (JavaModelException e) {
throw new UnhandledException(visited, e);
}
}
Aggregations