I'm parsing this string:
rewriteRun(
spec -> spec
.parser(JavaParser.fromJavaVersion().classpath("lombok")
.logCompilationWarningsAndErrors(false)),
// language=java
java(
"""
import lombok.Getter;
import lombok.Setter;
@Getter
public class A {
public A() {
}
@Setter
private int i;
}
"""
...
But I have trouble locating the annotations in my visitClassDeclaration
.
classDecl.type.getAnnotations()
is null
and classDecl.type.getMembers().get(0).getAnnotations()
is empty.
classDecl.getAnnotations()
has only one field: classDecl
itself (classDecl.getAnnotations().t == classDecl
)
classDecl.getLeadingAnnotations()
has the getter, but I cannot find the setter.
Where is the Setter?
Why are the annotations under classDecl.type
empty/null?
Can we zoom out a bit on what you're trying to achieve on a higher level? That might help give direction to what I recommend. And what version of OpenRewrite are you using?
We recently added an AnnotationService abstraction that might help for instance, or the static FindAnnotations.find method depending on your use case.
Hope either of that helps you already; we also have a public Slack that you're welcome to join for followup questions.