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


Java MultipleCompilationErrorsException类代码示例

本文整理汇总了Java中org.codehaus.groovy.control.MultipleCompilationErrorsException的典型用法代码示例。如果您正苦于以下问题:Java MultipleCompilationErrorsException类的具体用法?Java MultipleCompilationErrorsException怎么用?Java MultipleCompilationErrorsException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: wrapCompilationFailure

import org.codehaus.groovy.control.MultipleCompilationErrorsException; //导入依赖的package包/类
private void wrapCompilationFailure(ScriptSource source, MultipleCompilationErrorsException e) {
    // Fix the source file name displayed in the error messages
    for (Object message : e.getErrorCollector().getErrors()) {
        if (message instanceof SyntaxErrorMessage) {
            try {
                SyntaxErrorMessage syntaxErrorMessage = (SyntaxErrorMessage) message;
                Field sourceField = SyntaxErrorMessage.class.getDeclaredField("source");
                sourceField.setAccessible(true);
                SourceUnit sourceUnit = (SourceUnit) sourceField.get(syntaxErrorMessage);
                Field nameField = SourceUnit.class.getDeclaredField("name");
                nameField.setAccessible(true);
                nameField.set(sourceUnit, source.getDisplayName());
            } catch (Exception failure) {
                throw UncheckedException.throwAsUncheckedException(failure);
            }
        }
    }

    SyntaxException syntaxError = e.getErrorCollector().getSyntaxError(0);
    Integer lineNumber = syntaxError == null ? null : syntaxError.getLine();
    throw new ScriptCompilationException(String.format("Could not compile %s.", source.getDisplayName()), e, source, lineNumber);
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:23,代码来源:DefaultScriptCompilationHandler.java

示例2: shouldNotEvalColorWhenCallingMethods

import org.codehaus.groovy.control.MultipleCompilationErrorsException; //导入依赖的package包/类
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldNotEvalColorWhenCallingMethods() throws Exception {
    final CompilerCustomizerProvider standardSandbox = new CompileStaticCustomizerProvider(AllowColorSandboxExtension.class.getName());
    try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(standardSandbox)) {
        assertEquals(new java.awt.Color(255,255,255), engine.eval("new java.awt.Color(255,255,255)"));
    }

    try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(standardSandbox)) {
        engine.eval("new java.awt.Color(255,255,255).getRed()");
        fail("Type checking should have forced an error as 'getRed()' is not authorized - just Color construction");
    } catch (Exception ex) {
        assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass());
        assertThat(ex.getMessage(), containsString("Not authorized to call this method"));
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:17,代码来源:GremlinGroovyScriptEngineTinkerPopSandboxTest.java

示例3: shouldNotEvalColorWhenCallingProperties

import org.codehaus.groovy.control.MultipleCompilationErrorsException; //导入依赖的package包/类
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldNotEvalColorWhenCallingProperties() throws Exception {
    final CompilerCustomizerProvider standardSandbox = new CompileStaticCustomizerProvider(AllowColorSandboxExtension.class.getName());
    try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(standardSandbox)) {
        assertEquals(new java.awt.Color(255,255,255), engine.eval("new java.awt.Color(255,255,255)"));
    }

    try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(standardSandbox)) {
        engine.eval("new java.awt.Color(255,255,255).red");
        fail("Type checking should have forced an error as 'red' is not authorized - just Color construction");
    } catch (Exception ex) {
        assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass());
        assertThat(ex.getMessage(), containsString("Not authorized to call this method"));
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:17,代码来源:GremlinGroovyScriptEngineTinkerPopSandboxTest.java

示例4: shouldCompileStatic

import org.codehaus.groovy.control.MultipleCompilationErrorsException; //导入依赖的package包/类
@Test
public void shouldCompileStatic() throws Exception {
    // with no type checking this should pass
    try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine()) {
        assertEquals(255, scriptEngine.eval("((Object) new java.awt.Color(255, 255, 255)).getRed()"));
    }

    final CompileStaticCustomizerProvider provider = new CompileStaticCustomizerProvider();
    try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(provider)) {
        scriptEngine.eval("((Object) new java.awt.Color(255, 255, 255)).getRed()");
        fail("Should have failed type checking");
    } catch (ScriptException se) {
        final Throwable root = ExceptionUtils.getRootCause(se);
        assertEquals(MultipleCompilationErrorsException.class, root.getClass());
        assertThat(se.getMessage(), containsString("[Static type checking] - Cannot find matching method java.lang.Object#getRed(). Please check if the declared type is right and if the method exists."));
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:18,代码来源:GremlinGroovyScriptEngineCompileStaticTest.java

示例5: shouldCompileStaticWithExtension

import org.codehaus.groovy.control.MultipleCompilationErrorsException; //导入依赖的package包/类
@Test
public void shouldCompileStaticWithExtension() throws Exception {
    // with no type checking extension this should pass
    final CompileStaticCustomizerProvider providerNoExtension = new CompileStaticCustomizerProvider();
    try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerNoExtension)) {
        assertEquals(255, scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red"));
    }

    final CompileStaticCustomizerProvider providerWithExtension = new CompileStaticCustomizerProvider(
            PrecompiledExtensions.PreventColorUsageExtension.class.getName());
    try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerWithExtension)) {
        scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red");
        fail("Should have failed type checking");
    } catch (ScriptException se) {
        assertEquals(MultipleCompilationErrorsException.class, se.getCause().getClass());
        assertThat(se.getMessage(), containsString("Method call is not allowed!"));
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:19,代码来源:GremlinGroovyScriptEngineCompileStaticTest.java

示例6: shouldTypeCheck

import org.codehaus.groovy.control.MultipleCompilationErrorsException; //导入依赖的package包/类
@Test
public void shouldTypeCheck() throws Exception {
    // with no type checking this should pass
    try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine()) {
        assertEquals(255, scriptEngine.eval("((Object) new java.awt.Color(255, 255, 255)).getRed()"));
    }

    final TypeCheckedCustomizerProvider provider = new TypeCheckedCustomizerProvider();
    try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(provider)) {
        scriptEngine.eval("((Object) new java.awt.Color(255, 255, 255)).getRed()");
        fail("Should have failed type checking");
    } catch (ScriptException se) {
        final Throwable root = ExceptionUtils.getRootCause(se);
        assertEquals(MultipleCompilationErrorsException.class, root.getClass());
        assertThat(se.getMessage(), containsString("[Static type checking] - Cannot find matching method java.lang.Object#getRed(). Please check if the declared type is right and if the method exists."));
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:18,代码来源:GremlinGroovyScriptEngineTypeCheckedTest.java

示例7: shouldTypeCheckWithExtension

import org.codehaus.groovy.control.MultipleCompilationErrorsException; //导入依赖的package包/类
@Test
public void shouldTypeCheckWithExtension() throws Exception {
    // with no type checking extension this should pass
    final TypeCheckedCustomizerProvider providerNoExtension = new TypeCheckedCustomizerProvider();
    try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerNoExtension)) {
        assertEquals(255, scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red"));
    }

    final CompileStaticCustomizerProvider providerWithExtension = new CompileStaticCustomizerProvider(
            PrecompiledExtensions.PreventColorUsageExtension.class.getName());
    try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerWithExtension)) {
        scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red");
        fail("Should have failed type checking");
    } catch (ScriptException se) {
        assertEquals(MultipleCompilationErrorsException.class, se.getCause().getClass());
        assertThat(se.getMessage(), containsString("Method call is not allowed!"));
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:19,代码来源:GremlinGroovyScriptEngineTypeCheckedTest.java

示例8: shouldCompileStatic

import org.codehaus.groovy.control.MultipleCompilationErrorsException; //导入依赖的package包/类
@Test
public void shouldCompileStatic() throws Exception {
    // with no type checking this should pass
    try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine()) {
        assertEquals(255, scriptEngine.eval("((Object) new java.awt.Color(255, 255, 255)).getRed()"));
    }

    final CompileStaticGroovyCustomizer provider = new CompileStaticGroovyCustomizer();
    try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(provider)) {
        scriptEngine.eval("((Object) new java.awt.Color(255, 255, 255)).getRed()");
        fail("Should have failed type checking");
    } catch (ScriptException se) {
        final Throwable root = ExceptionUtils.getRootCause(se);
        assertEquals(MultipleCompilationErrorsException.class, root.getClass());
        assertThat(se.getMessage(), containsString("[Static type checking] - Cannot find matching method java.lang.Object#getRed(). Please check if the declared type is right and if the method exists."));
    }
}
 
开发者ID:apache,项目名称:tinkerpop,代码行数:18,代码来源:GremlinGroovyScriptEngineCompileStaticTest.java

示例9: shouldCompileStaticWithExtension

import org.codehaus.groovy.control.MultipleCompilationErrorsException; //导入依赖的package包/类
@Test
public void shouldCompileStaticWithExtension() throws Exception {
    // with no type checking extension this should pass
    final CompileStaticGroovyCustomizer providerNoExtension = new CompileStaticGroovyCustomizer();
    try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerNoExtension)) {
        assertEquals(255, scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red"));
    }

    final CompileStaticGroovyCustomizer providerWithExtension = new CompileStaticGroovyCustomizer(
            PrecompiledExtensions.PreventColorUsageExtension.class.getName());
    try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerWithExtension)) {
        scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red");
        fail("Should have failed type checking");
    } catch (ScriptException se) {
        assertEquals(MultipleCompilationErrorsException.class, se.getCause().getClass());
        assertThat(se.getMessage(), containsString("Method call is not allowed!"));
    }
}
 
开发者ID:apache,项目名称:tinkerpop,代码行数:19,代码来源:GremlinGroovyScriptEngineCompileStaticTest.java

示例10: shouldTypeCheck

import org.codehaus.groovy.control.MultipleCompilationErrorsException; //导入依赖的package包/类
@Test
public void shouldTypeCheck() throws Exception {
    // with no type checking this should pass
    try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine()) {
        assertEquals(255, scriptEngine.eval("((Object) new java.awt.Color(255, 255, 255)).getRed()"));
    }

    final TypeCheckedGroovyCustomizer provider = new TypeCheckedGroovyCustomizer();
    try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(provider)) {
        scriptEngine.eval("((Object) new java.awt.Color(255, 255, 255)).getRed()");
        fail("Should have failed type checking");
    } catch (ScriptException se) {
        final Throwable root = ExceptionUtils.getRootCause(se);
        assertEquals(MultipleCompilationErrorsException.class, root.getClass());
        assertThat(se.getMessage(), containsString("[Static type checking] - Cannot find matching method java.lang.Object#getRed(). Please check if the declared type is right and if the method exists."));
    }
}
 
开发者ID:apache,项目名称:tinkerpop,代码行数:18,代码来源:GremlinGroovyScriptEngineTypeCheckedTest.java

示例11: shouldTypeCheckWithExtension

import org.codehaus.groovy.control.MultipleCompilationErrorsException; //导入依赖的package包/类
@Test
public void shouldTypeCheckWithExtension() throws Exception {
    // with no type checking extension this should pass
    final TypeCheckedGroovyCustomizer providerNoExtension = new TypeCheckedGroovyCustomizer();
    try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerNoExtension)) {
        assertEquals(255, scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red"));
    }

    final TypeCheckedGroovyCustomizer providerWithExtension = new TypeCheckedGroovyCustomizer(
            PrecompiledExtensions.PreventColorUsageExtension.class.getName());
    try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerWithExtension)) {
        scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red");
        fail("Should have failed type checking");
    } catch (ScriptException se) {
        assertEquals(MultipleCompilationErrorsException.class, se.getCause().getClass());
        assertThat(se.getMessage(), containsString("Method call is not allowed!"));
    }
}
 
开发者ID:apache,项目名称:tinkerpop,代码行数:19,代码来源:GremlinGroovyScriptEngineTypeCheckedTest.java

示例12: describe

import org.codehaus.groovy.control.MultipleCompilationErrorsException; //导入依赖的package包/类
@Override
public int describe(InputStream contents, IContentDescription description) throws IOException {
    
    try {
        GradleScriptASTParser parser = new GradleScriptASTParser(contents);
        PluginsSyntaxDescriberVisitor pluginsVisitor = new PluginsSyntaxDescriberVisitor();
        ApplySyntaxDescriberVisitor visitor = new ApplySyntaxDescriberVisitor();
        
        parser.walkScript(pluginsVisitor);
        
        if (pluginsVisitor.isFoundPlugin()) {
        	return IContentDescriber.VALID;
        }
        
        parser.walkScript(visitor);
        
        if (visitor.isFoundplugin()) {
            return IContentDescriber.VALID;
        }
        
    } catch (MultipleCompilationErrorsException ex) {
        return IContentDescriber.INDETERMINATE;
    }
    return IContentDescriber.INVALID;
}
 
开发者ID:mulesoft,项目名称:mule-tooling-incubator,代码行数:26,代码来源:StudioGradleEnabledContentDescriber.java

示例13: fromGroovyException

import org.codehaus.groovy.control.MultipleCompilationErrorsException; //导入依赖的package包/类
public static ScriptError fromGroovyException(MultipleCompilationErrorsException e) {
    ErrorCollector errorCollector = e.getErrorCollector();
    if (errorCollector.getErrorCount() > 0) {
        Message error = errorCollector.getError(0);
        if (error instanceof SyntaxErrorMessage) {
            SyntaxException cause = ((SyntaxErrorMessage) error).getCause();
            return new ScriptError(cause.getMessage(), cause.getStartLine(), cause.getStartColumn(),
                    cause.getEndLine(), cause.getEndColumn());
        } else {
            throw new AssertionError("SyntaxErrorMessage is expected");
        }
    } else {
        throw new AssertionError("At least one error is expected");
    }
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:16,代码来源:ScriptError.java

示例14: shouldNotEvalBecauseSandboxIsConfiguredToNotAcceptGraphInstances

import org.codehaus.groovy.control.MultipleCompilationErrorsException; //导入依赖的package包/类
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldNotEvalBecauseSandboxIsConfiguredToNotAcceptGraphInstances() throws Exception {
    final CompilerCustomizerProvider customSandbox = new CompileStaticCustomizerProvider(
            BlockSomeVariablesSandboxExtension.class.getName());
    try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(customSandbox)) {
        final Bindings bindings = engine.createBindings();
        bindings.put("graph", graph);
        engine.eval("graph.vertices()", bindings);
        fail("Should have a compile error because sandbox does not allow Graph");
    } catch (Exception ex) {
        assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass());
        assertThat(ex.getMessage(), containsString("The variable [graph] is undeclared."));
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:16,代码来源:GremlinGroovyScriptEngineSandboxCustomTest.java

示例15: shouldNotEvalBecauseSandboxIsConfiguredToNotAcceptShortVarNames

import org.codehaus.groovy.control.MultipleCompilationErrorsException; //导入依赖的package包/类
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldNotEvalBecauseSandboxIsConfiguredToNotAcceptShortVarNames() throws Exception {
    final CompilerCustomizerProvider customSandbox = new CompileStaticCustomizerProvider(
            BlockSomeVariablesSandboxExtension.class.getName());
    try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(customSandbox)) {
        final Bindings bindings = engine.createBindings();
        bindings.put("g", 1);
        engine.eval("g+1", bindings);
        fail("Should have a compile error because sandbox wants names > 3");
    } catch (Exception ex) {
        assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass());
        assertThat(ex.getMessage(), containsString("The variable [g] is undeclared."));
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:16,代码来源:GremlinGroovyScriptEngineSandboxCustomTest.java


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