Skip to content

Commit fbd7427

Browse files
committed
Add comments
1 parent b8f68af commit fbd7427

4 files changed

Lines changed: 44 additions & 24 deletions

File tree

fixture-monkey/src/test/java/com/navercorp/fixturemonkey/test/FixtureMonkeyOptionsAdditionalTestSpecs.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@
4646
import com.navercorp.fixturemonkey.api.introspector.ArbitraryIntrospectorResult;
4747
import com.navercorp.fixturemonkey.api.matcher.AssignableTypeMatcher;
4848
import com.navercorp.fixturemonkey.api.matcher.Matcher;
49-
import com.navercorp.fixturemonkey.api.property.ElementProperty;
49+
import com.navercorp.fixturemonkey.api.property.DefaultContainerElementProperty;
5050
import com.navercorp.fixturemonkey.api.property.Property;
51+
import com.navercorp.fixturemonkey.api.property.TypeParameterProperty;
5152
import com.navercorp.fixturemonkey.api.type.TypeReference;
5253
import com.navercorp.fixturemonkey.buildergroup.ArbitraryBuilderGroup;
5354
import com.navercorp.fixturemonkey.customizer.InnerSpec;
@@ -191,8 +192,10 @@ public ContainerProperty generate(ContainerPropertyGeneratorContext context) {
191192
com.navercorp.objectfarm.api.type.JvmType firstElementType = elementTypes.get(0);
192193
com.navercorp.objectfarm.api.type.JvmType secondElementType = elementTypes.get(1);
193194
List<com.navercorp.fixturemonkey.api.property.Property> elementProperties = new ArrayList<>();
194-
elementProperties.add(new ElementProperty(property, firstElementType, 0, 0));
195-
elementProperties.add(new ElementProperty(property, secondElementType, 1, 1));
195+
elementProperties.add(
196+
new DefaultContainerElementProperty(property, new TypeParameterProperty(firstElementType), 0, 0));
197+
elementProperties.add(
198+
new DefaultContainerElementProperty(property, new TypeParameterProperty(secondElementType), 1, 1));
196199

197200
return new ContainerProperty(elementProperties, new ArbitraryContainerInfo(1, 1));
198201
}

fixture-monkey/src/test/java/com/navercorp/fixturemonkey/test/ValueProjectionAssembleSpecs.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
import com.navercorp.fixturemonkey.api.introspector.ArbitraryIntrospectorResult;
4343
import com.navercorp.fixturemonkey.api.matcher.AssignableTypeMatcher;
4444
import com.navercorp.fixturemonkey.api.matcher.Matcher;
45-
import com.navercorp.fixturemonkey.api.property.ElementProperty;
45+
import com.navercorp.fixturemonkey.api.property.DefaultContainerElementProperty;
46+
import com.navercorp.fixturemonkey.api.property.TypeParameterProperty;
4647

4748
public class ValueProjectionAssembleSpecs {
4849

@@ -1141,8 +1142,10 @@ public ContainerProperty generate(ContainerPropertyGeneratorContext context) {
11411142
com.navercorp.objectfarm.api.type.JvmType firstElementType = elementTypes.get(0);
11421143
com.navercorp.objectfarm.api.type.JvmType secondElementType = elementTypes.get(1);
11431144
List<com.navercorp.fixturemonkey.api.property.Property> elementProperties = new ArrayList<>();
1144-
elementProperties.add(new ElementProperty(property, firstElementType, 0, 0));
1145-
elementProperties.add(new ElementProperty(property, secondElementType, 1, 1));
1145+
elementProperties.add(
1146+
new DefaultContainerElementProperty(property, new TypeParameterProperty(firstElementType), 0, 0));
1147+
elementProperties.add(
1148+
new DefaultContainerElementProperty(property, new TypeParameterProperty(secondElementType), 1, 1));
11461149

11471150
return new ContainerProperty(elementProperties, new ArbitraryContainerInfo(1, 1));
11481151
}

object-farm-api/src/main/java/com/navercorp/objectfarm/api/tree/JvmNodeCandidateTree.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -377,11 +377,11 @@ private boolean isContainerType(JvmType jvmType) {
377377
if (isCollectionOrMap) {
378378
return Types.isJavaType(rawType);
379379
}
380-
// For non-Collection/Map types, defer to registered JvmContainerNodeGenerators
381-
// (e.g., Pair, Triple). Without this, custom container types' children would be
382-
// generated via PropertyGenerator in the candidate tree, which may produce an
383-
// unordered result for Kotlin reflection. Collection/Map user classes are
384-
// intentionally excluded above so their declared fields are processed normally.
380+
// For non-Collection/Map types, defer to the container types registered with
381+
// jvmNodeContext (e.g., Pair, Triple). Without this, such custom container types would be
382+
// expanded as regular objects in the candidate tree, which may produce an unordered
383+
// result for Kotlin reflection. Collection/Map user classes are intentionally excluded
384+
// above so their declared fields are processed normally.
385385
return jvmNodeContext.isContainerType(jvmType);
386386
}
387387

object-farm-api/src/main/java/com/navercorp/objectfarm/api/type/ReflectiveJvmType.java

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import java.lang.annotation.Annotation;
2222
import java.lang.reflect.AnnotatedType;
23-
import java.lang.reflect.Array;
2423
import java.lang.reflect.GenericArrayType;
2524
import java.lang.reflect.Type;
2625
import java.util.Arrays;
@@ -53,14 +52,29 @@ public final class ReflectiveJvmType implements JvmType {
5352
private final Boolean nullable;
5453
private int cachedHashCode;
5554

55+
/**
56+
* Use for a bare raw class with no generics, annotations, or nullability information.
57+
* This is the common case for constants and simple value types (e.g. {@code String.class}).
58+
*/
5659
public ReflectiveJvmType(Class<?> rawType) {
5760
this(rawType, Collections.emptyList(), Collections.emptyList());
5861
}
5962

63+
/**
64+
* Use when the raw class plus its generics and annotations are known but nullability is not
65+
* (nullability defaults to {@code null}, meaning "unknown").
66+
* The component type is derived automatically: for an array raw type, {@code typeVariables}
67+
* are treated as the component type's generics.
68+
*/
6069
public ReflectiveJvmType(Class<?> rawType, List<? extends JvmType> typeVariables, List<Annotation> annotations) {
6170
this(rawType, typeVariables, annotations, deriveComponentType(rawType, typeVariables), null);
6271
}
6372

73+
/**
74+
* Use when the raw class, generics, annotations, and an explicit nullability are all known.
75+
* The component type is derived automatically, as in
76+
* {@link #ReflectiveJvmType(Class, List, List)}.
77+
*/
6478
public ReflectiveJvmType(
6579
Class<?> rawType,
6680
List<? extends JvmType> typeVariables,
@@ -70,6 +84,12 @@ public ReflectiveJvmType(
7084
this(rawType, typeVariables, annotations, deriveComponentType(rawType, typeVariables), nullable);
7185
}
7286

87+
/**
88+
* Canonical constructor that all other {@code Class}-based constructors delegate to.
89+
* Use when the component type must be supplied explicitly rather than derived &mdash; for
90+
* example, to preserve a container or array element type taken from an existing
91+
* {@link JvmType} (see {@code SingleElementProperty}).
92+
*/
7393
public ReflectiveJvmType(
7494
Class<?> rawType,
7595
List<? extends JvmType> typeVariables,
@@ -84,11 +104,16 @@ public ReflectiveJvmType(
84104
this.nullable = nullable;
85105
}
86106

107+
/**
108+
* Use when building from a reflection-backed type reference. Resolves wildcards to their
109+
* upper bound and derives the raw type, generics, annotations, and component type from the
110+
* JDK {@link AnnotatedType}.
111+
*/
87112
public ReflectiveJvmType(ObjectTypeReference<?> typeReference) {
88113
AnnotatedType originalType = typeReference.getAnnotatedType();
89114
// Resolve wildcard types to their upper bound
90115
AnnotatedType resolvedType = Types.resolveWildcardType(originalType);
91-
this.rawType = resolveRawType(resolvedType);
116+
this.rawType = Types.getActualType(resolvedType);
92117
this.typeVariables = Types.getGenericsTypes(resolvedType).stream()
93118
.map(annotatedType -> new ReflectiveJvmType(Types.toTypeReference(annotatedType)))
94119
.collect(Collectors.toList());
@@ -98,17 +123,6 @@ public ReflectiveJvmType(ObjectTypeReference<?> typeReference) {
98123
this.nullable = null;
99124
}
100125

101-
private static Class<?> resolveRawType(AnnotatedType annotatedType) {
102-
Type type = annotatedType.getType();
103-
if (type instanceof GenericArrayType) {
104-
// For GenericArrayType, we need the array class, not the component class
105-
GenericArrayType genericArrayType = (GenericArrayType)type;
106-
Class<?> componentClass = Types.getActualType(genericArrayType.getGenericComponentType());
107-
return Array.newInstance(componentClass, 0).getClass();
108-
}
109-
return Types.getActualType(annotatedType);
110-
}
111-
112126
@Nullable
113127
private static JvmType resolveComponentType(AnnotatedType annotatedType, Class<?> rawType) {
114128
Type type = annotatedType.getType();

0 commit comments

Comments
 (0)