Skip to content

Commit b60f87b

Browse files
committed
No functional change, refactor tidy ControllerReader and MethodReader
1 parent 38b72e2 commit b60f87b

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

http-generator-core/src/main/java/io/avaje/http/generator/core/ControllerReader.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,18 @@ private boolean initDocHidden() {
141141
}
142142

143143
private boolean initHasValid() {
144-
Annotation jakarta = null;
144+
Annotation jakartaValidAnnotation = null;
145145
try {
146-
var anno =
147-
(Class<Annotation>)
148-
Class.forName(Valid.class.getCanonicalName().replace("javax", "jakarta"));
149-
jakarta = findAnnotation(anno);
146+
jakartaValidAnnotation = findAnnotation(jakarataValidAnnotation());
150147
} catch (final ClassNotFoundException e) {
151-
148+
// ignore
152149
}
150+
return findAnnotation(Valid.class) != null || jakartaValidAnnotation != null;
151+
}
153152

154-
return findAnnotation(Valid.class) != null || jakarta != null;
153+
@SuppressWarnings("unchecked")
154+
private static Class<Annotation> jakarataValidAnnotation() throws ClassNotFoundException {
155+
return (Class<Annotation>)Class.forName(Valid.class.getCanonicalName().replace("javax", "jakarta"));
155156
}
156157

157158
String produces() {

http-generator-core/src/main/java/io/avaje/http/generator/core/MethodReader.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,7 @@ public class MethodReader {
6161
private final PathSegments pathSegments;
6262
private final boolean hasValid;
6363

64-
MethodReader(
65-
ControllerReader bean,
66-
ExecutableElement element,
67-
ExecutableType actualExecutable,
68-
ProcessingContext ctx) {
64+
MethodReader(ControllerReader bean, ExecutableElement element, ExecutableType actualExecutable, ProcessingContext ctx) {
6965
this.ctx = ctx;
7066
this.bean = bean;
7167
this.element = element;
@@ -78,25 +74,25 @@ public class MethodReader {
7874
this.apiResponses = getApiResponses();
7975
initWebMethodViaAnnotation();
8076
if (isWebMethod()) {
81-
82-
Annotation jakarta = null;
77+
Annotation jakartaValidAnnotation = null;
8378
try {
84-
final var anno =
85-
(Class<Annotation>)
86-
Class.forName(Valid.class.getCanonicalName().replace("javax", "jakarta"));
87-
jakarta = findAnnotation(anno);
79+
jakartaValidAnnotation = findAnnotation(jakartaValidAnnotation());
8880
} catch (final ClassNotFoundException e) {
89-
81+
// ignore
9082
}
91-
92-
this.hasValid = findAnnotation(Valid.class) != null || jakarta != null;
83+
this.hasValid = findAnnotation(Valid.class) != null || jakartaValidAnnotation != null;
9384
this.pathSegments = PathSegments.parse(Util.combinePath(bean.path(), webMethodPath));
9485
} else {
9586
this.hasValid = false;
9687
this.pathSegments = null;
9788
}
9889
}
9990

91+
@SuppressWarnings("unchecked")
92+
private static Class<Annotation> jakartaValidAnnotation() throws ClassNotFoundException {
93+
return (Class<Annotation>) Class.forName(Valid.class.getCanonicalName().replace("javax", "jakarta"));
94+
}
95+
10096
@Override
10197
public String toString() {
10298
return element.toString();

0 commit comments

Comments
 (0)