Repository: checkstyle/checkstyle

Problem statement:
Update AbstractChecks to log DetailAST - InterfaceMemberImpliedModifier
Child of https://github.com/checkstyle/checkstyle/issues/5777

This issue specifically focuses on InterfaceMemberImpliedModifier.


Hints:
i am on it

@romani @rnveach can you help me to resolve this issue.
I read bit about Xpath and about checkstyle filter from https://checkstyle.org/config_filters.html but didn't get much idea.
@pkpale Look at work done by other contributors for similar issues and it will give you an idea of what needs to be done. https://github.com/checkstyle/checkstyle/issues?q=label%3A%22gsoc+second+issue%22+is%3Aclosed
I'm on it!


Patch:
diff --git a/src/it/java/org/checkstyle/suppressionxpathfilter/XpathRegressionInterfaceMemberImpliedModifierTest.java b/src/it/java/org/checkstyle/suppressionxpathfilter/XpathRegressionInterfaceMemberImpliedModifierTest.java
new file mode 100644
--- /dev/null
+++ b/src/it/java/org/checkstyle/suppressionxpathfilter/XpathRegressionInterfaceMemberImpliedModifierTest.java
@@ -0,0 +1,136 @@
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2020 the original author or authors.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+////////////////////////////////////////////////////////////////////////////////
+
+package org.checkstyle.suppressionxpathfilter;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.jupiter.api.Test;
+
+import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
+import com.puppycrawl.tools.checkstyle.checks.modifier.InterfaceMemberImpliedModifierCheck;
+
+public class XpathRegressionInterfaceMemberImpliedModifierTest extends AbstractXpathTestSupport {
+
+    @Override
+    protected String getCheckName() {
+        return InterfaceMemberImpliedModifierCheck.class.getSimpleName();
+    }
+
+    @Test
+    public void testOne() throws Exception {
+        final File fileToProcess = new File(
+            getPath("SuppressionXpathRegressionInterfaceMemberImpliedModifier1.java")
+        );
+
+        final DefaultConfiguration moduleConfig =
+            createModuleConfig(InterfaceMemberImpliedModifierCheck.class);
+
+        final String[] expectedViolation = {
+            "4:5: " + getCheckMessage(InterfaceMemberImpliedModifierCheck.class,
+                InterfaceMemberImpliedModifierCheck.MSG_KEY, "final"),
+        };
+
+        final List<String> expectedXpathQueries = Arrays.asList(
+            "/INTERFACE_DEF[./IDENT"
+                + "[@text='SuppressionXpathRegressionInterfaceMemberImpliedModifier1']]"
+                + "/OBJBLOCK/VARIABLE_DEF[./IDENT[@text='str']]",
+
+            "/INTERFACE_DEF[./IDENT"
+                + "[@text='SuppressionXpathRegressionInterfaceMemberImpliedModifier1']]"
+                + "/OBJBLOCK/VARIABLE_DEF[./IDENT[@text='str']]"
+                + "/MODIFIERS",
+
+            "/INTERFACE_DEF[./IDENT"
+                + "[@text='SuppressionXpathRegressionInterfaceMemberImpliedModifier1']]"
+                + "/OBJBLOCK/VARIABLE_DEF[./IDENT[@text='str']]"
+                + "/MODIFIERS/LITERAL_PUBLIC"
+        );
+
+        runVerifications(moduleConfig, fileToProcess, expectedViolation, expectedXpathQueries);
+    }
+
+    @Test
+    public void testTwo() throws Exception {
+        final File fileToProcess = new File(
+            getPath("SuppressionXpathRegressionInterfaceMemberImpliedModifier2.java")
+        );
+
+        final DefaultConfiguration moduleConfig =
+            createModuleConfig(InterfaceMemberImpliedModifierCheck.class);
+
+        final String[] expectedViolation = {
+            "4:5: " + getCheckMessage(InterfaceMemberImpliedModifierCheck.class,
+                InterfaceMemberImpliedModifierCheck.MSG_KEY, "public"),
+        };
+
+        final List<String> expectedXpathQueries = Arrays.asList(
+            "/INTERFACE_DEF[./IDENT"
+                + "[@text='SuppressionXpathRegressionInterfaceMemberImpliedModifier2']]"
+                + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='setData']]",
+
+            "/INTERFACE_DEF[./IDENT"
+                + "[@text='SuppressionXpathRegressionInterfaceMemberImpliedModifier2']]"
+                + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='setData']]"
+                + "/MODIFIERS",
+
+            "/INTERFACE_DEF[./IDENT"
+                + "[@text='SuppressionXpathRegressionInterfaceMemberImpliedModifier2']]"
+                + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='setData']]"
+                + "/MODIFIERS/ABSTRACT"
+        );
+
+        runVerifications(moduleConfig, fileToProcess, expectedViolation, expectedXpathQueries);
+    }
+
+    @Test
+    public void testThree() throws Exception {
+        final File fileToProcess = new File(
+            getPath("SuppressionXpathRegressionInterfaceMemberImpliedModifier3.java")
+        );
+
+        final DefaultConfiguration moduleConfig =
+            createModuleConfig(InterfaceMemberImpliedModifierCheck.class);
+
+        final String[] expectedViolation = {
+            "4:5: " + getCheckMessage(InterfaceMemberImpliedModifierCheck.class,
+                InterfaceMemberImpliedModifierCheck.MSG_KEY, "static"),
+        };
+
+        final List<String> expectedXpathQueries = Arrays.asList(
+            "/INTERFACE_DEF[./IDENT"
+                + "[@text='SuppressionXpathRegressionInterfaceMemberImpliedModifier3']]"
+                + "/OBJBLOCK/INTERFACE_DEF[./IDENT[@text='Data']]",
+
+            "/INTERFACE_DEF[./IDENT"
+                + "[@text='SuppressionXpathRegressionInterfaceMemberImpliedModifier3']]"
+                + "/OBJBLOCK/INTERFACE_DEF[./IDENT[@text='Data']]"
+                + "/MODIFIERS",
+
+            "/INTERFACE_DEF[./IDENT"
+                + "[@text='SuppressionXpathRegressionInterfaceMemberImpliedModifier3']]"
+                + "/OBJBLOCK/INTERFACE_DEF[./IDENT[@text='Data']]"
+                + "/MODIFIERS/LITERAL_PUBLIC"
+        );
+
+        runVerifications(moduleConfig, fileToProcess, expectedViolation, expectedXpathQueries);
+    }
+}
diff --git a/src/it/resources/org/checkstyle/suppressionxpathfilter/interfacememberimpliedmodifier/SuppressionXpathRegressionInterfaceMemberImpliedModifier1.java b/src/it/resources/org/checkstyle/suppressionxpathfilter/interfacememberimpliedmodifier/SuppressionXpathRegressionInterfaceMemberImpliedModifier1.java
new file mode 100644
--- /dev/null
+++ b/src/it/resources/org/checkstyle/suppressionxpathfilter/interfacememberimpliedmodifier/SuppressionXpathRegressionInterfaceMemberImpliedModifier1.java
@@ -0,0 +1,5 @@
+package org.checkstyle.suppressionxpathfilter.interfacememberimpliedmodifier;
+
+public interface SuppressionXpathRegressionInterfaceMemberImpliedModifier1 {
+    public static String str = "random string"; // warn
+}
diff --git a/src/it/resources/org/checkstyle/suppressionxpathfilter/interfacememberimpliedmodifier/SuppressionXpathRegressionInterfaceMemberImpliedModifier2.java b/src/it/resources/org/checkstyle/suppressionxpathfilter/interfacememberimpliedmodifier/SuppressionXpathRegressionInterfaceMemberImpliedModifier2.java
new file mode 100644
--- /dev/null
+++ b/src/it/resources/org/checkstyle/suppressionxpathfilter/interfacememberimpliedmodifier/SuppressionXpathRegressionInterfaceMemberImpliedModifier2.java
@@ -0,0 +1,5 @@
+package org.checkstyle.suppressionxpathfilter.interfacememberimpliedmodifier;
+
+public interface SuppressionXpathRegressionInterfaceMemberImpliedModifier2 {
+    abstract void setData(); // warn
+}
diff --git a/src/it/resources/org/checkstyle/suppressionxpathfilter/interfacememberimpliedmodifier/SuppressionXpathRegressionInterfaceMemberImpliedModifier3.java b/src/it/resources/org/checkstyle/suppressionxpathfilter/interfacememberimpliedmodifier/SuppressionXpathRegressionInterfaceMemberImpliedModifier3.java
new file mode 100644
--- /dev/null
+++ b/src/it/resources/org/checkstyle/suppressionxpathfilter/interfacememberimpliedmodifier/SuppressionXpathRegressionInterfaceMemberImpliedModifier3.java
@@ -0,0 +1,5 @@
+package org.checkstyle.suppressionxpathfilter.interfacememberimpliedmodifier;
+
+public interface SuppressionXpathRegressionInterfaceMemberImpliedModifier3 {
+    public interface Data {} // warn
+}
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressionXpathFilter.java b/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressionXpathFilter.java
--- a/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressionXpathFilter.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressionXpathFilter.java
@@ -59,9 +59,6 @@
  * Indentation
  * </li>
  * <li>
- * InterfaceMemberImpliedModifier
- * </li>
- * <li>
  * JavadocMethod
  * </li>
  * <li>


Test patch:
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/internal/XpathRegressionTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/internal/XpathRegressionTest.java
--- a/src/test/java/com/puppycrawl/tools/checkstyle/internal/XpathRegressionTest.java
+++ b/src/test/java/com/puppycrawl/tools/checkstyle/internal/XpathRegressionTest.java
@@ -59,7 +59,6 @@ public class XpathRegressionTest extends AbstractModuleTestSupport {
             "CustomImportOrder",
             "EmptyLineSeparator",
             "Indentation",
-            "InterfaceMemberImpliedModifier",
             "JavadocMethod",
             "JavadocType",
             "MissingJavadocType",