SeparatorWrap: add support for method reference operator #3951

Closed
rnveach opened this Issue Mar 7, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@rnveach
Member

rnveach commented Mar 7, 2017

"::" is separator, NOT a operator - https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.11

$ cat MethodRef.java

import java.util.Objects;
import java.util.stream.Stream;

public class MethodRef
{
    {
        Stream.of().filter(Objects
            ::nonNull); // VIOLATION -- want '::' operator at end of previous line
    }
}

$ cat config.xml

<!DOCTYPE module PUBLIC
  "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
  "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="Checker">
    <module name="TreeWalker">
        <module name="SeparatorWrap">
            <message key="line.previous" value="Separtor ''{0}'' should be at end of previous line" />
            <property name="tokens" value="METHOD_REF" />
            <property name="option" value="eol" />
        </module>
    </module>
</module>

/var/tmp $ java -jar checkstyle-7.0-all.jar -c config.xml MethodRef.java
C:\Users\U0076777>java -jar checkstyle-7.0-all.jar -c config.xml MethodRef.java
com.puppycrawl.tools.checkstyle.api.CheckstyleException: cannot initialize module TreeWalker - Token "METHOD_REF" was
not found in Acceptable tokens list in check com.puppycrawl.tools.checkstyle.checks.whitespace.SeparatorWrapCheck
at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:407)
at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:138)
at com.puppycrawl.tools.checkstyle.Main.runCheckstyle(Main.java:385)
at com.puppycrawl.tools.checkstyle.Main.runCli(Main.java:323)
at com.puppycrawl.tools.checkstyle.Main.main(Main.java:161)
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Token "METHOD_REF" was not found in Acceptable tokens list in check com.puppycrawl.tools.checkstyle.checks.whitespace.SeparatorWrapCheck
at com.puppycrawl.tools.checkstyle.TreeWalker.registerCheck(TreeWalker.java:226)
at com.puppycrawl.tools.checkstyle.TreeWalker.setupChild(TreeWalker.java:163)
at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:138)
at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:402)
... 4 more
Checkstyle ends with 1 errors.


need METHOD_REF added to OperatorWrap check to be able to enforce the wrapping policy.

@Luolc

This comment has been minimized.

Show comment
Hide comment
@Luolc

Luolc Apr 3, 2017

Contributor

I am on it.

Contributor

Luolc commented Apr 3, 2017

I am on it.

Luolc added a commit to Luolc/checkstyle that referenced this issue Apr 3, 2017

Luolc added a commit to Luolc/checkstyle that referenced this issue Apr 3, 2017

Luolc added a commit to Luolc/checkstyle that referenced this issue Apr 6, 2017

Luolc added a commit to Luolc/checkstyle that referenced this issue Apr 9, 2017

Luolc added a commit to Luolc/checkstyle that referenced this issue Apr 9, 2017

rnveach added a commit that referenced this issue Apr 26, 2017

@rnveach

This comment has been minimized.

Show comment
Hide comment
@rnveach

rnveach Apr 26, 2017

Member

fix is merged

Member

rnveach commented Apr 26, 2017

fix is merged

@rnveach rnveach closed this Apr 26, 2017

@rnveach rnveach added the new feature label Apr 26, 2017

@rnveach rnveach added this to the 7.7 milestone Apr 26, 2017

timurt added a commit to timurt/checkstyle that referenced this issue May 6, 2017

timurt added a commit to timurt/checkstyle that referenced this issue May 6, 2017

timurt added a commit to timurt/checkstyle that referenced this issue May 6, 2017

timurt added a commit to timurt/checkstyle that referenced this issue May 6, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment