Skip to content

Commit 2857ee5

Browse files
authored
Merge pull request #115 from avaje/feature/cascade-array-type
Refactor, no functional change
2 parents d0d0598 + cbc891e commit 2857ee5

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

validator-generator/src/main/java/io/avaje/validation/generator/AdapterHelper.java

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,10 @@ final class AdapterHelper {
2929
}
3030

3131
void write() {
32-
final var annotations = elementAnnotations.annotations();
3332
final var typeUse1 = elementAnnotations.typeUse1();
3433
final var typeUse2 = elementAnnotations.typeUse2();
3534
final var hasValid = elementAnnotations.hasValid();
36-
boolean first = true;
37-
for (final var a : annotations.entrySet()) {
38-
if (first) {
39-
writer.append("%sctx.<%s>adapter(%s.class, %s)", indent, type, a.getKey().shortName(), a.getValue());
40-
first = false;
41-
continue;
42-
}
43-
writer.eol().append("%s .andThen(ctx.adapter(%s.class,%s))", indent, a.getKey().shortName(), a.getValue());
44-
}
45-
46-
if (annotations.isEmpty()) {
47-
writer.append("%sctx.<%s>noop()", indent, type);
48-
}
35+
writeFirst(elementAnnotations.annotations());
4936

5037
if (!typeUse1.isEmpty() && (isAssignable2Interface(genericType.topType(), "java.lang.Iterable"))) {
5138
writer.eol().append("%s .list()", indent);
@@ -58,9 +45,7 @@ void write() {
5845
writer.eol().append("%s .andThenMulti(ctx.adapter(%s.class))", indent, Util.shortName(topType.firstParamType()));
5946
}
6047

61-
} else if ((!typeUse1.isEmpty() || !typeUse2.isEmpty())
62-
&& "java.util.Map".equals(genericType.topType())) {
63-
48+
} else if (isMapType(typeUse1, typeUse2)) {
6449
writer.eol().append("%s .mapKeys()", indent);
6550
writeTypeUse(genericType.firstParamType(), typeUse1);
6651

@@ -81,11 +66,28 @@ void write() {
8166
}
8267
}
8368

84-
private boolean isTopTypeIterable() {
85-
if (topType != null && isAssignable2Interface(topType.topType(), "java.lang.Iterable")) {
86-
return true;
69+
private void writeFirst(Map<GenericType, String> annotations) {
70+
boolean first = true;
71+
for (final var a : annotations.entrySet()) {
72+
if (first) {
73+
writer.append("%sctx.<%s>adapter(%s.class, %s)", indent, type, a.getKey().shortName(), a.getValue());
74+
first = false;
75+
continue;
76+
}
77+
writer.eol().append("%s .andThen(ctx.adapter(%s.class,%s))", indent, a.getKey().shortName(), a.getValue());
8778
}
88-
return false;
79+
if (annotations.isEmpty()) {
80+
writer.append("%sctx.<%s>noop()", indent, type);
81+
}
82+
}
83+
84+
private boolean isMapType(Map<GenericType, String> typeUse1, Map<GenericType, String> typeUse2) {
85+
return (!typeUse1.isEmpty() || !typeUse2.isEmpty())
86+
&& "java.util.Map".equals(genericType.topType());
87+
}
88+
89+
private boolean isTopTypeIterable() {
90+
return topType != null && isAssignable2Interface(topType.topType(), "java.lang.Iterable");
8991
}
9092

9193
private void writeTypeUse(String firstParamType, Map<GenericType, String> typeUse12) {

0 commit comments

Comments
 (0)