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


Java GroovyRuntimeException类代码示例

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


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

示例1: handleEvaluationException

import groovy.lang.GroovyRuntimeException; //导入依赖的package包/类
@Override
protected Object handleEvaluationException(JRExpression expression, Throwable e) throws JRExpressionEvalException
{
	if (ignoreNPE && e instanceof GroovyRuntimeException && e.getMessage() != null)
	{
		//in Groovy 2.0.1, 1 + null (and other e.g. BigDecimal * null) was throwing NPE
		//in 2.4.3, it fails with "Ambiguous method overloading..."
		//we're catching this exception (by message) and treating it like a NPE
		Matcher matcher = GROOVY_EXCEPTION_PATTERN_AMBIGUOUS_NULL.matcher(e.getMessage());
		if (matcher.matches())
		{
			//evaluating the expression to null to match Groovy 2.0.1 behaviour
			return null;
		}
	}
	
	//throw the exception
	return super.handleEvaluationException(expression, e);
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:20,代码来源:GroovyEvaluator.java

示例2: processException

import groovy.lang.GroovyRuntimeException; //导入依赖的package包/类
private void processException(Throwable exception, String prefix) {
  if (exception instanceof GroovyRuntimeException) {
    addErrorMessage((GroovyRuntimeException) exception);
    return;
  }

  if (forStubs) {
    collector.add(new CompilerMessage(GroovyCompilerMessageCategories.INFORMATION,
                                      GroovyRtConstants.GROOVYC_STUB_GENERATION_FAILED, null, -1, -1));
  }

  final StringWriter writer = new StringWriter();
  writer.append(prefix);
  if (!prefix.endsWith("\n")) {
    writer.append("\n\n");
  }
  //noinspection IOResourceOpenedButNotSafelyClosed
  exception.printStackTrace(new PrintWriter(writer));
  collector.add(new CompilerMessage(forStubs ? GroovyCompilerMessageCategories.INFORMATION : GroovyCompilerMessageCategories.ERROR, writer.toString(), null, -1, -1));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:GroovyCompilerWrapper.java

示例3: testFileNameInStackTrace

import groovy.lang.GroovyRuntimeException; //导入依赖的package包/类
private void testFileNameInStackTrace(final String target, final String fileNamePattern) {
    try {
        project.executeTarget(target);
        fail();
    }
    catch (final BuildException e) {
        assertEquals(BuildException.class, e.getClass());
        final Throwable cause = e.getCause();
        assertTrue(cause instanceof GroovyRuntimeException);

        final Writer sw = new StringBuilderWriter();
        cause.printStackTrace(new PrintWriter(sw));
        
        final String stackTrace = sw.toString();
        final Pattern pattern = Pattern.compile(fileNamePattern);
        assertTrue("Does >" + stackTrace + "< contain >" + fileNamePattern + "<?", 
                pattern.matcher(stackTrace).find());
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:20,代码来源:GroovyTest.java

示例4: shouldFail

import groovy.lang.GroovyRuntimeException; //导入依赖的package包/类
/**
 * Asserts that the given code closure fails when it is evaluated
 *
 * @param code the code expected to throw the exception
 * @return the message of the thrown Throwable
 */
public static Throwable shouldFail(Closure code) {
    boolean failed = false;
    Throwable th = null;
    try {
        code.call();
    } catch (GroovyRuntimeException gre) {
        failed = true;
        th = ScriptBytecodeAdapter.unwrap(gre);
    } catch (Throwable e) {
        failed = true;
        th = e;
    }
    assertTrue("Closure " + code + " should have failed", failed);
    return th;
}
 
开发者ID:apache,项目名称:groovy,代码行数:22,代码来源:GroovyAssert.java

示例5: shouldFail

import groovy.lang.GroovyRuntimeException; //导入依赖的package包/类
/**
 * Asserts that the given code closure fails when it is evaluated
 *
 * @param code the code expected to fail
 * @return the caught exception
 */
public static Throwable shouldFail(Closure code) {
    boolean failed = false;
    Throwable th = null;
    try {
        code.call();
    } catch (GroovyRuntimeException gre) {
        failed = true;
        th = ScriptBytecodeAdapter.unwrap(gre);
    } catch (Throwable e) {
        failed = true;
        th = e;
    }
    assertTrue("Closure " + code + " should have failed", failed);
    return th;
}
 
开发者ID:apache,项目名称:groovy,代码行数:22,代码来源:GroovyAssert.java

示例6: visit

import groovy.lang.GroovyRuntimeException; //导入依赖的package包/类
private static void visit(Closure closure, CodeVisitorSupport visitor) {
    if (closure != null) {
        ClassNode classNode = closure.getMetaClass().getClassNode();
        if (classNode == null) {
            throw new GroovyRuntimeException(
                    "DataSet unable to evaluate expression. AST not available for closure: " + closure.getMetaClass().getTheClass().getName() +
                            ". Is the source code on the classpath?");
        }
        List methods = classNode.getDeclaredMethods("doCall");
        if (!methods.isEmpty()) {
            MethodNode method = (MethodNode) methods.get(0);
            if (method != null) {
                Statement statement = method.getCode();
                if (statement != null) {
                    statement.visit(visitor);
                }
            }
        }
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:21,代码来源:DataSet.java

示例7: run

import groovy.lang.GroovyRuntimeException; //导入依赖的package包/类
/**
 * Utility method to run a TestNG test.
 *
 * @param scriptClass the class we want to run as a test
 * @param loader the class loader to use
 * @return the result of running the test
 */
@Override
public Object run(Class<?> scriptClass, GroovyClassLoader loader) {
    try {
        Class<?> testNGClass = loader.loadClass("org.testng.TestNG");
        Object testng = InvokerHelper.invokeConstructorOf(testNGClass, new Object[]{});
        InvokerHelper.invokeMethod(testng, "setTestClasses", new Object[]{scriptClass});
        Class<?> listenerClass = loader.loadClass("org.testng.TestListenerAdapter");
        Object listener = InvokerHelper.invokeConstructorOf(listenerClass, new Object[]{});
        InvokerHelper.invokeMethod(testng, "addListener", new Object[]{listener});
        if (OUTPUT_DIRECTORY != null) {
            InvokerHelper.invokeMethod(testng, "setOutputDirectory", new Object[]{OUTPUT_DIRECTORY});
        }
        return InvokerHelper.invokeMethod(testng, "run", new Object[]{});
    } catch (ClassNotFoundException e) {
        throw new GroovyRuntimeException("Error running TestNG test.", e);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:25,代码来源:TestNgRunner.java

示例8: run

import groovy.lang.GroovyRuntimeException; //导入依赖的package包/类
/**
 * Run the specified class extending TestCase as a unit test.
 * This is done through reflection, to avoid adding a dependency to the JUnit framework.
 * Otherwise, developers embedding Groovy and using GroovyShell to load/parse/compile
 * groovy scripts and classes would have to add another dependency on their classpath.
 *
 * @param scriptClass the class to be run as a unit test
 * @param loader the class loader
 */
@Override
public Object run(Class<?> scriptClass, GroovyClassLoader loader) {
    try {
        Class<?> junitCoreClass = loader.loadClass("org.junit.runner.JUnitCore");
        Object result = InvokerHelper.invokeStaticMethod(junitCoreClass,
                "runClasses", new Object[]{scriptClass});
        System.out.print("JUnit 4 Runner, Tests: " + InvokerHelper.getProperty(result, "runCount"));
        System.out.print(", Failures: " + InvokerHelper.getProperty(result, "failureCount"));
        System.out.println(", Time: " + InvokerHelper.getProperty(result, "runTime"));
        List<?> failures = (List<?>) InvokerHelper.getProperty(result, "failures");
        for (Object f : failures) {
            System.out.println("Test Failure: " + InvokerHelper.getProperty(f, "description"));
            System.out.println(InvokerHelper.getProperty(f, "trace"));
        }
        return result;
    } catch (ClassNotFoundException e) {
        throw new GroovyRuntimeException("Error running JUnit 4 test.", e);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:29,代码来源:DefaultRunners.java

示例9: dispatch

import groovy.lang.GroovyRuntimeException; //导入依赖的package包/类
/**
*  Runs the report once all initialization is complete.
*/

protected void dispatch( Throwable object, boolean child )
{
    if( object instanceof CompilationFailedException )
    {
        report( (CompilationFailedException)object, child );
    }
    else if( object instanceof GroovyExceptionInterface )
    {
        report( (GroovyExceptionInterface)object, child );
    }
    else if( object instanceof GroovyRuntimeException )
    {
        report( (GroovyRuntimeException)object, child );
    }
    else if( object instanceof Exception )
    {
        report( (Exception)object, child );
    }
    else
    {
        report( object, child );
    }

}
 
开发者ID:apache,项目名称:groovy,代码行数:29,代码来源:ErrorReporter.java

示例10: parseClass

import groovy.lang.GroovyRuntimeException; //导入依赖的package包/类
/**
 * Loads the URL contents and parses them with ASM, producing a {@link ClassStub} object representing the structure of
 * the corresponding class file. Stubs are cached and reused if queried several times with equal URLs.
 *
 * @param url an URL from a class loader, most likely a file system file or a JAR entry.
 * @return the class stub
 * @throws IOException if reading from this URL is impossible
 */
public static ClassStub parseClass(URL url) throws IOException {
    URI uri;
    try {
        uri = url.toURI();
    } catch (URISyntaxException e) {
        throw new GroovyRuntimeException(e);
    }

    SoftReference<ClassStub> ref = StubCache.map.get(uri);
    ClassStub stub = ref == null ? null : ref.get();
    if (stub == null) {
        DecompilingVisitor visitor = new DecompilingVisitor();
        InputStream stream = url.openStream();
        try {
            new ClassReader(new BufferedInputStream(stream)).accept(visitor, ClassReader.SKIP_FRAMES);
        } finally {
            stream.close();
        }
        stub = visitor.result;
        StubCache.map.put(uri, new SoftReference<ClassStub>(stub));
    }
    return stub;
}
 
开发者ID:apache,项目名称:groovy,代码行数:32,代码来源:AsmDecompiler.java

示例11: realRunJUnit4Test

import groovy.lang.GroovyRuntimeException; //导入依赖的package包/类
/**
 * Utility method to run a JUnit4 test.
 *
 * @param scriptClass the class we want to run as a test
 * @return the result of running the test
 */
static Object realRunJUnit4Test(Class scriptClass, GroovyClassLoader loader) {
    // invoke through reflection to eliminate mandatory JUnit 4 jar dependency

    try {
        Class junitCoreClass = loader.loadClass("org.junit.runner.JUnitCore");
        Object result = InvokerHelper.invokeStaticMethod(junitCoreClass,
                "runClasses", new Object[]{scriptClass});
        System.out.print("JUnit 4 Runner, Tests: " + InvokerHelper.getProperty(result, "runCount"));
        System.out.print(", Failures: " + InvokerHelper.getProperty(result, "failureCount"));
        System.out.println(", Time: " + InvokerHelper.getProperty(result, "runTime"));
        List failures = (List) InvokerHelper.getProperty(result, "failures");
        for (int i = 0; i < failures.size(); i++) {
            Object f = failures.get(i);
            System.out.println("Test Failure: " + InvokerHelper.getProperty(f, "description"));
            System.out.println(InvokerHelper.getProperty(f, "trace"));
        }
        return result;
    } catch (ClassNotFoundException e) {
        throw new GroovyRuntimeException("Error running JUnit 4 test.", e);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:28,代码来源:JUnit4Utils.java

示例12: compare

import groovy.lang.GroovyRuntimeException; //导入依赖的package包/类
public int compare(T o1, T o2) {
    try {
        return DefaultTypeTransformation.compareTo(o1, o2);
    } catch (ClassCastException cce) {
        /* ignore */
    } catch (GroovyRuntimeException gre) {
        /* ignore */
    } catch (IllegalArgumentException iae) {
        /* ignore */
    }
    // since the object does not have a valid compareTo method
    // we compare using the hashcodes. null cases are handled by
    // DefaultTypeTransformation.compareTo
    // This is not exactly a mathematical valid approach, since we compare object
    // that cannot be compared. To avoid strange side effects we do a pseudo order
    // using hashcodes, but without equality. Since then an x and y with the same
    // hashcodes will behave different depending on if we compare x with y or
    // x with y, the result might be unstable as well. Setting x and y to equal
    // may mean the removal of x or y in a sorting operation, which we don't want.
    int x1 = o1.hashCode();
    int x2 = o2.hashCode();
    if (x1 == x2 && o1.equals(o2)) return 0;
    if (x1 > x2) return 1;
    return -1;
}
 
开发者ID:apache,项目名称:groovy,代码行数:26,代码来源:NumberAwareComparator.java

示例13: call

import groovy.lang.GroovyRuntimeException; //导入依赖的package包/类
public final Object call(Object receiver, Object[] args) throws Throwable {
    if (checkCall(receiver)) {
        try {
            try {
                return metaClass.invokeMethod(receiver, name, args);
            } catch (MissingMethodException e) {
                if (e instanceof MissingMethodExecutionFailed) {
                    throw (MissingMethodException)e.getCause();
                } else if (receiver.getClass() == e.getType() && e.getMethod().equals(name)) {
                    // in case there's nothing else, invoke the object's own invokeMethod()
                    return ((GroovyObject)receiver).invokeMethod(name, args);
                } else {
                    throw e;
                }
            }
        } catch (GroovyRuntimeException gre) {
            throw ScriptBytecodeAdapter.unwrap(gre);
        }
    } else {
      return CallSiteArray.defaultCall(this, receiver, args);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:23,代码来源:PogoMetaClassSite.java

示例14: callCurrent

import groovy.lang.GroovyRuntimeException; //导入依赖的package包/类
public final Object callCurrent(GroovyObject receiver, Object[] args) throws Throwable {
    if (checkCall(receiver)) {
        try {
            try {
                return metaClass.invokeMethod(array.owner, receiver, name, args, false, true);
            } catch (MissingMethodException e) {
                if (e instanceof MissingMethodExecutionFailed) {
                    throw (MissingMethodException)e.getCause();
                } else if (receiver.getClass() == e.getType() && e.getMethod().equals(name)) {
                    // in case there's nothing else, invoke the object's own invokeMethod()
                    return ((GroovyObject)receiver).invokeMethod(name, args);
                } else {
                    throw e;
                }
            }
        } catch (GroovyRuntimeException gre) {
            throw ScriptBytecodeAdapter.unwrap(gre);
        }
    } else {
      return CallSiteArray.defaultCallCurrent(this, receiver, args);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:23,代码来源:PogoMetaClassSite.java

示例15: asType

import groovy.lang.GroovyRuntimeException; //导入依赖的package包/类
/**
 * Coerces this map to the given type, using the map's keys as the public
 * method names, and values as the implementation.  Typically the value
 * would be a closure which behaves like the method implementation.
 *
 * @param map   this map
 * @param clazz the target type
 * @return a Proxy of the given type, which defers calls to this map's elements.
 * @since 1.0
 */
@SuppressWarnings("unchecked")
public static <T> T asType(Map map, Class<T> clazz) {
    if (!(clazz.isInstance(map)) && clazz.isInterface() && !Traits.isTrait(clazz)) {
        return (T) Proxy.newProxyInstance(
                clazz.getClassLoader(),
                new Class[]{clazz},
                new ConvertedMap(map));
    }
    try {
        return asType((Object) map, clazz);
    } catch (GroovyCastException ce) {
        try {
            return (T) ProxyGenerator.INSTANCE.instantiateAggregateFromBaseClass(map, clazz);
        } catch (GroovyRuntimeException cause) {
            throw new GroovyCastException("Error casting map to " + clazz.getName() +
                    ", Reason: " + cause.getMessage());
        }
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:30,代码来源:DefaultGroovyMethods.java


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