NoWhitespaceBefore: add support for method reference operator #3949

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

Comments

Projects
None yet
3 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); // 1 VIOLATIONS -- want no spaces around '::' operator
    }
}

$ 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="NoWhitespaceBefore">
            <message key="ws.preceded" value="Whitespace before ''{0}'' should be removed" />
            <property name="tokens" value="METHOD_REF" />
        </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.NoWhitespaceBeforeCheck
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.NoWhitespaceBeforeCheck
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.


Want to enforce no whitespace around the new '::' operator.

@osho-agyeya

This comment has been minimized.

Show comment
Hide comment
@osho-agyeya

osho-agyeya Mar 8, 2017

I am on it.

I am on it.

Kietzmann added a commit to Kietzmann/checkstyle that referenced this issue Apr 20, 2017

Kietzmann added a commit to Kietzmann/checkstyle that referenced this issue Apr 20, 2017

Kietzmann added a commit to Kietzmann/checkstyle that referenced this issue Apr 21, 2017

romani added a commit that referenced this issue Apr 22, 2017

@romani romani added the new feature label Apr 22, 2017

@romani romani added this to the 7.7 milestone Apr 22, 2017

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Apr 22, 2017

Member

Fix is merged

Member

romani commented Apr 22, 2017

Fix is merged

@romani romani closed this Apr 22, 2017

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