本文整理汇总了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;
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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 };
}
示例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);
}
}
示例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);
}
}