1

我正在使用 Spoon 8.2.0 并尝试使用 Spoon 8.3.0 beta 10:在下面的代码中,我尝试向注释添加多个值,但它没有按预期工作。我SummarySummary.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在注释中显示键和值,并且dategetAllValues().

4

0 回答 0