Java Code Examples for jdk.nashorn.internal.ir.VarNode#getInit()

The following examples show how to use jdk.nashorn.internal.ir.VarNode#getInit() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IRTranslator.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterVarNode(final VarNode varNode) {
    final Expression initNode = varNode.getInit();
    if (initNode instanceof FunctionNode && ((FunctionNode)initNode).isDeclared()) {
        final FunctionNode funcNode = (FunctionNode) initNode;

        final List<? extends ExpressionTree> paramTrees = translateParameters(funcNode);
        final BlockTree blockTree = (BlockTree) translateBlock(funcNode.getBody(), true);
        curStat = new FunctionDeclarationTreeImpl(varNode, paramTrees, blockTree);
    } else if (initNode instanceof ClassNode && ((ClassNode)initNode).isStatement()) {
        final ClassNode classNode = (ClassNode) initNode;

        curStat = new ClassDeclarationTreeImpl(varNode,
                translateIdent(classNode.getIdent()),
                translateExpr(classNode.getClassHeritage()),
                translateProperty(classNode.getConstructor()),
                translateProperties(classNode.getClassElements()));
    } else {
        curStat = new VariableTreeImpl(varNode, translateIdent(varNode.getName()), translateExpr(initNode));
    }

    return false;
}
 
Example 2
Source File: LocalVariableTypesCalculator.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterVarNode(final VarNode varNode) {
    if (!reachable) {
        return false;
    }
    final Expression init = varNode.getInit();
    if(init != null) {
        onAssignment(varNode.getName(), visitExpression(init));
    }
    return false;
}
 
Example 3
Source File: PrintVisitor.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterVarNode(final VarNode varNode) {
    sb.append("var ");
    varNode.getName().toString(sb, printTypes);
    printLocalVariableConversion(varNode.getName());
    final Node init = varNode.getInit();
    if (init != null) {
        sb.append(" = ");
        init.accept(this);
    }

    return false;
}
 
Example 4
Source File: LocalVariableTypesCalculator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterVarNode(final VarNode varNode) {
    if (!reachable) {
        return false;
    }
    final Expression init = varNode.getInit();
    if(init != null) {
        onAssignment(varNode.getName(), visitExpression(init));
    }
    return false;
}
 
Example 5
Source File: PrintVisitor.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterVarNode(final VarNode varNode) {
    sb.append(varNode.isConst() ? "const " : varNode.isLet() ? "let " : "var ");
    varNode.getName().toString(sb, printTypes);
    printLocalVariableConversion(varNode.getName());
    final Node init = varNode.getInit();
    if (init != null) {
        sb.append(" = ");
        init.accept(this);
    }

    return false;
}
 
Example 6
Source File: LocalVariableTypesCalculator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterVarNode(final VarNode varNode) {
    if (!reachable) {
        return false;
    }
    final Expression init = varNode.getInit();
    if(init != null) {
        onAssignment(varNode.getName(), visitExpression(init));
    }
    return false;
}
 
Example 7
Source File: PrintVisitor.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterVarNode(final VarNode varNode) {
    sb.append(varNode.isConst() ? "const " : varNode.isLet() ? "let " : "var ");
    varNode.getName().toString(sb, printTypes);
    printLocalVariableConversion(varNode.getName());
    final Node init = varNode.getInit();
    if (init != null) {
        sb.append(" = ");
        init.accept(this);
    }

    return false;
}
 
Example 8
Source File: LocalVariableTypesCalculator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterVarNode(final VarNode varNode) {
    if (!reachable) {
        return false;
    }
    final Expression init = varNode.getInit();
    if(init != null) {
        onAssignment(varNode.getName(), visitExpression(init));
    }
    return false;
}
 
Example 9
Source File: PrintVisitor.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterVarNode(final VarNode varNode) {
    sb.append("var ");
    varNode.getName().toString(sb);
    final Node init = varNode.getInit();
    if (init != null) {
        sb.append(" = ");
        init.accept(this);
    }

    return false;
}
 
Example 10
Source File: LocalVariableTypesCalculator.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterVarNode(final VarNode varNode) {
    if (!reachable) {
        return false;
    }
    final Expression init = varNode.getInit();
    if(init != null) {
        onAssignment(varNode.getName(), visitExpression(init));
    }
    return false;
}
 
Example 11
Source File: PrintVisitor.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterVarNode(final VarNode varNode) {
    sb.append("var ");
    varNode.getName().toString(sb, printTypes);
    printLocalVariableConversion(varNode.getName());
    final Node init = varNode.getInit();
    if (init != null) {
        sb.append(" = ");
        init.accept(this);
    }

    return false;
}
 
Example 12
Source File: PrintVisitor.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterVarNode(final VarNode varNode) {
    sb.append("var ");
    varNode.getName().toString(sb);
    final Node init = varNode.getInit();
    if (init != null) {
        sb.append(" = ");
        init.accept(this);
    }

    return false;
}
 
Example 13
Source File: JSONWriter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean enterVarNode(final VarNode varNode) {
    final Node init = varNode.getInit();
    if (init instanceof FunctionNode && ((FunctionNode)init).isDeclared()) {
        // function declaration - don't emit VariableDeclaration instead
        // just emit FunctionDeclaration using 'init' Node.
        init.accept(this);
        return false;
    }

    enterDefault(varNode);

    type("VariableDeclaration");
    comma();

    arrayStart("declarations");

    // VariableDeclarator
    objectStart();
    location(varNode.getName());

    type("VariableDeclarator");
    comma();

    property("id");
    varNode.getName().accept(this);
    comma();

    property("init");
    if (init != null) {
        init.accept(this);
    } else {
        nullValue();
    }

    // VariableDeclarator
    objectEnd();

    // declarations
    arrayEnd();

    return leave();
}
 
Example 14
Source File: JSONWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean enterVarNode(final VarNode varNode) {
    final Node init = varNode.getInit();
    if (init instanceof FunctionNode && ((FunctionNode)init).isDeclared()) {
        // function declaration - don't emit VariableDeclaration instead
        // just emit FunctionDeclaration using 'init' Node.
        init.accept(this);
        return false;
    }

    enterDefault(varNode);

    type("VariableDeclaration");
    comma();

    arrayStart("declarations");

    // VariableDeclarator
    objectStart();
    location(varNode.getName());

    type("VariableDeclarator");
    comma();

    property("id");
    varNode.getName().accept(this);
    comma();

    property("init");
    if (init != null) {
        init.accept(this);
    } else {
        nullValue();
    }

    // VariableDeclarator
    objectEnd();

    // declarations
    arrayEnd();

    return leave();
}
 
Example 15
Source File: JSONWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean enterVarNode(final VarNode varNode) {
    final Node init = varNode.getInit();
    if (init instanceof FunctionNode && ((FunctionNode)init).isDeclared()) {
        // function declaration - don't emit VariableDeclaration instead
        // just emit FunctionDeclaration using 'init' Node.
        init.accept(this);
        return false;
    }

    enterDefault(varNode);

    type("VariableDeclaration");
    comma();

    arrayStart("declarations");

    // VariableDeclarator
    objectStart();
    location(varNode.getName());

    type("VariableDeclarator");
    comma();

    property("id");
    varNode.getName().accept(this);
    comma();

    property("init");
    if (init != null) {
        init.accept(this);
    } else {
        nullValue();
    }

    // VariableDeclarator
    objectEnd();

    // declarations
    arrayEnd();

    return leave();
}
 
Example 16
Source File: JSONWriter.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean enterVarNode(final VarNode varNode) {
    final Node init = varNode.getInit();
    if (init instanceof FunctionNode && ((FunctionNode)init).isDeclared()) {
        // function declaration - don't emit VariableDeclaration instead
        // just emit FunctionDeclaration using 'init' Node.
        init.accept(this);
        return false;
    }

    enterDefault(varNode);

    type("VariableDeclaration");
    comma();

    arrayStart("declarations");

    // VariableDeclarator
    objectStart();
    location(varNode.getName());

    type("VariableDeclarator");
    comma();

    property("id");
    varNode.getName().accept(this);
    comma();

    property("init");
    if (init != null) {
        init.accept(this);
    } else {
        nullValue();
    }

    // VariableDeclarator
    objectEnd();

    // declarations
    arrayEnd();

    return leave();
}
 
Example 17
Source File: JSONWriter.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean enterVarNode(final VarNode varNode) {
    final Node init = varNode.getInit();
    if (init instanceof FunctionNode && ((FunctionNode)init).isDeclared()) {
        // function declaration - don't emit VariableDeclaration instead
        // just emit FunctionDeclaration using 'init' Node.
        init.accept(this);
        return false;
    }

    enterDefault(varNode);

    type("VariableDeclaration");
    comma();

    arrayStart("declarations");

    // VariableDeclarator
    objectStart();
    location(varNode.getName());

    type("VariableDeclarator");
    comma();

    property("id");
    varNode.getName().accept(this);
    comma();

    property("init");
    if (init != null) {
        init.accept(this);
    } else {
        nullValue();
    }

    // VariableDeclarator
    objectEnd();

    // declarations
    arrayEnd();

    return leave();
}
 
Example 18
Source File: JSONWriter.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean enterVarNode(final VarNode varNode) {
    final Node init = varNode.getInit();
    if (init instanceof FunctionNode && ((FunctionNode)init).isDeclared()) {
        // function declaration - don't emit VariableDeclaration instead
        // just emit FunctionDeclaration using 'init' Node.
        init.accept(this);
        return false;
    }

    enterDefault(varNode);

    type("VariableDeclaration");
    comma();

    arrayStart("declarations");

    // VariableDeclarator
    objectStart();
    location(varNode.getName());

    type("VariableDeclarator");
    comma();

    property("id");
    varNode.getName().accept(this);
    comma();

    property("init");
    if (init != null) {
        init.accept(this);
    } else {
        nullValue();
    }

    // VariableDeclarator
    objectEnd();

    // declarations
    arrayEnd();

    return leave();
}
 
Example 19
Source File: JSONWriter.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean enterVarNode(final VarNode varNode) {
    final Node init = varNode.getInit();
    if (init instanceof FunctionNode && ((FunctionNode)init).isDeclared()) {
        // function declaration - don't emit VariableDeclaration instead
        // just emit FunctionDeclaration using 'init' Node.
        init.accept(this);
        return false;
    }

    enterDefault(varNode);

    type("VariableDeclaration");
    comma();

    arrayStart("declarations");

    // VariableDeclarator
    objectStart();
    location(varNode.getName());

    type("VariableDeclarator");
    comma();

    property("id");
    varNode.getName().accept(this);
    comma();

    property("init");
    if (init != null) {
        init.accept(this);
    } else {
        nullValue();
    }

    // VariableDeclarator
    objectEnd();

    // declarations
    arrayEnd();

    return leave();
}
 
Example 20
Source File: JSONWriter.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean enterVarNode(final VarNode varNode) {
    final Node init = varNode.getInit();
    if (init instanceof FunctionNode && ((FunctionNode)init).isDeclared()) {
        // function declaration - don't emit VariableDeclaration instead
        // just emit FunctionDeclaration using 'init' Node.
        init.accept(this);
        return false;
    }

    enterDefault(varNode);

    type("VariableDeclaration");
    comma();

    arrayStart("declarations");

    // VariableDeclarator
    objectStart();
    location(varNode.getName());

    type("VariableDeclarator");
    comma();

    property("id");
    varNode.getName().accept(this);
    comma();

    property("init");
    if (init != null) {
        init.accept(this);
    } else {
        nullValue();
    }

    // VariableDeclarator
    objectEnd();

    // declarations
    arrayEnd();

    return leave();
}