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

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

Introduction

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

Prototype

ChildPropertyDescriptor BODY_PROPERTY

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

Click Source Link

Document

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

Usage

From source file:org.eclipse.emf.codegen.merge.java.facade.ast.ASTJInitializer.java

License:Open Source License

public void setBody(String body) {
    this.body = body;
    setTrackedNodeProperty(getASTNode(), body, Initializer.BODY_PROPERTY, ASTNode.BLOCK);
}

From source file:org.moe.natjgen.InitializerEditor.java

License:Apache License

@SuppressWarnings("unchecked")
public boolean hasNatJRegister() {
    Block block = (Block) getRewrite().get(decl, Initializer.BODY_PROPERTY);

    if (block == null) {
        return false;
    }//  w  w w  . j  ava 2  s  .c  o m

    ListRewrite block_stmts = getRewrite().getListRewrite(block, Block.STATEMENTS_PROPERTY);
    for (Statement stmt : (List<Statement>) block_stmts.getRewrittenList()) {
        if (stmt instanceof ExpressionStatement) {
            Expression expr = (Expression) getRewrite().get(stmt, ExpressionStatement.EXPRESSION_PROPERTY);
            if (expr instanceof MethodInvocation) {
                Expression cls = (Expression) getRewrite().get(expr, MethodInvocation.EXPRESSION_PROPERTY);
                if (!(cls instanceof SimpleName)) {
                    continue;
                }

                String identifier = (String) getRewrite().get(cls, SimpleName.IDENTIFIER_PROPERTY);
                if (!identifier.equals(Constants.NatJ) && !identifier.equals(Constants.NatJFQ)) {
                    continue;
                }

                SimpleName method = (SimpleName) getRewrite().get(expr, MethodInvocation.NAME_PROPERTY);
                String methodId = (String) getRewrite().get(method, SimpleName.IDENTIFIER_PROPERTY);
                if (methodId.equals(Constants.NatJRegisterMethod)) {
                    return true;
                }
            }
        }
    }
    return false;
}

From source file:org.moe.natjgen.InitializerEditor.java

License:Apache License

public void insertNatJRegister() throws GeneratorException {
    editLock();//  ww w.ja va2s  .  c  o  m

    Block block = (Block) getRewrite().get(decl, Initializer.BODY_PROPERTY);

    if (block == null) {
        block = getAST().newBlock();
        getRewrite().set(decl, Initializer.BODY_PROPERTY, block, getEditGroup());
    }

    ListRewrite block_stmts = getRewrite().getListRewrite(block, Block.STATEMENTS_PROPERTY);
    MethodInvocation invoke = getAST().newMethodInvocation();
    ExpressionStatement expr_stmt = getAST().newExpressionStatement(invoke);
    block_stmts.insertFirst(expr_stmt, getEditGroup());
    getRewrite().set(invoke, MethodInvocation.EXPRESSION_PROPERTY,
            getAST().newSimpleName(getManager().addImport(Constants.NatJFQ)), getEditGroup());
    getRewrite().set(invoke, MethodInvocation.NAME_PROPERTY,
            getAST().newSimpleName(Constants.NatJRegisterMethod), getEditGroup());
}