Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ private boolean matchesType(J.Annotation ann) {

private boolean isQualifiedClass(@Nullable TypeTree tree) {
return tree instanceof J.FieldAccess ||
(tree instanceof J.ParameterizedType && ((J.ParameterizedType) tree).getClazz() instanceof J.FieldAccess) ||
tree instanceof J.ArrayType;
(tree instanceof J.ParameterizedType && ((J.ParameterizedType) tree).getClazz() instanceof J.FieldAccess);
}

private TypeTree annotateInnerClass(TypeTree qualifiedClassRef, J.Annotation annotation) {
Expand Down Expand Up @@ -182,10 +181,6 @@ private TypeTree annotateInnerClass(TypeTree qualifiedClassRef, J.Annotation ann
J.ParameterizedType pt = (J.ParameterizedType) qualifiedClassRef;
return pt.withClazz(annotateInnerClass((TypeTree) pt.getClazz(), usedAnnotation));
}
if (qualifiedClassRef instanceof J.ArrayType) {
J.ArrayType at = (J.ArrayType) qualifiedClassRef;
return at.withAnnotations(ListUtils.concat(annotation.withPrefix(Space.SINGLE_SPACE), at.getAnnotations()));
}
return qualifiedClassRef;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,33 @@ class Test {
}

@Test
void arrayFieldAnnotation() {
void arrayFieldAnnotationUnchanged() {
// As per: https://jspecify.dev/docs/user-guide/#type-use-annotation-syntax
rewriteRun(
//language=java
java(
"""
import org.openrewrite.internal.lang.Nullable;
class Test {
class ArrayOfNullableElements {
@Nullable String[] l;
}
""",
"""
),
java(
"""
import org.openrewrite.internal.lang.Nullable;
class Test {
class ArrayItselfNullable {
String @Nullable[] l;
}
"""
),
java(
"""
import org.openrewrite.internal.lang.Nullable;
class NullableArrayOfNullableElements {
@Nullable String @Nullable[] l;
}
"""
)
);
}
Expand Down