Search in sources :

Example 21 with AnonymousClassDeclaration

use of org.eclipse.jdt.core.dom.AnonymousClassDeclaration in project flux by eclipse.

the class Bindings method getBindingOfParentTypeContext.

/**
	 * Returns the type binding of the node's type context or null if the node is inside
	 * an annotation, type parameter, super type declaration, or Javadoc of a top level type.
	 * The result of this method is equal to the result of {@link #getBindingOfParentType(ASTNode)} for nodes in the type's body.
	 * 
	 * @param node an AST node
	 * @return the type binding of the node's parent type context, or <code>null</code>
	 */
public static ITypeBinding getBindingOfParentTypeContext(ASTNode node) {
    StructuralPropertyDescriptor lastLocation = null;
    while (node != null) {
        if (node instanceof AbstractTypeDeclaration) {
            AbstractTypeDeclaration decl = (AbstractTypeDeclaration) node;
            if (lastLocation == decl.getBodyDeclarationsProperty() || lastLocation == decl.getJavadocProperty()) {
                return decl.resolveBinding();
            } else if (decl instanceof EnumDeclaration && lastLocation == EnumDeclaration.ENUM_CONSTANTS_PROPERTY) {
                return decl.resolveBinding();
            }
        } else if (node instanceof AnonymousClassDeclaration) {
            return ((AnonymousClassDeclaration) node).resolveBinding();
        }
        lastLocation = node.getLocationInParent();
        node = node.getParent();
    }
    return null;
}
Also used : AnonymousClassDeclaration(org.eclipse.jdt.core.dom.AnonymousClassDeclaration) StructuralPropertyDescriptor(org.eclipse.jdt.core.dom.StructuralPropertyDescriptor) AbstractTypeDeclaration(org.eclipse.jdt.core.dom.AbstractTypeDeclaration) EnumDeclaration(org.eclipse.jdt.core.dom.EnumDeclaration)

Example 22 with AnonymousClassDeclaration

use of org.eclipse.jdt.core.dom.AnonymousClassDeclaration in project AutoRefactor by JnRouvignac.

the class RemoveSemiColonRefactoring method visit.

private boolean visit(BodyDeclaration node) {
    final BodyDeclaration nextSibling = getNextSibling(node);
    final ASTNode parent = node.getParent();
    if (nextSibling != null) {
        return removeSuperfluousSemiColons(node, getEndPosition(node), nextSibling.getStartPosition());
    } else if (parent instanceof AbstractTypeDeclaration) {
        final AbstractTypeDeclaration typeDecl = (AbstractTypeDeclaration) parent;
        return removeSuperfluousSemiColons(node, getEndPosition(node), getEndPosition(typeDecl) - 1);
    } else if (parent instanceof AnonymousClassDeclaration) {
        final AnonymousClassDeclaration classDecl = (AnonymousClassDeclaration) parent;
        return removeSuperfluousSemiColons(node, getEndPosition(node), getEndPosition(classDecl) - 1);
    } else if (parent instanceof CompilationUnit) {
        final CompilationUnit cu = (CompilationUnit) parent;
        return removeSuperfluousSemiColons(node, getEndPosition(node), getEndPosition(cu) - 1);
    } else if (parent instanceof TypeDeclarationStatement) {
        return VISIT_SUBTREE;
    }
    throw new NotImplementedException(node, "for a parent of type " + (parent != null ? parent.getClass().getSimpleName() : null));
}
Also used : CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) TypeDeclarationStatement(org.eclipse.jdt.core.dom.TypeDeclarationStatement) NotImplementedException(org.autorefactor.util.NotImplementedException) ASTNode(org.eclipse.jdt.core.dom.ASTNode) AnonymousClassDeclaration(org.eclipse.jdt.core.dom.AnonymousClassDeclaration) BodyDeclaration(org.eclipse.jdt.core.dom.BodyDeclaration) AbstractTypeDeclaration(org.eclipse.jdt.core.dom.AbstractTypeDeclaration)

Aggregations

AnonymousClassDeclaration (org.eclipse.jdt.core.dom.AnonymousClassDeclaration)22 AbstractTypeDeclaration (org.eclipse.jdt.core.dom.AbstractTypeDeclaration)17 ASTNode (org.eclipse.jdt.core.dom.ASTNode)12 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)10 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)8 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)7 BodyDeclaration (org.eclipse.jdt.core.dom.BodyDeclaration)4 ClassInstanceCreation (org.eclipse.jdt.core.dom.ClassInstanceCreation)4 SimpleName (org.eclipse.jdt.core.dom.SimpleName)4 NotImplementedException (org.autorefactor.util.NotImplementedException)3 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)3 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)3 EnumDeclaration (org.eclipse.jdt.core.dom.EnumDeclaration)3 FieldDeclaration (org.eclipse.jdt.core.dom.FieldDeclaration)3 StructuralPropertyDescriptor (org.eclipse.jdt.core.dom.StructuralPropertyDescriptor)3 TypeDeclaration (org.eclipse.jdt.core.dom.TypeDeclaration)3 ASTRewrite (org.eclipse.jdt.core.dom.rewrite.ASTRewrite)3 ImportRewriteContext (org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext)3 CodeGenerationSettings (org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationSettings)3 ContextSensitiveImportRewriteContext (org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext)3