incorporte patch 607481 from Ville Skyttä to enforce wrap on operator at EOL

This commit is contained in:
Lars Kühne 2002-09-13 05:43:47 +00:00
parent 92ea4cfb51
commit 3fecb73fb3
6 changed files with 59 additions and 11 deletions

View File

@ -118,7 +118,7 @@
</tr>
<tr>
<td><span class="code">eol</span></td>
<td>The brace must always be on the end of the line. For example:
<td>The brace must always be at the end of the line. For example:
<pre>
if (condition) {
...
@ -354,6 +354,15 @@
This is the default value.
</td>
</tr>
<tr>
<td><span class="code">eol</span></td>
<td>The operator must be at the end of the line. For example:
<pre>
someVariable = aBigVariableNameToMakeThings + "this may work" +
lookVeryInteresting;
</pre>
</td>
</tr>
</table>

View File

@ -104,6 +104,15 @@ following table describes the valid options:</p>
<pre>
someVariable = aBigVariableNameToMakeThings + "this may work"
+ lookVeryInteresting;
</pre>
</td>
</tr>
<tr>
<td><span class="code">eol</span></td>
<td>The operator must be at the end of the line. For example:
<pre>
someVariable = aBigVariableNameToMakeThings + "this may work" +
lookVeryInteresting;
</pre>
</td>
</tr>

View File

@ -51,6 +51,7 @@
<li class="body">Incorporate patch 566855 from Rob Worth to optionally check that parenthesis are padded with spaces.</li>
<li class="body">Incorporate patch 590931 from Vijay Aravamudhan to improve documentation of the build.xml file.</li>
<li class="body">Incorporate patch from Vijay Aravamudhan to enforce requiring @version tag (request 543964).</li>
<li class="body">Incorporate patch 607481 from Ville Skyttä to enforce wrap on operator at EOL.</li>
</ul>
</p>

View File

@ -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);
}
}
}

View File

@ -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");

View File

@ -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());