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


Java ScriptNode.getFunctionCount方法代码示例

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


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

示例1: getFunctionIndex

import org.mozilla.javascript.ast.ScriptNode; //导入方法依赖的package包/类
/**
 * get the function node index
 * 
 * @param functionName
 * @param tree
 * @return
 */
private int getFunctionIndex( String functionName, ScriptNode tree )
{
	int index = -1;
	for ( int i = 0; i < tree.getFunctionCount( ); i++ )
	{
		if ( tree.getFunctionNode( i )
				.getFunctionName( ).getString()
				.equals( functionName ) )
		{
			index = i;
			break;
		}
	}
	return index;
}
 
开发者ID:eclipse,项目名称:birt,代码行数:23,代码来源:ExpressionParserUtility.java

示例2: 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

示例3: 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

示例4: collectScriptNodes_r

import org.mozilla.javascript.ast.ScriptNode; //导入方法依赖的package包/类
private static void collectScriptNodes_r(ScriptNode n,
                                             ObjArray x)
{
    x.add(n);
    int nestedCount = n.getFunctionCount();
    for (int i = 0; i != nestedCount; ++i) {
        collectScriptNodes_r(n.getFunctionNode(i), x);
    }
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:10,代码来源:Codegen.java

示例5: optimize

import org.mozilla.javascript.ast.ScriptNode; //导入方法依赖的package包/类
void optimize(ScriptNode scriptOrFn)
{
    //  run on one function at a time for now
    int functionCount = scriptOrFn.getFunctionCount();
    for (int i = 0; i != functionCount; ++i) {
        OptFunctionNode f = OptFunctionNode.get(scriptOrFn, i);
        optimizeFunction(f);
    }
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:10,代码来源:Optimizer.java

示例6: 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

示例7: 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

示例8: transform

import org.mozilla.javascript.ast.ScriptNode; //导入方法依赖的package包/类
private void transform(ScriptNode tree)
{
    initOptFunctions_r(tree);

    int optLevel = compilerEnv.getOptimizationLevel();

    Map<String,OptFunctionNode> possibleDirectCalls = null;
    if (optLevel > 0) {
       /*
        * Collect all of the contained functions into a hashtable
        * so that the call optimizer can access the class name & parameter
        * count for any call it encounters
        */
        if (tree.getType() == Token.SCRIPT) {
            int functionCount = tree.getFunctionCount();
            for (int i = 0; i != functionCount; ++i) {
                OptFunctionNode ofn = OptFunctionNode.get(tree, i);
                if (ofn.fnode.getFunctionType()
                    == FunctionNode.FUNCTION_STATEMENT)
                {
                    String name = ofn.fnode.getName();
                    if (name.length() != 0) {
                        if (possibleDirectCalls == null) {
                            possibleDirectCalls = new HashMap<String,OptFunctionNode>();
                        }
                        possibleDirectCalls.put(name, ofn);
                    }
                }
            }
        }
    }

    if (possibleDirectCalls != null) {
        directCallTargets = new ObjArray();
    }

    OptTransformer ot = new OptTransformer(possibleDirectCalls,
                                           directCallTargets);
    ot.transform(tree, compilerEnv);

    if (optLevel > 0) {
        (new Optimizer()).optimize(tree);
    }
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:45,代码来源:Codegen.java

示例9: transform

import org.mozilla.javascript.ast.ScriptNode; //导入方法依赖的package包/类
private void transform(ScriptNode tree)
{
    initOptFunctions_r(tree);

    int optLevel = compilerEnv.getOptimizationLevel();

    Map<String,OptFunctionNode> possibleDirectCalls = null;
    if (optLevel > 0) {
       /*
        * Collect all of the contained functions into a hashtable
        * so that the call optimizer can access the class name & parameter
        * count for any call it encounters
        */
        if (tree.getType() == Token.SCRIPT) {
            int functionCount = tree.getFunctionCount();
            for (int i = 0; i != functionCount; ++i) {
                OptFunctionNode ofn = OptFunctionNode.get(tree, i);
                if (ofn.fnode.getFunctionType()
                    == FunctionNode.FUNCTION_STATEMENT)
                {
                    String name = ofn.fnode.getName();
                    if (name.length() != 0) {
                        if (possibleDirectCalls == null) {
                            possibleDirectCalls = new HashMap<String,OptFunctionNode>();
                        }
                        possibleDirectCalls.put(name, ofn);
                    }
                }
            }
        }
    }

    if (possibleDirectCalls != null) {
        directCallTargets = new ObjArray();
    }

    OptTransformer ot = new OptTransformer(possibleDirectCalls,
                                           directCallTargets);
    ot.transform(tree);

    if (optLevel > 0) {
        (new Optimizer()).optimize(tree);
    }
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:45,代码来源:Codegen.java


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