Skip to content

Commit a0768e6

Browse files
committed
Add javadoc
1 parent 0dfcec5 commit a0768e6

22 files changed

+472
-80
lines changed

src/groovy/java/dev/lukebemish/codecextras/groovy/structured/reflective/implementation/GroovyReflectiveStructureCreator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public String value() {
104104
public Function<CreationContext, List<Discoverer>> make() {
105105
return context -> List.of(new Discoverer() {
106106
@Override
107-
public void modifyProperties(Class<?> clazz, Map<String, java.lang.reflect.Type> known) {
107+
public void modifyProperties(Class<?> clazz, Map<String, java.lang.reflect.Type> known, java.lang.reflect.Type[] parameters) {
108108
var metaClass = DefaultGroovyMethods.getMetaClass(clazz);
109109
if (Objects.equals(known.get("metaClass"), MetaClass.class)) {
110110
known.remove("metaClass");

src/main/java/dev/lukebemish/codecextras/structured/reflective/CreationContext.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
import java.util.Map;
1212
import java.util.function.Function;
1313

14+
/**
15+
* Context provided to systems in reflective structure creation
16+
*/
1417
public final class CreationContext {
1518
private final Map<ReflectiveStructureCreator.CreatorSystem.Type<?, ?, ?>, Object> systems;
1619
private final Map<ReflectiveStructureCreator.CreatorSystem.Type<?, ?, ?>, Object> bakedSystems = new IdentityHashMap<>();
@@ -19,11 +22,21 @@ public final class CreationContext {
1922
this.systems = systems;
2023
}
2124

25+
/**
26+
* {@return whether the given creation option is present}
27+
*/
2228
public boolean hasOption(CreationOption option) {
2329
var options = retrieve(CreationOptions.TYPE);
2430
return options.contains(option);
2531
}
2632

33+
/**
34+
* Retrieves a system of the given type, baking it as necessary.
35+
* @param type the type of the system to retrieve
36+
* @return the system's results
37+
* @param <R> the intermediary type of the system
38+
* @param <T> the result type of the system
39+
*/
2740
@SuppressWarnings("unchecked")
2841
public synchronized <R, T> T retrieve(ReflectiveStructureCreator.CreatorSystem.Type<T, R, ?> type) {
2942
var existingBaked = bakedSystems.get(type);
@@ -39,6 +52,11 @@ public synchronized <R, T> T retrieve(ReflectiveStructureCreator.CreatorSystem.T
3952
return (T) bakedSystems.computeIfAbsent(type, t -> type.bake(type.empty(), this));
4053
}
4154

55+
/**
56+
* Parses the given annotation using the {@link AnnotationParsers} system.
57+
* @param annotation the annotation to parse
58+
* @return the parsed annotation information
59+
*/
4260
@SuppressWarnings({"unchecked", "rawtypes"})
4361
public List<AnnotationParsers.AnnotationInfo<?>> parseAnnotation(Annotation annotation) {
4462
var annotationParsers = retrieve(AnnotationParsers.TYPE);
@@ -49,6 +67,11 @@ public List<AnnotationParsers.AnnotationInfo<?>> parseAnnotation(Annotation anno
4967
return List.of();
5068
}
5169

70+
/**
71+
* Find a contextual transform using the {@link ContextualTransforms} system.
72+
* @param elements the elements associated with the target property
73+
* @return a function to transform the property's structure
74+
*/
5275
public Function<Structure<?>, Structure<?>> contextualTransform(List<AnnotatedElement> elements) {
5376
var contextualTransforms = retrieve(ContextualTransforms.TYPE);
5477
Function<Structure<?>, Structure<?>> function = Function.identity();
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
package dev.lukebemish.codecextras.structured.reflective;
22

3+
/**
4+
* An option to modify reflective creation of structures.
5+
*/
36
public interface CreationOption {}

src/main/java/dev/lukebemish/codecextras/structured/reflective/PropertyNamingOption.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
import java.util.List;
55
import java.util.Locale;
66

7+
/**
8+
* {@link CreationOption}s for modifying the naming of properties within a structure.
9+
*/
710
public enum PropertyNamingOption implements CreationOption {
11+
/**
12+
* Structure fields are given the same name as the property
13+
*/
814
IDENTITY {
915
@Override
1016
protected String formatPart(String part) {
@@ -16,6 +22,10 @@ protected String joinParts(List<String> parts) {
1622
return String.join("", parts);
1723
}
1824
},
25+
26+
/**
27+
* Property names are converted to {@code PascalCase}
28+
*/
1929
PASCAL_CASE {
2030
@Override
2131
protected String formatPart(String part) {
@@ -27,6 +37,10 @@ protected String joinParts(List<String> parts) {
2737
return String.join("", parts);
2838
}
2939
},
40+
41+
/**
42+
* Property names are converted to {@code camelCase}
43+
*/
3044
CAMEL_CASE {
3145
@Override
3246
protected String formatPart(String part) {
@@ -46,6 +60,10 @@ protected String joinParts(List<String> parts) {
4660
return result.toString();
4761
}
4862
},
63+
64+
/**
65+
* Property names are converted to {@code snake_case}
66+
*/
4967
SNAKE_CASE {
5068
@Override
5169
protected String formatPart(String part) {
@@ -57,6 +75,10 @@ protected String joinParts(List<String> parts) {
5775
return String.join("_", parts);
5876
}
5977
},
78+
79+
/**
80+
* Property names are converted to {@code SCREAMING_SNAKE_CASE}
81+
*/
6082
SCREAMING_SNAKE_CASE {
6183
@Override
6284
protected String formatPart(String part) {
@@ -68,6 +90,10 @@ protected String joinParts(List<String> parts) {
6890
return String.join("_", parts);
6991
}
7092
},
93+
94+
/**
95+
* Property names are converted to {@code kebab-case}
96+
*/
7197
KEBAB_CASE {
7298
@Override
7399
protected String formatPart(String part) {
@@ -79,6 +105,10 @@ protected String joinParts(List<String> parts) {
79105
return String.join("-", parts);
80106
}
81107
},
108+
109+
/**
110+
* Property names are converted to {@code SCREAMING-KEBAB-CASE}
111+
*/
82112
SCREAMING_KEBAB_CASE {
83113
@Override
84114
protected String formatPart(String part) {

0 commit comments

Comments
 (0)