Example usage for jdk.nashorn.internal.ir BinaryNode isAssignment

List of usage examples for jdk.nashorn.internal.ir BinaryNode isAssignment

Introduction

In this page you can find the example usage for jdk.nashorn.internal.ir BinaryNode isAssignment.

Prototype

@Override
public boolean isAssignment() 

Source Link

Document

Check if this node is an assignment

Usage

From source file:com.bearsoft.org.netbeans.modules.form.JsCodeGenerator.java

private int findHandlerPosition(String componentName, String handlerName, PlatypusFormDataObject dataObject) {
    FunctionNode constructor = dataObject.getConstructor();
    if (constructor != null && constructor.getBody() != null) {
        for (Statement st : constructor.getBody().getStatements()) {
            if (st instanceof ExpressionStatement
                    && ((ExpressionStatement) st).getExpression() instanceof BinaryNode) {
                BinaryNode a = (BinaryNode) ((ExpressionStatement) st).getExpression();
                if (a.isAssignment() && a.getAssignmentDest() instanceof AccessNode) {
                    AccessNode pg = (AccessNode) a.getAssignmentDest();
                    if (handlerName.equals(pg.getProperty())) {
                        if (pg.getBase() instanceof AccessNode) {
                            AccessNode componentPg = (AccessNode) pg.getBase();
                            if (componentName.equals(componentPg.getProperty())
                                    && componentPg.getBase() instanceof IdentNode
                                    && FORM_OBJECT_NAME.equals(((IdentNode) componentPg.getBase()).getName())) {
                                if (a.getAssignmentSource() instanceof FunctionNode) {
                                    FunctionNode handlerFn = (FunctionNode) a.getAssignmentSource();
                                    return handlerFn.getStart();
                                }/*from   w  w  w. j  av  a2 s  .c  o  m*/
                            }
                        }
                    }
                }
            }
        }
    }
    return NOT_FOUND;
}

From source file:com.eas.script.PropertiesAnnotationsMiner.java

@Override
public boolean enterBinaryNode(BinaryNode binaryNode) {
    if (scopeLevel == TOP_CONSTRUCTORS_SCOPE_LEVEL && binaryNode.isAssignment()
            && !binaryNode.isSelfModifying()) {
        if (binaryNode.getAssignmentDest() instanceof AccessNode) {
            AccessNode left = (AccessNode) binaryNode.getAssignmentDest();
            if (left.getBase() instanceof IdentNode
                    && thisAliases.contains(((IdentNode) left.getBase()).getName())) {
                long ft = left.getBase().getToken();
                if (prevComments.containsKey(ft)) {
                    long prevComment = prevComments.get(ft);
                    commentedProperty(left.getProperty(), source.getString(prevComment));
                }// ww w  .  j  av  a2 s .  co  m
                property(left.getProperty(), binaryNode.getAssignmentSource());
            }
        }
    }
    return super.enterBinaryNode(binaryNode);
}

From source file:edu.brown.cs.bubbles.nobase.NobaseNashorn.java

License:Open Source License

/********************************************************************************/

private static NashornAstNode createNashornAstNode(Node pn, NashornAstNode par) {
    if (pn == null)
        return null;
    NashornAstNode rslt = null;/* w  ww .  j av a 2 s  . c o m*/
    if (pn instanceof LiteralNode.ArrayLiteralNode) {
        rslt = new NashornAstArrayConstructor(pn, par);
    } else if (pn instanceof BinaryNode) {
        BinaryNode bin = (BinaryNode) pn;
        switch (bin.tokenType()) {
        case COMMALEFT:
        case COMMARIGHT:
            rslt = new NashornAstCommaOperation(pn, par);
            break;
        case AND:
        case OR:
            rslt = new NashornAstControlOperation(pn, par);
            break;
        case DELETE:
            rslt = new NashornAstDeleteOperation(pn, par);
            break;
        case IN:
            rslt = new NashornAstInOperation(pn, par);
            break;
        default:
            break;
        }
        if (rslt == null && bin.isAssignment()) {
            rslt = new NashornAstAssignOperation(pn, par);
        } else if (rslt == null) {
            rslt = new NashornAstSimpleOperation(pn, par);
        }
    } else if (pn instanceof UnaryNode) {
        UnaryNode uny = (UnaryNode) pn;
        switch (uny.tokenType()) {
        case TYPEOF:
            rslt = new NashornAstTypeofOperation(pn, par);
            break;
        case VOID:
            rslt = new NashornAstVoidOperation(pn, par);
            break;
        default:
            break;
        }
        if (rslt == null) {
            rslt = new NashornAstSimpleOperation(pn, par);
        }
    } else if (pn instanceof TernaryNode) {
        rslt = new NashornAstSimpleOperation(pn, par);
    } else if (pn instanceof AccessNode) {
        return new NashornAstMemberAccess(pn, par);
    } else if (pn instanceof Block) {
        if (par instanceof NashornAstSwitchStatement) {
            NashornAstNode npar = new NashornAstFinallyStatement(pn, par);
            rslt = new NashornAstBlock(pn, npar);
        } else
            rslt = new NashornAstBlock(pn, par);
    } else if (pn instanceof BlockStatement) {
        BlockStatement bs = (BlockStatement) pn;
        rslt = new NashornAstBlock(bs.getBlock(), par);
    } else if (pn instanceof BreakNode) {
        rslt = new NashornAstBreakStatement(pn, par);
    } else if (pn instanceof CallNode) {
        CallNode cn = (CallNode) pn;
        if (cn.isNew())
            rslt = new NashornAstConstructorCall(pn, par);
        else
            rslt = new NashornAstFunctionCall(pn, par);
    } else if (pn instanceof CaseNode) {
        CaseNode cn = (CaseNode) pn;
        if (cn.getTest() == null)
            rslt = new NashornAstDefaultCaseStatement(pn, par);
        else
            rslt = new NashornAstCaseStatement(pn, par);
    } else if (pn instanceof CatchNode) {
        rslt = new NashornAstCatchStatement(pn, par);
    } else if (pn instanceof ContinueNode) {
        rslt = new NashornAstContinueStatement(pn, par);
    } else if (pn instanceof EmptyNode) {
        rslt = new NashornAstNoopStatement(pn, par);
    } else if (pn instanceof ExpressionStatement) {
        rslt = new NashornAstExpressionStatement(pn, par);
    } else if (pn instanceof ForNode) {
        ForNode fn = (ForNode) pn;
        if (fn.isForEach() || fn.isForIn()) {
            rslt = new NashornAstForEachLoop(pn, par);
        } else
            rslt = new NashornAstForLoop(pn, par);
    } else if (pn instanceof FunctionNode) {
        rslt = new NashornAstFunctionConstructor(pn, par);
    } else if (pn instanceof IdentNode) {
        rslt = new NashornAstIdentifier(pn, par);
    } else if (pn instanceof IndexNode) {
        rslt = new NashornAstArrayIndex(pn, par);
    } else if (pn instanceof IfNode) {
        rslt = new NashornAstIfStatement(pn, par);
    } else if (pn instanceof LabelNode) {
        rslt = new NashornAstLabeledStatement(pn, par);
    } else if (pn instanceof LiteralNode) {
        LiteralNode<?> ln = (LiteralNode<?>) pn;
        if (ln.isNull()) {
            rslt = new NashornAstNullLiteral(pn, par);
        } else if (ln.isString()) {
            rslt = new NashornAstStringLiteral(pn, par);
        } else if (ln.getValue() instanceof Boolean) {
            rslt = new NashornAstBooleanLiteral(pn, par);
        } else if (ln.getValue() instanceof Long || ln.getValue() instanceof Integer) {
            rslt = new NashornAstIntegerLiteral(pn, par);
        } else if (ln.isNumeric()) {
            rslt = new NashornAstRealLiteral(pn, par);
        } else if (ln.getValue() instanceof Lexer.RegexToken) {
            rslt = new NashornAstRegexpLiteral(pn, par);
        }
        // handle regex
    } else if (pn instanceof ObjectNode) {
        rslt = new NashornAstObjectConstructor(pn, par);
    } else if (pn instanceof PropertyNode) {
        PropertyNode prop = (PropertyNode) pn;
        // getter/etter might not be correct
        if (prop.getGetter() != null) {
            rslt = new NashornAstGetterProperty(pn, par);
        } else if (prop.getSetter() != null) {
            rslt = new NashornAstSetterProperty(pn, par);
        } else
            rslt = new NashornAstValueProperty(pn, par);
    } else if (pn instanceof ReturnNode) {
        rslt = new NashornAstReturnStatement(pn, par);
    } else if (pn instanceof SwitchNode) {
        rslt = new NashornAstSwitchStatement(pn, par);
    } else if (pn instanceof ThrowNode) {
        rslt = new NashornAstThrowStatement(pn, par);
    } else if (pn instanceof TryNode) {
        rslt = new NashornAstTryStatement(pn, par);
    } else if (pn instanceof VarNode) {
        rslt = new NashornAstDeclaration(pn, par);
    } else if (pn instanceof WhileNode) {
        WhileNode wn = (WhileNode) pn;
        if (wn.isDoWhile())
            rslt = new NashornAstDoWhileLoop(pn, par);
        else
            rslt = new NashornAstWhileLoop(pn, par);
    } else if (pn instanceof WithNode) {
        rslt = new NashornAstWithStatement(pn, par);
    }

    if (rslt == null) {
        System.err.println("UNKNOWN AST: " + pn);
    }

    return rslt;
}