use of org.eclipse.jdt.core.search.IJavaSearchScope in project bndtools by bndtools.
the class NewTypeWizardPage method chooseEnclosingType.
/**
* Opens a selection dialog that allows to select an enclosing type.
*
* @return returns the selected type or <code>null</code> if the dialog has been canceled. The caller typically sets
* the result to the enclosing type input field.
* <p>
* Clients can override this method if they want to offer a different dialog.
* </p>
* @since 3.2
*/
protected IType chooseEnclosingType() {
IPackageFragmentRoot root = getPackageFragmentRoot();
if (root == null) {
return null;
}
IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { root });
FilteredTypesSelectionDialog dialog = new FilteredTypesSelectionDialog(getShell(), false, getWizard().getContainer(), scope, IJavaSearchConstants.TYPE);
dialog.setTitle(NewWizardMessages.NewTypeWizardPage_ChooseEnclosingTypeDialog_title);
dialog.setMessage(NewWizardMessages.NewTypeWizardPage_ChooseEnclosingTypeDialog_description);
dialog.setInitialPattern(Signature.getSimpleName(getEnclosingTypeText()));
if (dialog.open() == Window.OK) {
return (IType) dialog.getFirstResult();
}
return null;
}
use of org.eclipse.jdt.core.search.IJavaSearchScope in project che by eclipse.
the class JavaContext method addImport.
/**
* Adds an import for type with type name <code>type</code> if possible.
* Returns a string which can be used to reference the type.
*
* @param type the fully qualified name of the type to import
* @return returns a type to which the type binding can be assigned to.
* The returned type contains is unqualified when an import could be added or was already known.
* It is fully qualified, if an import conflict prevented the import.
* @since 3.4
*/
public String addImport(String type) {
if (isReadOnly())
return type;
ICompilationUnit cu = getCompilationUnit();
if (cu == null)
return type;
try {
boolean qualified = type.indexOf('.') != -1;
if (!qualified) {
IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(new IJavaElement[] { cu.getJavaProject() });
SimpleName nameNode = null;
TypeNameMatch[] matches = findAllTypes(type, searchScope, nameNode, null, cu);
if (// only add import if we have a single match
matches.length != 1)
return type;
type = matches[0].getFullyQualifiedName();
}
CompilationUnit root = getASTRoot(cu);
if (fImportRewrite == null) {
if (root == null) {
fImportRewrite = StubUtility.createImportRewrite(cu, true);
} else {
fImportRewrite = StubUtility.createImportRewrite(root, true);
}
}
ImportRewriteContext context;
if (root == null)
context = null;
else
context = new ContextSensitiveImportRewriteContext(root, getCompletionOffset(), fImportRewrite);
return fImportRewrite.addImport(type, context);
} catch (JavaModelException e) {
handleException(null, e);
return type;
}
}
use of org.eclipse.jdt.core.search.IJavaSearchScope in project che by eclipse.
the class RenameFieldProcessor method addAccessorOccurrences.
private void addAccessorOccurrences(IProgressMonitor pm, IMethod accessor, String editName, String newAccessorName, RefactoringStatus status) throws CoreException {
Assert.isTrue(accessor.exists());
IJavaSearchScope scope = RefactoringScopeFactory.create(accessor);
SearchPattern pattern = SearchPattern.createPattern(accessor, IJavaSearchConstants.ALL_OCCURRENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
SearchResultGroup[] groupedResults = RefactoringSearchEngine.search(pattern, scope, new MethodOccurenceCollector(accessor.getElementName()), pm, status);
for (int i = 0; i < groupedResults.length; i++) {
ICompilationUnit cu = groupedResults[i].getCompilationUnit();
if (cu == null)
continue;
SearchMatch[] results = groupedResults[i].getSearchResults();
for (int j = 0; j < results.length; j++) {
SearchMatch searchResult = results[j];
TextEdit edit = new ReplaceEdit(searchResult.getOffset(), searchResult.getLength(), newAccessorName);
addTextEdit(fChangeManager.get(cu), editName, edit);
}
}
}
use of org.eclipse.jdt.core.search.IJavaSearchScope in project che by eclipse.
the class RenameMethodProcessor method searchForOuterTypesOfReferences.
private IType[] searchForOuterTypesOfReferences(IMethod[] newNameMethods, IProgressMonitor pm) throws CoreException {
final Set<IType> outerTypesOfReferences = new HashSet<IType>();
SearchPattern pattern = RefactoringSearchEngine.createOrPattern(newNameMethods, IJavaSearchConstants.REFERENCES);
IJavaSearchScope scope = createRefactoringScope(getMethod());
SearchRequestor requestor = new SearchRequestor() {
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
Object element = match.getElement();
if (!(element instanceof IMember))
// e.g. an IImportDeclaration for a static method import
return;
IMember member = (IMember) element;
IType declaring = member.getDeclaringType();
if (declaring == null)
return;
IType outer = declaring.getDeclaringType();
if (outer != null)
outerTypesOfReferences.add(declaring);
}
};
new SearchEngine().search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm);
return outerTypesOfReferences.toArray(new IType[outerTypesOfReferences.size()]);
}
use of org.eclipse.jdt.core.search.IJavaSearchScope in project che by eclipse.
the class RippleMethodFinder2 method findAllDeclarations.
private void findAllDeclarations(IProgressMonitor monitor, WorkingCopyOwner owner) throws CoreException {
fDeclarations = new ArrayList<IMethod>();
class MethodRequestor extends SearchRequestor {
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
IMethod method = (IMethod) match.getElement();
boolean isBinary = method.isBinary();
if (fBinaryRefs != null || !(fExcludeBinaries && isBinary)) {
fDeclarations.add(method);
}
if (isBinary && fBinaryRefs != null) {
fDeclarationToMatch.put(method, match);
}
}
}
int limitTo = IJavaSearchConstants.DECLARATIONS | IJavaSearchConstants.IGNORE_DECLARING_TYPE | IJavaSearchConstants.IGNORE_RETURN_TYPE;
int matchRule = SearchPattern.R_ERASURE_MATCH | SearchPattern.R_CASE_SENSITIVE;
SearchPattern pattern = SearchPattern.createPattern(fMethod, limitTo, matchRule);
SearchParticipant[] participants = SearchUtils.getDefaultSearchParticipants();
IJavaSearchScope scope = RefactoringScopeFactory.createRelatedProjectsScope(fMethod.getJavaProject(), IJavaSearchScope.SOURCES | IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SYSTEM_LIBRARIES);
MethodRequestor requestor = new MethodRequestor();
SearchEngine searchEngine = owner != null ? new SearchEngine(owner) : new SearchEngine();
searchEngine.search(pattern, participants, scope, requestor, monitor);
}
Aggregations