我正在使用 Spoon 8.2.0 并尝试使用 Spoon 8.3.0 beta 10:在下面的代码中,我尝试向注释添加多个值,但它没有按预期工作。我Summary
在Summary.java中有一个 Java 注释:
package tryspoon;
public @interface Summary {
String title();
String date();
}
在Spooner
Spooner.java 中
package tryspoon;
import spoon.Launcher;
import spoon.SpoonAPI;
import spoon.reflect.declaration.CtAnnotation;
import spoon.reflect.reference.CtTypeReference;
public class Spooner {
public static void main(String[] args) {
SpoonAPI spoon = new Launcher();
CtTypeReference<Summary> typeRef = spoon.getFactory().createCtTypeReference(Summary.class);
CtAnnotation<Summary> annotation = spoon.getFactory().createAnnotation(typeRef);
annotation.addValue("title", "First summary");
annotation.addValue("date", "2020-10-05");
// This outputs @tryspoon.Summary(date = "2020-10-05")
System.out.println(annotation);
// This outputs {date="2020-10-05", title=null}
System.out.println(annotation.getAllValues());
}
}
annotation.addValue("title", "First Summary")
交换和的顺序annotation.addValue("date", "2020-10-05")
将使其仅title
在注释中显示键和值,并且date
从getAllValues()
.