|
|
Re: How to set multiple properties of a java annotation [message #1081054 is a reply to message #1080987] |
Tue, 06 August 2013 18:49 |
|
Hi,
i dont get this point. the tipp was 100% straight forward
[code]public class ExtendedJvmTypesBuilder extends JvmTypesBuilder {
@Inject
private TypeReferences references;
@Inject
private TypesFactory typesFactory;
@Nullable
public JvmAnnotationReference toAnnotationExtended(@Nullable EObject sourceElement, @Nullable String annotationTypeName,
Pair<String, String> ... values) {
JvmAnnotationReference result = typesFactory.createJvmAnnotationReference();
JvmType jvmType = references.findDeclaredType(annotationTypeName, sourceElement);
if (jvmType == null) {
throw new IllegalArgumentException("The type "+annotationTypeName +" is not on the classpath.");
}
if (!(jvmType instanceof JvmAnnotationType)) {
throw new IllegalArgumentException("The given class " + annotationTypeName + " is not an annotation type.");
}
JvmAnnotationType annotationType = (JvmAnnotationType) jvmType;
result.setAnnotation(annotationType);
for (Pair<String, String> value : values) {
JvmStringAnnotationValue annotationValue = typesFactory.createJvmStringAnnotationValue();
annotationValue.getValues().add(value.getValue());
JvmOperation operation = getJvmOperation(annotationType, value.getKey());
if (operation != null) {
annotationValue.setOperation(operation);
}
result.getValues().add(annotationValue);
}
return result;
}
private JvmOperation getJvmOperation(JvmAnnotationType type, String name) {
for (JvmOperation op : type.getDeclaredOperations()) {
if (op.getSimpleName().equals(name)) {
return op;
}
}
return null;
}
}[/code]
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Powered by
FUDForum. Page generated in 0.03383 seconds