use of com.intellij.codeInsight.NullableNotNullManager in project intellij-community by JetBrains.
the class IntroduceVariableBase method stripNullabilityAnnotationsFromTargetType.
private static PsiType stripNullabilityAnnotationsFromTargetType(SmartTypePointer selectedType, final Project project) {
PsiType type = selectedType.getType();
if (type == null)
return null;
final PsiAnnotation[] annotations = type.getAnnotations();
type = type.annotate(new TypeAnnotationProvider() {
@NotNull
@Override
public PsiAnnotation[] getAnnotations() {
final NullableNotNullManager manager = NullableNotNullManager.getInstance(project);
final Set<String> nullables = new HashSet<>();
nullables.addAll(manager.getNotNulls());
nullables.addAll(manager.getNullables());
return Arrays.stream(annotations).filter(annotation -> !nullables.contains(annotation.getQualifiedName())).toArray(PsiAnnotation[]::new);
}
});
return type;
}
use of com.intellij.codeInsight.NullableNotNullManager in project intellij-community by JetBrains.
the class DfaPsiUtil method isNotNullLocally.
private static boolean isNotNullLocally(@NotNull PsiModifierListOwner owner) {
NullableNotNullManager nnnm = NullableNotNullManager.getInstance(owner.getProject());
PsiAnnotation notNullAnno = nnnm.getNotNullAnnotation(owner, true);
if (notNullAnno == null)
return false;
// notnull on a super method requires all inheritors to return notnull as well
if (!(owner instanceof PsiParameter))
return true;
// so treat parameters as @NotNull only if they're annotated explicitly, or if they're in a scope of some nullity default annotation.
return isOwnAnnotation(owner, notNullAnno) || nnnm.isContainerAnnotation(notNullAnno);
}
use of com.intellij.codeInsight.NullableNotNullManager in project intellij-community by JetBrains.
the class NullableStuffInspectionBase method check.
private static Annotated check(final PsiModifierListOwner parameter, final ProblemsHolder holder, PsiType type) {
final NullableNotNullManager manager = NullableNotNullManager.getInstance(holder.getProject());
PsiAnnotation isDeclaredNotNull = AnnotationUtil.findAnnotation(parameter, manager.getNotNulls());
PsiAnnotation isDeclaredNullable = AnnotationUtil.findAnnotation(parameter, manager.getNullables());
if (isDeclaredNullable != null && isDeclaredNotNull != null) {
reportNullableNotNullConflict(holder, parameter, isDeclaredNullable, isDeclaredNotNull);
}
if ((isDeclaredNotNull != null || isDeclaredNullable != null) && type != null && TypeConversionUtil.isPrimitive(type.getCanonicalText())) {
PsiAnnotation annotation = isDeclaredNotNull == null ? isDeclaredNullable : isDeclaredNotNull;
reportPrimitiveType(holder, annotation, annotation, parameter);
}
return new Annotated(isDeclaredNotNull != null, isDeclaredNullable != null);
}
use of com.intellij.codeInsight.NullableNotNullManager in project intellij-community by JetBrains.
the class NullableStuffInspectionBase method getPresentableAnnoName.
@NotNull
private static String getPresentableAnnoName(@NotNull PsiModifierListOwner owner) {
NullableNotNullManager manager = NullableNotNullManager.getInstance(owner.getProject());
Set<String> names = ContainerUtil.newHashSet(manager.getNullables());
names.addAll(manager.getNotNulls());
PsiAnnotation annotation = AnnotationUtil.findAnnotationInHierarchy(owner, names);
if (annotation != null)
return getPresentableAnnoName(annotation);
String anno = manager.getNotNull(owner);
return StringUtil.getShortName(anno != null ? anno : StringUtil.notNullize(manager.getNullable(owner), "???"));
}
use of com.intellij.codeInsight.NullableNotNullManager in project intellij-community by JetBrains.
the class NullableStuffInspectionBase method isNullableNotInferred.
public static boolean isNullableNotInferred(@NotNull PsiModifierListOwner owner, boolean checkBases) {
Project project = owner.getProject();
NullableNotNullManager manager = NullableNotNullManager.getInstance(project);
if (!manager.isNullable(owner, checkBases))
return false;
PsiAnnotation anno = manager.getNullableAnnotation(owner, checkBases);
return !(anno != null && AnnotationUtil.isInferredAnnotation(anno));
}
Aggregations