Skip to content

Commit

Permalink
Issue checkstyle#3949: NoWhitespaceBefore: add support for method ref…
Browse files Browse the repository at this point in the history
…erence operator
  • Loading branch information
Kietzmann committed Apr 21, 2017
1 parent 735a46d commit a8a56e5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/checkstyle_checks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@
<module name="NoWhitespaceBefore"/>
<module name="NoWhitespaceBefore">
<property name="tokens" value="DOT"/>
<property name="tokens" value="METHOD_REF"/>
<property name="allowLineBreaks" value="true"/>
</module>
<module name="OperatorWrap">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public int[] getAcceptableTokens() {
TokenTypes.GENERIC_START,
TokenTypes.GENERIC_END,
TokenTypes.ELLIPSIS,
TokenTypes.METHOD_REF,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,14 @@ public void testDotAllowLineBreaks() throws Exception {
};
verify(checkConfig, getPath("InputNoWhitespaceBeforeDotAllowLineBreaks.java"), expected);
}

@Test
public void testMethodReference() throws Exception {
checkConfig.addAttribute("tokens", "METHOD_REF");
final String[] expected = {
"17:31: " + getCheckMessage(MSG_KEY, "::"),
"18:60: " + getCheckMessage(MSG_KEY, "::"),
};
verify(checkConfig, getPath("InputNoWhitespaceBeforeMethodRef.java"), expected);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.puppycrawl.tools.checkstyle.checks.whitespace.nowhitespacebefore;

import java.util.function.Supplier;

public class InputNoWhitespaceBeforeMethodRef {
public static class SomeClass {
public static class Nested<V> {
private Nested() {
}
}
}

public static class Nested2<V> {
}

public <V> void methodName(V value) {
Supplier<?> t = Nested2<V> ::new; //violation
Supplier<SomeClass.Nested<V>> passes = SomeClass.Nested ::new; //violation
Supplier<SomeClass.Nested<V>> fails = SomeClass.Nested<V>::new;
}
}
3 changes: 2 additions & 1 deletion src/xdocs/config_whitespace.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,8 @@ import static java.math.BigInteger.ZERO;
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#DOT">DOT</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#GENERIC_START">GENERIC_START</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#GENERIC_END">GENERIC_END</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ELLIPSIS">ELLIPSIS</a>.
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ELLIPSIS">ELLIPSIS</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ELLIPSIS">METHOD_REF</a>.
</td>
<td>
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#COMMA">COMMA</a>,
Expand Down

0 comments on commit a8a56e5

Please sign in to comment.