private static RuleMetadata getRuleMetadata(Closure<?> closure) { RuleMetadata ruleMetadata = closure.getClass().getAnnotation(RuleMetadata.class); if (ruleMetadata == null) { throw new IllegalStateException( String.format( "Expected %s annotation to be used on the argument closure.", RuleMetadata.class.getName())); } return ruleMetadata; }
@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); } }
public static boolean isTransformedBlock(Closure<?> closure) { Class<?> closureClass = closure.getClass(); RulesBlock annotation = closureClass.getAnnotation(RulesBlock.class); return annotation != null; }