Class CachedSAMClass
java.lang.Object
org.codehaus.groovy.reflection.CachedClass
org.codehaus.groovy.reflection.stdclasses.CachedSAMClass
Provides optimized reflection caching for Single Abstract Method (SAM) types.
Converts
Closure arguments to SAM interface implementations via dynamic proxies or aggregates.-
Nested Class Summary
Nested classes/interfaces inherited from class org.codehaus.groovy.reflection.CachedClass
CachedClass.CachedMethodComparatorByName, CachedClass.CachedMethodComparatorWithString -
Field Summary
Fields inherited from class org.codehaus.groovy.reflection.CachedClass
classInfo, EMPTY_ARRAY, isArray, isInterface, isNumber, isPrimitive, modifiers, mopMethods -
Constructor Summary
ConstructorsConstructorDescriptionCachedSAMClass(Class clazz, ClassInfo classInfo) Constructs a cached class representation for a SAM type. -
Method Summary
Modifier and TypeMethodDescriptioncoerceArgument(Object argument) Coerces the given argument to this SAM type.static ObjectcoerceToSAM(Closure argument, Method method, Class clazz) Coerces a closure to a SAM interface implementation.static ObjectcoerceToSAM(Closure argument, Method method, Class clazz, boolean isInterface) Coerces a closure to a SAM interface or class implementation.static MethodgetSAMMethod(Class<?> c) Finds the abstract method of given class, if it is a SAM type.booleanisAssignableFrom(Class argument) Determines if the given class is assignable to this SAM type.Methods inherited from class org.codehaus.groovy.reflection.CachedClass
addNewMopMethods, getCachedClass, getCachedSuperClass, getCallSiteLoader, getConstructors, getDeclaredInterfaces, getFields, getHierarchy, getInterfaces, getMethods, getModifiers, getName, getNewMetaMethods, getSuperClassDistance, getTheClass, getTypeDescription, hashCode, isDirectlyAssignable, isInterface, isPrimitive, isVoid, searchMethods, setNewMopMethods, toString
-
Constructor Details
-
CachedSAMClass
Constructs a cached class representation for a SAM type. Locates and caches the single abstract method of the class.- Parameters:
clazz- the SAM type to cacheclassInfo- the class information associated with this cached class- Throws:
GroovyBugError- if the class does not have exactly one abstract method
-
-
Method Details
-
isAssignableFrom
Determines if the given class is assignable to this SAM type. Acceptsnull,Closureinstances, and instances already assignable to the SAM type.- Overrides:
isAssignableFromin classCachedClass- Parameters:
argument- the class to check- Returns:
trueif the class can be assigned to this SAM type,falseotherwise
-
coerceArgument
Coerces the given argument to this SAM type. ConvertsClosurearguments to SAM interface implementations via dynamic proxies.- Overrides:
coerceArgumentin classCachedClass- Parameters:
argument- the argument to coerce- Returns:
- the coerced SAM instance, or the original argument if already compatible
-
coerceToSAM
Coerces a closure to a SAM interface implementation. Automatically detects whether the SAM type is an interface or class.- Parameters:
argument- the closure to convertmethod- the single abstract method of the SAM typeclazz- the SAM class or interface to coerce to- Returns:
- a dynamic proxy or aggregate instance implementing the SAM type
-
coerceToSAM
Coerces a closure to a SAM interface or class implementation. For interfaces, uses dynamic proxies or trait-aware aggregates. For classes, uses proxy generators to instantiate from base class.- Parameters:
argument- the closure to convertmethod- the single abstract method of the SAM typeclazz- the SAM class or interface to coerce toisInterface-trueif the SAM type is an interface,falsefor a class- Returns:
- a dynamic proxy or aggregate instance implementing the SAM type
-
getSAMMethod
Finds the abstract method of given class, if it is a SAM type.
-