diff --git a/java/java-impl/src/com/intellij/codeInspection/DefaultAnnotationParamInspection.java b/java/java-impl/src/com/intellij/codeInspection/DefaultAnnotationParamInspection.java index 14a2e5967e7f..b313fbd4d847 100644 --- a/java/java-impl/src/com/intellij/codeInspection/DefaultAnnotationParamInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/DefaultAnnotationParamInspection.java @@ -26,22 +26,28 @@ public class DefaultAnnotationParamInspection extends AbstractBaseJavaLocalInspe PsiAnnotationMemberValue defaultValue = ((PsiAnnotationMethod)element).getDefaultValue(); if (defaultValue == null) return; if (AnnotationUtil.equal(value, defaultValue)) { - holder.registerProblem(value, "Redundant default parameter value assignment", ProblemHighlightType.LIKE_UNUSED_SYMBOL, new LocalQuickFix() { - @Nls - @NotNull - @Override - public String getFamilyName() { - return "Remove redundant parameter"; - } - - @Override - public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { - PsiElement parent = descriptor.getPsiElement().getParent(); - parent.delete(); - } - }); + holder.registerProblem(value, "Redundant default parameter value assignment", ProblemHighlightType.LIKE_UNUSED_SYMBOL, + createRemoveParameterFix()); } } }; } + + @NotNull + private static LocalQuickFix createRemoveParameterFix() { + return new LocalQuickFix() { + @Nls + @NotNull + @Override + public String getFamilyName() { + return "Remove redundant parameter"; + } + + @Override + public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { + PsiElement parent = descriptor.getPsiElement().getParent(); + parent.delete(); + } + }; + } } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/inheritance/MissingOverrideAnnotationInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/inheritance/MissingOverrideAnnotationInspection.java index 61d584af67d5..44fb180adc50 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/inheritance/MissingOverrideAnnotationInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/inheritance/MissingOverrideAnnotationInspection.java @@ -32,11 +32,11 @@ import java.util.stream.Stream; public class MissingOverrideAnnotationInspection extends AbstractBaseJavaLocalInspectionTool implements CleanupLocalInspectionTool{ private static final String OVERRIDE_SHORT_NAME = StringUtil.getShortName(CommonClassNames.JAVA_LANG_OVERRIDE); - @SuppressWarnings({"PublicField"}) + @SuppressWarnings("PublicField") public boolean ignoreObjectMethods = true; - @SuppressWarnings({"PublicField"}) - public boolean ignoreAnonymousClassMethods = false; + @SuppressWarnings("PublicField") + public boolean ignoreAnonymousClassMethods; @Override @NotNull @@ -75,7 +75,7 @@ public class MissingOverrideAnnotationInspection extends AbstractBaseJavaLocalIn } /** - * @deprecated. To be removed in 2019.1. + * @deprecated To be removed in 2019.1. */ @Deprecated @SuppressWarnings("unused") @@ -84,7 +84,7 @@ public class MissingOverrideAnnotationInspection extends AbstractBaseJavaLocalIn } /** - * @deprecated. To be removed in 2019.1. + * @deprecated To be removed in 2019.1. */ @Deprecated protected BaseInspectionVisitor buildVisitor() { @@ -137,17 +137,7 @@ public class MissingOverrideAnnotationInspection extends AbstractBaseJavaLocalIn InspectionGadgetsBundle.message(result.requireAnnotation ? "missing.override.annotation.problem.descriptor" : "missing.override.annotation.in.overriding.problem.descriptor"), - new AnnotateMethodFix(CommonClassNames.JAVA_LANG_OVERRIDE) { - @Override - protected boolean annotateSelf() { - return result.requireAnnotation; - } - - @Override - protected boolean annotateOverriddenMethods() { - return result.hierarchyAnnotated == ThreeState.NO; - } - }); + createAnnotateFix(result.requireAnnotation, result.hierarchyAnnotated)); } } @@ -236,8 +226,23 @@ public class MissingOverrideAnnotationInspection extends AbstractBaseJavaLocalIn }; } + @NotNull + private static AnnotateMethodFix createAnnotateFix(final boolean requireAnnotation, final ThreeState hierarchyAnnotated) { + return new AnnotateMethodFix(CommonClassNames.JAVA_LANG_OVERRIDE) { + @Override + protected boolean annotateSelf() { + return requireAnnotation; + } + + @Override + protected boolean annotateOverriddenMethods() { + return hierarchyAnnotated == ThreeState.NO; + } + }; + } + private static class InspectionResult { - private boolean requireAnnotation = false; + private boolean requireAnnotation; private ThreeState hierarchyAnnotated = ThreeState.UNSURE; } diff --git a/xml/xml-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/XmlDefaultAttributeValueInspection.java b/xml/xml-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/XmlDefaultAttributeValueInspection.java index f54342306459..422b65287576 100644 --- a/xml/xml-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/XmlDefaultAttributeValueInspection.java +++ b/xml/xml-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/XmlDefaultAttributeValueInspection.java @@ -52,22 +52,27 @@ public class XmlDefaultAttributeValueInspection extends XmlSuppressableInspectio String defaultValue = descriptor.getDefaultValue(); if (defaultValue != null && defaultValue.equals(value.getValue())) { holder.registerProblem(value, "Redundant default attribute value assignment", ProblemHighlightType.LIKE_UNUSED_SYMBOL, - new LocalQuickFix() { - @Nls - @NotNull - @Override - public String getFamilyName() { - return XmlErrorMessages.message("remove.attribute.quickfix.family"); - } + createDeleteFix()); + } + } + }; + } - @Override - public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { - XmlAttribute attribute = PsiTreeUtil.getParentOfType(descriptor.getPsiElement(), XmlAttribute.class); - if (attribute != null) { - attribute.delete(); - } - } - }); + @NotNull + private static LocalQuickFix createDeleteFix() { + return new LocalQuickFix() { + @Nls + @NotNull + @Override + public String getFamilyName() { + return XmlErrorMessages.message("remove.attribute.quickfix.family"); + } + + @Override + public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { + XmlAttribute attribute = PsiTreeUtil.getParentOfType(descriptor.getPsiElement(), XmlAttribute.class); + if (attribute != null) { + attribute.delete(); } } };