private void doBrowseTypes(StringButtonDialogField dialogField) { IRunnableContext context= new BusyIndicatorRunnableContext(); IJavaSearchScope scope= SearchEngine.createWorkspaceScope(); int style= IJavaElementSearchConstants.CONSIDER_ANNOTATION_TYPES; try { SelectionDialog dialog= JavaUI.createTypeDialog(getShell(), context, scope, style, false, dialogField.getText()); dialog.setTitle(PreferencesMessages.NullAnnotationsConfigurationDialog_browse_title); dialog.setMessage(PreferencesMessages.NullAnnotationsConfigurationDialog_choose_annotation); if (dialog.open() == Window.OK) { IType res= (IType) dialog.getResult()[0]; dialogField.setText(res.getFullyQualifiedName('.')); } } catch (JavaModelException e) { ExceptionHandler.handle(e, getShell(), PreferencesMessages.NullAnnotationsConfigurationDialog_error_title, PreferencesMessages.NullAnnotationsConfigurationDialog_error_message); } }
/** * 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); }
/** * Searches for a class that matches a pattern. */ @VisibleForTesting static boolean performSearch(SearchPattern pattern, IJavaSearchScope scope, IProgressMonitor monitor) { try { SearchEngine searchEngine = new SearchEngine(); TypeSearchRequestor requestor = new TypeSearchRequestor(); searchEngine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, monitor); return requestor.foundMatch(); } catch (CoreException ex) { logger.log(Level.SEVERE, ex.getMessage()); return false; } }
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; }
public IType[] getMainTypes(IProgressMonitor monitor) { IJavaProject javaProject = getJavaProject(); if (javaProject != null) { // Returns main method types boolean includeSubtypes = true; MainMethodSearchEngine engine = new MainMethodSearchEngine(); int constraints = IJavaSearchScope.SOURCES; constraints |= IJavaSearchScope.APPLICATION_LIBRARIES; IJavaSearchScope scope = SearchEngine.createJavaSearchScope( new IJavaElement[] { javaProject }, constraints); return engine.searchMainMethods(monitor, scope, includeSubtypes); } return new IType[] {}; }
/** * Uses the standard container selection dialog to * choose the new value for the container field. */ private void handleManifestmainclassBrowse() { String mainClass = getManifestmainclass(); ILabelProvider lp= new WorkbenchLabelProvider(); ITreeContentProvider cp= new WorkbenchContentProvider(); IResource[] res=jproject.getResource(); IJavaSearchScope searchScope= JavaSearchScopeFactory.getInstance().createJavaSearchScope(res, true); SelectionDialog dialog = JavaUI.createMainTypeDialog(getShell(), getContainer(), searchScope, 0, false); dialog.setMessage("Select Main-Class for JAR file"); dialog.setTitle("Fat Jar Config"); if (dialog.open() == SelectionDialog.OK) { Object[] elements= dialog.getResult(); if (elements.length == 1) { SourceType mainElement = (SourceType)elements[0]; mainClass = mainElement.getFullyQualifiedName(); manifestmainclassText.setText(mainClass); } } }
private static List<Controller> search(IJavaProject project, SearchPattern namePattern) throws JavaModelException, CoreException { List<Controller> controllers = new ArrayList<Controller>(); IJavaSearchScope scope = SearchEngine.createJavaSearchScope(project.getPackageFragments()); SearchRequestor requestor = new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) { if (match.getElement() instanceof IJavaElement) { IJavaElement element = (IJavaElement) match.getElement(); controllers.add(new Controller((IType) element)); } } }; SearchEngine searchEngine = new SearchEngine(); searchEngine.search(namePattern, new SearchParticipant[] {SearchEngine .getDefaultSearchParticipant()}, scope, requestor, null); return controllers; }
/** * Creates a new java element visibility adjustor. * * @param referencing the referencing element used to compute the visibility * @param referenced the referenced member which causes the visibility changes */ public MemberVisibilityAdjustor(final IJavaElement referencing, final IMember referenced) { Assert.isTrue(!(referenced instanceof IInitializer)); Assert.isTrue( referencing instanceof ICompilationUnit || referencing instanceof IType || referencing instanceof IPackageFragment); fScope = RefactoringScopeFactory.createReferencedScope( new IJavaElement[] {referenced}, IJavaSearchScope.REFERENCED_PROJECTS | IJavaSearchScope.SOURCES | IJavaSearchScope.APPLICATION_LIBRARIES); fReferencing = referencing; fReferenced = referenced; }
private TextMatchUpdater( TextChangeManager manager, IJavaSearchScope scope, String currentName, String currentQualifier, String newName, SearchResultGroup[] references, boolean onlyQualified) { Assert.isNotNull(manager); Assert.isNotNull(scope); Assert.isNotNull(references); fManager = manager; fScope = scope; fReferences = references; fOnlyQualified = onlyQualified; fNewName = newName; fCurrentNameLength = currentName.length(); fScanner = new RefactoringScanner(currentName, currentQualifier); }
static void perform( IProgressMonitor pm, IJavaSearchScope scope, ITextUpdating processor, TextChangeManager manager, SearchResultGroup[] references) throws JavaModelException { new TextMatchUpdater( manager, scope, processor.getCurrentElementName(), processor.getCurrentElementQualifier(), processor.getNewElementName(), references, false) .updateTextMatches(pm); }
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 IMethod[] searchForDeclarationsOfClashingMethods(IProgressMonitor pm) throws CoreException { final List<IMethod> results = new ArrayList<IMethod>(); SearchPattern pattern = createNewMethodPattern(); IJavaSearchScope scope = RefactoringScopeFactory.create(getMethod().getJavaProject()); SearchRequestor requestor = new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { Object method = match.getElement(); if (method instanceof IMethod) // check for bug 90138: [refactoring] [rename] Renaming method throws // internal exception results.add((IMethod) method); else JavaPlugin.logErrorMessage( "Unexpected element in search match: " + match.toString()); // $NON-NLS-1$ } }; new SearchEngine() .search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm); return results.toArray(new IMethod[results.size()]); }
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[] {}; }
/** * Creates a new search scope with all compilation units possibly referencing <code>javaElement * </code>. * * @param javaElement the java element * @param considerVisibility consider visibility of javaElement iff <code>true</code> * @param sourceReferencesOnly consider references in source only (no references in binary) * @return the search scope * @throws JavaModelException if an error occurs */ public static IJavaSearchScope create( IJavaElement javaElement, boolean considerVisibility, boolean sourceReferencesOnly) throws JavaModelException { if (considerVisibility & javaElement instanceof IMember) { IMember member = (IMember) javaElement; if (JdtFlags.isPrivate(member)) { if (member.getCompilationUnit() != null) return SearchEngine.createJavaSearchScope( new IJavaElement[] {member.getCompilationUnit()}); else return SearchEngine.createJavaSearchScope(new IJavaElement[] {member}); } // Removed code that does some optimizations regarding package visible members. The problem is // that // there can be a package fragment with the same name in a different source folder or project. // So we // have to treat package visible members like public or protected members. } IJavaProject javaProject = javaElement.getJavaProject(); return SearchEngine.createJavaSearchScope( getAllScopeElements(javaProject, sourceReferencesOnly), false); }
public static SearchResultGroup[] search( SearchPattern pattern, WorkingCopyOwner owner, IJavaSearchScope scope, CollectingSearchRequestor requestor, IProgressMonitor monitor, RefactoringStatus status) throws JavaModelException { return internalSearch( owner != null ? new SearchEngine(owner) : new SearchEngine(), pattern, scope, requestor, monitor, status); }
private static SearchResultGroup[] internalSearch( SearchEngine searchEngine, SearchPattern pattern, IJavaSearchScope scope, CollectingSearchRequestor requestor, IProgressMonitor monitor, RefactoringStatus status) throws JavaModelException { try { searchEngine.search( pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, monitor); } catch (CoreException e) { throw new JavaModelException(e); } return groupByCu(requestor.getResults(), status); }
public void cleanUpIndexes() { SimpleSet knownPaths = new SimpleSet(); IJavaSearchScope scope = BasicSearchEngine.createWorkspaceScope(); PatternSearchJob job = new PatternSearchJob(null, SearchEngine.getDefaultSearchParticipant(), scope, null); Index[] selectedIndexes = job.getIndexes(null); for (int i = 0, l = selectedIndexes.length; i < l; i++) { IndexLocation IndexLocation = selectedIndexes[i].getIndexLocation(); knownPaths.add(IndexLocation); } if (this.indexStates != null) { Object[] keys = this.indexStates.keyTable; IndexLocation[] locations = new IndexLocation[this.indexStates.elementSize]; int count = 0; for (int i = 0, l = keys.length; i < l; i++) { IndexLocation key = (IndexLocation) keys[i]; if (key != null && !knownPaths.includes(key)) locations[count++] = key; } if (count > 0) removeIndexesState(locations); } deleteIndexFiles(knownPaths); }
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<IField> getReferencedFields(IProgressMonitor monitor) throws CoreException { boolean searchOnlyStatics = conf.get(ISearchConfiguration.SEARCH_STATICS_ONLY); searchOnlyStatics = searchOnlyStatics && searchRoot.isVisibleRoot(); FieldReferencesRequestor searchRequestor = SearchUtils.createFieldRequestor(conf, searchOnlyStatics); IType[] typesForAllElements = SearchUtils.getAlSuperTypesForAllElements( searchRoot, monitor); IJavaElement javaElement = searchRoot.getJavaElement(); if(typesForAllElements.length == 0 || javaElement instanceof IPackageFragmentRoot || javaElement instanceof IPackageFragment){ pattern = SearchHelper.createAnyFieldPattern(); scope = SearchEngine.createJavaSearchScope(new IJavaElement[]{javaElement}, IJavaSearchScope.SOURCES); } else { pattern = SearchHelper.createAnyFieldPattern(typesForAllElements); scope = SearchEngine.createJavaSearchScope(typesForAllElements, IJavaSearchScope.SOURCES); } return search(searchRequestor, monitor); }
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; }
private IType chooseIntermediaryClass() { IJavaProject proj= getIntroduceIndirectionRefactoring().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.IntroduceIndirectionInputPage_dialog_choose_declaring_class); dialog.setMessage(RefactoringMessages.IntroduceIndirectionInputPage_dialog_choose_declaring_class_long); if (dialog.open() == Window.OK) { return (IType) dialog.getFirstResult(); } return null; }
private IMethod[] searchForDeclarationsOfClashingMethods(IProgressMonitor pm) throws CoreException { final List<IMethod> results= new ArrayList<IMethod>(); SearchPattern pattern= createNewMethodPattern(); IJavaSearchScope scope= RefactoringScopeFactory.create(getMethod().getJavaProject()); SearchRequestor requestor= new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { Object method= match.getElement(); if (method instanceof IMethod) // check for bug 90138: [refactoring] [rename] Renaming method throws internal exception results.add((IMethod) method); else JavaPlugin.logErrorMessage("Unexpected element in search match: " + match.toString()); //$NON-NLS-1$ } }; new SearchEngine().search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm); return results.toArray(new IMethod[results.size()]); }
public void searchMainMethods(IProgressMonitor pm, IJavaSearchScope scope, Collection<IType> dst) throws CoreException { pm.beginTask("Searching for main methods...", 100); try { SearchPattern pattern = SearchPattern.createPattern("main(String[]) void", IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); //$NON-NLS-1$ SearchParticipant[] participants = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }; IProgressMonitor searchMonitor = new SubProgressMonitor(pm, 100); ResultAggregator collector = new ResultAggregator(dst); new SearchEngine().search(pattern, participants, scope, collector, searchMonitor); } finally { pm.done(); } }
/** * 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; }
/** * Searches for all main methods in the given scope. * Valid styles are IJavaElementSearchConstants.CONSIDER_BINARIES and * IJavaElementSearchConstants.CONSIDER_EXTERNAL_JARS * @param context runnable context * @param scope the search scope * @param style style search style constants (see {@link IJavaElementSearchConstants}) * @return the types found * @throws InvocationTargetException * @throws InterruptedException */ public IType[] searchMainMethods(IRunnableContext context, final IJavaSearchScope scope, final int style) throws InvocationTargetException, InterruptedException { int allFlags= IJavaElementSearchConstants.CONSIDER_EXTERNAL_JARS | IJavaElementSearchConstants.CONSIDER_BINARIES; Assert.isTrue((style | allFlags) == allFlags); final IType[][] res= new IType[1][]; IRunnableWithProgress runnable= new IRunnableWithProgress() { public void run(IProgressMonitor pm) throws InvocationTargetException { try { res[0]= searchMainMethods(pm, scope, style); } catch (CoreException e) { throw new InvocationTargetException(e); } } }; context.run(true, true, runnable); return res[0]; }
private void doBrowseTypes() { IRunnableContext context= new BusyIndicatorRunnableContext(); IJavaSearchScope scope= SearchEngine.createWorkspaceScope(); int style= IJavaElementSearchConstants.CONSIDER_ALL_TYPES; try { SelectionDialog dialog= JavaUI.createTypeDialog(getShell(), context, scope, style, false, fNameDialogField.getText()); dialog.setTitle(PreferencesMessages.FavoriteStaticMemberInputDialog_ChooseTypeDialog_title); dialog.setMessage(PreferencesMessages.FavoriteStaticMemberInputDialog_ChooseTypeDialog_description); if (dialog.open() == Window.OK) { IType res= (IType) dialog.getResult()[0]; fNameDialogField.setText(res.getFullyQualifiedName('.')); } } catch (JavaModelException e) { ExceptionHandler.handle(e, getShell(), PreferencesMessages.FavoriteStaticMemberInputDialog_ChooseTypeDialog_title, PreferencesMessages.FavoriteStaticMemberInputDialog_ChooseTypeDialog_error_message); } }
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)); }
@Override QuerySpecification createQuery(IJavaElement element) throws JavaModelException { JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance(); JavaEditor editor= getEditor(); IJavaSearchScope scope; String description; boolean isInsideJRE= true; if (editor != null) { scope= factory.createJavaProjectSearchScope(editor.getEditorInput(), isInsideJRE); description= factory.getProjectScopeDescription(editor.getEditorInput(), isInsideJRE); } else { scope= factory.createJavaProjectSearchScope(element.getJavaProject(), isInsideJRE); description= factory.getProjectScopeDescription(element.getJavaProject(), isInsideJRE); } return new ElementQuerySpecification(element, getLimitTo(), scope, description); }
@Override public void find() { SearchEngine engine = new SearchEngine(); IJavaSearchScope workspaceScope = null; if(getProject() != null) { workspaceScope = SearchEngine.createJavaSearchScope(createSearchScope()); } else { workspaceScope = SearchEngine.createWorkspaceScope(); } SearchPattern pattern = SearchPattern.createPattern( getElement().getPrimaryElement().getElementName().replace(Constants.JAVA_EXTENSION, Constants.EMPTY_STRING), IJavaSearchConstants.TYPE, IJavaSearchConstants.REFERENCES, SearchPattern.R_EXACT_MATCH); SearchParticipant[] participant = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }; try { engine.search(pattern, participant, workspaceScope, createSearchRequestor(), new NullProgressMonitor()); } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
/** * Creates a new search scope with all compilation units possibly referencing <code>javaElement</code>. * * @param javaElement the java element * @param considerVisibility consider visibility of javaElement iff <code>true</code> * @param sourceReferencesOnly consider references in source only (no references in binary) * @return the search scope * @throws JavaModelException if an error occurs */ public static IJavaSearchScope create(IJavaElement javaElement, boolean considerVisibility, boolean sourceReferencesOnly) throws JavaModelException { if (considerVisibility & javaElement instanceof IMember) { IMember member= (IMember) javaElement; if (JdtFlags.isPrivate(member)) { if (member.getCompilationUnit() != null) return SearchEngine.createJavaSearchScope(new IJavaElement[] { member.getCompilationUnit()}); else return SearchEngine.createJavaSearchScope(new IJavaElement[] { member}); } // Removed code that does some optimizations regarding package visible members. The problem is that // there can be a package fragment with the same name in a different source folder or project. So we // have to treat package visible members like public or protected members. } IJavaProject javaProject= javaElement.getJavaProject(); return SearchEngine.createJavaSearchScope(getAllScopeElements(javaProject, sourceReferencesOnly), false); }
private void openTypeSelectionDialog(){ int elementKinds= IJavaSearchConstants.TYPE; final IJavaSearchScope scope= createWorkspaceSourceScope(); FilteredTypesSelectionDialog dialog= new FilteredTypesSelectionDialog(getShell(), false, getWizard().getContainer(), scope, elementKinds); dialog.setTitle(RefactoringMessages.MoveMembersInputPage_choose_Type); dialog.setMessage(RefactoringMessages.MoveMembersInputPage_dialogMessage); dialog.setValidator(new ISelectionStatusValidator(){ public IStatus validate(Object[] selection) { Assert.isTrue(selection.length <= 1); if (selection.length == 0) return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.OK, RefactoringMessages.MoveMembersInputPage_Invalid_selection, null); Object element= selection[0]; if (! (element instanceof IType)) return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.OK, RefactoringMessages.MoveMembersInputPage_Invalid_selection, null); IType type= (IType)element; return validateDestinationType(type, type.getElementName()); } }); dialog.setInitialPattern(createInitialFilter()); if (dialog.open() == Window.CANCEL) return; IType firstResult= (IType)dialog.getFirstResult(); fDestinationField.setText(firstResult.getFullyQualifiedName('.')); }
private static List<TypeNameMatch> findTypeInfos(String typeName, IType contextType, IProgressMonitor pm) throws JavaModelException { IJavaSearchScope scope= SearchEngine.createJavaSearchScope(new IJavaProject[]{contextType.getJavaProject()}, true); IPackageFragment currPackage= contextType.getPackageFragment(); ArrayList<TypeNameMatch> collectedInfos= new ArrayList<TypeNameMatch>(); TypeNameMatchCollector requestor= new TypeNameMatchCollector(collectedInfos); int matchMode= SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE; new SearchEngine().searchAllTypeNames(null, matchMode, typeName.toCharArray(), matchMode, IJavaSearchConstants.TYPE, scope, requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, pm); List<TypeNameMatch> result= new ArrayList<TypeNameMatch>(); for (Iterator<TypeNameMatch> iter= collectedInfos.iterator(); iter.hasNext();) { TypeNameMatch curr= iter.next(); IType type= curr.getType(); if (type != null) { boolean visible=true; try { visible= JavaModelUtil.isVisible(type, currPackage); } catch (JavaModelException e) { //Assume visibile if not available } if (visible) { result.add(curr); } } } return result; }
/** * Creates the type hierarchy for type selection. */ private void doBrowseTypes() { IRunnableContext context= new BusyIndicatorRunnableContext(); IJavaSearchScope scope= SearchEngine.createWorkspaceScope(); int style= IJavaElementSearchConstants.CONSIDER_ALL_TYPES; try { SelectionDialog dialog= JavaUI.createTypeDialog(getShell(), context, scope, style, false, fNameDialogField.getText()); dialog.setTitle(CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_ChooseTypeDialog_title); dialog.setMessage(CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_ChooseTypeDialog_description); if (dialog.open() == Window.OK) { IType res= (IType)dialog.getResult()[0]; fNameDialogField.setText(res.getFullyQualifiedName('.')); } } catch (JavaModelException e) { ExceptionHandler.handle(e, getShell(), CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_ChooseTypeDialog_title, CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_ChooseTypeDialog_error_message); } }
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 String[] choosePackage() { IJavaSearchScope scope= SearchEngine.createWorkspaceScope(); BusyIndicatorRunnableContext context= new BusyIndicatorRunnableContext(); int flags= PackageSelectionDialog.F_SHOW_PARENTS | PackageSelectionDialog.F_HIDE_DEFAULT_PACKAGE | PackageSelectionDialog.F_REMOVE_DUPLICATES; PackageSelectionDialog dialog = new PackageSelectionDialog(getShell(), context, flags , scope); dialog.setTitle(PreferencesMessages.TypeFilterPreferencePage_choosepackage_label); dialog.setMessage(PreferencesMessages.TypeFilterPreferencePage_choosepackage_description); dialog.setMultipleSelection(true); if (dialog.open() == IDialogConstants.OK_ID) { Object[] fragments= dialog.getResult(); String[] res= new String[fragments.length]; for (int i= 0; i < res.length; i++) { res[i]= ((IPackageFragment) fragments[i]).getElementName() + ".*"; //$NON-NLS-1$ } return res; } return null; }
/** * 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; }