Package org.mozilla.javascript.ast

Examples of org.mozilla.javascript.ast.FunctionNode


                }
            } else if (this instanceof Scope) {
                if (this instanceof ScriptNode) {
                    ScriptNode sof = (ScriptNode)this;
                    if (this instanceof FunctionNode) {
                        FunctionNode fn = (FunctionNode)this;
                        sb.append(' ');
                        sb.append(fn.getName());
                    }
                    sb.append(" [source name: ");
                    sb.append(sof.getSourceName());
                    sb.append("] [encoded source length: ");
                    sb.append(sof.getEncodedSourceEnd()
View Full Code Here


            for (Node cursor = n.getFirstChild(); cursor != null;
                 cursor = cursor.getNext())
            {
                if (cursor.getType() == Token.FUNCTION) {
                    int fnIndex = cursor.getExistingIntProp(Node.FUNCTION_PROP);
                    FunctionNode fn = treeTop.getFunctionNode(fnIndex);
                    toStringTreeHelper(fn, fn, null, level + 1, sb);
                } else {
                    toStringTreeHelper(treeTop, cursor, printIds, level+1, sb);
                }
            }
View Full Code Here

    public final void transform(ScriptNode tree)
    {
        transformCompilationUnit(tree);
        for (int i = 0; i != tree.getFunctionCount(); ++i) {
            FunctionNode fn = tree.getFunctionNode(i);
            transform(fn);
        }
    }
View Full Code Here

    }

    private static void initOptFunctions_r(ScriptNode scriptOrFn)
    {
        for (int i = 0, N = scriptOrFn.getFunctionCount(); i != N; ++i) {
            FunctionNode fn = scriptOrFn.getFunctionNode(i);
            new OptFunctionNode(fn);
            initOptFunctions_r(fn);
        }
    }
View Full Code Here

            return new Object[] { scriptClassName, scriptClassBytes };
        }
        int functionCount = tree.getFunctionCount();
        ObjToIntMap functionNames = new ObjToIntMap(functionCount);
        for (int i = 0; i != functionCount; ++i) {
            FunctionNode ofn = tree.getFunctionNode(i);
            String name = ofn.getName();
            if (name != null && name.length() != 0) {
                functionNames.put(name, ofn.getParamCount());
            }
        }
        if (superClass == null) {
            superClass = ScriptRuntime.ObjectClass;
        }
View Full Code Here

        assertThat(statement.toSource(), equalTo("_$jscoverage['test.js'].branchData['4'][2].ranCondition(result);\n"));
    }

    @Test
    public void shouldBuildLineAndConditionRecordingFunction() {
        FunctionNode statement = builder.buildBranchRecordingFunction("test.js", 1, 4, 2);
        assertThat(statement.toSource(), equalTo("function visit1_4_2(result) {\n" +
                "  _$jscoverage['test.js'].branchData['4'][2].ranCondition(result);\n" +
                "  return result;\n" +
                "}"));
    }
View Full Code Here

    return c;
  }

  @Override
  public AstNode function(String name, Iterable<AstNode> params, AstNode body) {
    FunctionNode func = new FunctionNode();
    if (name != null) {
      func.setFunctionName((Name) name(name));
    }
    func.setParams(list(params));
    if (body == null) {
      func.setBody(new Block());
    } else if (body instanceof Block) {
      func.setBody(body);
    } else {
      func.setBody(addStatement(null, body));
    }
    return func;
  }
View Full Code Here

         */
        protected void assertNumberVars(CharSequence source, String... numbers) {
            // wrap source in function
            ScriptNode tree = compile("function f(o, fn){" + source + "}");

            FunctionNode fnode = tree.getFunctionNode(0);
            assertNotNull(fnode);
            OptFunctionNode opt = OptFunctionNode.get(fnode);
            assertNotNull(opt);
            assertSame(fnode, opt.fnode);

            for (int i = 0, c = fnode.getParamCount(); i < c; ++i) {
                assertTrue(opt.isParameter(i));
                assertFalse(opt.isNumberVar(i));
            }

            Set<String> set = new HashSet<String>(asList(numbers));
            for (int i = fnode.getParamCount(), c = fnode.getParamAndVarCount(); i < c; ++i) {
                assertFalse(opt.isParameter(i));
                String name = fnode.getParamOrVarName(i);
                String msg = format("{%s -> number? = %b}", name, opt.isNumberVar(i));
                assertEquals(msg, set.contains(name), opt.isNumberVar(i));
            }
        }
View Full Code Here

                }
            } else if (this instanceof Scope) {
                if (this instanceof ScriptNode) {
                    ScriptNode sof = (ScriptNode)this;
                    if (this instanceof FunctionNode) {
                        FunctionNode fn = (FunctionNode)this;
                        sb.append(' ');
                        sb.append(fn.getName());
                    }
                    sb.append(" [source name: ");
                    sb.append(sof.getSourceName());
                    sb.append("] [encoded source length: ");
                    sb.append(sof.getEncodedSourceEnd()
View Full Code Here

            for (Node cursor = n.getFirstChild(); cursor != null;
                 cursor = cursor.getNext())
            {
                if (cursor.getType() == Token.FUNCTION) {
                    int fnIndex = cursor.getExistingIntProp(Node.FUNCTION_PROP);
                    FunctionNode fn = treeTop.getFunctionNode(fnIndex);
                    toStringTreeHelper(fn, fn, null, level + 1, sb);
                } else {
                    toStringTreeHelper(treeTop, cursor, printIds, level+1, sb);
                }
            }
View Full Code Here

TOP

Related Classes of org.mozilla.javascript.ast.FunctionNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.