@Override protected void clearCaches() { super.clearCaches(); fCachedMembersReferences.clear(); fCachedDestinationTypeHierarchy= null; fCachedDeclaringSuperTypeHierarchy= null; }
protected void copyParameters(final ASTRewrite rewrite, final ICompilationUnit unit, final MethodDeclaration oldMethod, final MethodDeclaration newMethod, final TypeVariableMaplet[] mapping) throws JavaModelException { SingleVariableDeclaration newDeclaration= null; for (int index= 0, size= oldMethod.parameters().size(); index < size; index++) { final SingleVariableDeclaration oldDeclaration= (SingleVariableDeclaration) oldMethod.parameters().get(index); if (mapping.length > 0) newDeclaration= createPlaceholderForSingleVariableDeclaration(oldDeclaration, unit, mapping, rewrite); else newDeclaration= createPlaceholderForSingleVariableDeclaration(oldDeclaration, unit, rewrite); newMethod.parameters().add(newDeclaration); } }
protected void copyReturnType(final ASTRewrite rewrite, final ICompilationUnit unit, final MethodDeclaration oldMethod, final MethodDeclaration newMethod, final TypeVariableMaplet[] mapping) throws JavaModelException { Type newReturnType= null; if (mapping.length > 0) newReturnType= createPlaceholderForType(oldMethod.getReturnType2(), unit, mapping, rewrite); else newReturnType= createPlaceholderForType(oldMethod.getReturnType2(), unit, rewrite); newMethod.setReturnType2(newReturnType); }
protected static FieldDeclaration createNewFieldDeclarationNode(final ASTRewrite rewrite, final CompilationUnit unit, final IField field, final VariableDeclarationFragment oldFieldFragment, final TypeVariableMaplet[] mapping, final IProgressMonitor monitor, final RefactoringStatus status, final int modifiers) throws JavaModelException { final VariableDeclarationFragment newFragment= rewrite.getAST().newVariableDeclarationFragment(); copyExtraDimensions(oldFieldFragment, newFragment); if (oldFieldFragment.getInitializer() != null) { Expression newInitializer= null; if (mapping.length > 0) newInitializer= createPlaceholderForExpression(oldFieldFragment.getInitializer(), field.getCompilationUnit(), mapping, rewrite); else newInitializer= createPlaceholderForExpression(oldFieldFragment.getInitializer(), field.getCompilationUnit(), rewrite); newFragment.setInitializer(newInitializer); } newFragment.setName(((SimpleName) ASTNode.copySubtree(rewrite.getAST(), oldFieldFragment.getName()))); final FieldDeclaration newField= rewrite.getAST().newFieldDeclaration(newFragment); final FieldDeclaration oldField= ASTNodeSearchUtil.getFieldDeclarationNode(field, unit); copyJavadocNode(rewrite, oldField, newField); copyAnnotations(oldField, newField); newField.modifiers().addAll(ASTNodeFactory.newModifiers(rewrite.getAST(), modifiers)); final Type oldType= oldField.getType(); Type newType= null; if (mapping.length > 0) { newType= createPlaceholderForType(oldType, field.getCompilationUnit(), mapping, rewrite); } else newType= createPlaceholderForType(oldType, field.getCompilationUnit(), rewrite); newField.setType(newType); return newField; }
protected static void deleteDeclarationNodes(final CompilationUnitRewrite sourceRewriter, final boolean sameCu, final CompilationUnitRewrite unitRewriter, final List members, final GroupCategorySet set) throws JavaModelException { final List declarationNodes= getDeclarationNodes(unitRewriter.getRoot(), members); for (final Iterator iterator= declarationNodes.iterator(); iterator.hasNext();) { final ASTNode node= (ASTNode) iterator.next(); final ASTRewrite rewriter= unitRewriter.getASTRewrite(); final ImportRemover remover= unitRewriter.getImportRemover(); if (node instanceof VariableDeclarationFragment) { if (node.getParent() instanceof FieldDeclaration) { final FieldDeclaration declaration= (FieldDeclaration) node.getParent(); if (areAllFragmentsDeleted(declaration, declarationNodes)) { rewriter.remove(declaration, unitRewriter.createCategorizedGroupDescription(RefactoringCoreMessages.HierarchyRefactoring_remove_member, set)); if (!sameCu) remover.registerRemovedNode(declaration); } else { rewriter.remove(node, unitRewriter.createCategorizedGroupDescription(RefactoringCoreMessages.HierarchyRefactoring_remove_member, set)); if (!sameCu) remover.registerRemovedNode(node); } } } else { rewriter.remove(node, unitRewriter.createCategorizedGroupDescription(RefactoringCoreMessages.HierarchyRefactoring_remove_member, set)); if (!sameCu) remover.registerRemovedNode(node); } } }
protected RefactoringStatus checkDeclaringType(final IProgressMonitor monitor) throws JavaModelException { final RefactoringStatus status= super.checkDeclaringType(monitor); if (JavaModelUtil.getFullyQualifiedName(getDeclaringType()).equals("java.lang.Object")) //$NON-NLS-1$ status.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.PullUpRefactoring_no_java_lang_Object)); status.merge(checkDeclaringSuperTypes(monitor)); return status; }
protected boolean canBeAccessedFrom(final IMember member, final IType target, final ITypeHierarchy hierarchy) throws JavaModelException { if (super.canBeAccessedFrom(member, target, hierarchy)) { if (target.isInterface()) return true;
protected static FieldDeclaration createNewFieldDeclarationNode(final ASTRewrite rewrite, final CompilationUnit unit, final IField field, final VariableDeclarationFragment oldFieldFragment, final TypeVariableMaplet[] mapping, final IProgressMonitor monitor, final RefactoringStatus status, final int modifiers) throws JavaModelException { final VariableDeclarationFragment newFragment= rewrite.getAST().newVariableDeclarationFragment(); copyExtraDimensions(oldFieldFragment, newFragment); if (oldFieldFragment.getInitializer() != null) { Expression newInitializer= null; if (mapping.length > 0) newInitializer= createPlaceholderForExpression(oldFieldFragment.getInitializer(), field.getCompilationUnit(), mapping, rewrite); else newInitializer= createPlaceholderForExpression(oldFieldFragment.getInitializer(), field.getCompilationUnit(), rewrite); newFragment.setInitializer(newInitializer); } newFragment.setName(((SimpleName) ASTNode.copySubtree(rewrite.getAST(), oldFieldFragment.getName()))); final FieldDeclaration newField= rewrite.getAST().newFieldDeclaration(newFragment); final FieldDeclaration oldField= ASTNodeSearchUtil.getFieldDeclarationNode(field, unit); copyJavadocNode(rewrite, oldField, newField); copyAnnotations(oldField, newField); newField.modifiers().addAll(ASTNodeFactory.newModifiers(rewrite.getAST(), modifiers)); final Type oldType= oldField.getType(); Type newType= null; if (mapping.length > 0) { newType= createPlaceholderForType(oldType, field.getCompilationUnit(), mapping, rewrite); } else newType= createPlaceholderForType(oldType, field.getCompilationUnit(), rewrite); newField.setType(newType); return newField; }
protected static void deleteDeclarationNodes(final CompilationUnitRewrite sourceRewriter, final boolean sameCu, final CompilationUnitRewrite unitRewriter, final List<IMember> members, final GroupCategorySet set) throws JavaModelException { final List<ASTNode> declarationNodes= getDeclarationNodes(unitRewriter.getRoot(), members); for (final Iterator<ASTNode> iterator= declarationNodes.iterator(); iterator.hasNext();) { final ASTNode node= iterator.next(); final ASTRewrite rewriter= unitRewriter.getASTRewrite(); final ImportRemover remover= unitRewriter.getImportRemover(); if (node instanceof VariableDeclarationFragment) { if (node.getParent() instanceof FieldDeclaration) { final FieldDeclaration declaration= (FieldDeclaration) node.getParent(); if (areAllFragmentsDeleted(declaration, declarationNodes)) { rewriter.remove(declaration, unitRewriter.createCategorizedGroupDescription(RefactoringCoreMessages.HierarchyRefactoring_remove_member, set)); if (!sameCu) remover.registerRemovedNode(declaration); } else { rewriter.remove(node, unitRewriter.createCategorizedGroupDescription(RefactoringCoreMessages.HierarchyRefactoring_remove_member, set)); if (!sameCu) remover.registerRemovedNode(node); } } } else { rewriter.remove(node, unitRewriter.createCategorizedGroupDescription(RefactoringCoreMessages.HierarchyRefactoring_remove_member, set)); if (!sameCu) remover.registerRemovedNode(node); } } }
@Override protected RefactoringStatus checkDeclaringType(final IProgressMonitor monitor) throws JavaModelException { final RefactoringStatus status= super.checkDeclaringType(monitor); if (getDeclaringType().getFullyQualifiedName('.').equals("java.lang.Object")) //$NON-NLS-1$ status.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.PullUpRefactoring_no_java_lang_Object)); status.merge(checkDeclaringSuperTypes(monitor)); return status; }
@Override protected boolean canBeAccessedFrom(final IMember member, final IType target, final ITypeHierarchy hierarchy) throws JavaModelException { if (super.canBeAccessedFrom(member, target, hierarchy)) { if (target.isInterface()) return true;
protected static FieldDeclaration createNewFieldDeclarationNode(final ASTRewrite rewrite, final CompilationUnit unit, final IField field, final VariableDeclarationFragment oldFieldFragment, final TypeVariableMaplet[] mapping, final IProgressMonitor monitor, final RefactoringStatus status, final int modifiers) throws JavaModelException { final VariableDeclarationFragment newFragment= rewrite.getAST().newVariableDeclarationFragment(); newFragment.setExtraDimensions(oldFieldFragment.getExtraDimensions()); if (oldFieldFragment.getInitializer() != null) { Expression newInitializer= null; if (mapping.length > 0) newInitializer= createPlaceholderForExpression(oldFieldFragment.getInitializer(), field.getCompilationUnit(), mapping, rewrite); else newInitializer= createPlaceholderForExpression(oldFieldFragment.getInitializer(), field.getCompilationUnit(), rewrite); newFragment.setInitializer(newInitializer); } newFragment.setName(((SimpleName) ASTNode.copySubtree(rewrite.getAST(), oldFieldFragment.getName()))); final FieldDeclaration newField= rewrite.getAST().newFieldDeclaration(newFragment); final FieldDeclaration oldField= ASTNodeSearchUtil.getFieldDeclarationNode(field, unit); copyJavadocNode(rewrite, field, oldField, newField); copyAnnotations(oldField, newField); newField.modifiers().addAll(ASTNodeFactory.newModifiers(rewrite.getAST(), modifiers)); final Type oldType= oldField.getType(); Type newType= null; if (mapping.length > 0) { newType= createPlaceholderForType(oldType, field.getCompilationUnit(), mapping, rewrite); } else newType= createPlaceholderForType(oldType, field.getCompilationUnit(), rewrite); newField.setType(newType); return newField; }
protected static void deleteDeclarationNodes(final CompilationUnitRewrite sourceRewriter, final boolean sameCu, final CompilationUnitRewrite unitRewriter, final List<IMember> members, final GroupCategorySet set) throws JavaModelException { final List<ASTNode> declarationNodes= getDeclarationNodes(unitRewriter.getRoot(), members); for (final Iterator<ASTNode> iterator= declarationNodes.iterator(); iterator.hasNext();) { final ASTNode node= iterator.next(); final ASTRewrite rewriter= unitRewriter.getASTRewrite(); final ImportRemover remover= unitRewriter.getImportRemover(); if (node instanceof VariableDeclarationFragment) { if (node.getParent() instanceof FieldDeclaration) { final FieldDeclaration declaration= (FieldDeclaration) node.getParent(); if (areAllFragmentsDeleted(declaration, declarationNodes)) { rewriter.remove(declaration, unitRewriter.createCategorizedGroupDescription(RefactoringCoreMessages.HierarchyRefactoring_remove_member, set)); if (!sameCu) remover.registerRemovedNode(declaration); } else { rewriter.remove(node, unitRewriter.createCategorizedGroupDescription(RefactoringCoreMessages.HierarchyRefactoring_remove_member, set)); if (!sameCu) remover.registerRemovedNode(node); } } } else { rewriter.remove(node, unitRewriter.createCategorizedGroupDescription(RefactoringCoreMessages.HierarchyRefactoring_remove_member, set)); if (!sameCu) remover.registerRemovedNode(node); } } }
protected void copyParameters(final ASTRewrite rewrite, final ICompilationUnit unit, final MethodDeclaration oldMethod, final MethodDeclaration newMethod, final TypeVariableMaplet[] mapping) throws JavaModelException { SingleVariableDeclaration newDeclaration= null; for (int index= 0, size= oldMethod.parameters().size(); index < size; index++) { final SingleVariableDeclaration oldDeclaration= (SingleVariableDeclaration) oldMethod.parameters().get(index); if (mapping.length > 0) newDeclaration= createPlaceholderForSingleVariableDeclaration(oldDeclaration, unit, mapping, rewrite); else newDeclaration= createPlaceholderForSingleVariableDeclaration(oldDeclaration, unit, rewrite); newMethod.parameters().add(index, newDeclaration); } }
@Override protected RefactoringStatus checkDeclaringType(final IProgressMonitor monitor) throws JavaModelException { final RefactoringStatus status= super.checkDeclaringType(monitor); if (getDeclaringType().getFullyQualifiedName('.').equals("java.lang.Object")) //$NON-NLS-1$ status.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.PullUpRefactoring_no_java_lang_Object)); status.merge(checkDeclaringSuperTypes(monitor)); return status; }
protected void copyReturnType(final ASTRewrite rewrite, final ICompilationUnit unit, final MethodDeclaration oldMethod, final MethodDeclaration newMethod, final TypeVariableMaplet[] mapping) throws JavaModelException { Type newReturnType= null; if (mapping.length > 0) newReturnType= createPlaceholderForType(oldMethod.getReturnType2(), unit, mapping, rewrite); else newReturnType= createPlaceholderForType(oldMethod.getReturnType2(), unit, rewrite); newMethod.setReturnType2(newReturnType); }
protected void clearCaches() { super.clearCaches(); fCachedMembersReferences.clear(); fCachedDestinationTypeHierarchy= null; fCachedDeclaringSuperTypeHierarchy= null; }
@Override protected boolean canBeAccessedFrom(final IMember member, final IType target, final ITypeHierarchy hierarchy) throws JavaModelException { if (super.canBeAccessedFrom(member, target, hierarchy)) { if (target.isInterface()) return true;
protected void copyParameters(final ASTRewrite rewrite, final ICompilationUnit unit, final MethodDeclaration oldMethod, final MethodDeclaration newMethod, final TypeVariableMaplet[] mapping) throws JavaModelException { SingleVariableDeclaration newDeclaration= null; for (int index= 0, size= oldMethod.parameters().size(); index < size; index++) { final SingleVariableDeclaration oldDeclaration= (SingleVariableDeclaration) oldMethod.parameters().get(index); if (mapping.length > 0) newDeclaration= createPlaceholderForSingleVariableDeclaration(oldDeclaration, unit, mapping, rewrite); else newDeclaration= createPlaceholderForSingleVariableDeclaration(oldDeclaration, unit, rewrite); newMethod.parameters().add(newDeclaration); } }
protected void copyReturnType(final ASTRewrite rewrite, final ICompilationUnit unit, final MethodDeclaration oldMethod, final MethodDeclaration newMethod, final TypeVariableMaplet[] mapping) throws JavaModelException { Type newReturnType= null; if (mapping.length > 0) newReturnType= createPlaceholderForType(oldMethod.getReturnType2(), unit, mapping, rewrite); else newReturnType= createPlaceholderForType(oldMethod.getReturnType2(), unit, rewrite); newMethod.setReturnType2(newReturnType); }