Example usage for org.eclipse.jdt.core.dom BodyDeclaration getParent

List of usage examples for org.eclipse.jdt.core.dom BodyDeclaration getParent

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom BodyDeclaration getParent.

Prototype

public final ASTNode getParent() 

Source Link

Document

Returns this node's parent node, or null if this is the root node.

Usage

From source file:at.bestsolution.fxide.jdt.corext.util.JdtFlags.java

License:Open Source License

public static boolean isStatic(BodyDeclaration bodyDeclaration) {
    if (isNestedInterfaceOrAnnotation(bodyDeclaration))
        return true;
    int nodeType = bodyDeclaration.getNodeType();
    if (!(nodeType == ASTNode.METHOD_DECLARATION || nodeType == ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION)
            && isInterfaceOrAnnotationMember(bodyDeclaration))
        return true;
    if (bodyDeclaration instanceof EnumConstantDeclaration)
        return true;
    if (bodyDeclaration instanceof EnumDeclaration
            && bodyDeclaration.getParent() instanceof AbstractTypeDeclaration)
        return true;
    return Modifier.isStatic(bodyDeclaration.getModifiers());
}

From source file:at.bestsolution.fxide.jdt.corext.util.JdtFlags.java

License:Open Source License

private static boolean isInterfaceOrAnnotationMember(BodyDeclaration bodyDeclaration) {
    return isInterfaceOrAnnotation(bodyDeclaration.getParent());
}

From source file:at.bestsolution.fxide.jdt.corext.util.JdtFlags.java

License:Open Source License

private static boolean isNestedInterfaceOrAnnotation(BodyDeclaration bodyDeclaration) {
    return bodyDeclaration.getParent() instanceof AbstractTypeDeclaration
            && isInterfaceOrAnnotation(bodyDeclaration);
}

From source file:com.google.currysrc.api.process.ast.EnumConstantLocator.java

License:Apache License

@Override
public boolean matches(BodyDeclaration node) {
    if (!(node instanceof EnumConstantDeclaration)) {
        return false;
    }//from  ww w .ja v  a 2s .  com

    if (typeLocator.matches((BodyDeclaration) node.getParent())) {
        EnumConstantDeclaration enumConstantDeclaration = (EnumConstantDeclaration) node;
        if (enumConstantDeclaration.getName().getFullyQualifiedName().equals(constantName)) {
            return true;
        }
    }
    return false;
}

From source file:com.google.currysrc.api.process.ast.FieldLocator.java

License:Apache License

@Override
public boolean matches(BodyDeclaration node) {
    if (node instanceof FieldDeclaration) {
        FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
        for (VariableDeclarationFragment variableDeclarationFragment : (List<VariableDeclarationFragment>) fieldDeclaration
                .fragments()) {//from www  .  ja  v  a  2 s. c  o  m
            String nodeFieldName = variableDeclarationFragment.getName().getFullyQualifiedName();
            if (nodeFieldName.equals(fieldName)) {
                BodyDeclaration parentNode = (BodyDeclaration) node.getParent();
                return typeLocator.matches(parentNode);
            }
        }
    }
    return false;
}

From source file:com.google.currysrc.api.process.ast.MethodLocator.java

License:Apache License

@Override
public boolean matches(BodyDeclaration node) {
    if (node instanceof MethodDeclaration) {
        BodyDeclaration parentNode = (BodyDeclaration) node.getParent();
        MethodDeclaration methodDeclaration = (MethodDeclaration) node;
        return typeLocator.matches(parentNode)
                && methodDeclaration.getName().getFullyQualifiedName().equals(methodName)
                && parameterMatcher.matches(methodDeclaration);
    }//from   w w w . j av  a2s .  com
    return false;
}

From source file:com.google.currysrc.api.process.ast.TypeLocator.java

License:Apache License

/**
 * Finds the type declaration associated with the supplied {@code bodyDeclaration}. Can
 * return {@code bodyDeclaration} if the node itself is a type declaration. Can return null (e.g.)
 * if the bodyDeclaration is declared on an anonymous type.
 *//*from   w  w  w.j  a va 2  s .  c om*/
public static AbstractTypeDeclaration findTypeDeclarationNode(BodyDeclaration bodyDeclaration) {
    if (bodyDeclaration instanceof AbstractTypeDeclaration) {
        return (AbstractTypeDeclaration) bodyDeclaration;
    }
    ASTNode parentNode = bodyDeclaration.getParent();
    if (parentNode instanceof AbstractTypeDeclaration) {
        return (AbstractTypeDeclaration) parentNode;
    }
    return null;
}

From source file:com.google.devtools.j2objc.ast.TreeUtil.java

License:Apache License

public static List<BodyDeclaration> asDeclarationSublist(BodyDeclaration node) {
    List<BodyDeclaration> declarations = getBodyDeclarations(node.getParent());
    int index = declarations.indexOf(node);
    assert index != -1;
    return declarations.subList(index, index + 1);
}

From source file:edu.illinois.jflow.core.transformations.code.ExtractClosureRefactoring.java

License:Open Source License

private void createMethodBundle(final CompilationUnitChange result) {
    BodyDeclaration methodDecl = locateSelectedMethod();

    TextEditGroup insertClassDesc = new TextEditGroup(
            JFlowRefactoringCoreMessages.ExtractClosureRefactoring_bundle_textedit_description);
    result.addTextEditGroup(insertClassDesc);

    BundleCreator bc = new BundleCreator(stages.values());
    AbstractTypeDeclaration newClass = bc.createNewNestedClass();

    ChildListPropertyDescriptor methodDeclDescriptor = (ChildListPropertyDescriptor) methodDecl
            .getLocationInParent();//  w  w w . ja v a 2s.  c  o  m
    ListRewrite methodDeclContainer = fRewriter.getListRewrite(methodDecl.getParent(), methodDeclDescriptor);
    methodDeclContainer.insertBefore(newClass, methodDecl, insertClassDesc);
}

From source file:org.autorefactor.refactoring.ASTHelper.java

License:Open Source License

private static BodyDeclaration getSibling(BodyDeclaration node, boolean lookForPrevious) {
    final ASTNode parent = node.getParent();
    if (parent instanceof AbstractTypeDeclaration) {
        final AbstractTypeDeclaration typeDecl = (AbstractTypeDeclaration) parent;
        return getSibling(node, typeDecl, lookForPrevious);
    } else if (parent instanceof AnonymousClassDeclaration) {
        final AnonymousClassDeclaration classDecl = (AnonymousClassDeclaration) parent;
        return getSibling(node, classDecl, lookForPrevious);
    } else if (parent instanceof CompilationUnit) {
        final CompilationUnit cu = (CompilationUnit) parent;
        final List<AbstractTypeDeclaration> types = types(cu);
        final int index = types.indexOf(node);
        if (index != -1 && index + 1 < types.size()) {
            return types.get(index + 1);
        }//from   w w w . j a  v a 2s . c om
    }
    return null;
}