当前位置: 首页>>代码示例>>Java>>正文


Java Node.accept方法代码示例

本文整理汇总了Java中jdk.nashorn.internal.ir.Node.accept方法的典型用法代码示例。如果您正苦于以下问题:Java Node.accept方法的具体用法?Java Node.accept怎么用?Java Node.accept使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jdk.nashorn.internal.ir.Node的用法示例。


在下文中一共展示了Node.accept方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: extractVarNodesFromDeadCode

import jdk.nashorn.internal.ir.Node; //导入方法依赖的package包/类
/**
 * When we eliminate dead code, we must preserve var declarations as they are scoped to the whole
 * function. This method gathers var nodes from code passed to it, removing their initializers.
 *
 * @param deadCodeRoot the root node of eliminated dead code
 * @param statements a list that will be receiving the var nodes from the dead code, with their
 * initializers removed.
 */
static void extractVarNodesFromDeadCode(final Node deadCodeRoot, final List<Statement> statements) {
    deadCodeRoot.accept(new SimpleNodeVisitor() {
        @Override
        public boolean enterVarNode(final VarNode varNode) {
            statements.add(varNode.setInit(null));
            return false;
        }

        @Override
        public boolean enterFunctionNode(final FunctionNode functionNode) {
            // Don't descend into nested functions
            return false;
        }
    });
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:FoldConstants.java

示例2: enterIfNode

import jdk.nashorn.internal.ir.Node; //导入方法依赖的package包/类
@Override
public boolean enterIfNode(final IfNode ifNode) {
    enterDefault(ifNode);

    type("IfStatement");
    comma();

    property("test");
    ifNode.getTest().accept(this);
    comma();

    property("consequent");
    ifNode.getPass().accept(this);
    final Node elsePart = ifNode.getFail();
    comma();

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

    return leave();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:26,代码来源:JSONWriter.java

示例3: enterReturnNode

import jdk.nashorn.internal.ir.Node; //导入方法依赖的package包/类
@Override
public boolean enterReturnNode(final ReturnNode returnNode) {
    enterDefault(returnNode);

    type("ReturnStatement");
    comma();

    final Node arg = returnNode.getExpression();
    property("argument");
    if (arg != null) {
        arg.accept(this);
    } else {
        nullValue();
    }

    return leave();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:JSONWriter.java

示例4: array

import jdk.nashorn.internal.ir.Node; //导入方法依赖的package包/类
private void array(final String name, final List<? extends Node> nodes) {
    // The size, idx comparison is just to avoid trailing comma..
    final int size = nodes.size();
    int idx = 0;
    arrayStart(name);
    for (final Node node : nodes) {
        if (node != null) {
            node.accept(this);
        } else {
            nullValue();
        }
        if (idx != (size - 1)) {
            comma();
        }
        idx++;
    }
    arrayEnd();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:JSONWriter.java

示例5: enterCatchNode

import jdk.nashorn.internal.ir.Node; //导入方法依赖的package包/类
@Override
public boolean enterCatchNode(final CatchNode catchNode) {
    enterDefault(catchNode);

    type("CatchClause");
    comma();

    property("param");
    catchNode.getException().accept(this);
    comma();

    final Node guard = catchNode.getExceptionCondition();
    if (guard != null) {
        property("guard");
        guard.accept(this);
        comma();
    }

    property("body");
    catchNode.getBody().accept(this);

    return leave();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:JSONWriter.java

示例6: emitProgram

import jdk.nashorn.internal.ir.Node; //导入方法依赖的package包/类
private boolean emitProgram(final FunctionNode functionNode) {
    enterDefault(functionNode);
    type("Program");
    comma();

    // body consists of nested functions and statements
    final List<Statement> stats = functionNode.getBody().getStatements();
    final int size = stats.size();
    int idx = 0;
    arrayStart("body");

    for (final Node stat : stats) {
        stat.accept(this);
        if (idx != (size - 1)) {
            comma();
        }
        idx++;
    }
    arrayEnd();

    return leave();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:JSONWriter.java

示例7: enterVarNode

import jdk.nashorn.internal.ir.Node; //导入方法依赖的package包/类
@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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:PrintVisitor.java

示例8: enterLiteralNode

import jdk.nashorn.internal.ir.Node; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
public boolean enterLiteralNode(final LiteralNode literalNode) {
    weight += LITERAL_WEIGHT;

    if (literalNode instanceof ArrayLiteralNode) {
        final ArrayLiteralNode arrayLiteralNode = (ArrayLiteralNode)literalNode;
        final Node[]           value            = arrayLiteralNode.getValue();
        final int[]            postsets         = arrayLiteralNode.getPostsets();
        final List<Splittable.SplitRange>  units            = arrayLiteralNode.getSplitRanges();

        if (units == null) {
            for (final int postset : postsets) {
                weight += AASTORE_WEIGHT;
                final Node element = value[postset];

                if (element != null) {
                    element.accept(this);
                }
            }
        }

        return false;
    }

    return true;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:WeighNodes.java

示例9: enterVarNode

import jdk.nashorn.internal.ir.Node; //导入方法依赖的package包/类
@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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:14,代码来源:PrintVisitor.java

示例10: ensureUniqueNamesIn

import jdk.nashorn.internal.ir.Node; //导入方法依赖的package包/类
private static Node ensureUniqueNamesIn(final Node node) {
    return node.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
        @Override
        public Node leaveFunctionNode(final FunctionNode functionNode) {
            final String name = functionNode.getName();
            return functionNode.setName(lc, lc.getCurrentFunction().uniqueName(name));
        }

        @Override
        public Node leaveDefault(final Node labelledNode) {
            return labelledNode.ensureUniqueLabels(lc);
        }
    });
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:15,代码来源:Lower.java

示例11: enterLiteralNode

import jdk.nashorn.internal.ir.Node; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
public boolean enterLiteralNode(final LiteralNode literalNode) {
    weight += LITERAL_WEIGHT;

    if (literalNode instanceof ArrayLiteralNode) {
        final ArrayLiteralNode arrayLiteralNode = (ArrayLiteralNode)literalNode;
        final Node[]           value            = arrayLiteralNode.getValue();
        final int[]            postsets         = arrayLiteralNode.getPostsets();
        final List<ArrayUnit>  units            = arrayLiteralNode.getUnits();

        if (units == null) {
            for (final int postset : postsets) {
                weight += AASTORE_WEIGHT;
                final Node element = value[postset];

                if (element != null) {
                    element.accept(this);
                }
            }
        }

        return false;
    }

    return true;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:28,代码来源:WeighNodes.java

示例12: weigh

import jdk.nashorn.internal.ir.Node; //导入方法依赖的package包/类
static long weigh(final Node node, final Map<Node, Long> weightCache) {
    final WeighNodes weighNodes = new WeighNodes(node instanceof FunctionNode ? (FunctionNode)node : null, weightCache);
    node.accept(weighNodes);
    return weighNodes.weight;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:WeighNodes.java

示例13: enterPropertyNode

import jdk.nashorn.internal.ir.Node; //导入方法依赖的package包/类
@Override
public boolean enterPropertyNode(final PropertyNode propertyNode) {
    final Node key = propertyNode.getKey();

    final Node value = propertyNode.getValue();
    if (value != null) {
        objectStart();
        location(propertyNode);

        property("key");
        key.accept(this);
        comma();

        property("value");
        value.accept(this);
        comma();

        property("kind", "init");

        objectEnd();
    } else {
        // getter
        final Node getter = propertyNode.getGetter();
        if (getter != null) {
            objectStart();
            location(propertyNode);

            property("key");
            key.accept(this);
            comma();

            property("value");
            getter.accept(this);
            comma();

            property("kind", "get");

            objectEnd();
        }

        // setter
        final Node setter = propertyNode.getSetter();
        if (setter != null) {
            if (getter != null) {
                comma();
            }
            objectStart();
            location(propertyNode);

            property("key");
            key.accept(this);
            comma();

            property("value");
            setter.accept(this);
            comma();

            property("kind", "set");

            objectEnd();
        }
    }

    return false;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:66,代码来源:JSONWriter.java

示例14: enterVarNode

import jdk.nashorn.internal.ir.Node; //导入方法依赖的package包/类
@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();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:44,代码来源:JSONWriter.java

示例15: visit

import jdk.nashorn.internal.ir.Node; //导入方法依赖的package包/类
private void visit(final Node root) {
    root.accept(this);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:4,代码来源:PrintVisitor.java


注:本文中的jdk.nashorn.internal.ir.Node.accept方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。