PsiType (@NotNull SmartTypePointer selectedType, @NotNull PsiExpression expression) { PsiType type = selectedType.getType(); if (type == null) { throw new IncorrectOperationException("Unexpected empty type pointer"); } PsiDeclarationStatement probe = JavaPsiFacade.getElementFactory(expression.getProject()) .createVariableDeclarationStatement("x", TypeUtils.getObjectType(expression), null, expression); Project project = expression.getProject(); NullabilityAnnotationInfo nullabilityAnnotationInfo = NullableNotNullManager.getInstance(project).findExplicitNullability((PsiLocalVariable)probe.getDeclaredElements()[0]); NullabilityAnnotationInfo info = DfaPsiUtil.getTypeNullabilityInfo(type); if (info != null && nullabilityAnnotationInfo != null && info.getNullability() != nullabilityAnnotationInfo.getNullability() && // The type nullability could be inherited from hierarchy. E.g. if the type is type parameter T, // which is defined as <T extends @NotNull Foo>. In this case we should not add @NotNull explicitly ArrayUtil.contains(info.getAnnotation(), type.getAnnotations())) { return type.annotate(TypeAnnotationProvider.Static.create(new PsiAnnotation[]{info.getAnnotation()})); } return type.annotate(TypeAnnotationProvider.EMPTY); }