Search in sources :

Example 16 with NullableNotNullManager

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;
}
Also used : InjectedLanguageManager(com.intellij.lang.injection.InjectedLanguageManager) com.intellij.refactoring(com.intellij.refactoring) RefactoringUIUtil(com.intellij.refactoring.util.RefactoringUIUtil) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) NullableNotNullManager(com.intellij.codeInsight.NullableNotNullManager) HighlightManager(com.intellij.codeInsight.highlighting.HighlightManager) FeatureUsageTracker(com.intellij.featureStatistics.FeatureUsageTracker) RefactoringEventData(com.intellij.refactoring.listeners.RefactoringEventData) Logger(com.intellij.openapi.diagnostic.Logger) MultiMap(com.intellij.util.containers.MultiMap) ReferencesSearch(com.intellij.psi.search.searches.ReferencesSearch) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) JspCodeBlock(com.intellij.psi.impl.source.jsp.jspJava.JspCodeBlock) FieldConflictsResolver(com.intellij.refactoring.util.FieldConflictsResolver) IncorrectOperationException(com.intellij.util.IncorrectOperationException) ChainCallExtractor(com.intellij.refactoring.chainCall.ChainCallExtractor) WindowManager(com.intellij.openapi.wm.WindowManager) LookupManager(com.intellij.codeInsight.lookup.LookupManager) TextRange(com.intellij.openapi.util.TextRange) CodeStyleSettingsManager(com.intellij.psi.codeStyle.CodeStyleSettingsManager) RefactoringSupportProvider(com.intellij.lang.refactoring.RefactoringSupportProvider) ReplaceExpressionUtil(com.intellij.psi.impl.source.tree.java.ReplaceExpressionUtil) AbstractInplaceIntroducer(com.intellij.refactoring.introduce.inplace.AbstractInplaceIntroducer) Nullable(org.jetbrains.annotations.Nullable) ExpressionOccurrenceManager(com.intellij.refactoring.util.occurrences.ExpressionOccurrenceManager) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) Pass(com.intellij.openapi.util.Pass) OccurrencesChooser(com.intellij.refactoring.introduce.inplace.OccurrencesChooser) VariableKind(com.intellij.psi.codeStyle.VariableKind) ScopeHighlighter(com.intellij.codeInsight.unwrap.ScopeHighlighter) JspHolderMethod(com.intellij.psi.impl.source.jsp.jspJava.JspHolderMethod) Processor(com.intellij.util.Processor) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Registry(com.intellij.openapi.util.registry.Registry) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) SuggestedNameInfo(com.intellij.psi.codeStyle.SuggestedNameInfo) java.util(java.util) TypeSelectorManagerImpl(com.intellij.refactoring.ui.TypeSelectorManagerImpl) DataContext(com.intellij.openapi.actionSystem.DataContext) com.intellij.openapi.editor(com.intellij.openapi.editor) NonNls(org.jetbrains.annotations.NonNls) Computable(com.intellij.openapi.util.Computable) ElementToWorkOn(com.intellij.refactoring.introduceField.ElementToWorkOn) ArrayUtilRt(com.intellij.util.ArrayUtilRt) RefactoringEventListener(com.intellij.refactoring.listeners.RefactoringEventListener) ContainerUtil(com.intellij.util.containers.ContainerUtil) CodeInsightUtil(com.intellij.codeInsight.CodeInsightUtil) JavaCodeStyleManager(com.intellij.psi.codeStyle.JavaCodeStyleManager) MessageFormat(java.text.MessageFormat) LanguageRefactoringSupport(com.intellij.lang.LanguageRefactoringSupport) Project(com.intellij.openapi.project.Project) InjectedLanguageUtil(com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil) NotInSuperCallOccurrenceFilter(com.intellij.refactoring.util.occurrences.NotInSuperCallOccurrenceFilter) ProductivityFeatureNames(com.intellij.featureStatistics.ProductivityFeatureNames) StringUtil(com.intellij.openapi.util.text.StringUtil) com.intellij.psi.util(com.intellij.psi.util) Key(com.intellij.openapi.util.Key) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) CommandProcessor(com.intellij.openapi.command.CommandProcessor) CommonRefactoringUtil(com.intellij.refactoring.util.CommonRefactoringUtil) EditorColors(com.intellij.openapi.editor.colors.EditorColors) JavaCompletionUtil(com.intellij.codeInsight.completion.JavaCompletionUtil) PsiDiamondTypeUtil(com.intellij.psi.impl.PsiDiamondTypeUtil) RefactoringUtil(com.intellij.refactoring.util.RefactoringUtil) NullableNotNullManager(com.intellij.codeInsight.NullableNotNullManager)

Example 17 with NullableNotNullManager

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);
}
Also used : NullableNotNullManager(com.intellij.codeInsight.NullableNotNullManager)

Example 18 with NullableNotNullManager

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);
}
Also used : NullableNotNullManager(com.intellij.codeInsight.NullableNotNullManager)

Example 19 with NullableNotNullManager

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), "???"));
}
Also used : NullableNotNullManager(com.intellij.codeInsight.NullableNotNullManager) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with NullableNotNullManager

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));
}
Also used : Project(com.intellij.openapi.project.Project) NullableNotNullManager(com.intellij.codeInsight.NullableNotNullManager)

Aggregations

NullableNotNullManager (com.intellij.codeInsight.NullableNotNullManager)22 Project (com.intellij.openapi.project.Project)6 NotNull (org.jetbrains.annotations.NotNull)4 Nullable (org.jetbrains.annotations.Nullable)3 JavaCodeStyleManager (com.intellij.psi.codeStyle.JavaCodeStyleManager)2 NonNls (org.jetbrains.annotations.NonNls)2 CodeInsightUtil (com.intellij.codeInsight.CodeInsightUtil)1 ExternalAnnotationsManager (com.intellij.codeInsight.ExternalAnnotationsManager)1 JavaChainLookupElement (com.intellij.codeInsight.completion.JavaChainLookupElement)1 JavaCompletionUtil (com.intellij.codeInsight.completion.JavaCompletionUtil)1 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)1 AddAnnotationPsiFix (com.intellij.codeInsight.intention.AddAnnotationPsiFix)1 AddNullableNotNullAnnotationFix (com.intellij.codeInsight.intention.impl.AddNullableNotNullAnnotationFix)1 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 LookupManager (com.intellij.codeInsight.lookup.LookupManager)1 ScopeHighlighter (com.intellij.codeInsight.unwrap.ScopeHighlighter)1 AnnotateMethodFix (com.intellij.codeInspection.AnnotateMethodFix)1 ChainCompletionLookupElementUtil.createLookupElement (com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.ChainCompletionLookupElementUtil.createLookupElement)1 ChainCompletionNewVariableLookupElement (com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.ChainCompletionNewVariableLookupElement)1 WeightableChainLookupElement (com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.WeightableChainLookupElement)1