Search in sources :

Example 6 with AddAnnotationPsiFix

use of com.intellij.codeInsight.intention.AddAnnotationPsiFix in project intellij-community by JetBrains.

the class AssignmentToNullInspection method buildFix.

@Override
protected InspectionGadgetsFix buildFix(Object... infos) {
    final Object info = infos[0];
    if (!(info instanceof PsiReferenceExpression)) {
        return null;
    }
    final PsiReferenceExpression referenceExpression = (PsiReferenceExpression) info;
    if (TypeUtils.isOptional(referenceExpression.getType())) {
        return null;
    }
    final PsiElement target = referenceExpression.resolve();
    if (!(target instanceof PsiVariable)) {
        return null;
    }
    final PsiVariable variable = (PsiVariable) target;
    if (NullableNotNullManager.isNotNull(variable)) {
        return null;
    }
    final NullableNotNullManager manager = NullableNotNullManager.getInstance(target.getProject());
    return new DelegatingFix(new AddAnnotationPsiFix(manager.getDefaultNullable(), variable, PsiNameValuePair.EMPTY_ARRAY));
}
Also used : AddAnnotationPsiFix(com.intellij.codeInsight.intention.AddAnnotationPsiFix) DelegatingFix(com.siyeh.ig.DelegatingFix) NullableNotNullManager(com.intellij.codeInsight.NullableNotNullManager)

Example 7 with AddAnnotationPsiFix

use of com.intellij.codeInsight.intention.AddAnnotationPsiFix in project intellij-community by JetBrains.

the class AnnotateMethodFix method annotateMethod.

private void annotateMethod(@NotNull PsiMethod method) {
    AddAnnotationPsiFix fix = new AddAnnotationPsiFix(myAnnotation, method, PsiNameValuePair.EMPTY_ARRAY, myAnnotationsToRemove);
    fix.invoke(method.getProject(), method.getContainingFile(), method, method);
}
Also used : AddAnnotationPsiFix(com.intellij.codeInsight.intention.AddAnnotationPsiFix)

Aggregations

AddAnnotationPsiFix (com.intellij.codeInsight.intention.AddAnnotationPsiFix)7 DelegatingFix (com.siyeh.ig.DelegatingFix)3 ArrayList (java.util.ArrayList)2 NullableNotNullManager (com.intellij.codeInsight.NullableNotNullManager)1 Project (com.intellij.openapi.project.Project)1 PsiElement (com.intellij.psi.PsiElement)1 PsiMethod (com.intellij.psi.PsiMethod)1 PsiParameter (com.intellij.psi.PsiParameter)1 InspectionGadgetsFix (com.siyeh.ig.InspectionGadgetsFix)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1