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


Java ScriptNode.getFunctionNode方法代码示例

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


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

示例1: assertNumberVars

import org.mozilla.javascript.ast.ScriptNode; //导入方法依赖的package包/类
/**
 * Checks every variable {@code v} in {@code source} is marked as a
 * number-variable iff {@code numbers} contains {@code v}
 */
protected void assertNumberVars(CharSequence source, String... numbers) {
    // wrap source in function
    ScriptNode tree = compile("function f(){" + 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));
    }
}
 
开发者ID:F43nd1r,项目名称:rhino-android,代码行数:28,代码来源:Bug782363Test.java

示例2: assertNumberVars

import org.mozilla.javascript.ast.ScriptNode; //导入方法依赖的package包/类
/**
 * Checks every variable {@code v} in {@code source} is marked as a
 * number-variable iff {@code numbers} contains {@code v}
 */
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));
    }
}
 
开发者ID:F43nd1r,项目名称:rhino-android,代码行数:28,代码来源:Bug708801Test.java

示例3: toStringTreeHelper

import org.mozilla.javascript.ast.ScriptNode; //导入方法依赖的package包/类
private static void toStringTreeHelper(ScriptNode treeTop, Node n,
                                       ObjToIntMap printIds,
                                       int level, StringBuilder sb)
{
    if (Token.printTrees) {
        if (printIds == null) {
            printIds = new ObjToIntMap();
            generatePrintIds(treeTop, printIds);
        }
        for (int i = 0; i != level; ++i) {
            sb.append("    ");
        }
        n.toString(printIds, sb);
        sb.append('\n');
        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);
            }
        }
    }
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:28,代码来源:Node.java

示例4: transform

import org.mozilla.javascript.ast.ScriptNode; //导入方法依赖的package包/类
public final void transform(ScriptNode tree, boolean inStrictMode, CompilerEnvirons env)
{
    boolean useStrictMode = inStrictMode;
    // Support strict mode inside a function only for "ES6" language level
    // and above. Otherwise, we will end up breaking backward compatibility for
    // many existing scripts.
    if ((env.getLanguageVersion() >= Context.VERSION_ES6) && tree.isInStrictMode()) {
      useStrictMode = true;
    }
    transformCompilationUnit(tree, useStrictMode);
    for (int i = 0; i != tree.getFunctionCount(); ++i) {
        FunctionNode fn = tree.getFunctionNode(i);
        transform(fn, useStrictMode, env);
    }
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:16,代码来源:NodeTransformer.java

示例5: compileToClassFile

import org.mozilla.javascript.ast.ScriptNode; //导入方法依赖的package包/类
public byte[] compileToClassFile(CompilerEnvirons compilerEnv,
                                 String mainClassName,
                                 ScriptNode scriptOrFn,
                                 String encodedSource,
                                 boolean returnFunction)
{
    this.compilerEnv = compilerEnv;

    transform(scriptOrFn);

    if (Token.printTrees) {
        System.out.println(scriptOrFn.toStringTree(scriptOrFn));
    }

    if (returnFunction) {
        scriptOrFn = scriptOrFn.getFunctionNode(0);
    }

    initScriptNodesData(scriptOrFn);

    this.mainClassName = mainClassName;
    this.mainClassSignature
        = ClassFileWriter.classNameToSignature(mainClassName);

    try {
        return generateCode(encodedSource);
    } catch (ClassFileWriter.ClassFileFormatException e) {
        throw reportClassFileFormatException(scriptOrFn, e.getMessage());
    }
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:31,代码来源:Codegen.java

示例6: initOptFunctions_r

import org.mozilla.javascript.ast.ScriptNode; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:9,代码来源:Codegen.java

示例7: compile

import org.mozilla.javascript.ast.ScriptNode; //导入方法依赖的package包/类
public InterpreterData compile(CompilerEnvirons compilerEnv,
                               ScriptNode tree,
                               String encodedSource,
                               boolean returnFunction)
{
    this.compilerEnv = compilerEnv;

    if (Token.printTrees) {
        System.out.println("before transform:");
        System.out.println(tree.toStringTree(tree));
    }

    new NodeTransformer().transform(tree, compilerEnv);

    if (Token.printTrees) {
        System.out.println("after transform:");
        System.out.println(tree.toStringTree(tree));
    }

    if (returnFunction) {
        scriptOrFn = tree.getFunctionNode(0);
    } else {
        scriptOrFn = tree;
    }

    itsData = new InterpreterData(compilerEnv.getLanguageVersion(),
                                  scriptOrFn.getSourceName(),
                                  encodedSource,
                                  scriptOrFn.isInStrictMode());
    itsData.topLevel = true;

    if (returnFunction) {
        generateFunctionICode();
    } else {
        generateICodeFromTree(scriptOrFn);
    }
    return itsData;
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:39,代码来源:CodeGenerator.java

示例8: toStringTreeHelper

import org.mozilla.javascript.ast.ScriptNode; //导入方法依赖的package包/类
private static void toStringTreeHelper(ScriptNode treeTop, Node n,
                                       ObjToIntMap printIds,
                                       int level, StringBuffer sb)
{
    if (Token.printTrees) {
        if (printIds == null) {
            printIds = new ObjToIntMap();
            generatePrintIds(treeTop, printIds);
        }
        for (int i = 0; i != level; ++i) {
            sb.append("    ");
        }
        n.toString(printIds, sb);
        sb.append('\n');
        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);
            }
        }
    }
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:28,代码来源:Node.java

示例9: transform

import org.mozilla.javascript.ast.ScriptNode; //导入方法依赖的package包/类
public final void transform(ScriptNode tree)
{
    transformCompilationUnit(tree);
    for (int i = 0; i != tree.getFunctionCount(); ++i) {
        FunctionNode fn = tree.getFunctionNode(i);
        transform(fn);
    }
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:9,代码来源:NodeTransformer.java

示例10: compileToClassFile

import org.mozilla.javascript.ast.ScriptNode; //导入方法依赖的package包/类
byte[] compileToClassFile(CompilerEnvirons compilerEnv,
                          String mainClassName,
                          ScriptNode scriptOrFn,
                          String encodedSource,
                          boolean returnFunction)
{
    this.compilerEnv = compilerEnv;

    transform(scriptOrFn);

    if (Token.printTrees) {
        System.out.println(scriptOrFn.toStringTree(scriptOrFn));
    }

    if (returnFunction) {
        scriptOrFn = scriptOrFn.getFunctionNode(0);
    }

    initScriptNodesData(scriptOrFn);

    this.mainClassName = mainClassName;
    this.mainClassSignature
        = ClassFileWriter.classNameToSignature(mainClassName);

    try {
        return generateCode(encodedSource);
    } catch (ClassFileWriter.ClassFileFormatException e) {
        throw reportClassFileFormatException(scriptOrFn, e.getMessage());
    }
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:31,代码来源:Codegen.java

示例11: compile

import org.mozilla.javascript.ast.ScriptNode; //导入方法依赖的package包/类
public InterpreterData compile(CompilerEnvirons compilerEnv,
                               ScriptNode tree,
                               String encodedSource,
                               boolean returnFunction)
{
    this.compilerEnv = compilerEnv;

    if (Token.printTrees) {
        System.out.println("before transform:");
        System.out.println(tree.toStringTree(tree));
    }

    new NodeTransformer().transform(tree);

    if (Token.printTrees) {
        System.out.println("after transform:");
        System.out.println(tree.toStringTree(tree));
    }

    if (returnFunction) {
        scriptOrFn = tree.getFunctionNode(0);
    } else {
        scriptOrFn = tree;
    }
    itsData = new InterpreterData(compilerEnv.getLanguageVersion(),
                                  scriptOrFn.getSourceName(),
                                  encodedSource,
                                  ((AstRoot)tree).isInStrictMode());
    itsData.topLevel = true;

    if (returnFunction) {
        generateFunctionICode();
    } else {
        generateICodeFromTree(scriptOrFn);
    }
    return itsData;
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:38,代码来源:CodeGenerator.java

示例12: compileToClassFiles

import org.mozilla.javascript.ast.ScriptNode; //导入方法依赖的package包/类
/**
 * Compile JavaScript source into one or more Java class files.
 * The first compiled class will have name mainClassName.
 * If the results of {@link #getTargetExtends()} or
 * {@link #getTargetImplements()} are not null, then the first compiled
 * class will extend the specified super class and implement
 * specified interfaces.
 *
 * @return array where elements with even indexes specifies class name
 *         and the following odd index gives class file body as byte[]
 *         array. The initial element of the array always holds
 *         mainClassName and array[1] holds its byte code.
 */
public Object[] compileToClassFiles(String source,
                                    String sourceLocation,
                                    int lineno,
                                    String mainClassName)
{
    Parser p = new Parser(compilerEnv);
    AstRoot ast = p.parse(source, sourceLocation, lineno);
    IRFactory irf = new IRFactory(compilerEnv);
    ScriptNode tree = irf.transformTree(ast);

    // release reference to original parse tree & parser
    irf = null;
    ast = null;
    p = null;

    Class<?> superClass = getTargetExtends();
    Class<?>[] interfaces = getTargetImplements();
    String scriptClassName;
    boolean isPrimary = (interfaces == null && superClass == null);
    if (isPrimary) {
        scriptClassName = mainClassName;
    } else {
        scriptClassName = makeAuxiliaryClassName(mainClassName, "1");
    }

    Codegen codegen = new Codegen();
    codegen.setMainMethodClass(mainMethodClassName);
    byte[] scriptClassBytes
        = codegen.compileToClassFile(compilerEnv, scriptClassName,
                                     tree, tree.getEncodedSource(),
                                     false);

    if (isPrimary) {
        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;
    }
    byte[] mainClassBytes
        = JavaAdapter.createAdapterCode(
            functionNames, mainClassName,
            superClass, interfaces, scriptClassName);

    return new Object[] { mainClassName, mainClassBytes,
                          scriptClassName, scriptClassBytes };
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:69,代码来源:ClassCompiler.java

示例13: get

import org.mozilla.javascript.ast.ScriptNode; //导入方法依赖的package包/类
public static OptFunctionNode get(ScriptNode scriptOrFn, int i)
{
    FunctionNode fnode = scriptOrFn.getFunctionNode(i);
    return (OptFunctionNode)fnode.getCompilerData();
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:6,代码来源:OptFunctionNode.java

示例14: get

import org.mozilla.javascript.ast.ScriptNode; //导入方法依赖的package包/类
static OptFunctionNode get(ScriptNode scriptOrFn, int i)
{
    FunctionNode fnode = scriptOrFn.getFunctionNode(i);
    return (OptFunctionNode)fnode.getCompilerData();
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:6,代码来源:OptFunctionNode.java


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