Example usage for org.eclipse.jdt.core.dom InfixExpression LEFT_OPERAND_PROPERTY

List of usage examples for org.eclipse.jdt.core.dom InfixExpression LEFT_OPERAND_PROPERTY

Introduction

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

Prototype

ChildPropertyDescriptor LEFT_OPERAND_PROPERTY

To view the source code for org.eclipse.jdt.core.dom InfixExpression LEFT_OPERAND_PROPERTY.

Click Source Link

Document

The "leftOperand" structural property of this node type (child type: Expression ).

Usage

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

License:Apache License

@SuppressWarnings("unchecked")
public void updateSafePropertyBinding(String getter, String setter, CalleeArgument calleeArgument) {
    Block block = (Block) getRewrite().get(methodDecl, MethodDeclaration.BODY_PROPERTY);
    if (block == null) {
        block = getAST().newBlock();/*from ww  w.j  a  v  a  2s.c om*/
        getRewrite().set(methodDecl, MethodDeclaration.BODY_PROPERTY, block, getEditGroup());
    }
    ListRewrite block_stmts = getRewrite().getListRewrite(block, Block.STATEMENTS_PROPERTY);
    for (ASTNode object : (List<ASTNode>) block_stmts.getRewrittenList()) {
        block_stmts.remove(object, getEditGroup());
    }

    /**
     * <ObjCRuntimeFQ>
     */
    Name objc_runtime = getAST().newName(Constants.ObjCRuntimeFQ);

    /**
     * Object __old = <getter>()
     */
    SimpleType objcobj_type = getAST().newSimpleType(getAST().newName("Object"));
    MethodInvocation getter_inv = getAST().newMethodInvocation();
    getRewrite().set(getter_inv, MethodInvocation.NAME_PROPERTY, getAST().newName(getter), getEditGroup());

    Name old_obj = getAST().newName("__old");
    VariableDeclarationFragment vdf = getAST().newVariableDeclarationFragment();
    getRewrite().set(vdf, VariableDeclarationFragment.NAME_PROPERTY, old_obj, getEditGroup());
    getRewrite().set(vdf, VariableDeclarationFragment.INITIALIZER_PROPERTY, getter_inv, getEditGroup());
    VariableDeclarationExpression vde = getAST().newVariableDeclarationExpression(vdf);
    getRewrite().set(vde, VariableDeclarationExpression.TYPE_PROPERTY,
            ASTNode.copySubtree(getAST(), objcobj_type), getEditGroup());
    insertStatement(block_stmts, vde);

    /**
     * <ObjCRuntimeFQ>.associateObjCObject(this, <argument>)
     */
    MethodInvocation assoc_inv = getAST().newMethodInvocation();
    getRewrite().set(assoc_inv, MethodInvocation.EXPRESSION_PROPERTY, objc_runtime, getEditGroup());
    getRewrite().set(assoc_inv, MethodInvocation.NAME_PROPERTY, getAST().newName("associateObjCObject"),
            getEditGroup());
    ListRewrite assoc_inv_args = getRewrite().getListRewrite(assoc_inv, MethodInvocation.ARGUMENTS_PROPERTY);
    assoc_inv_args.insertLast(getAST().newThisExpression(), getEditGroup());
    assoc_inv_args.insertLast(getAST().newSimpleName(calleeArgument.getName()), getEditGroup());

    /**
     * if (<arg> != null) { ObjCRuntime.associateObjCObject(this, <arg>); }
     */
    {
        Block con_block = getAST().newBlock();
        ListRewrite con_block_stmt = getRewrite().getListRewrite(con_block, Block.STATEMENTS_PROPERTY);
        insertStatement(con_block_stmt, assoc_inv);

        InfixExpression con_obj_nonnull = getAST().newInfixExpression();
        getRewrite().set(con_obj_nonnull, InfixExpression.OPERATOR_PROPERTY,
                InfixExpression.Operator.NOT_EQUALS, getEditGroup());
        getRewrite().set(con_obj_nonnull, InfixExpression.LEFT_OPERAND_PROPERTY,
                getAST().newSimpleName(calleeArgument.getName()), getEditGroup());
        getRewrite().set(con_obj_nonnull, InfixExpression.RIGHT_OPERAND_PROPERTY, getAST().newNullLiteral(),
                getEditGroup());

        IfStatement if_obj_nonnull = getAST().newIfStatement();
        getRewrite().set(if_obj_nonnull, IfStatement.EXPRESSION_PROPERTY, con_obj_nonnull, getEditGroup());
        getRewrite().set(if_obj_nonnull, IfStatement.THEN_STATEMENT_PROPERTY, con_block, getEditGroup());
        block_stmts.insertLast(if_obj_nonnull, getEditGroup());
    }

    /**
     * <setter>(...)
     */
    MethodInvocation setter_inv = getAST().newMethodInvocation();
    getRewrite().set(setter_inv, MethodInvocation.NAME_PROPERTY, getAST().newName(setter), getEditGroup());
    ListRewrite setter_inv_args = getRewrite().getListRewrite(setter_inv, MethodInvocation.ARGUMENTS_PROPERTY);
    setter_inv_args.insertLast(getAST().newSimpleName(calleeArgument.getName()), getEditGroup());
    insertStatement(block_stmts, setter_inv);

    /**
     * <ObjCRuntimeFQ>.dissociateObjCObject(this, old)
     */
    MethodInvocation unassoc_inv = getAST().newMethodInvocation();
    getRewrite().set(unassoc_inv, MethodInvocation.EXPRESSION_PROPERTY,
            ASTNode.copySubtree(getAST(), objc_runtime), getEditGroup());
    getRewrite().set(unassoc_inv, MethodInvocation.NAME_PROPERTY, getAST().newName("dissociateObjCObject"),
            getEditGroup());
    ListRewrite unassoc_inv_args = getRewrite().getListRewrite(unassoc_inv,
            MethodInvocation.ARGUMENTS_PROPERTY);
    unassoc_inv_args.insertLast(getAST().newThisExpression(), getEditGroup());
    unassoc_inv_args.insertLast(ASTNode.copySubtree(getAST(), old_obj), getEditGroup());

    /**
     * if (__old != null) { ObjCRuntime.dissociateObjCObject(this, __old); }
     */
    {
        Block con_block = getAST().newBlock();
        ListRewrite con_block_stmt = getRewrite().getListRewrite(con_block, Block.STATEMENTS_PROPERTY);
        insertStatement(con_block_stmt, unassoc_inv);

        InfixExpression con_obj_nonnull = getAST().newInfixExpression();
        getRewrite().set(con_obj_nonnull, InfixExpression.OPERATOR_PROPERTY,
                InfixExpression.Operator.NOT_EQUALS, getEditGroup());
        getRewrite().set(con_obj_nonnull, InfixExpression.LEFT_OPERAND_PROPERTY,
                ASTNode.copySubtree(getAST(), old_obj), getEditGroup());
        getRewrite().set(con_obj_nonnull, InfixExpression.RIGHT_OPERAND_PROPERTY, getAST().newNullLiteral(),
                getEditGroup());

        IfStatement if_obj_nonnull = getAST().newIfStatement();
        getRewrite().set(if_obj_nonnull, IfStatement.EXPRESSION_PROPERTY, con_obj_nonnull, getEditGroup());
        getRewrite().set(if_obj_nonnull, IfStatement.THEN_STATEMENT_PROPERTY, con_block, getEditGroup());
        block_stmts.insertLast(if_obj_nonnull, getEditGroup());
    }
}