Example usage for org.eclipse.jdt.core.dom SwitchStatement STATEMENTS_PROPERTY

List of usage examples for org.eclipse.jdt.core.dom SwitchStatement STATEMENTS_PROPERTY

Introduction

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

Prototype

ChildListPropertyDescriptor STATEMENTS_PROPERTY

To view the source code for org.eclipse.jdt.core.dom SwitchStatement STATEMENTS_PROPERTY.

Click Source Link

Document

The "statements" structural property of this node type (element type: Statement ).

Usage

From source file:de.ovgu.cide.language.jdt.ASTID.java

License:Open Source License

public static String calculateId(ASTNode node) {
    if (node == null)
        return "/";
    String id = calculateId(node.getParent());

    if (node.getParent() instanceof Block) {
        Block block = (Block) node.getParent();
        int idx = block.statements().indexOf(node);
        id += "[" + idx + "]";
    }// ww  w  .  j a va 2  s.c  om
    if (node.getParent() instanceof ArrayInitializer) {
        ArrayInitializer block = (ArrayInitializer) node.getParent();
        int idx = block.expressions().indexOf(node);
        id += "[" + idx + "]";
    }
    if (node.getLocationInParent() != null && node.getParent() != null) {
        id += ":" + node.getLocationInParent().getId();
    }
    if (node.getParent() instanceof TryStatement) {
        TryStatement trystmt = (TryStatement) node.getParent();
        if (trystmt.getBody() == node)
            id += "[body]";
    }
    // if (node.getLocationInParent() instanceof
    // ChildListPropertyDescriptor) {
    // List children = (List) node.getParent().getStructuralProperty(
    // node.getLocationInParent());
    // id += "[" + children.indexOf(node) + "]";
    // }

    id += "/" + clean(node.getClass().getSimpleName());

    if (node instanceof TypeDeclaration) {
        id += ":" + clean(((TypeDeclaration) node).getName().toString());
    }
    if (node instanceof FieldDeclaration) {
        for (Object fragment : ((FieldDeclaration) node).fragments()) {
            id += ":" + clean(((VariableDeclarationFragment) fragment).getName().toString());
        }
    }
    if (node instanceof Type) {
        ITypeBinding b = ((Type) node).resolveBinding();
        id += "::" + (b == null ? "null" : b.getQualifiedName());
    }
    if (node instanceof VariableDeclaration)
        id += ":" + clean(((VariableDeclaration) node).getName().toString());
    if (node instanceof Name)
        id += ":" + clean(((Name) node).getFullyQualifiedName());
    if (node instanceof ImportDeclaration)
        id += ":" + clean(((ImportDeclaration) node).getName().toString());
    if (node instanceof MethodDeclaration) {
        Type rt = ((MethodDeclaration) node).getReturnType2();
        id += ":" + clean(rt == null ? "void" : rt.toString());
        id += ":" + clean(((MethodDeclaration) node).getName().toString());
        id += ":" + clean(getParameterTypes(((MethodDeclaration) node).parameters()));
    }

    ChildListPropertyDescriptor[] enumLists = new ChildListPropertyDescriptor[] {
            SwitchStatement.STATEMENTS_PROPERTY, InfixExpression.EXTENDED_OPERANDS_PROPERTY,
            TryStatement.CATCH_CLAUSES_PROPERTY, MethodInvocation.ARGUMENTS_PROPERTY,
            ConstructorInvocation.ARGUMENTS_PROPERTY, ClassInstanceCreation.ARGUMENTS_PROPERTY,
            SuperConstructorInvocation.ARGUMENTS_PROPERTY, SuperMethodInvocation.ARGUMENTS_PROPERTY };
    for (ChildListPropertyDescriptor prop : enumLists) {
        if (node.getLocationInParent() == prop) {
            List<?> childList = (List<?>) node.getParent().getStructuralProperty(prop);
            int idx = childList.indexOf(node);
            id += "[" + idx + "]";
        }
    }

    if (node instanceof CompilationUnit) {
        // IJavaElement je = ((CompilationUnit) node).getJavaElement();
        CompilationUnit cu = ((CompilationUnit) node);
        id += "[";
        if (cu.getPackage() != null && cu.getPackage().getName() != null)
            id += clean(cu.getPackage().getName().getFullyQualifiedName() + ".");
        if (cu.types() != null && cu.types().size() >= 1
                && ((AbstractTypeDeclaration) cu.types().get(0)).getName() != null)
            id += ((AbstractTypeDeclaration) cu.types().get(0)).getName().getFullyQualifiedName();
        id += "]";
        // id += "[" + clean(je.getPath().toPortableString()) + "]";
    }
    return id;
}

From source file:de.ovgu.cide.language.jdt.ASTID.java

License:Open Source License

public static String calculateId_old(ASTNode node) {
    if (node == null)
        return "/";
    String id = calculateId(node.getParent());

    if (node.getParent() instanceof Block) {
        Block block = (Block) node.getParent();
        int idx = block.statements().indexOf(node);
        id += "[" + idx + "]";
    }/*from  w w  w .ja v  a  2 s.com*/
    if (node.getLocationInParent() != null && node.getParent() != null) {
        id += ":" + node.getLocationInParent().getId();
    }
    if (node.getParent() instanceof TryStatement) {
        TryStatement trystmt = (TryStatement) node.getParent();
        if (trystmt.getBody() == node)
            id += "[body]";
    }
    // if (node.getLocationInParent() instanceof
    // ChildListPropertyDescriptor) {
    // List children = (List) node.getParent().getStructuralProperty(
    // node.getLocationInParent());
    // id += "[" + children.indexOf(node) + "]";
    // }

    id += "/" + clean(node.getClass().getSimpleName());

    if (node instanceof TypeDeclaration) {
        id += ":" + clean(((TypeDeclaration) node).getName().toString());
    }
    if (node instanceof FieldDeclaration) {
        for (Object fragment : ((FieldDeclaration) node).fragments()) {
            id += ":" + clean(((VariableDeclarationFragment) fragment).getName().toString());
        }
    }
    if (node instanceof Type) {
        ITypeBinding b = ((Type) node).resolveBinding();
        id += "::" + (b == null ? "null" : b.getQualifiedName());
    }
    if (node instanceof VariableDeclaration)
        id += ":" + clean(((VariableDeclaration) node).getName().toString());
    if (node instanceof Name)
        id += ":" + clean(((Name) node).getFullyQualifiedName());
    if (node instanceof ImportDeclaration)
        id += ":" + clean(((ImportDeclaration) node).getName().toString());
    if (node instanceof MethodDeclaration) {
        Type rt = ((MethodDeclaration) node).getReturnType2();
        id += ":" + clean(rt == null ? "void" : rt.toString());
        id += ":" + clean(((MethodDeclaration) node).getName().toString());
        id += ":" + clean(getParameterTypes(((MethodDeclaration) node).parameters()));
    }

    ChildListPropertyDescriptor[] enumLists = new ChildListPropertyDescriptor[] {
            SwitchStatement.STATEMENTS_PROPERTY, InfixExpression.EXTENDED_OPERANDS_PROPERTY,
            TryStatement.CATCH_CLAUSES_PROPERTY };
    for (ChildListPropertyDescriptor prop : enumLists) {
        if (node.getLocationInParent() == prop) {
            List<?> childList = (List<?>) node.getParent().getStructuralProperty(prop);
            int idx = childList.indexOf(node);
            id += "[" + idx + "]";
        }
    }

    if (node instanceof CompilationUnit) {
        // IJavaElement je = ((CompilationUnit) node).getJavaElement();
        CompilationUnit cu = ((CompilationUnit) node);
        id += "[";
        if (cu.getPackage() != null && cu.getPackage().getName() != null)
            id += clean(cu.getPackage().getName().getFullyQualifiedName() + ".");
        if (cu.types() != null && cu.types().size() >= 1
                && ((AbstractTypeDeclaration) cu.types().get(0)).getName() != null)
            id += ((AbstractTypeDeclaration) cu.types().get(0)).getName().getFullyQualifiedName();
        id += "]";
        // id += "[" + clean(je.getPath().toPortableString()) + "]";
    }
    return id;
}

From source file:org.jboss.tools.arquillian.ui.internal.refactoring.AddMissingTypeRefactoring.java

License:Open Source License

private void insertAt(ASTNode target, Statement declaration) {
    //ASTRewrite rewrite= fCURewrite.getASTRewrite();
    //TextEditGroup groupDescription= fCURewrite.createGroupDescription(RefactoringCoreMessages.ExtractTempRefactoring_declare_local_variable);

    ASTNode parent = target.getParent();
    StructuralPropertyDescriptor locationInParent = target.getLocationInParent();
    while (locationInParent != Block.STATEMENTS_PROPERTY
            && locationInParent != SwitchStatement.STATEMENTS_PROPERTY) {
        if (locationInParent == IfStatement.THEN_STATEMENT_PROPERTY
                || locationInParent == IfStatement.ELSE_STATEMENT_PROPERTY
                || locationInParent == ForStatement.BODY_PROPERTY
                || locationInParent == EnhancedForStatement.BODY_PROPERTY
                || locationInParent == DoStatement.BODY_PROPERTY
                || locationInParent == WhileStatement.BODY_PROPERTY) {
            // create intermediate block if target was the body property of a control statement:
            Block replacement = rewrite.getAST().newBlock();
            ListRewrite replacementRewrite = rewrite.getListRewrite(replacement, Block.STATEMENTS_PROPERTY);
            replacementRewrite.insertFirst(declaration, null);
            replacementRewrite.insertLast(rewrite.createMoveTarget(target), null);
            rewrite.replace(target, replacement, null);
            return;
        }//w ww  . j  a  v a2 s  . c  o m
        target = parent;
        parent = parent.getParent();
        locationInParent = target.getLocationInParent();
    }
    ListRewrite lw = rewrite.getListRewrite(parent, (ChildListPropertyDescriptor) locationInParent);
    lw.insertBefore(declaration, target, null);
}