本文整理汇总了Java中org.mozilla.javascript.ast.AstNode.visit方法的典型用法代码示例。如果您正苦于以下问题:Java AstNode.visit方法的具体用法?Java AstNode.visit怎么用?Java AstNode.visit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.mozilla.javascript.ast.AstNode
的用法示例。
在下文中一共展示了AstNode.visit方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isSuitableForInlining
import org.mozilla.javascript.ast.AstNode; //导入方法依赖的package包/类
public static AstNode isSuitableForInlining(MethodReference method, String[] parameters, AstNode ast) {
AstNode statement = isSingleStatement(ast);
if (statement == null) {
return null;
}
AstNode expression = getExpression(method, statement);
if (expression == null) {
return null;
}
ComplexityCounter complexityCounter = new ComplexityCounter();
expression.visit(complexityCounter);
if (complexityCounter.getComplexity() > COMPLEXITY_THRESHOLD) {
return null;
}
VariableUsageCounter usageCounter = new VariableUsageCounter();
expression.visit(usageCounter);
for (String param : parameters) {
if (usageCounter.getUsage(param) > 1) {
return null;
}
}
return expression;
}
示例2: findPropertyRefsUnder
import org.mozilla.javascript.ast.AstNode; //导入方法依赖的package包/类
protected static Set<String> findPropertyRefsUnder(String objectName, Node node) {
PropertyRefsUnderNodeVisitor visitor = new PropertyRefsUnderNodeVisitor(objectName);
if (node == null) {
return visitor.getResult();
}
AstNode aNode = (AstNode)node;
aNode.visit(visitor);
return visitor.getResult();
}
示例3: hoist
import org.mozilla.javascript.ast.AstNode; //导入方法依赖的package包/类
public void hoist(AstNode node) {
node.visit(n -> {
if (n instanceof Scope) {
Scope scope = (Scope) n;
if (scope.getSymbolTable() != null) {
for (String name : scope.getSymbolTable().keySet()) {
declareName(name);
}
}
}
return true;
});
}
示例4: resolveNode
import org.mozilla.javascript.ast.AstNode; //导入方法依赖的package包/类
/**
* Resolve node type to TypeDeclaration. Called instead of #compileText(String text) when document is already parsed
* @param node AstNode to resolve
* @return TypeDeclaration for node or null if not found.
*/
@Override
public TypeDeclaration resolveNode(AstNode node) {
if(node == null) return provider.getTypesFactory().getDefaultTypeDeclaration();
CompilerNodeVisitor visitor = new CompilerNodeVisitor(true);
node.visit(visitor);
return lastJavaScriptType != null ? lastJavaScriptType.getType()
: provider.getTypesFactory().getDefaultTypeDeclaration();
}
示例5: collectAllNodes
import org.mozilla.javascript.ast.AstNode; //导入方法依赖的package包/类
/**
* Get all nodes within AstNode and add to an ArrayList
*
* @param node
*/
private void collectAllNodes(AstNode node) {
if (node.getType() == Token.CALL) {
// collect all argument nodes
FunctionCall call = (FunctionCall) node;
Iterator<AstNode> args = call.getArguments().iterator();
while (args.hasNext()) {
AstNode arg = args.next();
VisitorAll all = new VisitorAll();
arg.visit(all);
paramNodes.addAll(all.getAllNodes());
}
}
}
示例6: findVariablesUnder
import org.mozilla.javascript.ast.AstNode; //导入方法依赖的package包/类
protected static Set<String> findVariablesUnder(Node node) {
AstNode aNode = (AstNode)node;
FindVariablesNodeVisitor visitor = new FindVariablesNodeVisitor();
aNode.visit(visitor);
return visitor.getResults();
}
示例7: findFunctionsUnder
import org.mozilla.javascript.ast.AstNode; //导入方法依赖的package包/类
protected static Set<String> findFunctionsUnder(Node node) {
AstNode aNode = (AstNode) node;
FunctionsUnderNodeVisitor visitor = new FunctionsUnderNodeVisitor();
aNode.visit(visitor);
return visitor.getResult();
}
示例8: findArrayIndexesUnder
import org.mozilla.javascript.ast.AstNode; //导入方法依赖的package包/类
protected static Set<String> findArrayIndexesUnder(String arrayName, Node node) {
ArrayIndexesUnderNodeVisitor visitor = new ArrayIndexesUnderNodeVisitor(arrayName);
AstNode aNode = (AstNode)node;
aNode.visit(visitor);
return visitor.getResult();
}
示例9: process
import org.mozilla.javascript.ast.AstNode; //导入方法依赖的package包/类
public void process(CallLocation location, AstNode root) {
this.location = location;
root.visit(this);
}
示例10: visit
import org.mozilla.javascript.ast.AstNode; //导入方法依赖的package包/类
private boolean visit(FunctionCall call) {
if (!(call.getTarget() instanceof PropertyGet)) {
return true;
}
PropertyGet propertyGet = (PropertyGet) call.getTarget();
MethodReference methodRef = getJavaMethodSelector(propertyGet.getTarget());
if (methodRef == null || !propertyGet.getProperty().getIdentifier().equals("invoke")) {
return true;
}
for (AstNode arg : call.getArguments()) {
arg.visit(this);
}
MethodReader method = classSource.resolve(methodRef);
if (method == null) {
diagnostics.error(location, "Java method not found: {{m0}}", methodRef);
return false;
}
int requiredParams = methodRef.parameterCount();
if (!method.hasModifier(ElementModifier.STATIC)) {
++requiredParams;
}
if (call.getArguments().size() != requiredParams) {
diagnostics.error(location, "Invalid number of arguments for method {{m0}}. Expected: " + requiredParams
+ ", encountered: " + call.getArguments().size(), methodRef);
}
MethodReference caller = createCallbackMethod(method);
MethodReference delegate = repository.methodMap.get(location.getMethod());
repository.callbackCallees.put(caller, methodRef);
repository.callbackMethods.computeIfAbsent(delegate, key -> new HashSet<>()).add(caller);
validateSignature(method);
StringLiteral newTarget = new StringLiteral();
newTarget.setValue("$$JSO$$_" + caller);
propertyGet.setTarget(newTarget);
return false;
}