Search in sources :

Example 1 with DelegatingFix

use of com.siyeh.ig.DelegatingFix in project intellij-community by JetBrains.

the class NullArgumentToVariableArgMethodInspection method buildFixes.

@NotNull
@Override
protected InspectionGadgetsFix[] buildFixes(Object... infos) {
    final PsiExpression argument = (PsiExpression) infos[0];
    final PsiType type1 = (PsiType) infos[1];
    final PsiType type2 = (PsiType) infos[2];
    return new InspectionGadgetsFix[] { new DelegatingFix(new AddTypeCastFix(type1, argument)), new DelegatingFix(new AddTypeCastFix(type2, argument)) };
}
Also used : DelegatingFix(com.siyeh.ig.DelegatingFix) AddTypeCastFix(com.intellij.codeInsight.daemon.impl.quickfix.AddTypeCastFix) InspectionGadgetsFix(com.siyeh.ig.InspectionGadgetsFix) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with DelegatingFix

use of com.siyeh.ig.DelegatingFix in project intellij-community by JetBrains.

the class CallToSuspiciousStringMethodInspection method buildFixes.

@Override
@NotNull
protected InspectionGadgetsFix[] buildFixes(Object... infos) {
    final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression) infos[0];
    final List<InspectionGadgetsFix> result = new ArrayList<>();
    final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
    final PsiModifierListOwner annotatableQualifier = NonNlsUtils.getAnnotatableQualifier(methodExpression);
    if (annotatableQualifier != null) {
        final InspectionGadgetsFix fix = new DelegatingFix(new AddAnnotationPsiFix(AnnotationUtil.NON_NLS, annotatableQualifier, PsiNameValuePair.EMPTY_ARRAY));
        result.add(fix);
    }
    final PsiModifierListOwner annotatableArgument = NonNlsUtils.getAnnotatableArgument(methodCallExpression);
    if (annotatableArgument != null) {
        final InspectionGadgetsFix fix = new DelegatingFix(new AddAnnotationPsiFix(AnnotationUtil.NON_NLS, annotatableArgument, PsiNameValuePair.EMPTY_ARRAY));
        result.add(fix);
    }
    return result.toArray(new InspectionGadgetsFix[result.size()]);
}
Also used : AddAnnotationPsiFix(com.intellij.codeInsight.intention.AddAnnotationPsiFix) DelegatingFix(com.siyeh.ig.DelegatingFix) ArrayList(java.util.ArrayList) InspectionGadgetsFix(com.siyeh.ig.InspectionGadgetsFix) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with DelegatingFix

use of com.siyeh.ig.DelegatingFix in project intellij-community by JetBrains.

the class StringToUpperWithoutLocaleInspection method buildFix.

@Override
@Nullable
protected InspectionGadgetsFix buildFix(Object... infos) {
    final PsiReferenceExpression methodExpression = (PsiReferenceExpression) infos[0];
    final PsiModifierListOwner annotatableQualifier = NonNlsUtils.getAnnotatableQualifier(methodExpression);
    if (annotatableQualifier == null) {
        return null;
    }
    return new DelegatingFix(new AddAnnotationPsiFix(AnnotationUtil.NON_NLS, annotatableQualifier, PsiNameValuePair.EMPTY_ARRAY));
}
Also used : AddAnnotationPsiFix(com.intellij.codeInsight.intention.AddAnnotationPsiFix) DelegatingFix(com.siyeh.ig.DelegatingFix) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with DelegatingFix

use of com.siyeh.ig.DelegatingFix in project intellij-community by JetBrains.

the class PrimitiveArrayArgumentToVariableArgMethodInspection method buildFix.

@Nullable
@Override
protected InspectionGadgetsFix buildFix(Object... infos) {
    final PsiExpression argument = (PsiExpression) infos[0];
    final PsiType type = (PsiType) infos[1];
    return new DelegatingFix(new AddTypeCastFix(type, argument));
}
Also used : DelegatingFix(com.siyeh.ig.DelegatingFix) AddTypeCastFix(com.intellij.codeInsight.daemon.impl.quickfix.AddTypeCastFix) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with DelegatingFix

use of com.siyeh.ig.DelegatingFix 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)

Aggregations

DelegatingFix (com.siyeh.ig.DelegatingFix)5 AddAnnotationPsiFix (com.intellij.codeInsight.intention.AddAnnotationPsiFix)3 AddTypeCastFix (com.intellij.codeInsight.daemon.impl.quickfix.AddTypeCastFix)2 InspectionGadgetsFix (com.siyeh.ig.InspectionGadgetsFix)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 NullableNotNullManager (com.intellij.codeInsight.NullableNotNullManager)1 ArrayList (java.util.ArrayList)1