diff options
3 files changed, 41 insertions, 0 deletions
diff --git a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule451wheretobreak/SeparatorWrapTest.java b/src/it/java/com/google/checkstyle/test/chapter4formatting/rule451wheretobreak/SeparatorWrapTest.java index a63d92f3d..393f773d7 100644 --- a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule451wheretobreak/SeparatorWrapTest.java +++ b/src/it/java/com/google/checkstyle/test/chapter4formatting/rule451wheretobreak/SeparatorWrapTest.java @@ -19,6 +19,8 @@ package com.google.checkstyle.test.chapter4formatting.rule451wheretobreak; +import static com.puppycrawl.tools.checkstyle.checks.whitespace.SeparatorWrapCheck.MSG_LINE_NEW; + import java.io.File; import java.io.IOException; @@ -63,4 +65,18 @@ public class SeparatorWrapTest extends BaseCheckTestSupport { final Integer[] warnList = getLinesWithWarn(filePath); verify(checkConfig, filePath, expected, warnList); } + + @Test + public void separatorWrapMethodRefTest() throws Exception { + + final String[] expected = { + "17:49: " + getCheckMessage(SeparatorWrapCheck.class, MSG_LINE_NEW, "::"), + }; + + final Configuration checkConfig = getCheckConfig("SeparatorWrap", "SeparatorWrapMethodRef"); + final String filePath = getPath("InputSeparatorWrapMethodRef.java"); + + final Integer[] warnList = getLinesWithWarn(filePath); + verify(checkConfig, filePath, expected, warnList); + } } diff --git a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule451wheretobreak/InputSeparatorWrapMethodRef.java b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule451wheretobreak/InputSeparatorWrapMethodRef.java new file mode 100644 index 000000000..af314afdd --- /dev/null +++ b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule451wheretobreak/InputSeparatorWrapMethodRef.java @@ -0,0 +1,20 @@ +package com.google.checkstyle.test.chapter4formatting.rule451wheretobreak; + +import java.util.Arrays; + +public class InputSeparatorWrapMethodRef { + + void goodCase() { + String[] stringArray = { "Barbara", "James", "Mary", "John", + "Patricia", "Robert", "Michael", "Linda" }; + Arrays.sort(stringArray, String + ::compareToIgnoreCase); + } + + void badCase() { + String[] stringArray = { "Barbara", "James", "Mary", "John", + "Patricia", "Robert", "Michael", "Linda" }; + /*warn*/ Arrays.sort(stringArray, String:: + compareToIgnoreCase); + } +} diff --git a/src/main/resources/google_checks.xml b/src/main/resources/google_checks.xml index a98447470..3817fb168 100644 --- a/src/main/resources/google_checks.xml +++ b/src/main/resources/google_checks.xml @@ -93,6 +93,11 @@ <property name="tokens" value="COMMA"/> <property name="option" value="EOL"/> </module> + <module name="SeparatorWrap"> + <property name="id" value="SeparatorWrapMethodRef"/> + <property name="tokens" value="METHOD_REF"/> + <property name="option" value="nl"/> + </module> <module name="PackageName"> <property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/> <message key="name.invalidPattern" |