From 4a3b65d95bb35c772af28abdfb0bad9af7c12fd4 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Mon, 11 Mar 2013 13:39:06 +0100 Subject: [PATCH] simplify inspection warning and cleanup --- .../siyeh/InspectionGadgetsBundle.properties | 3 +- ...nnecessaryInterfaceModifierInspection.java | 69 ++++++------------- 2 files changed, 22 insertions(+), 50 deletions(-) diff --git a/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties b/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties index 4841d4de6227..85a3bdd08b62 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties +++ b/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties @@ -1345,8 +1345,7 @@ unnecessarily.qualified.static.usage.problem.descriptor1=Unnecessarily qualified unnecessarily.qualified.static.usage.ignore.field.option=Ignore unnecessarily qualified field accesses unnecessarily.qualified.static.usage.ignore.method.option=Ignore unnecessarily qualified method calls unnecessary.interface.modifier.problem.descriptor=Modifier #ref is redundant for interfaces #loc -unnecessary.interface.modifier.inner.interface.of.interface.problem.descriptor=Modifier #ref is redundant for inner interfaces of interfaces #loc -unnecessary.interface.modifier.inner.interface.of.class.problem.descriptor=Modifier #ref is redundant for inner interfaces of classes #loc +unnecessary.interface.modifier.inner.interface.of.interface.problem.descriptor=Modifier #ref is redundant for inner interfaces #loc unnecessary.interface.modifier.problem.descriptor2=Modifier #ref is redundant for interface methods #loc unnecessary.interface.modifier.problem.descriptor3=Modifier #ref is redundant for inner classes of interfaces #loc unnecessary.interface.modifier.problem.descriptor4=Modifier #ref is redundant for interface fields #loc diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/style/UnnecessaryInterfaceModifierInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/style/UnnecessaryInterfaceModifierInspection.java index 67246337c22b..cfa66387b071 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/style/UnnecessaryInterfaceModifierInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/style/UnnecessaryInterfaceModifierInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2009 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2012 Dave Griffith, Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ package com.siyeh.ig.style; import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.openapi.project.Project; import com.intellij.psi.*; -import com.intellij.util.IncorrectOperationException; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; @@ -33,26 +32,20 @@ import java.util.Set; public class UnnecessaryInterfaceModifierInspection extends BaseInspection { private static final Set INTERFACE_REDUNDANT_MODIFIERS = - new HashSet(Arrays.asList(PsiModifier.ABSTRACT, - PsiModifier.STATIC)); + new HashSet(Arrays.asList(PsiModifier.ABSTRACT, PsiModifier.STATIC)); private static final Set INNER_CLASS_REDUNDANT_MODIFIERS = - new HashSet(Arrays.asList(PsiModifier.PUBLIC, - PsiModifier.STATIC)); + new HashSet(Arrays.asList(PsiModifier.PUBLIC, PsiModifier.STATIC)); private static final Set INNER_INTERFACE_REDUNDANT_MODIFIERS = - new HashSet(Arrays.asList(PsiModifier.PUBLIC, - PsiModifier.ABSTRACT, PsiModifier.STATIC)); + new HashSet(Arrays.asList(PsiModifier.PUBLIC, PsiModifier.ABSTRACT, PsiModifier.STATIC)); private static final Set FIELD_REDUNDANT_MODIFIERS = - new HashSet(Arrays.asList(PsiModifier.PUBLIC, - PsiModifier.STATIC, PsiModifier.FINAL)); + new HashSet(Arrays.asList(PsiModifier.PUBLIC, PsiModifier.STATIC, PsiModifier.FINAL)); private static final Set METHOD_REDUNDANT_MODIFIERS = - new HashSet(Arrays.asList(PsiModifier.PUBLIC, - PsiModifier.ABSTRACT)); + new HashSet(Arrays.asList(PsiModifier.PUBLIC, PsiModifier.ABSTRACT)); @Override @NotNull public String getDisplayName() { - return InspectionGadgetsBundle.message( - "unnecessary.interface.modifier.display.name"); + return InspectionGadgetsBundle.message("unnecessary.interface.modifier.display.name"); } @Override @@ -65,32 +58,21 @@ public class UnnecessaryInterfaceModifierInspection extends BaseInspection { final PsiClass containingClass = aClass.getContainingClass(); if (containingClass != null) { if (aClass.isInterface()) { - if (containingClass.isInterface()) { - return InspectionGadgetsBundle.message( - "unnecessary.interface.modifier.inner.interface.of.interface.problem.descriptor"); - } - else { - return InspectionGadgetsBundle.message( - "unnecessary.interface.modifier.inner.interface.of.class.problem.descriptor"); - } + return InspectionGadgetsBundle.message("unnecessary.interface.modifier.inner.interface.of.interface.problem.descriptor"); } else { - return InspectionGadgetsBundle.message( - "unnecessary.interface.modifier.problem.descriptor3"); + return InspectionGadgetsBundle.message("unnecessary.interface.modifier.problem.descriptor3"); } } else { - return InspectionGadgetsBundle.message( - "unnecessary.interface.modifier.problem.descriptor"); + return InspectionGadgetsBundle.message("unnecessary.interface.modifier.problem.descriptor"); } } else if (parent instanceof PsiMethod) { - return InspectionGadgetsBundle.message( - "unnecessary.interface.modifier.problem.descriptor2"); + return InspectionGadgetsBundle.message("unnecessary.interface.modifier.problem.descriptor2"); } else { - return InspectionGadgetsBundle.message( - "unnecessary.interface.modifier.problem.descriptor4"); + return InspectionGadgetsBundle.message("unnecessary.interface.modifier.problem.descriptor4"); } } @@ -104,8 +86,7 @@ public class UnnecessaryInterfaceModifierInspection extends BaseInspection { return new UnnecessaryInterfaceModifiersFix((String)infos[0]); } - private static class UnnecessaryInterfaceModifiersFix - extends InspectionGadgetsFix { + private static class UnnecessaryInterfaceModifiersFix extends InspectionGadgetsFix { private final String modifiersText; @@ -115,13 +96,11 @@ public class UnnecessaryInterfaceModifierInspection extends BaseInspection { @NotNull public String getName() { - return InspectionGadgetsBundle.message( - "smth.unnecessary.remove.quickfix", modifiersText); + return InspectionGadgetsBundle.message("smth.unnecessary.remove.quickfix", modifiersText); } @Override - public void doFix(Project project, ProblemDescriptor descriptor) - throws IncorrectOperationException { + public void doFix(Project project, ProblemDescriptor descriptor) { final PsiElement element = descriptor.getPsiElement(); final PsiModifierList modifierList; if (element instanceof PsiModifierList) { @@ -142,8 +121,7 @@ public class UnnecessaryInterfaceModifierInspection extends BaseInspection { if (aClass.isInterface()) { modifierList.setModifierProperty(PsiModifier.ABSTRACT, false); } - final PsiClass containingClass = - ClassUtils.getContainingClass(modifierOwner); + final PsiClass containingClass = ClassUtils.getContainingClass(modifierOwner); if (containingClass != null && containingClass.isInterface()) { // do the inner classes modifierList.setModifierProperty(PsiModifier.PUBLIC, false); @@ -160,8 +138,7 @@ public class UnnecessaryInterfaceModifierInspection extends BaseInspection { } } - private static class UnnecessaryInterfaceModifierVisitor - extends BaseInspectionVisitor { + private static class UnnecessaryInterfaceModifierVisitor extends BaseInspectionVisitor { @Override public void visitClass(@NotNull PsiClass aClass) { @@ -169,18 +146,15 @@ public class UnnecessaryInterfaceModifierInspection extends BaseInspection { if (parent != null && parent.isInterface()) { final PsiModifierList modifiers = aClass.getModifierList(); if (aClass.isInterface()) { - checkForRedundantModifiers(modifiers, - INNER_INTERFACE_REDUNDANT_MODIFIERS); + checkForRedundantModifiers(modifiers, INNER_INTERFACE_REDUNDANT_MODIFIERS); } else { - checkForRedundantModifiers(modifiers, - INNER_CLASS_REDUNDANT_MODIFIERS); + checkForRedundantModifiers(modifiers, INNER_CLASS_REDUNDANT_MODIFIERS); } } else if (aClass.isInterface()) { final PsiModifierList modifiers = aClass.getModifierList(); - checkForRedundantModifiers(modifiers, - INTERFACE_REDUNDANT_MODIFIERS); + checkForRedundantModifiers(modifiers, INTERFACE_REDUNDANT_MODIFIERS); } } @@ -212,8 +186,7 @@ public class UnnecessaryInterfaceModifierInspection extends BaseInspection { checkForRedundantModifiers(modifiers, METHOD_REDUNDANT_MODIFIERS); } - public void checkForRedundantModifiers(PsiModifierList list, - Set modifiers) { + public void checkForRedundantModifiers(PsiModifierList list, Set modifiers) { if (list == null) { return; }