Skip to content

Commit

Permalink
Core: improve AnnotationProxyProvider so that the resulting proxy als…
Browse files Browse the repository at this point in the history
…o implements annotation members
  • Loading branch information
Ladicek committed Oct 8, 2024
1 parent 7a5a621 commit 655fc53
Showing 1 changed file with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,21 +186,33 @@ public A build(ClassOutput classOutput) {
new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
switch (method.getName()) {
case "getAnnotationLiteralType":
return annotationLiteral;
case "getAnnotationClass":
return annotationClass;
case "getAnnotationInstance":
return annotationInstance;
case "getDefaultValues":
return defaultValues;
case "getValues":
return values;
default:
break;
}
throw new UnsupportedOperationException("Method " + method + " not implemented");
String name = method.getName();
return switch (name) {
case "getAnnotationLiteralType" -> annotationLiteral;
case "getAnnotationClass" -> annotationClass;
case "getAnnotationInstance" -> annotationInstance;
case "getDefaultValues" -> defaultValues;
case "getValues" -> values;
default -> {
MethodInfo member = annotationClass.firstMethod(name);
if (member != null) {
if (values.containsKey(name)) {
yield values.get(name);
}
if (annotationInstance.value(name) != null) {
yield annotationInstance.value(name).value();
}
if (defaultValues.containsKey(name)) {
yield defaultValues.get(name);
}
if (member.defaultValue() != null) {
yield member.defaultValue().value();
}
throw new UnsupportedOperationException("Unknown value of annotation member " + name);
}
throw new UnsupportedOperationException("Method " + method + " not implemented");
}
};
}
});
}
Expand Down

0 comments on commit 655fc53

Please sign in to comment.