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


Java AstNode.visit方法代码示例

本文整理汇总了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;
}
 
开发者ID:konsoletyper,项目名称:teavm,代码行数:27,代码来源:JSBodyInlineUtil.java

示例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();
}
 
开发者ID:nasa,项目名称:OpenSPIFe,代码行数:10,代码来源:FormulaInfo.java

示例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;
    });
}
 
开发者ID:konsoletyper,项目名称:teavm,代码行数:14,代码来源:AstWriter.java

示例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();
}
 
开发者ID:bobbylight,项目名称:RSTALanguageSupport,代码行数:14,代码来源:JavaScriptCompletionResolver.java

示例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());
		}
	}
}
 
开发者ID:bobbylight,项目名称:RSTALanguageSupport,代码行数:19,代码来源:JavaScriptCompletionResolver.java

示例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();
}
 
开发者ID:nasa,项目名称:OpenSPIFe,代码行数:7,代码来源:FormulaInfo.java

示例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();
}
 
开发者ID:nasa,项目名称:OpenSPIFe,代码行数:7,代码来源:FormulaInfo.java

示例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();
}
 
开发者ID:nasa,项目名称:OpenSPIFe,代码行数:7,代码来源:FormulaInfo.java

示例9: process

import org.mozilla.javascript.ast.AstNode; //导入方法依赖的package包/类
public void process(CallLocation location, AstNode root) {
    this.location = location;
    root.visit(this);
}
 
开发者ID:konsoletyper,项目名称:teavm,代码行数:5,代码来源:JavaInvocationProcessor.java

示例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;
}
 
开发者ID:konsoletyper,项目名称:teavm,代码行数:43,代码来源:JavaInvocationProcessor.java


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