java - 如何使用 xtend 设置 java 注释的多个属性(使用 xbase)

标签 java annotations xtext xtend xbase

根据the JvmTypesBuilder documentation ,我使用需要使用 toAnnotation(EObject sourceElement, Class type, Object value)

我不明白我应该在那里放什么值?因为我有一个注释 w

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

我完全不知道如何设置这些值。也许有一些关于java注释的东西我不知道/理解?

最佳答案

您需要使用

val jvmAnnotation = toAnnotation(EObject sourceElement, Class type)

并创建并添加每个值的注释值,并将其分配给 jvmAnnotationReference:

val annotationValue = TypesFactory.eInstance.createJvmStringAnnotationValue();
annotationValue.getValues().add(value);
annotationValue.setOperation(annotationTypesOperation); //i.e. the JvmOperation representing rowNames(), columnNames() or keyNames()
jvmAnnotation.getValues().add(annotationValue);

关于java - 如何使用 xtend 设置 java 注释的多个属性(使用 xbase),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18062449/

相关文章:

java - Struts 2 中插入更新删除但显示 NullPointerException

java - 告诉 Jetty 在 webapp 更改时重新加载,而不是 context.xml 更改

eclipse-rcp - 如何将 xText 编辑器添加到 Eclipse (e4) RCP 应用程序?

java - 如何向 JTable 添加 Action 监听器?

java - 如何仅检索关联的 ID 而不是实体?

Java 14 语言规范注释元素说明 - 可能是错别字?

未找到 Android 注释 MappingJackson2HttpMessageConverter.class

scope - XText 中的简单导入指令

java - 在 Xtext 大纲 View 中隐藏父节点

c# - 元编程 : write in one language X, C#、PHP、Java、C 等多种语言交叉编译