Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to set multiple properties of a java annotation (Stuck with annotation generation)
How to set multiple properties of a java annotation [message #1080781] Tue, 06 August 2013 11:20 Go to next message
Thomas Goossens is currently offline Thomas GoossensFriend
Messages: 32
Registered: August 2013
Member

According to the JvmTypesBuilder documentation, I use need to use toAnnotation(EObject sourceElement, Class type, Object value)

I do not understand what value I should put there? Because I have an annotation w

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface OResultInfo {
String rowNames() default "";
String columnNames() default "";
String keyNames() default "";
}

I have absolutely no idea how to to set these values. Maybe there is something about java annotations I do not know/understand?



Re: How to set multiple properties of a java annotation [message #1080987 is a reply to message #1080781] Tue, 06 August 2013 16:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
Hi

did you try to copy and paste the code of toAnnotation and do what is done for the value multiple times?
At least JvmModelGenerator looks like it could handle that.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to set multiple properties of a java annotation [message #1081054 is a reply to message #1080987] Tue, 06 August 2013 18:49 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
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
Previous Topic:Case Insensitivity for the 5 min Tutorial
Next Topic:Xtext 2.4.2 generating generic <T>
Goto Forum:
  


Current Time: Wed Sep 25 00:54:11 GMT 2024

Powered by FUDForum. Page generated in 0.03383 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top