Java Code Examples for org.codehaus.groovy.runtime.ScriptBytecodeAdapter#asType()

The following examples show how to use org.codehaus.groovy.runtime.ScriptBytecodeAdapter#asType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GroovyJavaMethods.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T> Callable<T> callableFromClosure(final Closure<T> job) {
    try {
        return (Callable<T>)ScriptBytecodeAdapter.asType(job, Callable.class);
    } catch (Throwable e) {
        throw Exceptions.propagate(e);
    }
}
 
Example 2
Source File: GroovyJavaMethods.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T> Callable<T> callableFromRunnable(final Runnable job) {
    try {
        if (safeGroovyIsCase(job, Callable.class)) {
            return (Callable<T>)ScriptBytecodeAdapter.asType(job, Callable.class);
        } else {
            return CallableFromRunnable.newInstance(job, null);
        }
    } catch (Throwable e) {
        throw Exceptions.propagate(e);
    }
}
 
Example 3
Source File: GroovyJavaMethods.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T> T fix(Object o) {
    try {
        if (safeGroovyIsCase(o, GString.class)) {
            return (T)ScriptBytecodeAdapter.asType(o, String.class);
        } else {
            return (T)o;
        }
    } catch (Throwable e) {
        throw Exceptions.propagate(e);
    }
}