Example usage for org.eclipse.jdt.core.dom ForStatement BODY_PROPERTY

List of usage examples for org.eclipse.jdt.core.dom ForStatement BODY_PROPERTY

Introduction

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

Prototype

ChildPropertyDescriptor BODY_PROPERTY

To view the source code for org.eclipse.jdt.core.dom ForStatement BODY_PROPERTY.

Click Source Link

Document

The "body" structural property of this node type (child type: Statement ).

Usage

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 w  w.ja v a  2  s.  c o m
        target = parent;
        parent = parent.getParent();
        locationInParent = target.getLocationInParent();
    }
    ListRewrite lw = rewrite.getListRewrite(parent, (ChildListPropertyDescriptor) locationInParent);
    lw.insertBefore(declaration, target, null);
}