I'm using Elements.getElementValuesWithDefaults to retrieve annotationvalues. Key of the returned Map is something extending ExecutableElement. I can iterate over the entrySet and check the name of each key but this leads to ugly if-else-cascades.
Map<? extends ExecutableElement, ? extends AnnotationValue> annotationValues =
elementUtils.getElementValuesWithDefaults(annotationMirror);
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annotationValues.entrySet()) {
if (entry.getKey().getSimpleName().contentEquals("method1")) {
// do something with value of method1
} else if (entry.getKey().getSimpleName().contentEquals("method2")) {
// do something with value of method2
} else if (entry.getKey().getSimpleName().contentEquals("method3")) {
// do something with value of method3
}
}
I did not find an easy way to create an ExecutableElement as key to get the value. Anyone knows one?