/** * search the bundle that contains the Main class. The search is done in the * workspace scope (ie. if it is defined in the current workspace it will * find it * * @return the name of the bundle containing the Main class or null if not * found */ private IType getITypeMainByWorkspaceScope(String className) { SearchPattern pattern = SearchPattern.createPattern(className, IJavaSearchConstants.CLASS, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH); IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); final List<IType> binaryType = new ArrayList<IType>(); SearchRequestor requestor = new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { binaryType.add((IType) match.getElement()); } }; SearchEngine engine = new SearchEngine(); try { engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, null); } catch (CoreException e1) { throw new RuntimeException("Error while searching the bundle: " + e1.getMessage()); // return new Status(IStatus.ERROR, Activator.PLUGIN_ID, ); } return binaryType.isEmpty() ? null : binaryType.get(0); }
/** * Find type * * @param className * @param monitor * @return type or <code>null</code> */ public IType findType(String className, IProgressMonitor monitor) { final IType[] result = { null }; TypeNameMatchRequestor nameMatchRequestor = new TypeNameMatchRequestor() { @Override public void acceptTypeNameMatch(TypeNameMatch match) { result[0] = match.getType(); } }; int lastDot = className.lastIndexOf('.'); char[] packageName = lastDot >= 0 ? className.substring(0, lastDot).toCharArray() : null; char[] typeName = (lastDot >= 0 ? className.substring(lastDot + 1) : className).toCharArray(); SearchEngine engine = new SearchEngine(); int packageMatchRule = SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE; try { engine.searchAllTypeNames(packageName, packageMatchRule, typeName, packageMatchRule, IJavaSearchConstants.TYPE, SearchEngine.createWorkspaceScope(), nameMatchRequestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, monitor); } catch (JavaModelException e) { EditorUtil.INSTANCE.logError("Was not able to search all type names",e); } return result[0]; }
private void findAllDeclarations(IProgressMonitor monitor, WorkingCopyOwner owner) throws CoreException { fDeclarations = new ArrayList<>(); class MethodRequestor extends SearchRequestor { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { IMethod method = (IMethod) match.getElement(); boolean isBinary = method.isBinary(); if (!isBinary) { fDeclarations.add(method); } } } 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); MethodRequestor requestor = new MethodRequestor(); SearchEngine searchEngine = owner != null ? new SearchEngine(owner) : new SearchEngine(); searchEngine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, createSearchScope(), requestor, monitor); }
protected SearchPattern createOccurrenceSearchPattern(IJavaElement[] elements) throws CoreException { if (elements == null || elements.length == 0) { return null; } Set<IJavaElement> set = new HashSet<>(Arrays.asList(elements)); Iterator<IJavaElement> iter = set.iterator(); IJavaElement first = iter.next(); SearchPattern pattern = SearchPattern.createPattern(first, IJavaSearchConstants.ALL_OCCURRENCES); if (pattern == null) { throw new CoreException(Status.CANCEL_STATUS); } while (iter.hasNext()) { IJavaElement each = iter.next(); SearchPattern nextPattern = SearchPattern.createPattern(each, IJavaSearchConstants.ALL_OCCURRENCES); if (nextPattern == null) { throw new CoreException(Status.CANCEL_STATUS); } pattern = SearchPattern.createOrPattern(pattern, nextPattern); } return pattern; }
public static String getURI(IProject project, String fqcn) throws JavaModelException { Assert.isNotNull(project, "Project can't be null"); Assert.isNotNull(fqcn, "FQCN can't be null"); IJavaProject javaProject = JavaCore.create(project); int lastDot = fqcn.lastIndexOf("."); String packageName = lastDot > 0? fqcn.substring(0, lastDot):""; String className = lastDot > 0? fqcn.substring(lastDot+1):fqcn; ClassUriExtractor extractor = new ClassUriExtractor(); new SearchEngine().searchAllTypeNames(packageName.toCharArray(),SearchPattern.R_EXACT_MATCH, className.toCharArray(), SearchPattern.R_EXACT_MATCH, IJavaSearchConstants.TYPE, JDTUtils.createSearchScope(javaProject), extractor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, new NullProgressMonitor()); return extractor.uri; }
private List<IType> searchType(String classFQN, IProgressMonitor monitor) { classFQN = classFQN.replace('$', '.'); final List<IType> types = new ArrayList<IType>(); IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); SearchEngine engine = new SearchEngine(); SearchPattern pattern = SearchPattern.createPattern(classFQN, IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH); SearchRequestor requestor = new SearchRequestor() { public void acceptSearchMatch(final SearchMatch match) throws CoreException { TypeDeclarationMatch typeMatch = (TypeDeclarationMatch) match; IType type = (IType) typeMatch.getElement(); types.add(type); } }; try { engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, monitor); } catch (final CoreException e) { return types; } return types; }
private int getSearchForConstant(int typeKinds) { final int CLASSES = SimilarElementsRequestor.CLASSES; final int INTERFACES = SimilarElementsRequestor.INTERFACES; final int ENUMS = SimilarElementsRequestor.ENUMS; final int ANNOTATIONS = SimilarElementsRequestor.ANNOTATIONS; switch (typeKinds & (CLASSES | INTERFACES | ENUMS | ANNOTATIONS)) { case CLASSES: return IJavaSearchConstants.CLASS; case INTERFACES: return IJavaSearchConstants.INTERFACE; case ENUMS: return IJavaSearchConstants.ENUM; case ANNOTATIONS: return IJavaSearchConstants.ANNOTATION_TYPE; case CLASSES | INTERFACES: return IJavaSearchConstants.CLASS_AND_INTERFACE; case CLASSES | ENUMS: return IJavaSearchConstants.CLASS_AND_ENUM; default: return IJavaSearchConstants.TYPE; } }
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)) return; // e.g. an IImportDeclaration for a static method import 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()]); }
private SearchResultGroup[] findReferences(IProgressMonitor pm, RefactoringStatus status) throws JavaModelException { final RefactoringSearchEngine2 engine = new RefactoringSearchEngine2( SearchPattern.createPattern(fField, IJavaSearchConstants.REFERENCES)); engine.setFiltering(true, true); engine.setScope(RefactoringScopeFactory.create(fField)); engine.setStatus(status); engine.setRequestor( new IRefactoringSearchRequestor() { public SearchMatch acceptSearchMatch(SearchMatch match) { return match.isInsideDocComment() ? null : match; } }); engine.searchPattern(new SubProgressMonitor(pm, 1)); return (SearchResultGroup[]) engine.getResults(); }
/** * @param ctor * @param methodBinding * @return a <code>SearchPattern</code> that finds all calls to the constructor identified by the * argument <code>methodBinding</code>. */ private SearchPattern createSearchPattern(IMethod ctor, IMethodBinding methodBinding) { Assert.isNotNull( methodBinding, RefactoringCoreMessages.IntroduceFactory_noBindingForSelectedConstructor); if (ctor != null) return SearchPattern.createPattern( ctor, IJavaSearchConstants.REFERENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE); else { // perhaps a synthetic method? (but apparently not always... hmmm...) // Can't find an IMethod for this method, so build a string pattern instead StringBuffer buf = new StringBuffer(); buf.append(methodBinding.getDeclaringClass().getQualifiedName()).append("("); // $NON-NLS-1$ for (int i = 0; i < fArgTypes.length; i++) { if (i != 0) buf.append(","); // $NON-NLS-1$ buf.append(fArgTypes[i].getQualifiedName()); } buf.append(")"); // $NON-NLS-1$ return SearchPattern.createPattern( buf.toString(), IJavaSearchConstants.CONSTRUCTOR, IJavaSearchConstants.REFERENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE); } }
private static SearchResultGroup[] getReferences( ICompilationUnit unit, IProgressMonitor pm, RefactoringStatus status) throws CoreException { final SearchPattern pattern = RefactoringSearchEngine.createOrPattern(unit.getTypes(), IJavaSearchConstants.REFERENCES); if (pattern != null) { String binaryRefsDescription = Messages.format( RefactoringCoreMessages.ReferencesInBinaryContext_ref_in_binaries_description, BasicElementLabels.getFileName(unit)); ReferencesInBinaryContext binaryRefs = new ReferencesInBinaryContext(binaryRefsDescription); Collector requestor = new Collector(((IPackageFragment) unit.getParent()), binaryRefs); IJavaSearchScope scope = RefactoringScopeFactory.create(unit, true, false); SearchResultGroup[] result = RefactoringSearchEngine.search( pattern, scope, requestor, new SubProgressMonitor(pm, 1), status); binaryRefs.addErrorIfNecessary(status); return result; } return new SearchResultGroup[] {}; }
@Override public boolean isApplicable(JavaSearchQuery query) { QuerySpecification spec = query.getSpecification(); switch (spec.getLimitTo()) { case IJavaSearchConstants.REFERENCES: case IJavaSearchConstants.ALL_OCCURRENCES: if (spec instanceof ElementQuerySpecification) { ElementQuerySpecification elementSpec = (ElementQuerySpecification) spec; return elementSpec.getElement() instanceof IMethod; } else if (spec instanceof PatternQuerySpecification) { PatternQuerySpecification patternSpec = (PatternQuerySpecification) spec; return patternSpec.getSearchFor() == IJavaSearchConstants.METHOD; } } return false; }
private List<IType> findTypeByFqn(char[][] packages, char[][] names, IJavaSearchScope scope) throws JavaModelException { List<IType> result = new ArrayList<>(); SearchEngine searchEngine = new SearchEngine(); searchEngine.searchAllTypeNames( packages, names, scope, new TypeNameMatchRequestor() { @Override public void acceptTypeNameMatch(TypeNameMatch typeNameMatch) { result.add(typeNameMatch.getType()); } }, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, new NullProgressMonitor()); return result; }
/** * Blocks current thread until search is done */ public List<IJavaElement> getReferences(IProgressMonitor monitor) throws CoreException { pattern = SearchPattern.createPattern(searchRoot.getJavaElement(), IJavaSearchConstants.REFERENCES | ~IJavaSearchConstants.IMPORT_DECLARATION_TYPE_REFERENCE, // | IJavaSearchConstants.IGNORE_DECLARING_TYPE, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE | SearchPattern.R_ERASURE_MATCH); if (pattern == null) { // this is packages??? // System.out.println("Search patter is null for: " + elt.getElementName()); return new ArrayList<IJavaElement>(); } scope = conf.createScope(searchRoot.getJavaElement()); JavaReferencesRequestor searchRequestor = new JavaReferencesRequestor(); return search(searchRequestor, monitor); }
private static SearchPattern createAnyFieldPattern(IType[] types) { if (types.length == 0) { return createAnyFieldPattern(); } SearchPattern result = null; for (IType type : types) { SearchPattern searchPattern = SearchPattern.createPattern(type.getFullyQualifiedName() + ".*", IJavaSearchConstants.FIELD, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE); if(result == null){ result = searchPattern; } else { result = SearchPattern.createOrPattern(result, searchPattern); } } return result; }
private Set<IIndexedJavaRef> findMatches(PatternQuerySpecification query) { // Translate the IJavaSearchConstant element type constants to IJavaElement // type constants. int elementType; switch (query.getSearchFor()) { case IJavaSearchConstants.TYPE: elementType = IJavaElement.TYPE; break; case IJavaSearchConstants.FIELD: elementType = IJavaElement.FIELD; break; case IJavaSearchConstants.METHOD: case IJavaSearchConstants.CONSTRUCTOR: // IJavaElement.METHOD represents both methods & ctors elementType = IJavaElement.METHOD; break; default: // We only support searching for types, fields, methods, and ctors return Collections.emptySet(); } return JavaRefIndex.getInstance().findElementReferences(query.getPattern(), elementType, query.isCaseSensitive()); }
private IType chooseResourceType() { IJavaSearchScope scope; try { scope = SearchEngine.createHierarchyScope(ClientBundleUtilities.findResourcePrototypeType(javaProject)); FilteredTypesSelectionDialog dialog = new FilteredTypesSelectionDialog( getShell(), false, PlatformUI.getWorkbench().getProgressService(), scope, IJavaSearchConstants.INTERFACE); dialog.setTitle("Resource Type Selection"); dialog.setMessage("Choose a resource type:"); if (dialog.open() == Window.OK) { return (IType) dialog.getFirstResult(); } } catch (JavaModelException e) { GWTPluginLog.logError(e); } return null; }
private IType chooseClientBundleType() { try { // Create a search scope for finding ClientBundle subtypes IJavaSearchScope scope = SearchEngine.createHierarchyScope(ClientBundleUtilities.findClientBundleType(getJavaProject())); // Configure the type selection dialog FilteredTypesSelectionDialog dialog = new FilteredTypesSelectionDialog( getShell(), false, PlatformUI.getWorkbench().getProgressService(), scope, IJavaSearchConstants.INTERFACE); dialog.setTitle("ClientBundle Type Selection"); dialog.setMessage("Choose a type:"); if (dialog.open() == Window.OK) { return (IType) dialog.getFirstResult(); } } catch (JavaModelException e) { GWTPluginLog.logError(e); } return null; }
/** * Searches for references to the original method. * * @param monitor * the progress monitor to use * @param status * the refactoring status to use * @return the array of search result groups * @throws CoreException * if an error occurred during search */ protected SearchResultGroup[] computeMethodReferences(final IProgressMonitor monitor, final RefactoringStatus status) throws CoreException { Assert.isNotNull(monitor); Assert.isNotNull(status); try { monitor.beginTask("", 1); //$NON-NLS-1$ monitor.setTaskName(RefactoringCoreMessages.MoveInstanceMethodProcessor_checking); SearchPattern pattern= SearchPattern.createPattern(fMethod, IJavaSearchConstants.REFERENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE); IJavaSearchScope scope= RefactoringScopeFactory.create(fMethod, true, false); String binaryRefsDescription= Messages.format(RefactoringCoreMessages.ReferencesInBinaryContext_ref_in_binaries_description , BasicElementLabels.getJavaElementName(fMethod.getElementName())); ReferencesInBinaryContext binaryRefs= new ReferencesInBinaryContext(binaryRefsDescription); CollectingSearchRequestor requestor= new CollectingSearchRequestor(binaryRefs); SearchResultGroup[] result= RefactoringSearchEngine.search(pattern, scope, requestor, new SubProgressMonitor(monitor, 1), status); binaryRefs.addErrorIfNecessary(status); return result; } finally { monitor.done(); } }
/** * Computes the compilation units referencing the subtype to replace. * * @param type * the subtype * @param monitor * the progress monitor to use * @param status * the refactoring status * @return the referenced compilation units (element type: * <code><IJavaProject, Collection<SearchResultGroup>></code>) * @throws JavaModelException * if an error occurs */ protected final Map<IJavaProject, Set<SearchResultGroup>> getReferencingCompilationUnits(final IType type, final IProgressMonitor monitor, final RefactoringStatus status) throws JavaModelException { try { monitor.beginTask("", 100); //$NON-NLS-1$ monitor.setTaskName(RefactoringCoreMessages.SuperTypeRefactoringProcessor_creating); final RefactoringSearchEngine2 engine= new RefactoringSearchEngine2(); engine.setOwner(fOwner); engine.setFiltering(true, true); engine.setStatus(status); engine.setScope(RefactoringScopeFactory.create(type)); engine.setPattern(SearchPattern.createPattern(type, IJavaSearchConstants.REFERENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE)); engine.searchPattern(new SubProgressMonitor(monitor, 100)); @SuppressWarnings("unchecked") Map<IJavaProject, Set<SearchResultGroup>> result= (Map<IJavaProject, Set<SearchResultGroup>>) engine.getAffectedProjects(); return result; } finally { monitor.done(); } }
private int getSearchForConstant(int typeKinds) { final int CLASSES= SimilarElementsRequestor.CLASSES; final int INTERFACES= SimilarElementsRequestor.INTERFACES; final int ENUMS= SimilarElementsRequestor.ENUMS; final int ANNOTATIONS= SimilarElementsRequestor.ANNOTATIONS; switch (typeKinds & (CLASSES | INTERFACES | ENUMS | ANNOTATIONS)) { case CLASSES: return IJavaSearchConstants.CLASS; case INTERFACES: return IJavaSearchConstants.INTERFACE; case ENUMS: return IJavaSearchConstants.ENUM; case ANNOTATIONS: return IJavaSearchConstants.ANNOTATION_TYPE; case CLASSES | INTERFACES: return IJavaSearchConstants.CLASS_AND_INTERFACE; case CLASSES | ENUMS: return IJavaSearchConstants.CLASS_AND_ENUM; default: return IJavaSearchConstants.TYPE; } }
protected void consumeTypeArgumentReferenceType2() { super.consumeTypeArgumentReferenceType2(); if ((this.patternFineGrain & IJavaSearchConstants.TYPE_ARGUMENT_TYPE_REFERENCE) != 0) { int length = this.genericsLengthStack[this.genericsLengthPtr]; if (length == 1) { TypeReference typeReference = (TypeReference)this.genericsStack[this.genericsPtr]; TypeReference[] typeArguments = null; if (typeReference instanceof ParameterizedSingleTypeReference) { typeArguments = ((ParameterizedSingleTypeReference) typeReference).typeArguments; } else if (typeReference instanceof ParameterizedQualifiedTypeReference) { TypeReference[][] allTypeArguments = ((ParameterizedQualifiedTypeReference) typeReference).typeArguments; typeArguments = allTypeArguments[allTypeArguments.length-1]; } if (typeArguments != null) { for (int i=0, ln=typeArguments.length; i<ln; i++) { if (!(typeArguments[i] instanceof Wildcard)) { this.patternLocator.match(typeArguments[i], this.nodeSet); } } } } } }
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()]); }
private List<SearchResultGroup> getReferencesToTypesInPackage(IProgressMonitor pm, ReferencesInBinaryContext binaryRefs, RefactoringStatus status) throws CoreException { pm.beginTask("", 2); //$NON-NLS-1$ IJavaSearchScope referencedFromNamesakesScope= RefactoringScopeFactory.create(fPackage, true, false); IPackageFragment[] namesakePackages= getNamesakePackages(referencedFromNamesakesScope, new SubProgressMonitor(pm, 1)); if (namesakePackages.length == 0) { pm.done(); return new ArrayList<SearchResultGroup>(0); } IJavaSearchScope scope= SearchEngine.createJavaSearchScope(namesakePackages); IType[] typesToSearch= getTypesInPackage(fPackage); if (typesToSearch.length == 0) { pm.done(); return new ArrayList<SearchResultGroup>(0); } SearchPattern pattern= RefactoringSearchEngine.createOrPattern(typesToSearch, IJavaSearchConstants.REFERENCES); CollectingSearchRequestor requestor= new CuCollectingSearchRequestor(binaryRefs); SearchResultGroup[] results= RefactoringSearchEngine.search(pattern, scope, requestor, new SubProgressMonitor(pm, 1), status); pm.done(); return new ArrayList<SearchResultGroup>(Arrays.asList(results)); }
private IType findNonPrimaryType(String fullyQualifiedName, IProgressMonitor pm, RefactoringStatus status) throws JavaModelException { SearchPattern p= SearchPattern.createPattern(fullyQualifiedName, IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE); final RefactoringSearchEngine2 engine= new RefactoringSearchEngine2(p); engine.setFiltering(true, true); engine.setScope(RefactoringScopeFactory.create(fCtorBinding.getJavaElement().getJavaProject())); engine.setStatus(status); engine.searchPattern(new SubProgressMonitor(pm, 1)); SearchResultGroup[] groups= (SearchResultGroup[]) engine.getResults(); if (groups.length != 0) { for(int i= 0; i < groups.length; i++) { SearchMatch[] matches= groups[i].getSearchResults(); for(int j= 0; j < matches.length; j++) { if (matches[j].getAccuracy() == SearchMatch.A_ACCURATE) return (IType) matches[j].getElement(); } } } return null; }
protected void browseForAccessorClass() { IProgressService service= PlatformUI.getWorkbench().getProgressService(); IPackageFragmentRoot root= fAccessorPackage.getSelectedFragmentRoot(); IJavaSearchScope scope= root != null ? SearchEngine.createJavaSearchScope(new IJavaElement[] { root }) : SearchEngine.createWorkspaceScope(); FilteredTypesSelectionDialog dialog= new FilteredTypesSelectionDialog (getShell(), false, service, scope, IJavaSearchConstants.CLASS); dialog.setTitle(NLSUIMessages.NLSAccessorConfigurationDialog_Accessor_Selection); dialog.setMessage(NLSUIMessages.NLSAccessorConfigurationDialog_Choose_the_accessor_file); dialog.setInitialPattern("*Messages"); //$NON-NLS-1$ if (dialog.open() == Window.OK) { IType selectedType= (IType) dialog.getFirstResult(); if (selectedType != null) { fAccessorClassName.setText(selectedType.getElementName()); fAccessorPackage.setSelected(selectedType.getPackageFragment()); } } }
private IType chooseFactoryClass() { IJavaProject proj= getUseFactoryRefactoring().getProject(); if (proj == null) return null; IJavaElement[] elements= new IJavaElement[] { proj }; IJavaSearchScope scope= SearchEngine.createJavaSearchScope(elements); FilteredTypesSelectionDialog dialog= new FilteredTypesSelectionDialog( getShell(), false, getWizard().getContainer(), scope, IJavaSearchConstants.CLASS); dialog.setTitle(RefactoringMessages.IntroduceFactoryInputPage_chooseFactoryClass_title); dialog.setMessage(RefactoringMessages.IntroduceFactoryInputPage_chooseFactoryClass_message); if (dialog.open() == Window.OK) { return (IType) dialog.getFirstResult(); } return null; }
private TypeNameMatch[] findAllTypes(String simpleTypeName, IJavaSearchScope searchScope, SimpleName nameNode, IProgressMonitor monitor, ICompilationUnit cu) throws JavaModelException { boolean is50OrHigher= JavaModelUtil.is50OrHigher(cu.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); new SearchEngine().searchAllTypeNames(null, 0, simpleTypeName.toCharArray(), SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE, getSearchForConstant(typeKinds), searchScope, requestor, IJavaSearchConstants.FORCE_IMMEDIATE_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, cu)) { typeRefsFound.add(curr); } } } return typeRefsFound.toArray(new TypeNameMatch[typeRefsFound.size()]); }
private boolean matchesModifiers(TypeNameMatch type) { if (fElementKind == IJavaSearchConstants.TYPE) return true; int modifiers= type.getModifiers() & TYPE_MODIFIERS; switch (fElementKind) { case IJavaSearchConstants.CLASS: return modifiers == 0; case IJavaSearchConstants.ANNOTATION_TYPE: return Flags.isAnnotation(modifiers); case IJavaSearchConstants.INTERFACE: return modifiers == Flags.AccInterface; case IJavaSearchConstants.ENUM: return Flags.isEnum(modifiers); case IJavaSearchConstants.CLASS_AND_INTERFACE: return modifiers == 0 || modifiers == Flags.AccInterface; case IJavaSearchConstants.CLASS_AND_ENUM: return modifiers == 0 || Flags.isEnum(modifiers); case IJavaSearchConstants.INTERFACE_AND_ANNOTATION: return Flags.isInterface(modifiers); } return false; }
/** * 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; }
/** * Opens a selection dialog that allows to select a super class. * * @return returns the selected type or <code>null</code> if the dialog has been canceled. * The caller typically sets the result to the super class input field. * <p> * Clients can override this method if they want to offer a different dialog. * </p> * * @since 3.2 */ protected IType chooseSuperClass() { IJavaProject project= getJavaProject(); if (project == null) { return null; } IJavaElement[] elements= new IJavaElement[] { project }; IJavaSearchScope scope= SearchEngine.createJavaSearchScope(elements); FilteredTypesSelectionDialog dialog= new FilteredTypesSelectionDialog(getShell(), false, getWizard().getContainer(), scope, IJavaSearchConstants.CLASS); dialog.setTitle(NewWizardMessages.NewTypeWizardPage_SuperClassDialog_title); dialog.setMessage(NewWizardMessages.NewTypeWizardPage_SuperClassDialog_message); dialog.setInitialPattern(getSuperClass()); if (dialog.open() == Window.OK) { return (IType) dialog.getFirstResult(); } return null; }
protected void consumeMethodInvocationName() { super.consumeMethodInvocationName(); MessageSend messageSend = (MessageSend) this.expressionStack[this.expressionPtr]; if (this.patternFineGrain == 0) { this.patternLocator.match(messageSend, this.nodeSet); } else { if (messageSend.receiver.isThis()) { if ((this.patternFineGrain & IJavaSearchConstants.IMPLICIT_THIS_REFERENCE) != 0) { this.patternLocator.match(messageSend, this.nodeSet); } } else { if ((this.patternFineGrain & IJavaSearchConstants.QUALIFIED_REFERENCE) != 0) { this.patternLocator.match(messageSend, this.nodeSet); } } } }
private static IJavaElement[] getReferencingElementsFromSameClass(IMember member, IProgressMonitor pm, RefactoringStatus status) throws JavaModelException { Assert.isNotNull(member); final RefactoringSearchEngine2 engine= new RefactoringSearchEngine2(SearchPattern.createPattern(member, IJavaSearchConstants.REFERENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE)); engine.setFiltering(true, true); engine.setScope(SearchEngine.createJavaSearchScope(new IJavaElement[] { member.getDeclaringType() })); engine.setStatus(status); engine.searchPattern(new SubProgressMonitor(pm, 1)); SearchResultGroup[] groups= (SearchResultGroup[]) engine.getResults(); Set<IJavaElement> result= new HashSet<IJavaElement>(3); for (int i= 0; i < groups.length; i++) { SearchResultGroup group= groups[i]; SearchMatch[] results= group.getSearchResults(); for (int j= 0; j < results.length; j++) { SearchMatch searchResult= results[i]; result.add(SearchUtils.getEnclosingJavaElement(searchResult)); } } return result.toArray(new IJavaElement[result.size()]); }
private List<SearchMatch> getImplicitConstructorReferencesInClassCreations(WorkingCopyOwner owner, IProgressMonitor pm, RefactoringStatus status) throws JavaModelException { //XXX workaround for jdt core bug 23112 SearchPattern pattern= SearchPattern.createPattern(fType, IJavaSearchConstants.REFERENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE); IJavaSearchScope scope= RefactoringScopeFactory.create(fType); SearchResultGroup[] refs= RefactoringSearchEngine.search(pattern, owner, scope, pm, status); List<SearchMatch> result= new ArrayList<SearchMatch>(); for (int i= 0; i < refs.length; i++) { SearchResultGroup group= refs[i]; ICompilationUnit cu= group.getCompilationUnit(); if (cu == null) continue; CompilationUnit cuNode= new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(cu, false); SearchMatch[] results= group.getSearchResults(); for (int j= 0; j < results.length; j++) { SearchMatch searchResult= results[j]; ASTNode node= ASTNodeSearchUtil.getAstNode(searchResult, cuNode); if (isImplicitConstructorReferenceNodeInClassCreations(node)) result.add(searchResult); } } return result; }
private void createMethodFieldMatchLocationsControls(Composite contents) { Composite composite= new Composite(contents, SWT.NONE); GridData gd= new GridData(SWT.LEFT, SWT.BEGINNING, true, true, 2, 1); gd.minimumWidth= convertHorizontalDLUsToPixels(200); composite.setLayoutData(gd); GridLayout blayout= new GridLayout(1, false); blayout.marginWidth= 0; blayout.marginHeight= 0; composite.setLayout(blayout); if (fSearchFor == IJavaSearchConstants.METHOD || fSearchFor == IJavaSearchConstants.FIELD) { createButton(composite, SearchMessages.MatchLocations_this_label, IJavaSearchConstants.THIS_REFERENCE); createButton(composite, SearchMessages.MatchLocations_implicit_this_label, IJavaSearchConstants.IMPLICIT_THIS_REFERENCE); createButton(composite, SearchMessages.MatchLocations_super_label, IJavaSearchConstants.SUPER_REFERENCE); createButton(composite, SearchMessages.MatchLocations_qualified_label, IJavaSearchConstants.QUALIFIED_REFERENCE); } if (fSearchFor == IJavaSearchConstants.METHOD || fSearchFor == IJavaSearchConstants.CONSTRUCTOR) { createButton(composite, SearchMessages.MatchLocations_method_reference_label, IJavaSearchConstants.METHOD_REFERENCE_EXPRESSION); } }