From 3fecb73fb3ea4da6bef4e5e9f3a5d555568f0a34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20K=C3=BChne?= Date: Fri, 13 Sep 2002 05:43:47 +0000 Subject: [PATCH] =?UTF-8?q?incorporte=20patch=20607481=20from=20Ville=20Sk?= =?UTF-8?q?ytt=C3=A4=20to=20enforce=20wrap=20on=20operator=20at=20EOL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/engine.html | 11 +++++++- docs/property_types.html | 9 +++++++ docs/releasenotes.html | 1 + .../puppycrawl/tools/checkstyle/Verifier.java | 27 +++++++++++++------ .../tools/checkstyle/WrapOpOption.java | 2 ++ .../tools/checkstyle/CheckerTest.java | 20 ++++++++++++-- 6 files changed, 59 insertions(+), 11 deletions(-) diff --git a/docs/engine.html b/docs/engine.html index 77aaea7d7..86a6bf87b 100644 --- a/docs/engine.html +++ b/docs/engine.html @@ -118,7 +118,7 @@ eol - The brace must always be on the end of the line. For example: + The brace must always be at the end of the line. For example:
     if (condition) {
         ...
@@ -354,6 +354,15 @@
       This is the default value.
     
   
+  
+    eol
+    The operator must be at the end of the line. For example:
+
+    someVariable = aBigVariableNameToMakeThings + "this may work" +
+                   lookVeryInteresting;
+
+ + diff --git a/docs/property_types.html b/docs/property_types.html index 13023c8af..ee896dddb 100644 --- a/docs/property_types.html +++ b/docs/property_types.html @@ -104,6 +104,15 @@ following table describes the valid options:

     someVariable = aBigVariableNameToMakeThings + "this may work"
                    + lookVeryInteresting;
+
+ + + + eol + The operator must be at the end of the line. For example: +
+    someVariable = aBigVariableNameToMakeThings + "this may work" +
+                   lookVeryInteresting;
 
diff --git a/docs/releasenotes.html b/docs/releasenotes.html index bd0eab990..6c788cc4c 100644 --- a/docs/releasenotes.html +++ b/docs/releasenotes.html @@ -51,6 +51,7 @@
  • Incorporate patch 566855 from Rob Worth to optionally check that parenthesis are padded with spaces.
  • Incorporate patch 590931 from Vijay Aravamudhan to improve documentation of the build.xml file.
  • Incorporate patch from Vijay Aravamudhan to enforce requiring @version tag (request 543964).
  • +
  • Incorporate patch 607481 from Ville Skyttä to enforce wrap on operator at EOL.
  • diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/Verifier.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/Verifier.java index 19aa82868..fbf5581d9 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/Verifier.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/Verifier.java @@ -1035,14 +1035,25 @@ class Verifier { verifyWSAroundBegin(aLineNo, aColNo, aText); - // Check if rest of line is whitespace, and not just the operator by - // itself. This last bit is to handle the operator on a line by itself - if ((mConfig.getWrapOpOption() != WrapOpOption.IGNORE) - && !aText.equals(mLines[aLineNo - 1].trim()) - && (mLines[aLineNo - 1].substring(aColNo + aText.length() - 1) - .trim().length() == 0)) - { - mMessages.add(aLineNo, aColNo - 1, "line.new", aText); + final WrapOpOption wOp = mConfig.getWrapOpOption(); + + if (wOp != WrapOpOption.IGNORE) { + + // Check if rest of line is whitespace, and not just the operator + // by itself. This last bit is to handle the operator on a line by + // itself. + if (wOp == WrapOpOption.NL + && !aText.equals(mLines[aLineNo - 1].trim()) + && (mLines[aLineNo - 1].substring(aColNo + aText.length() - 1) + .trim().length() == 0)) + { + mMessages.add(aLineNo, aColNo - 1, "line.new", aText); + } + else if (wOp == WrapOpOption.EOL + && Utils.whitespaceBefore(aColNo - 1, mLines[aLineNo - 1])) + { + mMessages.add(aLineNo, aColNo - 1, "line.previous", aText); + } } } diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/WrapOpOption.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/WrapOpOption.java index f6a3f7715..962c487a9 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/WrapOpOption.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/WrapOpOption.java @@ -37,6 +37,8 @@ public final class WrapOpOption /** represents operator on a new line **/ public static final WrapOpOption NL = new WrapOpOption("nl"); + /** represents operator at end of line **/ + public static final WrapOpOption EOL = new WrapOpOption("eol"); /** represents ignoring the wrapping **/ public static final WrapOpOption IGNORE = new WrapOpOption("ignore"); diff --git a/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java b/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java index 199d2c26b..7958ffb48 100644 --- a/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java +++ b/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java @@ -935,7 +935,7 @@ public class CheckerTest verify(c, filepath, expected); } - public void testOpWrapOn() + public void testOpWrapNL() throws Exception { mProps.setProperty(Defn.JAVADOC_CHECKSCOPE_PROP, Scope.NOTHING.getName()); @@ -951,7 +951,23 @@ public class CheckerTest verify(c, filepath, expected); } - public void testOpWrapOff() + public void testOpWrapEOL() + throws Exception + { + mProps.setProperty(Defn.JAVADOC_CHECKSCOPE_PROP, Scope.NOTHING.getName()); + mProps.setProperty(Defn.WRAP_OP_PROP, WrapOpOption.EOL.toString()); + final Checker c = createChecker(); + final String filepath = getPath("InputOpWrap.java"); + assertNotNull(c); + final String[] expected = { + filepath + ":18:13: '-' should be on the previous line.", + filepath + ":22:13: '&&' should be on the previous line.", + filepath + ":27:13: '&&' should be on the previous line.", + }; + verify(c, filepath, expected); + } + + public void testOpWrapIgnore() throws Exception { mProps.setProperty(Defn.JAVADOC_CHECKSCOPE_PROP, Scope.NOTHING.getName());