Repository: checkstyle/checkstyle

Problem statement:
`EmptyLineSeparator`: false negative in Enum and interface fields
I have read check documentation: https://checkstyle.org/config_whitespace.html#EmptyLineSeparator
I have downloaded the latest checkstyle from: https://checkstyle.org/cmdline.html#Download_and_Run
I have executed the cli and showed it below, as cli describes the problem better than 1,000 words

```bash
/var/tmp $ javac SomeEnum.java

/var/tmp $ cat config.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
        "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
        "https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
    <module name="TreeWalker">
        <module name="EmptyLineSeparator">
            <property name="allowMultipleEmptyLines" value="false"/>
            <property name="allowMultipleEmptyLinesInsideClassMembers" value="false"/>
        </module>
    </module>
</module>

/var/tmp $ cat SomeEnum.java
package some.pckg;

public enum SomeEnum {

    ONE("one"),
    TWO("two");




    private final String someString;

    SomeEnum(String someString) {
        this.someString = someString;
    }

    public String getSomeString() {
        return someString;
    }
}


/var/tmp $ RUN_LOCALE="-Duser.language=en -Duser.country=US"
/var/tmp $ java $RUN_LOCALE -jar checkstyle-9.2.1-all.jar -c config.xml SomeEnum.java
Checkstyle ends without errors.
```

---

Checkstyle ends without errors, but I expect violation to be found since there are more than 1 empty lines between enum constant `TWO` and field `someString`.



Hints:
I could reproduce the issue, will fix it soon.

Patch:
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/whitespace/EmptyLineSeparatorCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/whitespace/EmptyLineSeparatorCheck.java
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/whitespace/EmptyLineSeparatorCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/whitespace/EmptyLineSeparatorCheck.java
@@ -935,8 +935,7 @@ private static boolean isPrecededByJavadoc(DetailAST token) {
      * @return true variable definition is a type field.
      */
     private static boolean isTypeField(DetailAST variableDef) {
-        return TokenUtil.isOfType(variableDef.getParent().getParent(),
-             TokenTypes.CLASS_DEF, TokenTypes.RECORD_DEF);
+        return TokenUtil.isTypeDeclaration(variableDef.getParent().getParent().getType());
     }
 
 }


Test patch:
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/EmptyLineSeparatorCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/EmptyLineSeparatorCheckTest.java
--- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/EmptyLineSeparatorCheckTest.java
+++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/EmptyLineSeparatorCheckTest.java
@@ -248,6 +248,35 @@ public void testSingleCommentSeparatedFromPackage() throws Exception {
             expected);
     }
 
+    @Test
+    public void testEnumMembers() throws Exception {
+        final String[] expected = {
+            "22:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "VARIABLE_DEF"),
+            "27:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "VARIABLE_DEF"),
+            "28:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "VARIABLE_DEF"),
+            "31:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "CTOR_DEF"),
+            "36:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "STATIC_INIT"),
+            "40:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "STATIC_INIT"),
+        };
+        verifyWithInlineConfigParser(
+            getPath("InputEmptyLineSeparatorEnumMembers.java"), expected
+        );
+    }
+
+    @Test
+    public void testInterfaceFields() throws Exception {
+        final String[] expected = {
+            "21:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "VARIABLE_DEF"),
+            "25:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "VARIABLE_DEF"),
+            "34:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "VARIABLE_DEF"),
+            "38:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "VARIABLE_DEF"),
+            "45:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "VARIABLE_DEF"),
+        };
+        verifyWithInlineConfigParser(
+            getPath("InputEmptyLineSeparatorInterfaceFields.java"), expected
+        );
+    }
+
     @Test
     public void testGetAcceptableTokens() {
         final EmptyLineSeparatorCheck emptyLineSeparatorCheckObj = new EmptyLineSeparatorCheck();
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/whitespace/emptylineseparator/InputEmptyLineSeparatorEnumMembers.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/whitespace/emptylineseparator/InputEmptyLineSeparatorEnumMembers.java
new file mode 100644
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/whitespace/emptylineseparator/InputEmptyLineSeparatorEnumMembers.java
@@ -0,0 +1,47 @@
+/*
+EmptyLineSeparator
+allowNoEmptyLineBetweenFields = (default)false
+allowMultipleEmptyLines = false
+allowMultipleEmptyLinesInsideClassMembers = false
+tokens = (default)PACKAGE_DEF, IMPORT, STATIC_IMPORT, CLASS_DEF, INTERFACE_DEF, ENUM_DEF, \
+         STATIC_INIT, INSTANCE_INIT, METHOD_DEF, CTOR_DEF, VARIABLE_DEF, RECORD_DEF, \
+         COMPACT_CTOR_DEF
+
+
+*/
+
+package com.puppycrawl.tools.checkstyle.checks.whitespace.emptylineseparator;
+
+public class InputEmptyLineSeparatorEnumMembers {}
+
+enum A {
+    ONE("one"),
+    TWO("two");
+
+
+    private final String str; // violation ''VARIABLE_DEF' has more than 1 empty lines before.'
+
+    private String otherString; // ok
+
+
+    private String thirdString; // violation ''VARIABLE_DEF' has more than 1 empty lines before.'
+    private String fourth; // violation ''VARIABLE_DEF' should be separated from previous line.'
+
+
+    A(String s) { // violation ''CTOR_DEF' has more than 1 empty lines before.'
+        this.str = s;
+    }
+
+    private String fifth;
+    static { // violation ''STATIC_INIT' should be separated from previous line.'
+    }
+
+
+    static { // violation ''STATIC_INIT' has more than 1 empty lines before.'
+
+    }
+
+    public String getStr() {
+        return str;
+    }
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/whitespace/emptylineseparator/InputEmptyLineSeparatorInterfaceFields.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/whitespace/emptylineseparator/InputEmptyLineSeparatorInterfaceFields.java
new file mode 100644
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/whitespace/emptylineseparator/InputEmptyLineSeparatorInterfaceFields.java
@@ -0,0 +1,46 @@
+/*
+EmptyLineSeparator
+allowNoEmptyLineBetweenFields = (default)false
+allowMultipleEmptyLines = false
+allowMultipleEmptyLinesInsideClassMembers = false
+tokens = (default)PACKAGE_DEF, IMPORT, STATIC_IMPORT, CLASS_DEF, INTERFACE_DEF, ENUM_DEF, \
+         STATIC_INIT, INSTANCE_INIT, METHOD_DEF, CTOR_DEF, VARIABLE_DEF, RECORD_DEF, \
+         COMPACT_CTOR_DEF
+
+
+*/
+
+package com.puppycrawl.tools.checkstyle.checks.whitespace.emptylineseparator;
+
+public interface InputEmptyLineSeparatorInterfaceFields {
+    int a = 45; // ok
+
+    int b = 45; // ok
+
+
+    int c = 45; // violation ''VARIABLE_DEF' has more than 1 empty lines before.'
+
+
+
+    int d = 45; // violation ''VARIABLE_DEF' has more than 1 empty lines before.'
+}
+
+@interface Ann {
+    int a = 45; // ok
+
+    int b = 45; // ok
+
+
+    int c = 45; // violation ''VARIABLE_DEF' has more than 1 empty lines before.'
+
+
+
+    int d = 45; // violation ''VARIABLE_DEF' has more than 1 empty lines before.'
+}
+
+interface Abc {
+    Object apply(Object array, int index);
+
+    Abc A = (o, i) -> new Object();
+    Abc B = (o, i) -> o; // violation ''VARIABLE_DEF' should be separated from previous line.'
+}