From 39cafcc5bbe8b18ca95026e76cdaa3d846db2d6d Mon Sep 17 00:00:00 2001 From: rnveach Date: Thu, 5 Jan 2017 14:44:54 -0500 Subject: [PATCH] Issue #3582: marked enum field's final method as redundant --- .../checkstyle/checks/modifier/RedundantModifierCheck.java | 3 ++- .../checks/modifier/RedundantModifierCheckTest.java | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/modifier/RedundantModifierCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/modifier/RedundantModifierCheck.java index ce18e3325..33b21aa15 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/modifier/RedundantModifierCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/modifier/RedundantModifierCheck.java @@ -278,7 +278,8 @@ public class RedundantModifierCheck checkFinal = checkFinal || classModifiers.branchContains(TokenTypes.FINAL); parent = null; } - else if (parent.getType() == TokenTypes.LITERAL_NEW) { + else if (parent.getType() == TokenTypes.LITERAL_NEW + || parent.getType() == TokenTypes.ENUM_CONSTANT_DEF) { checkFinal = true; parent = null; } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/modifier/RedundantModifierCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/modifier/RedundantModifierCheckTest.java index 8bf986b9c..81590d69a 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/modifier/RedundantModifierCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/modifier/RedundantModifierCheckTest.java @@ -227,7 +227,10 @@ public class RedundantModifierCheckTest @Test public void testEnumMethods() throws Exception { final DefaultConfiguration checkConfig = createCheckConfig(RedundantModifierCheck.class); - final String[] expected = CommonUtils.EMPTY_STRING_ARRAY; + final String[] expected = { + "7:16: " + getCheckMessage(MSG_KEY, "final"), + "22:16: " + getCheckMessage(MSG_KEY, "final"), + }; verify(checkConfig, getPath("InputFinalInEnumMethods.java"), expected); } }