java type annotations: treat nullability annotations as type_use to avoid reordering of a modifier list (IDEA-206570)

GitOrigin-RevId: 292b1052c44815db83d6033a30b44e56c8b4fa34
This commit is contained in:
Anna Kozlova
2021-01-28 18:50:35 +01:00
committed by intellij-monorepo-bot
parent 38ed3bacc6
commit a5278f0dbb
2 changed files with 4 additions and 3 deletions

View File

@@ -280,7 +280,8 @@ public final class AnnotationTargetUtil {
}
/**
* Prefers "normal" target when type use annotation appears at the place where it's also applicable
* Prefers "normal" target when type use annotation appears at the place where it's also applicable.
* Treat nullability annotations as TYPE_USE: we need to copy these annotations otherwise, and then the place of the annotation in modifier list may differ
*
* @param modifierList the place where annotation appears
*
@@ -298,6 +299,7 @@ public final class AnnotationTargetUtil {
Set<PsiAnnotation.TargetType> targets = getAnnotationTargets(annotationClass);
if (targets != null && targets.contains(PsiAnnotation.TargetType.TYPE_USE) &&
(targets.size() == 1 ||
NullableNotNullManager.isNullabilityAnnotation(annotation) ||
!ContainerUtil.exists(getTargetsForLocation(modifierList),
target -> target != PsiAnnotation.TargetType.TYPE_USE && targets.contains(target)))) {
return true;

View File

@@ -9,9 +9,8 @@ abstract class Foo<T> {
class FooImpl extends Foo<String> {
@Nullable
@Override
public String getSmth() {
public @Nullable String getSmth() {
return null;
}
}