i18n: allow NonNls on Object, Serializable etc (IDEA-247438)

GitOrigin-RevId: 2504fd617e0a0caa31979dbc7f70e8ff0e91352d
This commit is contained in:
Anna Kozlova
2020-08-06 06:03:09 +00:00
committed by intellij-monorepo-bot
parent 533a006d5f
commit 827335a9c1
@@ -3,10 +3,7 @@ package com.intellij.codeInsight.externalAnnotation;
import com.intellij.codeInsight.AnnotationUtil;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiModifierListOwner;
import com.intellij.psi.PsiType;
import com.intellij.psi.PsiVariable;
import com.intellij.psi.*;
import com.siyeh.ig.psiutils.TypeUtils;
import org.jetbrains.annotations.NotNull;
@@ -19,12 +16,15 @@ public class NonNlsAnnotationProvider implements AnnotationProvider {
@Override
public boolean isAvailable(PsiModifierListOwner owner) {
return owner instanceof PsiMethod && isString(((PsiMethod)owner).getReturnType()) ||
owner instanceof PsiVariable && isString(((PsiVariable)owner).getType());
return owner instanceof PsiMethod && isAssignableFromString(((PsiMethod)owner).getReturnType(), owner) ||
owner instanceof PsiVariable && isAssignableFromString(((PsiVariable)owner).getType(), owner);
}
private static boolean isString(PsiType type) {
return type != null && TypeUtils.isJavaLangString(type.getDeepComponentType());
private static boolean isAssignableFromString(PsiType type, PsiElement context) {
if (type == null) {
return false;
}
return type.getDeepComponentType().isAssignableFrom(TypeUtils.getStringType(context));
}
@Override