Skip to content

Commit af1f86b

Browse files
authored
lift fixes (#16)
1 parent f31b9ec commit af1f86b

File tree

3 files changed

+4
-98
lines changed

3 files changed

+4
-98
lines changed

avaje-prisms/src/main/java/io/avaje/prism/internal/GeneratePrismPrism.java

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.util.HashMap;
77
import java.util.List;
88
import java.util.Map;
9-
import java.util.Optional;
109
import java.util.stream.Stream;
1110

1211
import javax.lang.model.element.AnnotationMirror;
@@ -36,13 +35,6 @@ final class GeneratePrismPrism {
3635

3736
public static final String PRISM_TYPE = "io.avaje.prism.GeneratePrism";
3837

39-
/**
40-
* An instance of the Values inner class whose
41-
* methods return the AnnotationValues used to build this prism.
42-
* Primarily intended to support using Messager.
43-
*/
44-
final Values values;
45-
4638
/** Returns true if the prism annotation is present on the element, else false.
4739
*
4840
* @param element element.
@@ -66,20 +58,6 @@ static GeneratePrismPrism getInstanceOn(Element element) {
6658
return getInstance(mirror);
6759
}
6860

69-
/** Return a Optional representing a nullable {@code @io.avaje.prism.GeneratePrism} annotation on 'e'.
70-
* similar to {@code element.getAnnotation(io.avaje.prism.GeneratePrism.class)} except that
71-
* an Optional of this class rather than an instance of {@code io.avaje.prism.GeneratePrism}
72-
* is returned.
73-
*
74-
* @param element element.
75-
* @return prism optional for element.
76-
*/
77-
static Optional<GeneratePrismPrism> getOptionalOn(Element element) {
78-
final var mirror = getMirror(element);
79-
if (mirror == null) return Optional.empty();
80-
return getOptional(mirror);
81-
}
82-
8361
/** Return a list of prisms representing the {@code @io.avaje.prism.GeneratePrism} annotation on 'e'.
8462
* similar to {@code e.getAnnotationsByType(io.avaje.prism.GeneratePrism.class)} except that
8563
* instances of this class rather than instances of {@code io.avaje.prism.GeneratePrism}
@@ -105,20 +83,6 @@ static GeneratePrismPrism getInstance(AnnotationMirror mirror) {
10583
return new GeneratePrismPrism(mirror);
10684
}
10785

108-
/** Return a {@code Optional<GeneratePrismPrism>} representing a {@code @io.avaje.prism.GeneratePrism} annotation mirror.
109-
* similar to {@code e.getAnnotation(io.avaje.prism.GeneratePrism.class)} except that
110-
* an Optional of this class rather than an instance of {@code io.avaje.prism.GeneratePrism}
111-
* is returned.
112-
*
113-
* @param mirror mirror.
114-
* @return prism optional for mirror.
115-
*/
116-
static Optional<GeneratePrismPrism> getOptional(AnnotationMirror mirror) {
117-
if (mirror == null || !PRISM_TYPE.equals(mirror.getAnnotationType().toString())) return Optional.empty();
118-
119-
return Optional.of(new GeneratePrismPrism(mirror));
120-
}
121-
12286
private GeneratePrismPrism(AnnotationMirror mirror) {
12387
for (final ExecutableElement key : mirror.getElementValues().keySet()) {
12488
memberValues.put(key.getSimpleName().toString(), mirror.getElementValues().get(key));
@@ -131,7 +95,6 @@ private GeneratePrismPrism(AnnotationMirror mirror) {
13195
_publicAccess = getValue("publicAccess", Boolean.class);
13296
_superClass = getValue("superClass", TypeMirror.class);
13397
_superInterfaces = getArrayValues("superInterfaces", TypeMirror.class);
134-
this.values = new Values(memberValues);
13598
this.mirror = mirror;
13699
this.isValid = valid;
137100
}
@@ -181,39 +144,7 @@ private GeneratePrismPrism(AnnotationMirror mirror) {
181144
* Primarily intended to support using Messager.
182145
*/
183146
final AnnotationMirror mirror;
184-
/**
185-
* A class whose members corespond to those of io.avaje.prism.GeneratePrism
186-
* but which each return the AnnotationValue corresponding to
187-
* that member in the model of the annotations. Returns null for
188-
* defaulted members. Used for Messager, so default values are not useful.
189-
*/
190-
static final class Values {
191-
private final Map<String, AnnotationValue> values;
192147

193-
private Values(Map<String, AnnotationValue> values) {
194-
this.values = values;
195-
}
196-
/** Return the AnnotationValue corresponding to the value()
197-
* member of the annotation, or null when the default value is implied.
198-
*/
199-
AnnotationValue value(){ return values.get("value");}
200-
/** Return the AnnotationValue corresponding to the name()
201-
* member of the annotation, or null when the default value is implied.
202-
*/
203-
AnnotationValue name(){ return values.get("name");}
204-
/** Return the AnnotationValue corresponding to the publicAccess()
205-
* member of the annotation, or null when the default value is implied.
206-
*/
207-
AnnotationValue publicAccess(){ return values.get("publicAccess");}
208-
/** Return the AnnotationValue corresponding to the superClass()
209-
* member of the annotation, or null when the default value is implied.
210-
*/
211-
AnnotationValue superClass(){ return values.get("superClass");}
212-
/** Return the AnnotationValue corresponding to the superInterfaces()
213-
* member of the annotation, or null when the default value is implied.
214-
*/
215-
AnnotationValue superInterfaces(){ return values.get("superInterfaces");}
216-
}
217148

218149
private final Map<String, AnnotationValue> defaults = new HashMap<>(10);
219150
private final Map<String, AnnotationValue> memberValues = new HashMap<>(10);

avaje-prisms/src/main/java/io/avaje/prism/internal/GeneratePrismsPrism.java

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@ class GeneratePrismsPrism {
4646
/** store prism value of value */
4747
private final List<GeneratePrismPrism> _value;
4848

49-
/**
50-
* An instance of the Values inner class whose methods return the AnnotationValues used to build
51-
* this prism. Primarily intended to support using Messager.
52-
*/
53-
final Values values;
5449
/**
5550
* Return a prism representing the {@code @io.avaje.prism.GeneratePrisms} annotation on 'e'.
5651
* similar to {@code e.getAnnotation(io.avaje.prism.GeneratePrisms.class)} except that an
@@ -84,7 +79,6 @@ private GeneratePrismsPrism(AnnotationMirror mirror) {
8479
for (final AnnotationMirror valueMirror : valueMirrors) {
8580
_value.add(GeneratePrismPrism.getInstance(valueMirror));
8681
}
87-
this.values = new Values(memberValues);
8882
this.mirror = mirror;
8983
this.isValid = valid;
9084
}
@@ -112,25 +106,6 @@ List<GeneratePrismPrism> value() {
112106
* to support using Messager.
113107
*/
114108
final AnnotationMirror mirror;
115-
/**
116-
* A class whose members corespond to those of io.avaje.prism.GeneratePrisms but which each
117-
* return the AnnotationValue corresponding to that member in the model of the annotations.
118-
* Returns null for defaulted members. Used for Messager, so default values are not useful.
119-
*/
120-
static class Values {
121-
private final Map<String, AnnotationValue> values;
122-
123-
private Values(Map<String, AnnotationValue> values) {
124-
this.values = values;
125-
}
126-
/**
127-
* Return the AnnotationValue corresponding to the value() member of the annotation, or null
128-
* when the default value is implied.
129-
*/
130-
AnnotationValue value() {
131-
return values.get("value");
132-
}
133-
}
134109

135110
private final Map<String, AnnotationValue> defaults = new HashMap<>(10);
136111
private final Map<String, AnnotationValue> memberValues = new HashMap<>(10);
@@ -159,20 +134,20 @@ private static <T> List<T> getArrayValues(
159134
AnnotationValue av = memberValues.get(name);
160135
if (av == null) av = defaults.get(name);
161136
if (av == null) {
162-
return null;
137+
return List.of();
163138
}
164139
if (av.getValue() instanceof List) {
165140
final List<T> result = new ArrayList<>();
166141
for (final AnnotationValue v : getValueAsList(av)) {
167142
if (clazz.isInstance(v.getValue())) {
168143
result.add(clazz.cast(v.getValue()));
169144
} else {
170-
return null;
145+
return List.of();
171146
}
172147
}
173148
return result;
174149
} else {
175-
return null;
150+
return List.of();
176151
}
177152
}
178153

avaje-prisms/src/main/java/io/avaje/prism/internal/PrismGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ private void generateIfNew(
156156
final String prismFqn = "".equals(packageName) ? name : packageName + "." + name;
157157
if (generated.containsKey(prismFqn)) {
158158
// if same value dont need to generate, if different then error
159-
if (generated.get(prismFqn).equals(ann.value())) {
159+
if (types.isSameType(generated.get(prismFqn), ann.value())) {
160160
return;
161161
}
162162
processingEnv

0 commit comments

Comments
 (0)