mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 06:39:38 +07:00
Support default annotation for types
Fixes IDEA-236740 NonNullByDefault not working with Generic Types. GitOrigin-RevId: 88bfc4b9dd87bd28f7a137bed4e3271485d89406
This commit is contained in:
committed by
intellij-monorepo-bot
parent
ffbfea53aa
commit
5195a3cb84
@@ -6,12 +6,18 @@ import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.RecursionManager;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.*;
|
||||
import com.intellij.psi.util.CachedValueProvider;
|
||||
import com.intellij.psi.util.CachedValuesManager;
|
||||
import com.intellij.psi.util.PsiModificationTracker;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.intellij.codeInsight.AnnotationUtil.*;
|
||||
|
||||
@@ -359,14 +365,24 @@ public abstract class NullableNotNullManager {
|
||||
return findNullityAnnotationWithDefault(owner, checkBases, false) != null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
NullabilityAnnotationInfo findNullityDefaultInHierarchy(@NotNull PsiModifierListOwner owner) {
|
||||
PsiAnnotation.TargetType[] placeTargetTypes = AnnotationTargetUtil.getTargetsForLocation(owner.getModifierList());
|
||||
/**
|
||||
* @param context place in PSI tree
|
||||
* @return default nullability for type-use elements at given place
|
||||
*/
|
||||
public @Nullable NullabilityAnnotationInfo findDefaultTypeUseNullability(PsiElement context) {
|
||||
return findNullabilityDefault(context, PsiAnnotation.TargetType.TYPE_USE);
|
||||
}
|
||||
|
||||
PsiElement element = owner.getParent();
|
||||
@Nullable NullabilityAnnotationInfo findNullityDefaultInHierarchy(@NotNull PsiModifierListOwner owner) {
|
||||
return findNullabilityDefault(owner, AnnotationTargetUtil.getTargetsForLocation(owner.getModifierList()));
|
||||
}
|
||||
|
||||
private @Nullable NullabilityAnnotationInfo findNullabilityDefault(@NotNull PsiElement place,
|
||||
@NotNull PsiAnnotation.TargetType @NotNull ... placeTargetTypes) {
|
||||
PsiElement element = place.getParent();
|
||||
while (element != null) {
|
||||
if (element instanceof PsiModifierListOwner) {
|
||||
NullabilityAnnotationInfo result = getNullityDefault((PsiModifierListOwner)element, placeTargetTypes, owner, false);
|
||||
NullabilityAnnotationInfo result = getNullityDefault((PsiModifierListOwner)element, placeTargetTypes, place, false);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
@@ -375,7 +391,7 @@ public abstract class NullableNotNullManager {
|
||||
if (element instanceof PsiClassOwner) {
|
||||
String packageName = ((PsiClassOwner)element).getPackageName();
|
||||
return findNullityDefaultOnPackage(placeTargetTypes, JavaPsiFacade.getInstance(element.getProject()).findPackage(packageName),
|
||||
owner);
|
||||
place);
|
||||
}
|
||||
|
||||
element = element.getContext();
|
||||
@@ -385,10 +401,10 @@ public abstract class NullableNotNullManager {
|
||||
|
||||
private @Nullable NullabilityAnnotationInfo findNullityDefaultOnPackage(PsiAnnotation.TargetType @NotNull [] placeTargetTypes,
|
||||
@Nullable PsiPackage psiPackage,
|
||||
PsiModifierListOwner owner) {
|
||||
PsiElement context) {
|
||||
boolean superPackage = false;
|
||||
while (psiPackage != null) {
|
||||
NullabilityAnnotationInfo onPkg = getNullityDefault(psiPackage, placeTargetTypes, owner, superPackage);
|
||||
NullabilityAnnotationInfo onPkg = getNullityDefault(psiPackage, placeTargetTypes, context, superPackage);
|
||||
if (onPkg != null) return onPkg;
|
||||
superPackage = true;
|
||||
psiPackage = psiPackage.getParentPackage();
|
||||
@@ -398,7 +414,7 @@ public abstract class NullableNotNullManager {
|
||||
|
||||
abstract @Nullable NullabilityAnnotationInfo getNullityDefault(@NotNull PsiModifierListOwner container,
|
||||
PsiAnnotation.TargetType @NotNull [] placeTargetTypes,
|
||||
PsiModifierListOwner owner, boolean superPackage);
|
||||
PsiElement context, boolean superPackage);
|
||||
|
||||
public abstract @NotNull List<String> getNullables();
|
||||
|
||||
|
||||
@@ -242,6 +242,13 @@ public abstract class PsiClassType extends PsiType implements JvmReferenceType {
|
||||
return getClassName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PsiElement at which given type is defined (e.g. {@link PsiJavaCodeReferenceElement}). Returns null if not applicable.
|
||||
*/
|
||||
public @Nullable PsiElement getPsiContext() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JvmTypeResolveResult resolveType() {
|
||||
|
||||
Reference in New Issue
Block a user