use of com.siyeh.ig.InspectionGadgetsFix in project intellij-community by JetBrains.
the class TooBroadCatchInspection method buildFixes.
@NotNull
@Override
protected InspectionGadgetsFix[] buildFixes(Object... infos) {
final PsiElement context = (PsiElement) infos[1];
final SmartTypePointerManager pointerManager = SmartTypePointerManager.getInstance(context.getProject());
final List<PsiType> maskedTypes = (List<PsiType>) infos[0];
final List<InspectionGadgetsFix> fixes = new ArrayList<>();
for (PsiType thrown : maskedTypes) {
final String typeText = thrown.getCanonicalText();
if (CommonClassNames.JAVA_LANG_RUNTIME_EXCEPTION.equals(typeText)) {
fixes.add(new ReplaceWithRuntimeExceptionFix());
} else {
fixes.add(new AddCatchSectionFix(pointerManager.createSmartTypePointer(thrown), typeText));
}
}
final InspectionGadgetsFix fix = SuppressForTestsScopeFix.build(this, context);
if (fix != null) {
fixes.add(fix);
}
return fixes.toArray(new InspectionGadgetsFix[fixes.size()]);
}
use of com.siyeh.ig.InspectionGadgetsFix in project intellij-community by JetBrains.
the class StringConcatenationInspectionBase method buildFixes.
@Override
@NotNull
protected InspectionGadgetsFix[] buildFixes(Object... infos) {
final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression) infos[0];
final Collection<InspectionGadgetsFix> result = new ArrayList<>();
final PsiElement parent = ParenthesesUtils.getParentSkipParentheses(polyadicExpression);
if (parent instanceof PsiVariable) {
final PsiVariable variable = (PsiVariable) parent;
final InspectionGadgetsFix fix = createAddAnnotationFix(variable);
result.add(fix);
} else if (parent instanceof PsiAssignmentExpression) {
final PsiAssignmentExpression assignmentExpression = (PsiAssignmentExpression) parent;
final PsiExpression lhs = assignmentExpression.getLExpression();
if (lhs instanceof PsiReferenceExpression) {
final PsiReferenceExpression referenceExpression = (PsiReferenceExpression) lhs;
final PsiElement target = referenceExpression.resolve();
if (target instanceof PsiModifierListOwner) {
final PsiModifierListOwner modifierListOwner = (PsiModifierListOwner) target;
final InspectionGadgetsFix fix = createAddAnnotationFix(modifierListOwner);
result.add(fix);
}
}
} else if (parent instanceof PsiExpressionList) {
final PsiElement grandParent = parent.getParent();
if (grandParent instanceof PsiMethodCallExpression) {
final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression) grandParent;
final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
final PsiExpression qualifierExpression = methodExpression.getQualifierExpression();
if (qualifierExpression instanceof PsiReferenceExpression) {
final PsiReferenceExpression referenceExpression = (PsiReferenceExpression) qualifierExpression;
final PsiElement target = referenceExpression.resolve();
if (target instanceof PsiModifierListOwner) {
final PsiModifierListOwner modifierListOwner = (PsiModifierListOwner) target;
result.add(createAddAnnotationFix(modifierListOwner));
}
}
}
}
final PsiExpression[] operands = polyadicExpression.getOperands();
for (PsiExpression operand : operands) {
final PsiModifierListOwner element1 = getAnnotatableElement(operand);
if (element1 != null) {
final InspectionGadgetsFix fix = createAddAnnotationFix(element1);
result.add(fix);
}
}
final PsiElement expressionParent = PsiTreeUtil.getParentOfType(polyadicExpression, PsiReturnStatement.class, PsiExpressionList.class);
if (!(expressionParent instanceof PsiExpressionList) && expressionParent != null) {
final PsiMethod method = PsiTreeUtil.getParentOfType(expressionParent, PsiMethod.class);
if (method != null) {
final InspectionGadgetsFix fix = createAddAnnotationFix(method);
result.add(fix);
}
}
return result.toArray(new InspectionGadgetsFix[result.size()]);
}
use of com.siyeh.ig.InspectionGadgetsFix in project intellij-community by JetBrains.
the class StringConcatenationInspection method buildFixes.
@NotNull
@Override
protected InspectionGadgetsFix[] buildFixes(Object... infos) {
final InspectionGadgetsFix[] fixes = super.buildFixes(infos);
final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression) infos[0];
final SuppressForTestsScopeFix suppressFix = SuppressForTestsScopeFix.build(this, polyadicExpression);
if (suppressFix == null) {
return fixes;
}
final InspectionGadgetsFix[] newFixes = Arrays.copyOf(fixes, fixes.length + 1);
newFixes[fixes.length] = suppressFix;
return newFixes;
}
use of com.siyeh.ig.InspectionGadgetsFix in project intellij-community by JetBrains.
the class ParameterizedParametersStaticCollectionInspection method buildFix.
@Override
protected InspectionGadgetsFix buildFix(final Object... infos) {
return new InspectionGadgetsFix() {
@Override
protected void doFix(final Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
final PsiElement element = descriptor.getPsiElement();
final PsiMethod method = PsiTreeUtil.getParentOfType(element, PsiMethod.class);
if (method != null && infos[1] instanceof PsiType) {
PsiType type = (PsiType) infos[1];
final ChangeSignatureProcessor csp = new ChangeSignatureProcessor(project, method, false, PsiModifier.PUBLIC, method.getName(), type, new ParameterInfoImpl[0]);
csp.run();
} else {
final PsiClass psiClass = PsiTreeUtil.getParentOfType(element, PsiClass.class);
if (psiClass != null) {
final CreateMethodQuickFix fix = CreateMethodQuickFix.createFix(psiClass, "@" + PARAMETERS_FQN + " public static java.util.Collection parameters()", "");
if (fix != null) {
fix.applyFix(project, descriptor);
}
}
}
}
@Override
@NotNull
public String getName() {
return infos.length > 0 ? (String) infos[0] : "Create @Parameterized.Parameters data provider";
}
@NotNull
@Override
public String getFamilyName() {
return "Fix data provider signature";
}
};
}
use of com.siyeh.ig.InspectionGadgetsFix in project intellij-community by JetBrains.
the class StaticImportInspection method buildFixes.
@NotNull
@Override
protected InspectionGadgetsFix[] buildFixes(Object... infos) {
final PsiElement context = (PsiElement) infos[0];
final SuppressForTestsScopeFix fix = SuppressForTestsScopeFix.build(this, context);
if (fix == null) {
return new InspectionGadgetsFix[] { buildFix(infos) };
}
return new InspectionGadgetsFix[] { buildFix(infos), fix };
}
Aggregations