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


Java CompilerEnvirons.setRecoverFromErrors方法代码示例

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


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

示例1: compileText

import org.mozilla.javascript.CompilerEnvirons; //导入方法依赖的package包/类
/**
 * Compiles Text and resolves the type.
 * e.g 
 * "Hello World".length; //resolve as a Number
 * 
 * @param text to compile and resolve  
 */
@Override
public JavaScriptType compileText(String text) throws IOException {
	CompilerEnvirons env = JavaScriptParser.createCompilerEnvironment(new JavaScriptParser.JSErrorReporter(), provider.getLanguageSupport());
	
	String parseText = JavaScriptHelper.removeLastDotFromText(text);
	
	int charIndex = JavaScriptHelper.findIndexOfFirstOpeningBracket(parseText);
	env.setRecoverFromErrors(true);
	Parser parser = new Parser(env);
	StringReader r = new StringReader(parseText);
	AstRoot root = parser.parse(r, null, 0);
	CompilerNodeVisitor visitor = new CompilerNodeVisitor(charIndex == 0);
	root.visitAll(visitor);
	return lastJavaScriptType;
}
 
开发者ID:bobbylight,项目名称:RSTALanguageSupport,代码行数:23,代码来源:JavaScriptCompletionResolver.java

示例2: resolveParamNode

import org.mozilla.javascript.CompilerEnvirons; //导入方法依赖的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 resolveParamNode(String text) throws IOException {
	
	if(text != null) {
		CompilerEnvirons env = JavaScriptParser.createCompilerEnvironment(new JavaScriptParser.JSErrorReporter(), provider.getLanguageSupport());
		
		
		int charIndex = JavaScriptHelper.findIndexOfFirstOpeningBracket(text);
		env.setRecoverFromErrors(true);
		Parser parser = new Parser(env);
		StringReader r = new StringReader(text);
		AstRoot root = parser.parse(r, null, 0);
		CompilerNodeVisitor visitor = new CompilerNodeVisitor(charIndex == 0);
		root.visitAll(visitor);
	}
	
	return lastJavaScriptType != null ? lastJavaScriptType.getType()
			: provider.getTypesFactory().getDefaultTypeDeclaration();
}
 
开发者ID:bobbylight,项目名称:RSTALanguageSupport,代码行数:25,代码来源:JavaScriptCompletionResolver.java

示例3: createCompilerEnvironment

import org.mozilla.javascript.CompilerEnvirons; //导入方法依赖的package包/类
/**
 * Creates options for Rhino based off of the user's preferences.
 *
 * @param errorHandler The container for errors found while parsing.
 * @return The properties for the JS compiler to use.
 */
public static CompilerEnvirons createCompilerEnvironment(ErrorReporter
		errorHandler, JavaScriptLanguageSupport langSupport) {
	CompilerEnvirons env = new CompilerEnvirons();
	env.setErrorReporter(errorHandler);
	env.setIdeMode(true);
	env.setRecordingComments(true);
	env.setRecordingLocalJsDocComments(true);
	env.setRecoverFromErrors(true);
	if(langSupport != null) {
		env.setXmlAvailable(langSupport.isXmlAvailable());
		env.setStrictMode(langSupport.isStrictMode());
		int version = langSupport.getLanguageVersion();
		if (version > 0) {
			Logger.log("[JavaScriptParser]: JS language version set to: " + version);
			env.setLanguageVersion(version);
		}
	}
	return env;
}
 
开发者ID:bobbylight,项目名称:RSTALanguageSupport,代码行数:26,代码来源:JavaScriptParser.java

示例4: transform

import org.mozilla.javascript.CompilerEnvirons; //导入方法依赖的package包/类
private String transform(String text) throws IOException {
    sb.setLength(0);
    CompilerEnvirons env = new CompilerEnvirons();
    env.setRecoverFromErrors(true);
    env.setLanguageVersion(Context.VERSION_1_8);
    JSParser factory = new JSParser(env);
    factory.enterFunction();
    AstRoot rootNode = factory.parse(new StringReader(text), null, 0);
    factory.exitFunction();
    writer.hoist(rootNode);
    writer.print(rootNode);
    return sb.toString();
}
 
开发者ID:konsoletyper,项目名称:teavm,代码行数:14,代码来源:AstWriterTest.java

示例5: processJSBody

import org.mozilla.javascript.CompilerEnvirons; //导入方法依赖的package包/类
private void processJSBody(Diagnostics diagnostics, MethodReader methodToProcess) {
    CallLocation location = new CallLocation(methodToProcess.getReference());
    boolean isStatic = methodToProcess.hasModifier(ElementModifier.STATIC);

    // validate parameter names
    AnnotationReader bodyAnnot = methodToProcess.getAnnotations().get(JSBody.class.getName());
    AnnotationValue paramsValue = bodyAnnot.getValue("params");
    int jsParamCount = paramsValue != null ? paramsValue.getList().size() : 0;
    if (methodToProcess.parameterCount() != jsParamCount) {
        diagnostics.error(location, "JSBody method {{m0}} declares " + methodToProcess.parameterCount()
                + " parameters, but annotation specifies " + jsParamCount, methodToProcess.getReference());
        return;
    }

    // generate parameter types for original method and validate
    int paramCount = methodToProcess.parameterCount();
    if (!isStatic) {
        ++paramCount;
    }
    if (!isStatic) {
        ValueType paramType = ValueType.object(methodToProcess.getOwnerName());
        if (!typeHelper.isSupportedType(paramType)) {
            diagnostics.error(location, "Non-static JSBody method {{m0}} is owned by non-JS class {{c1}}",
                    methodToProcess.getReference(), methodToProcess.getOwnerName());
        }
    }
    if (methodToProcess.getResultType() != ValueType.VOID
            && !typeHelper.isSupportedType(methodToProcess.getResultType())) {
        diagnostics.error(location, "JSBody method {{m0}} returns unsupported type {{t1}}",
                methodToProcess.getReference(), methodToProcess.getResultType());
    }

    // generate parameter types for proxy method
    ValueType[] proxyParamTypes = new ValueType[paramCount + 1];
    for (int i = 0; i < paramCount; ++i) {
        proxyParamTypes[i] = ValueType.parse(JSObject.class);
    }
    proxyParamTypes[paramCount] = methodToProcess.getResultType() == ValueType.VOID
            ? ValueType.VOID
            : ValueType.parse(JSObject.class);

    // create proxy method
    MethodReference proxyMethod = new MethodReference(methodToProcess.getOwnerName(),
            methodToProcess.getName() + "$js_body$_" + methodIndexGenerator++, proxyParamTypes);
    String script = bodyAnnot.getValue("script").getString();
    String[] parameterNames = paramsValue != null ? paramsValue.getList().stream()
            .map(AnnotationValue::getString)
            .toArray(String[]::new) : new String[0];

    // Parse JS script
    TeaVMErrorReporter errorReporter = new TeaVMErrorReporter(diagnostics,
            new CallLocation(methodToProcess.getReference()));
    CompilerEnvirons env = new CompilerEnvirons();
    env.setRecoverFromErrors(true);
    env.setLanguageVersion(Context.VERSION_1_8);
    env.setIdeMode(true);
    JSParser parser = new JSParser(env, errorReporter);
    AstRoot rootNode;
    try {
        rootNode = parser.parse(new StringReader("function(){" + script + "}"), null, 0);
    } catch (IOException e) {
        throw new RuntimeException("IO Error occurred", e);
    }
    AstNode body = ((FunctionNode) rootNode.getFirstChild()).getBody();

    repository.methodMap.put(methodToProcess.getReference(), proxyMethod);
    if (errorReporter.hasErrors()) {
        repository.emitters.put(proxyMethod, new JSBodyBloatedEmitter(isStatic, proxyMethod,
                script, parameterNames));
    } else {
        AstNode expr = JSBodyInlineUtil.isSuitableForInlining(methodToProcess.getReference(),
                parameterNames, body);
        if (expr != null) {
            repository.inlineMethods.add(methodToProcess.getReference());
        } else {
            expr = body;
        }
        javaInvocationProcessor.process(location, expr);
        repository.emitters.put(proxyMethod, new JSBodyAstEmitter(isStatic, expr, parameterNames));
    }
}
 
开发者ID:konsoletyper,项目名称:teavm,代码行数:82,代码来源:JSClassProcessor.java


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