use of com.intellij.codeInsight.NullableNotNullManager in project intellij-community by JetBrains.
the class NullableStuffInspectionBase method isNotNullNotInferred.
private static boolean isNotNullNotInferred(@NotNull PsiModifierListOwner owner, boolean checkBases, boolean skipExternal) {
Project project = owner.getProject();
NullableNotNullManager manager = NullableNotNullManager.getInstance(project);
if (!manager.isNotNull(owner, checkBases))
return false;
PsiAnnotation anno = manager.getNotNullAnnotation(owner, checkBases);
if (anno == null || AnnotationUtil.isInferredAnnotation(anno))
return false;
if (skipExternal && AnnotationUtil.isExternalAnnotation(anno))
return false;
return true;
}
use of com.intellij.codeInsight.NullableNotNullManager in project intellij-community by JetBrains.
the class NullableStuffInspectionBase method checkNullableStuffForMethod.
private void checkNullableStuffForMethod(PsiMethod method, final ProblemsHolder holder, boolean isOnFly) {
Annotated annotated = check(method, holder, method.getReturnType());
List<PsiMethod> superMethods = ContainerUtil.map(method.findSuperMethodSignaturesIncludingStatic(true), signature -> signature.getMethod());
final NullableNotNullManager nullableManager = NullableNotNullManager.getInstance(holder.getProject());
checkSupers(method, holder, annotated, superMethods);
checkParameters(method, holder, superMethods, nullableManager, isOnFly);
checkOverriders(method, holder, annotated, nullableManager);
}
use of com.intellij.codeInsight.NullableNotNullManager in project intellij-community by JetBrains.
the class DfaPsiUtil method getElementNullability.
@NotNull
public static Nullness getElementNullability(@Nullable PsiType resultType, @Nullable PsiModifierListOwner owner) {
if (resultType != null) {
for (PsiAnnotation annotation : resultType.getAnnotations()) {
String qualifiedName = annotation.getQualifiedName();
NullableNotNullManager nnn = NullableNotNullManager.getInstance(annotation.getProject());
if (nnn.getNullables().contains(qualifiedName)) {
return Nullness.NULLABLE;
}
if (nnn.getNotNulls().contains(qualifiedName)) {
return Nullness.NOT_NULL;
}
}
}
if (owner == null || resultType instanceof PsiPrimitiveType) {
return Nullness.UNKNOWN;
}
if (owner instanceof PsiEnumConstant || PsiUtil.isAnnotationMethod(owner)) {
return Nullness.NOT_NULL;
}
if (owner instanceof PsiMethod && isEnumPredefinedMethod((PsiMethod) owner)) {
return Nullness.NOT_NULL;
}
if (NullableNotNullManager.isNullable(owner)) {
return Nullness.NULLABLE;
}
if (isNotNullLocally(owner)) {
return Nullness.NOT_NULL;
}
if (PsiJavaPatterns.psiParameter().withParents(PsiParameterList.class, PsiLambdaExpression.class).accepts(owner)) {
PsiLambdaExpression lambda = (PsiLambdaExpression) owner.getParent().getParent();
int index = lambda.getParameterList().getParameterIndex((PsiParameter) owner);
Nullness nullness = inferLambdaParameterNullness(lambda, index);
if (nullness != Nullness.UNKNOWN) {
return nullness;
}
PsiMethod sam = LambdaUtil.getFunctionalInterfaceMethod(lambda.getFunctionalInterfaceType());
if (sam != null && index < sam.getParameterList().getParametersCount()) {
return getElementNullability(null, sam.getParameterList().getParameters()[index]);
}
}
return Nullness.UNKNOWN;
}
use of com.intellij.codeInsight.NullableNotNullManager in project intellij-community by JetBrains.
the class OverrideImplementsAnnotationsHandlerImpl method getAnnotations.
@Override
public String[] getAnnotations(Project project) {
final NullableNotNullManager manager = NullableNotNullManager.getInstance(project);
final Collection<String> anns = new ArrayList<>(manager.getNotNulls());
anns.addAll(manager.getNullables());
anns.add(AnnotationUtil.NLS);
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(project);
anns.addAll(settings.getRepeatAnnotations());
return ArrayUtil.toStringArray(anns);
}
use of com.intellij.codeInsight.NullableNotNullManager in project intellij-community by JetBrains.
the class ExtractMethodProcessor method initNullness.
private Nullness initNullness() {
if (!PsiUtil.isLanguageLevel5OrHigher(myElements[0]) || PsiUtil.resolveClassInType(myReturnType) == null)
return null;
final NullableNotNullManager manager = NullableNotNullManager.getInstance(myProject);
final PsiClass nullableAnnotationClass = JavaPsiFacade.getInstance(myProject).findClass(manager.getDefaultNullable(), myElements[0].getResolveScope());
if (nullableAnnotationClass != null) {
final PsiElement elementInCopy = myTargetClass.getContainingFile().copy().findElementAt(myTargetClass.getTextOffset());
final PsiClass classCopy = PsiTreeUtil.getParentOfType(elementInCopy, PsiClass.class);
if (classCopy == null) {
return null;
}
final PsiMethod emptyMethod = (PsiMethod) classCopy.addAfter(generateEmptyMethod("name"), classCopy.getLBrace());
prepareMethodBody(emptyMethod, false);
if (myNotNullConditionalCheck || myNullConditionalCheck) {
return Nullness.NULLABLE;
}
return DfaUtil.inferMethodNullity(emptyMethod);
}
return null;
}
Aggregations