public MethodDeclaration getEnclosingMethod() { ASTNode first= (ASTNode)fNodes.get(0); return (MethodDeclaration)ASTNodes.getParent(first, ASTNode.METHOD_DECLARATION); } }
private boolean isUsedInExplicitConstructorCall() throws JavaModelException { Expression selectedExpression= getSelectedExpression().getAssociatedExpression(); if (ASTNodes.getParent(selectedExpression, ConstructorInvocation.class) != null) return true; if (ASTNodes.getParent(selectedExpression, SuperConstructorInvocation.class) != null) return true; return false; }
private static ImportDeclaration getImportDeclaration(IProblemLocation problem, CompilationUnit compilationUnit) { ASTNode selectedNode= problem.getCoveringNode(compilationUnit); if (selectedNode != null) { ASTNode node= ASTNodes.getParent(selectedNode, ASTNode.IMPORT_DECLARATION); if (node instanceof ImportDeclaration) { return (ImportDeclaration)node; } } return null; }
public static VariableDeclarationFragment getFieldDeclarationFragmentNode(IField iField, CompilationUnit cuNode) throws JavaModelException { ASTNode node= getNameNode(iField, cuNode); if (node instanceof VariableDeclarationFragment) { return (VariableDeclarationFragment)node; } return ASTNodes.getParent(node, VariableDeclarationFragment.class); }
public static VariableDeclarationFragment getFieldDeclarationFragmentNode(IField iField, CompilationUnit cuNode) throws JavaModelException { ASTNode node= getNameNode(iField, cuNode); if (node instanceof VariableDeclarationFragment) return (VariableDeclarationFragment)node; return (VariableDeclarationFragment)ASTNodes.getParent(node, VariableDeclarationFragment.class); }
private ASTNode typeToDeclaration(IType type, CompilationUnit root) throws JavaModelException { Name intermediateName= (Name) NodeFinder.perform(root, type.getNameRange()); if (type.isAnonymous()) { return ASTNodes.getParent(intermediateName, AnonymousClassDeclaration.class); } else { return ASTNodes.getParent(intermediateName, AbstractTypeDeclaration.class); } }
private ASTNode typeToDeclaration(IType type, CompilationUnit root) throws JavaModelException { Name intermediateName= (Name) NodeFinder.perform(root, type.getNameRange()); if (type.isAnonymous()) { return ASTNodes.getParent(intermediateName, AnonymousClassDeclaration.class); } else { return ASTNodes.getParent(intermediateName, AbstractTypeDeclaration.class); } }
private Set getNamesDeclaredLocallyAtNewLocation() { if (fNamesDeclaredLocallyAtNewLocation != null) return fNamesDeclaredLocallyAtNewLocation; BodyDeclaration enclosingBodyDecl= (BodyDeclaration) ASTNodes.getParent(fNewLocation, BodyDeclaration.class); Assert.isTrue(!(enclosingBodyDecl instanceof AbstractTypeDeclaration)); return fNamesDeclaredLocallyAtNewLocation= getLocallyDeclaredNames(enclosingBodyDecl); }
private boolean classNameHidesEnclosingType() { ITypeBinding type= ASTNodes.getParent(fAnonymousInnerClassNode, AbstractTypeDeclaration.class).resolveBinding(); while (type != null) { if (fClassName.equals(type.getName())) return true; type= type.getDeclaringClass(); } return false; }
@Override public boolean visit(FieldDeclaration node) { TypeDeclaration typeDecl= ASTNodes.getParent(node, TypeDeclaration.class); if (typeDecl != null && typeDecl.isInterface()) { final int excluded= Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL; if ((node.getModifiers() & excluded) > 0) { rewriteOperations.add(new RemoveModifiersOperation(node, excluded)); } } return true; }
private boolean isInsideSubclassOfDeclaringType(ASTNode node) { Assert.isTrue((node instanceof ClassInstanceCreation) || (node instanceof SuperConstructorInvocation)); final AbstractTypeDeclaration declaration= (AbstractTypeDeclaration) ASTNodes.getParent(node, AbstractTypeDeclaration.class); Assert.isNotNull(declaration); final AnonymousClassDeclaration anonymous= (AnonymousClassDeclaration) ASTNodes.getParent(node, AnonymousClassDeclaration.class); boolean isAnonymous= anonymous != null && ASTNodes.isParent(anonymous, declaration); if (isAnonymous) return anonymous != null && isSubclassBindingOfEnclosingType(anonymous.resolveBinding()); return isSubclassBindingOfEnclosingType(declaration.resolveBinding()); }
@Override protected Expression createNewParamgument(ParameterInfo info, List<ParameterInfo> parameterInfos, List<Expression> nodes) { CompilationUnitRewrite cuRewrite= getCompilationUnitRewrite(); MethodDeclaration declaration= ASTNodes.getParent(fNode, MethodDeclaration.class); if (isRecursiveReference()) { return createNewExpressionRecursive(info, parameterInfos, nodes, cuRewrite, declaration); } else return createNewExpression(info, parameterInfos, nodes, cuRewrite, declaration); }
@Override public boolean visit(MethodDeclaration node) { if (node.isConstructor()) { AbstractTypeDeclaration decl= ASTNodes.getParent(node, AbstractTypeDeclaration.class); NameData name= fNames.get(decl.getName().resolveBinding()); if (name != null) { name.addReference(node.getName()); } } return true; } @Override
@Override public boolean visit(MethodDeclaration node) { if (node.isConstructor()) { AbstractTypeDeclaration decl= (AbstractTypeDeclaration) ASTNodes.getParent(node, AbstractTypeDeclaration.class); NameData name= fNames.get(decl.getName().resolveBinding()); if (name != null) { name.addReference(node.getName()); } } return true; } @Override
private String getTypeName(ASTNode type) { if (type instanceof AbstractTypeDeclaration) { return ((AbstractTypeDeclaration)type).getName().getIdentifier(); } else if (type instanceof AnonymousClassDeclaration) { ClassInstanceCreation node= ASTNodes.getParent(type, ClassInstanceCreation.class); return ASTNodes.asString(node.getType()); } Assert.isTrue(false, "Should not happen"); //$NON-NLS-1$ return null; }
void initialize(IType type) throws JavaModelException { RefactoringASTParser parser= new RefactoringASTParser(IASTSharedValues.SHARED_AST_LEVEL); fUnit= parser.parse(type.getCompilationUnit(), true); fTypeBinding= null; // type cannot be anonymous final AbstractTypeDeclaration declaration= ASTNodes.getParent(NodeFinder.perform(fUnit, type.getNameRange()), AbstractTypeDeclaration.class); if (declaration != null) fTypeBinding= declaration.resolveBinding(); }
void initialize(IType type) throws JavaModelException { RefactoringASTParser parser= new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL); fUnit= parser.parse(type.getCompilationUnit(), true); fTypeBinding= null; // type cannot be anonymous final AbstractTypeDeclaration declaration= (AbstractTypeDeclaration) ASTNodes.getParent(NodeFinder.perform(fUnit, type.getNameRange()), AbstractTypeDeclaration.class); if (declaration != null) fTypeBinding= declaration.resolveBinding(); }
public AddUnimplementedConstructorsContentProvider(IType type) throws JavaModelException { RefactoringASTParser parser= new RefactoringASTParser(AST.JLS3); fUnit= parser.parse(type.getCompilationUnit(), true); AbstractTypeDeclaration declaration= (AbstractTypeDeclaration) ASTNodes.getParent(NodeFinder.perform(fUnit, type.getNameRange()), AbstractTypeDeclaration.class); if (declaration != null) { ITypeBinding binding= declaration.resolveBinding(); if (binding != null) fMethodsList= StubUtility2.getVisibleConstructors(binding, true, false); } }
private void addNestedClass(CompilationUnitRewrite rewrite, ITypeBinding[] typeParameters) throws CoreException { final AbstractTypeDeclaration declarations= (AbstractTypeDeclaration) ASTNodes.getParent(fAnonymousInnerClassNode, AbstractTypeDeclaration.class); int index= findIndexOfFistNestedClass(declarations.bodyDeclarations()); if (index == -1) index= 0; rewrite.getASTRewrite().getListRewrite(declarations, declarations.getBodyDeclarationsProperty()).insertAt(createNewNestedClass(rewrite, typeParameters), index, null); }
private static String findAffectedParameterName(ASTNode selectedNode) { VariableDeclaration argDecl= (selectedNode instanceof VariableDeclaration) ? (VariableDeclaration) selectedNode : (VariableDeclaration) ASTNodes.getParent(selectedNode, VariableDeclaration.class); if (argDecl != null) return argDecl.getName().getIdentifier(); if (selectedNode.getNodeType() == ASTNode.SIMPLE_NAME) { IBinding binding= ((SimpleName) selectedNode).resolveBinding(); if (binding.getKind() == IBinding.VARIABLE && ((IVariableBinding) binding).isParameter()) return ((SimpleName) selectedNode).getIdentifier(); } return null; }