public static SearchResultGroup[] getConstructorReferences(IType type, WorkingCopyOwner owner, IProgressMonitor pm, RefactoringStatus status) throws JavaModelException{ return new ConstructorReferenceFinder(type).getConstructorReferences(pm, owner, IJavaSearchConstants.REFERENCES, status); }
private SearchResultGroup[] getConstructorReferences(IProgressMonitor pm, WorkingCopyOwner owner, int limitTo, RefactoringStatus status) throws JavaModelException{ IJavaSearchScope scope= createSearchScope(); SearchPattern pattern= RefactoringSearchEngine.createOrPattern(fConstructors, limitTo); if (pattern == null){ if (fConstructors.length != 0) return new SearchResultGroup[0]; return getImplicitConstructorReferences(pm, owner, status); } return removeUnrealReferences(RefactoringSearchEngine.search(pattern, owner, scope, pm, status)); }
private List<SearchMatch> getImplicitConstructorReferencesFromHierarchy(WorkingCopyOwner owner, IProgressMonitor pm) throws JavaModelException{ IType[] subTypes= getNonBinarySubtypes(owner, fType, pm); List<SearchMatch> result= new ArrayList<>(subTypes.length); for (int i= 0; i < subTypes.length; i++) { result.addAll(getAllSuperConstructorInvocations(subTypes[i])); } return result; }
private SearchResultGroup[] getImplicitConstructorReferences(IProgressMonitor pm, WorkingCopyOwner owner, RefactoringStatus status) throws JavaModelException { pm.beginTask("", 2); //$NON-NLS-1$ List<SearchMatch> searchMatches= new ArrayList<>(); searchMatches.addAll(getImplicitConstructorReferencesFromHierarchy(owner, new SubProgressMonitor(pm, 1))); searchMatches.addAll(getImplicitConstructorReferencesInClassCreations(owner, new SubProgressMonitor(pm, 1), status)); pm.done(); return RefactoringSearchEngine.groupByCu(searchMatches.toArray(new SearchMatch[searchMatches.size()]), status); }
private static Collection<SearchMatch> getAllSuperConstructorInvocations(IType type) throws JavaModelException { IMethod[] constructors= JavaElementUtil.getAllConstructors(type); CompilationUnit cuNode= new RefactoringASTParser(IASTSharedValues.SHARED_AST_LEVEL).parse(type.getCompilationUnit(), false); List<SearchMatch> result= new ArrayList<>(constructors.length); for (int i= 0; i < constructors.length; i++) { ASTNode superCall= getSuperConstructorCallNode(constructors[i], cuNode); if (superCall != null) result.add(createSearchResult(superCall, constructors[i])); } return result; }
protected RefactoringStatus checkConstructorCalls(final IType type, final IProgressMonitor monitor) throws JavaModelException { try { monitor.beginTask(RefactoringCoreMessages.PullUpRefactoring_checking, 2); final RefactoringStatus result= new RefactoringStatus(); final SearchResultGroup[] groups= ConstructorReferenceFinder.getConstructorReferences(type, fOwner, new SubProgressMonitor(monitor, 1), result); final String message= Messages.format(RefactoringCoreMessages.HierarchyRefactoring_gets_instantiated, new Object[] { JavaElementLabels.getTextLabel(type, JavaElementLabels.ALL_FULLY_QUALIFIED)}); ICompilationUnit unit= null; for (int index= 0; index < groups.length; index++) { unit= groups[index].getCompilationUnit(); if (unit != null) { final CompilationUnit cuNode= RefactoringASTParser.parseWithASTProvider(unit, false, new SubProgressMonitor(monitor, 1)); final ASTNode[] references= ASTNodeSearchUtil.getAstNodes(groups[index].getSearchResults(), cuNode); ASTNode node= null; for (int offset= 0; offset < references.length; offset++) { node= references[offset]; if ((node instanceof ClassInstanceCreation) || ConstructorReferenceFinder.isImplicitConstructorReferenceNodeInClassCreations(node)) { final RefactoringStatusContext context= JavaStatusContext.create(unit, node); result.addError(message, context); } } } } return result; } finally { monitor.done(); } }
private IJavaSearchScope createSearchScope() throws JavaModelException{ if (fConstructors.length == 0) return RefactoringScopeFactory.create(fType); return RefactoringScopeFactory.create(getMostVisibleConstructor()); }
private Map<ICompilationUnit, SearchMatch[]> createConstructorReferencesMapping(IProgressMonitor pm, RefactoringStatus status) throws JavaModelException { SearchResultGroup[] groups= ConstructorReferenceFinder.getConstructorReferences(fType, pm, status); Map<ICompilationUnit, SearchMatch[]> result= new HashMap<>(); for (int i= 0; i < groups.length; i++) { SearchResultGroup group= groups[i]; ICompilationUnit cu= group.getCompilationUnit(); if (cu == null) continue; result.put(cu, group.getSearchResults()); } return result; }
private SearchResultGroup[] getImplicitConstructorReferences(IProgressMonitor pm, WorkingCopyOwner owner, RefactoringStatus status) throws JavaModelException { pm.beginTask("", 2); //$NON-NLS-1$ List searchMatches= new ArrayList(); searchMatches.addAll(getImplicitConstructorReferencesFromHierarchy(owner, new SubProgressMonitor(pm, 1))); searchMatches.addAll(getImplicitConstructorReferencesInClassCreations(owner, new SubProgressMonitor(pm, 1), status)); pm.done(); return RefactoringSearchEngine.groupByCu((SearchMatch[]) searchMatches.toArray(new SearchMatch[searchMatches.size()]), status); }
private static Collection getAllSuperConstructorInvocations(IType type) throws JavaModelException { IMethod[] constructors= JavaElementUtil.getAllConstructors(type); CompilationUnit cuNode= new RefactoringASTParser(AST.JLS3).parse(type.getCompilationUnit(), false); List result= new ArrayList(constructors.length); for (int i= 0; i < constructors.length; i++) { ASTNode superCall= getSuperConstructorCallNode(constructors[i], cuNode); if (superCall != null) result.add(createSearchResult(superCall, constructors[i])); } return result; }
protected RefactoringStatus checkConstructorCalls(final IType type, final IProgressMonitor monitor) throws JavaModelException { try { monitor.beginTask(RefactoringCoreMessages.PullUpRefactoring_checking, 2); final RefactoringStatus result= new RefactoringStatus(); final SearchResultGroup[] groups= ConstructorReferenceFinder.getConstructorReferences(type, fOwner, new SubProgressMonitor(monitor, 1), result); final String message= Messages.format(RefactoringCoreMessages.HierarchyRefactoring_gets_instantiated, new Object[] { JavaElementLabels.getTextLabel(type, JavaElementLabels.ALL_FULLY_QUALIFIED)}); ICompilationUnit unit= null; for (int index= 0; index < groups.length; index++) { unit= groups[index].getCompilationUnit(); if (unit != null) { final CompilationUnit cuNode= RefactoringASTParser.parseWithASTProvider(unit, false, new SubProgressMonitor(monitor, 1)); final ASTNode[] references= ASTNodeSearchUtil.getAstNodes(groups[index].getSearchResults(), cuNode); ASTNode node= null; for (int offset= 0; offset < references.length; offset++) { node= references[offset]; if ((node instanceof ClassInstanceCreation) || ConstructorReferenceFinder.isImplicitConstructorReferenceNodeInClassCreations(node)) { final RefactoringStatusContext context= JavaStatusContext.create(unit, node); result.addError(message, context); } } } } return result; } finally { monitor.done(); } }
private IJavaSearchScope createSearchScope() throws JavaModelException{ if (fConstructors.length == 0) return RefactoringScopeFactory.create(fType); return RefactoringScopeFactory.create(getMostVisibleConstructor()); }
private Map createConstructorReferencesMapping(IProgressMonitor pm, RefactoringStatus status) throws JavaModelException { SearchResultGroup[] groups= ConstructorReferenceFinder.getConstructorReferences(fType, pm, status); Map result= new HashMap(); for (int i= 0; i < groups.length; i++) { SearchResultGroup group= groups[i]; ICompilationUnit cu= group.getCompilationUnit(); if (cu == null) continue; result.put(cu, group.getSearchResults()); } return result; }
public static SearchResultGroup[] getConstructorReferences(IType type, IProgressMonitor pm, RefactoringStatus status) throws JavaModelException{ return new ConstructorReferenceFinder(type).getConstructorReferences(pm, null, IJavaSearchConstants.REFERENCES, status); }
private SearchResultGroup[] getConstructorReferences(IProgressMonitor pm, WorkingCopyOwner owner, int limitTo, RefactoringStatus status) throws JavaModelException{ IJavaSearchScope scope= createSearchScope(); SearchPattern pattern= RefactoringSearchEngine.createOrPattern(fConstructors, limitTo); if (pattern == null){ if (fConstructors.length != 0) return new SearchResultGroup[0]; return getImplicitConstructorReferences(pm, owner, status); } return removeUnrealReferences(RefactoringSearchEngine.search(pattern, owner, scope, pm, status)); }
private SearchResultGroup[] getImplicitConstructorReferences(IProgressMonitor pm, WorkingCopyOwner owner, RefactoringStatus status) throws JavaModelException { pm.beginTask("", 2); //$NON-NLS-1$ List<SearchMatch> searchMatches= new ArrayList<>(); searchMatches.addAll(getImplicitConstructorReferencesFromHierarchy(owner, new SubProgressMonitor(pm, 1))); searchMatches.addAll(getImplicitConstructorReferencesInClassCreations(owner, new SubProgressMonitor(pm, 1), status)); pm.done(); return RefactoringSearchEngine.groupByCu(searchMatches.toArray(new SearchMatch[searchMatches.size()]), status); }
private List<SearchMatch> getImplicitConstructorReferencesFromHierarchy(WorkingCopyOwner owner, IProgressMonitor pm) throws JavaModelException{ IType[] subTypes= getNonBinarySubtypes(owner, fType, pm); List<SearchMatch> result= new ArrayList<>(subTypes.length); for (int i= 0; i < subTypes.length; i++) { result.addAll(getAllSuperConstructorInvocations(subTypes[i])); } return result; }
private static Collection<SearchMatch> getAllSuperConstructorInvocations(IType type) throws JavaModelException { IMethod[] constructors= JavaElementUtil.getAllConstructors(type); CompilationUnit cuNode= new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(type.getCompilationUnit(), false); List<SearchMatch> result= new ArrayList<>(constructors.length); for (int i= 0; i < constructors.length; i++) { ASTNode superCall= getSuperConstructorCallNode(constructors[i], cuNode); if (superCall != null) result.add(createSearchResult(superCall, constructors[i])); } return result; }
protected RefactoringStatus checkConstructorCalls(final IType type, final IProgressMonitor monitor) throws JavaModelException { try { monitor.beginTask(RefactoringCoreMessages.PullUpRefactoring_checking, 2); final RefactoringStatus result= new RefactoringStatus(); final SearchResultGroup[] groups= ConstructorReferenceFinder.getConstructorReferences(type, fOwner, new SubProgressMonitor(monitor, 1), result); final String message= Messages.format(RefactoringCoreMessages.HierarchyRefactoring_gets_instantiated, new Object[] { JavaElementLabels.getTextLabel(type, JavaElementLabels.ALL_FULLY_QUALIFIED)}); ICompilationUnit unit= null; for (int index= 0; index < groups.length; index++) { unit= groups[index].getCompilationUnit(); if (unit != null) { final CompilationUnit cuNode= RefactoringASTParser.parseWithASTProvider(unit, false, new SubProgressMonitor(monitor, 1)); final ASTNode[] references= ASTNodeSearchUtil.getAstNodes(groups[index].getSearchResults(), cuNode); ASTNode node= null; for (int offset= 0; offset < references.length; offset++) { node= references[offset]; if ((node instanceof ClassInstanceCreation) || ConstructorReferenceFinder.isImplicitConstructorReferenceNodeInClassCreations(node)) { final RefactoringStatusContext context= JavaStatusContext.create(unit, node); result.addError(message, context); } } } } return result; } finally { monitor.done(); } }
private IJavaSearchScope createSearchScope() throws JavaModelException{ if (fConstructors.length == 0) return RefactoringScopeFactory.create(fType); return RefactoringScopeFactory.create(getMostVisibleConstructor()); }