Skip to content

Commit 4049901

Browse files
committed
Add missing javadoc
1 parent d9e6ae1 commit 4049901

16 files changed

Lines changed: 454 additions & 3 deletions

src/main/java/org/codehaus/groovy/reflection/stdclasses/ArrayCachedClass.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,30 @@
2525

2626
import java.lang.reflect.Array;
2727

28+
/**
29+
* Provides optimized reflection caching for Java arrays.
30+
* Handles type coercion including conversion of boxed arrays to primitive arrays,
31+
* and {@link GString} arrays to {@link String} arrays.
32+
*/
2833
public class ArrayCachedClass extends CachedClass {
34+
/**
35+
* Constructs a cached class representation for the given array class.
36+
*
37+
* @param klazz the array class to cache
38+
* @param classInfo the class information associated with this cached class
39+
*/
2940
public ArrayCachedClass(Class klazz, ClassInfo classInfo) {
3041
super(klazz, classInfo);
3142
}
3243

44+
/**
45+
* Coerces the given argument to the appropriate array type.
46+
* Converts boxed arrays to primitive arrays if needed, and
47+
* {@link GString} arrays to {@link String} arrays.
48+
*
49+
* @param argument the argument to coerce
50+
* @return the coerced argument, or the original argument if no coercion is needed
51+
*/
3352
@Override
3453
public Object coerceArgument(Object argument) {
3554
Class argumentClass = argument.getClass();

src/main/java/org/codehaus/groovy/reflection/stdclasses/BigDecimalCachedClass.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,38 @@
2323

2424
import java.math.BigDecimal;
2525

26+
/**
27+
* Provides optimized reflection caching for {@link java.math.BigDecimal}.
28+
* Coerces numeric arguments to {@link BigDecimal} for type-safe method invocation.
29+
*/
2630
public class BigDecimalCachedClass extends DoubleCachedClass {
31+
/**
32+
* Constructs a cached class representation for {@link BigDecimal}.
33+
*
34+
* @param klazz the {@link BigDecimal} class to cache
35+
* @param classInfo the class information associated with this cached class
36+
*/
2737
public BigDecimalCachedClass(Class klazz, ClassInfo classInfo) {
2838
super(klazz, classInfo, true);
2939
}
3040

41+
/**
42+
* Checks if the given argument is directly assignable to {@link BigDecimal}.
43+
*
44+
* @param argument the argument to check
45+
* @return {@code true} if the argument is an instance of {@link BigDecimal}, {@code false} otherwise
46+
*/
3147
@Override
3248
public boolean isDirectlyAssignable(Object argument) {
3349
return argument instanceof BigDecimal;
3450
}
3551

52+
/**
53+
* Coerces the given numeric argument to {@link BigDecimal}.
54+
*
55+
* @param argument the argument to coerce
56+
* @return the argument as a {@link BigDecimal}, or the original argument if not a number
57+
*/
3658
@Override
3759
public Object coerceArgument(Object argument) {
3860
if (argument instanceof Number) {

src/main/java/org/codehaus/groovy/reflection/stdclasses/BigIntegerCachedClass.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,39 @@
2222

2323
import java.math.BigInteger;
2424

25+
/**
26+
* Provides optimized reflection caching for {@link java.math.BigInteger}.
27+
* Coerces integral and big numeric types to {@link BigInteger} for type-safe method invocation.
28+
*/
2529
public class BigIntegerCachedClass extends NumberCachedClass {
30+
/**
31+
* Constructs a cached class representation for {@link BigInteger}.
32+
*
33+
* @param klazz the {@link BigInteger} class to cache
34+
* @param classInfo the class information associated with this cached class
35+
*/
2636
public BigIntegerCachedClass(Class klazz, ClassInfo classInfo) {
2737
super(klazz, classInfo);
2838
}
2939

40+
/**
41+
* Checks if the given argument is directly assignable to {@link BigInteger}.
42+
*
43+
* @param argument the argument to check
44+
* @return {@code true} if the argument is an instance of {@link BigInteger}, {@code false} otherwise
45+
*/
3046
@Override
3147
public boolean isDirectlyAssignable(Object argument) {
3248
return argument instanceof BigInteger;
3349
}
3450

51+
/**
52+
* Determines if the given class can be transformed to {@link BigInteger}.
53+
* Accepts integral types, boxed integral types, and other big numeric types.
54+
*
55+
* @param classToTransformFrom the source class to check
56+
* @return {@code true} if the class can be transformed to {@link BigInteger}, {@code false} otherwise
57+
*/
3558
@Override
3659
public boolean isAssignableFrom(Class classToTransformFrom) {
3760
return classToTransformFrom == null

src/main/java/org/codehaus/groovy/reflection/stdclasses/BooleanCachedClass.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,42 @@
2121
import org.codehaus.groovy.reflection.CachedClass;
2222
import org.codehaus.groovy.reflection.ClassInfo;
2323

24+
/**
25+
* Provides optimized reflection caching for {@code boolean} and {@link java.lang.Boolean}.
26+
* Optionally allows {@code null} values for the boxed {@link Boolean} class variant.
27+
*/
2428
public class BooleanCachedClass extends CachedClass {
2529
private final boolean allowNull;
30+
31+
/**
32+
* Constructs a cached class representation for the given boolean class.
33+
*
34+
* @param klazz the boolean class to cache (either {@code boolean.class} or {@link Boolean}.class)
35+
* @param classInfo the class information associated with this cached class
36+
* @param allowNull {@code true} to allow {@code null} values (for {@link Boolean}.class), {@code false} for primitive {@code boolean}
37+
*/
2638
public BooleanCachedClass(Class klazz, ClassInfo classInfo, boolean allowNull) {
2739
super(klazz, classInfo);
2840
this.allowNull = allowNull;
2941
}
3042

43+
/**
44+
* Checks if the given argument is directly assignable without type conversion.
45+
*
46+
* @param argument the argument to check
47+
* @return {@code true} if the argument is a {@link Boolean} instance, or {@code null} is allowed, {@code false} otherwise
48+
*/
3149
@Override
3250
public boolean isDirectlyAssignable(Object argument) {
3351
return (allowNull && argument == null) || argument instanceof Boolean;
3452
}
3553

54+
/**
55+
* Determines if the given class can be transformed to boolean/Boolean.
56+
*
57+
* @param classToTransformFrom the source class to check
58+
* @return {@code true} if the class can be transformed to boolean, {@code false} otherwise
59+
*/
3660
@Override
3761
public boolean isAssignableFrom(Class classToTransformFrom) {
3862
return (allowNull && classToTransformFrom == null)

src/main/java/org/codehaus/groovy/reflection/stdclasses/ByteCachedClass.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,32 @@
2020

2121
import org.codehaus.groovy.reflection.ClassInfo;
2222

23+
/**
24+
* Provides optimized reflection caching for {@code byte} and {@link java.lang.Byte}.
25+
* Coerces numeric arguments to byte values for type-safe method invocation.
26+
* Optionally allows {@code null} values for the boxed {@link Byte} class variant.
27+
*/
2328
public class ByteCachedClass extends NumberCachedClass {
2429
private final boolean allowNull;
30+
31+
/**
32+
* Constructs a cached class representation for the given byte class.
33+
*
34+
* @param klazz the byte class to cache (either {@code byte.class} or {@link Byte}.class)
35+
* @param classInfo the class information associated with this cached class
36+
* @param allowNull {@code true} to allow {@code null} values (for {@link Byte}.class), {@code false} for primitive {@code byte}
37+
*/
2538
public ByteCachedClass(Class klazz, ClassInfo classInfo, boolean allowNull) {
2639
super(klazz, classInfo);
2740
this.allowNull = allowNull;
2841
}
2942

43+
/**
44+
* Coerces the given numeric argument to a byte value.
45+
*
46+
* @param argument the argument to coerce
47+
* @return the argument as a {@code byte}, or the original argument if not a number
48+
*/
3049
@Override
3150
public Object coerceArgument(Object argument) {
3251
if (argument instanceof Byte) {
@@ -39,11 +58,23 @@ public Object coerceArgument(Object argument) {
3958
return argument;
4059
}
4160

61+
/**
62+
* Checks if the given argument is directly assignable without type conversion.
63+
*
64+
* @param argument the argument to check
65+
* @return {@code true} if the argument is a {@link Byte} instance, or {@code null} is allowed, {@code false} otherwise
66+
*/
4267
@Override
4368
public boolean isDirectlyAssignable(Object argument) {
4469
return (allowNull && argument == null) || argument instanceof Byte;
4570
}
4671

72+
/**
73+
* Determines if the given class can be transformed to byte/Byte.
74+
*
75+
* @param classToTransformFrom the source class to check
76+
* @return {@code true} if the class can be transformed to byte, {@code false} otherwise
77+
*/
4778
@Override
4879
public boolean isAssignableFrom(Class classToTransformFrom) {
4980
return (allowNull && classToTransformFrom == null)

src/main/java/org/codehaus/groovy/reflection/stdclasses/CachedClosureClass.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,21 @@
2222
import org.codehaus.groovy.reflection.CachedMethod;
2323
import org.codehaus.groovy.reflection.ClassInfo;
2424

25+
/**
26+
* Provides optimized reflection caching for Groovy {@link groovy.lang.Closure} classes.
27+
* Analyzes closure {@code doCall} methods to determine parameter types and maximum parameters.
28+
*/
2529
public class CachedClosureClass extends CachedClass {
2630
private final Class[] parameterTypes;
2731
private final int maximumNumberOfParameters;
2832

33+
/**
34+
* Constructs a cached class representation for a closure class.
35+
* Inspects the closure's {@code doCall} methods to extract parameter metadata.
36+
*
37+
* @param klazz the closure class to cache
38+
* @param classInfo the class information associated with this cached class
39+
*/
2940
public CachedClosureClass(Class klazz, ClassInfo classInfo) {
3041
super(klazz, classInfo);
3142

@@ -51,10 +62,20 @@ public CachedClosureClass(Class klazz, ClassInfo classInfo) {
5162
this.parameterTypes = parameterTypes;
5263
}
5364

65+
/**
66+
* Returns the parameter types of the closure's {@code doCall} method with maximum parameters.
67+
*
68+
* @return the parameter types array, or {@code null} if no {@code doCall} method was found
69+
*/
5470
public Class[] getParameterTypes() {
5571
return parameterTypes;
5672
}
5773

74+
/**
75+
* Returns the maximum number of parameters accepted by the closure's {@code doCall} methods.
76+
*
77+
* @return the maximum number of parameters, or {@code 0} if no {@code doCall} method was found
78+
*/
5879
public int getMaximumNumberOfParameters() {
5980
return maximumNumberOfParameters;
6081
}

src/main/java/org/codehaus/groovy/reflection/stdclasses/CachedSAMClass.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,49 @@
3939
import java.util.Set;
4040
import java.util.stream.Collectors;
4141

42+
/**
43+
* Provides optimized reflection caching for Single Abstract Method (SAM) types.
44+
* Converts {@link Closure} arguments to SAM interface implementations via dynamic proxies or aggregates.
45+
*/
4246
public class CachedSAMClass extends CachedClass {
4347

4448
private final Method method;
4549

50+
/**
51+
* Constructs a cached class representation for a SAM type.
52+
* Locates and caches the single abstract method of the class.
53+
*
54+
* @param clazz the SAM type to cache
55+
* @param classInfo the class information associated with this cached class
56+
* @throws GroovyBugError if the class does not have exactly one abstract method
57+
*/
4658
public CachedSAMClass(Class clazz, ClassInfo classInfo) {
4759
super(clazz, classInfo);
4860
method = getSAMMethod(clazz);
4961
if (method == null) throw new GroovyBugError("assigned method should not have been null!");
5062
}
5163

64+
/**
65+
* Determines if the given class is assignable to this SAM type.
66+
* Accepts {@code null}, {@link Closure} instances, and instances already assignable to the SAM type.
67+
*
68+
* @param argument the class to check
69+
* @return {@code true} if the class can be assigned to this SAM type, {@code false} otherwise
70+
*/
5271
@Override
5372
public boolean isAssignableFrom(Class argument) {
5473
return argument == null
5574
|| Closure.class.isAssignableFrom(argument)
5675
|| getTheClass().isAssignableFrom(argument);
5776
}
5877

78+
/**
79+
* Coerces the given argument to this SAM type.
80+
* Converts {@link Closure} arguments to SAM interface implementations via dynamic proxies.
81+
*
82+
* @param argument the argument to coerce
83+
* @return the coerced SAM instance, or the original argument if already compatible
84+
*/
5985
@Override
6086
public Object coerceArgument(Object argument) {
6187
if (argument instanceof Closure) {
@@ -73,10 +99,30 @@ public Object coerceArgument(Object argument) {
7399
private static final int ABSTRACT_STATIC_PRIVATE = Modifier.ABSTRACT | Modifier.STATIC | Modifier.PRIVATE;
74100
private static final Set<String> OBJECT_METHOD_NAMES = Arrays.stream(Object.class.getMethods()).map(Method::getName).collect(Collectors.toUnmodifiableSet());
75101

102+
/**
103+
* Coerces a closure to a SAM interface implementation.
104+
* Automatically detects whether the SAM type is an interface or class.
105+
*
106+
* @param argument the closure to convert
107+
* @param method the single abstract method of the SAM type
108+
* @param clazz the SAM class or interface to coerce to
109+
* @return a dynamic proxy or aggregate instance implementing the SAM type
110+
*/
76111
public static Object coerceToSAM(Closure argument, Method method, Class clazz) {
77112
return coerceToSAM(argument, method, clazz, clazz.isInterface());
78113
}
79114

115+
/**
116+
* Coerces a closure to a SAM interface or class implementation.
117+
* For interfaces, uses dynamic proxies or trait-aware aggregates.
118+
* For classes, uses proxy generators to instantiate from base class.
119+
*
120+
* @param argument the closure to convert
121+
* @param method the single abstract method of the SAM type
122+
* @param clazz the SAM class or interface to coerce to
123+
* @param isInterface {@code true} if the SAM type is an interface, {@code false} for a class
124+
* @return a dynamic proxy or aggregate instance implementing the SAM type
125+
*/
80126
public static Object coerceToSAM(Closure argument, Method method, Class clazz, boolean isInterface) {
81127
if (argument != null && clazz.isAssignableFrom(argument.getClass())) {
82128
return argument;

src/main/java/org/codehaus/groovy/reflection/stdclasses/CharacterCachedClass.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,42 @@
2121
import org.codehaus.groovy.reflection.CachedClass;
2222
import org.codehaus.groovy.reflection.ClassInfo;
2323

24+
/**
25+
* Provides optimized reflection caching for {@code char} and {@link java.lang.Character}.
26+
* Optionally allows {@code null} values for the boxed {@link Character} class variant.
27+
*/
2428
public class CharacterCachedClass extends CachedClass {
2529
private final boolean allowNull;
2630

31+
/**
32+
* Constructs a cached class representation for the given character class.
33+
*
34+
* @param klazz the character class to cache (either {@code char.class} or {@link Character}.class)
35+
* @param classInfo the class information associated with this cached class
36+
* @param allowNull {@code true} to allow {@code null} values (for {@link Character}.class), {@code false} for primitive {@code char}
37+
*/
2738
public CharacterCachedClass(Class klazz, ClassInfo classInfo, boolean allowNull) {
2839
super(klazz, classInfo);
2940
this.allowNull = allowNull;
3041
}
3142

43+
/**
44+
* Checks if the given argument is directly assignable without type conversion.
45+
*
46+
* @param argument the argument to check
47+
* @return {@code true} if the argument is a {@link Character} instance, or {@code null} is allowed, {@code false} otherwise
48+
*/
3249
@Override
3350
public boolean isDirectlyAssignable(Object argument) {
3451
return (allowNull && argument == null) || argument instanceof Character;
3552
}
3653

54+
/**
55+
* Determines if the given class can be transformed to char/Character.
56+
*
57+
* @param classToTransformFrom the source class to check
58+
* @return {@code true} if the class can be transformed to char, {@code false} otherwise
59+
*/
3760
@Override
3861
public boolean isAssignableFrom(Class classToTransformFrom) {
3962
return (allowNull && classToTransformFrom == null)

0 commit comments

Comments
 (0)