@Override public void acceptSearchMatch(SearchMatch match) throws CoreException { IJavaElement enclosingElement= SearchUtils.getEnclosingJavaElement(match); if (enclosingElement instanceof IPackageFragment) { IPackageFragment pack= (IPackageFragment) enclosingElement; if (! fPackage.equals(pack)) packageFragments.add(pack); } } };
@Override public void acceptSearchMatch(SearchMatch match) throws CoreException { IJavaElement enclosingElement= SearchUtils.getEnclosingJavaElement(match); if (enclosingElement instanceof IPackageFragment) { IPackageFragment pack= (IPackageFragment) enclosingElement; if (! fPackage.equals(pack)) packageFragments.add(pack); } } };
public boolean isImportDeclaration() { return SearchUtils.getEnclosingJavaElement(this).getAncestor(IJavaElement.IMPORT_DECLARATION) != null; }
public boolean isImportDeclaration() { return SearchUtils.getEnclosingJavaElement(this).getAncestor(IJavaElement.IMPORT_DECLARATION) != null; }
public boolean isImportDeclaration() { return SearchUtils.getEnclosingJavaElement(this).getAncestor(IJavaElement.IMPORT_DECLARATION) != null; }
private static Set<IJavaElement> extractElements(SearchMatch[] searchResults, int elementType) { Set<IJavaElement> elements= new HashSet<>(); for (int i= 0; i < searchResults.length; i++) { IJavaElement el= SearchUtils.getEnclosingJavaElement(searchResults[i]); if (el.exists() && el.getElementType() == elementType) elements.add(el); } return elements; } }
private static Set<IJavaElement> extractElements(SearchMatch[] searchResults, int elementType) { Set<IJavaElement> elements= new HashSet<>(); for (int i= 0; i < searchResults.length; i++) { IJavaElement el= SearchUtils.getEnclosingJavaElement(searchResults[i]); if (el.exists() && el.getElementType() == elementType) elements.add(el); } return elements; } }
private static Set extractElements(SearchMatch[] searchResults, int elementType) { Set elements= new HashSet(); for (int i= 0; i < searchResults.length; i++) { IJavaElement el= SearchUtils.getEnclosingJavaElement(searchResults[i]); if (el.exists() && el.getElementType() == elementType) elements.add(el); } return elements; } }
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 result= new HashSet(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 (IJavaElement[]) result.toArray(new IJavaElement[result.size()]); }
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<>(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[j]; result.add(SearchUtils.getEnclosingJavaElement(searchResult)); } } return result.toArray(new IJavaElement[result.size()]); }
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<>(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[j]; result.add(SearchUtils.getEnclosingJavaElement(searchResult)); } } return result.toArray(new IJavaElement[result.size()]); }
/** * @param match * @return the enclosing {@link ICompilationUnit} of the given match, or null iff none */ public static ICompilationUnit getCompilationUnit(SearchMatch match) { IJavaElement enclosingElement = getEnclosingJavaElement(match); if (enclosingElement != null){ if (enclosingElement instanceof ICompilationUnit) return (ICompilationUnit) enclosingElement; ICompilationUnit cu= (ICompilationUnit) enclosingElement.getAncestor(IJavaElement.COMPILATION_UNIT); if (cu != null) return cu; } IJavaElement jElement= JavaCore.create(match.getResource()); if (jElement != null && jElement.exists() && jElement.getElementType() == IJavaElement.COMPILATION_UNIT) return (ICompilationUnit) jElement; return null; }
/** * @param match the search match * @return the enclosing {@link ICompilationUnit} of the given match, or null iff none */ public static ICompilationUnit getCompilationUnit(SearchMatch match) { IJavaElement enclosingElement = getEnclosingJavaElement(match); if (enclosingElement != null){ if (enclosingElement instanceof ICompilationUnit) return (ICompilationUnit) enclosingElement; ICompilationUnit cu= (ICompilationUnit) enclosingElement.getAncestor(IJavaElement.COMPILATION_UNIT); if (cu != null) return cu; } IJavaElement jElement= JavaCore.create(match.getResource()); if (jElement != null && jElement.exists() && jElement.getElementType() == IJavaElement.COMPILATION_UNIT) return (ICompilationUnit) jElement; return null; }
/** * @param match the search match * @return the enclosing {@link ICompilationUnit} of the given match, or null iff none */ public static ICompilationUnit getCompilationUnit(SearchMatch match) { IJavaElement enclosingElement = getEnclosingJavaElement(match); if (enclosingElement != null){ if (enclosingElement instanceof ICompilationUnit) return (ICompilationUnit) enclosingElement; ICompilationUnit cu= (ICompilationUnit) enclosingElement.getAncestor(IJavaElement.COMPILATION_UNIT); if (cu != null) return cu; } IJavaElement jElement= JavaCore.create(match.getResource()); if (jElement != null && jElement.exists() && jElement.getElementType() == IJavaElement.COMPILATION_UNIT) return (ICompilationUnit) jElement; return null; }
/** * Add new imports to types in <code>typeReferences</code> with package <code>fPackage</code>. */ private void addTypeImports(SearchResultGroup typeReferences) throws CoreException { SearchMatch[] searchResults= typeReferences.getSearchResults(); for (int i= 0; i < searchResults.length; i++) { SearchMatch result= searchResults[i]; IJavaElement enclosingElement= SearchUtils.getEnclosingJavaElement(result); if (! (enclosingElement instanceof IImportDeclaration)) { String reference= getNormalizedTypeReference(result); if (! reference.startsWith(fPackage.getElementName())) { // is unqualified reference= cutOffInnerTypes(reference); ImportChange importChange= fImportsManager.getImportChange(typeReferences.getCompilationUnit()); importChange.addImport(fPackage.getElementName() + '.' + reference); } } } }
/** * Add new imports to types in <code>typeReferences</code> with package <code>fPackage</code>. * @param typeReferences type references * @throws CoreException should not happen */ private void addTypeImports(SearchResultGroup typeReferences) throws CoreException { SearchMatch[] searchResults= typeReferences.getSearchResults(); for (int i= 0; i < searchResults.length; i++) { SearchMatch result= searchResults[i]; IJavaElement enclosingElement= SearchUtils.getEnclosingJavaElement(result); if (! (enclosingElement instanceof IImportDeclaration)) { String reference= getNormalizedTypeReference(result); if (! reference.startsWith(fPackage.getElementName())) { // is unqualified reference= cutOffInnerTypes(reference); ImportChange importChange= fImportsManager.getImportChange(typeReferences.getCompilationUnit()); importChange.addImport(fPackage.getElementName() + '.' + reference); } } } }
/** * Add new imports to types in <code>typeReferences</code> with package <code>fPackage</code>. * @param typeReferences type references * @throws CoreException should not happen */ private void addTypeImports(SearchResultGroup typeReferences) throws CoreException { SearchMatch[] searchResults= typeReferences.getSearchResults(); for (int i= 0; i < searchResults.length; i++) { SearchMatch result= searchResults[i]; IJavaElement enclosingElement= SearchUtils.getEnclosingJavaElement(result); if (! (enclosingElement instanceof IImportDeclaration)) { String reference= getNormalizedTypeReference(result); if (! reference.startsWith(fPackage.getElementName())) { // is unqualified reference= cutOffInnerTypes(reference); ImportChange importChange= fImportsManager.getImportChange(typeReferences.getCompilationUnit()); importChange.addImport(fPackage.getElementName() + '.' + reference); } } } }
/** * Add new imports to types in <code>typeReferences</code> with package <code>fNewElementName</code> * and remove old import with <code>fPackage</code>. */ private void updateTypeImports(SearchResultGroup typeReferences) throws CoreException { SearchMatch[] searchResults= typeReferences.getSearchResults(); for (int i= 0; i < searchResults.length; i++) { SearchMatch result= searchResults[i]; IJavaElement enclosingElement= SearchUtils.getEnclosingJavaElement(result); if (enclosingElement instanceof IImportDeclaration) { IImportDeclaration importDeclaration= (IImportDeclaration) enclosingElement; updateImport(typeReferences.getCompilationUnit(), importDeclaration, getUpdatedImport(importDeclaration)); } else { String reference= getNormalizedTypeReference(result); if (! reference.startsWith(fPackage.getElementName())) { reference= cutOffInnerTypes(reference); ImportChange importChange= fImportsManager.getImportChange(typeReferences.getCompilationUnit()); importChange.removeImport(fPackage.getElementName() + '.' + reference); importChange.addImport(getNewPackageName() + '.' + reference); } // else: already found & updated with package reference search } } }
/** * Add new imports to types in <code>typeReferences</code> with package <code>fNewElementName</code> * and remove old import with <code>fPackage</code>. * @param typeReferences type references * @throws CoreException should not happen */ private void updateTypeImports(SearchResultGroup typeReferences) throws CoreException { SearchMatch[] searchResults= typeReferences.getSearchResults(); for (int i= 0; i < searchResults.length; i++) { SearchMatch result= searchResults[i]; IJavaElement enclosingElement= SearchUtils.getEnclosingJavaElement(result); if (enclosingElement instanceof IImportDeclaration) { IImportDeclaration importDeclaration= (IImportDeclaration) enclosingElement; updateImport(typeReferences.getCompilationUnit(), importDeclaration, getUpdatedImport(importDeclaration)); } else { String reference= getNormalizedTypeReference(result); if (! reference.startsWith(fPackage.getElementName())) { reference= cutOffInnerTypes(reference); ImportChange importChange= fImportsManager.getImportChange(typeReferences.getCompilationUnit()); importChange.removeImport(fPackage.getElementName() + '.' + reference); importChange.addImport(getNewPackageName() + '.' + reference); } // else: already found & updated with package reference search } } }
/** * Add new imports to types in <code>typeReferences</code> with package <code>fNewElementName</code> * and remove old import with <code>fPackage</code>. * @param typeReferences type references * @throws CoreException should not happen */ private void updateTypeImports(SearchResultGroup typeReferences) throws CoreException { SearchMatch[] searchResults= typeReferences.getSearchResults(); for (int i= 0; i < searchResults.length; i++) { SearchMatch result= searchResults[i]; IJavaElement enclosingElement= SearchUtils.getEnclosingJavaElement(result); if (enclosingElement instanceof IImportDeclaration) { IImportDeclaration importDeclaration= (IImportDeclaration) enclosingElement; updateImport(typeReferences.getCompilationUnit(), importDeclaration, getUpdatedImport(importDeclaration)); } else { String reference= getNormalizedTypeReference(result); if (! reference.startsWith(fPackage.getElementName())) { reference= cutOffInnerTypes(reference); ImportChange importChange= fImportsManager.getImportChange(typeReferences.getCompilationUnit()); importChange.removeImport(fPackage.getElementName() + '.' + reference); importChange.addImport(getNewPackageName() + '.' + reference); } // else: already found & updated with package reference search } } }