Added the ability to turn off checking for wrapping on operators

This commit is contained in:
Oliver Burn 2002-05-29 12:41:01 +00:00
parent 474e266acd
commit ff0a2c0479
6 changed files with 72 additions and 14 deletions

View File

@ -573,6 +573,18 @@ public class CheckStyleTask
});
}
/** @param aIgnore whether to ignore operator wrapping **/
public void setIgnoreOpWrap(final boolean aIgnore)
{
mOptionMemory.add(new Runnable()
{
public void run()
{
mConfig.setIgnoreOpWrap(aIgnore);
}
});
}
/** @param aIgnore whether to ignore braces **/
public void setIgnoreBraces(final boolean aIgnore)
{

View File

@ -162,6 +162,8 @@ public class Configuration
private boolean mIgnoreWhitespace = false;
/** whether to ignore cast whitespace **/
private boolean mIgnoreCastWhitespace = false;
/** whether to ignore op wrapping **/
private boolean mIgnoreOpWrap = false;
/** whether to ignore braces **/
private boolean mIgnoreBraces = false;
/** whether to ignore 'public' keyword in interface definitions **/
@ -262,6 +264,9 @@ public class Configuration
setIgnoreCastWhitespace(getBooleanProperty(aProps,
IGNORE_CAST_WHITESPACE_PROP,
mIgnoreCastWhitespace));
setIgnoreOpWrap(getBooleanProperty(aProps,
IGNORE_OP_WRAP_PROP,
mIgnoreOpWrap));
setIgnoreBraces(getBooleanProperty(aProps,
IGNORE_BRACES_PROP,
mIgnoreBraces));
@ -583,6 +588,12 @@ public class Configuration
return mIgnoreCastWhitespace;
}
/** @return whether to ignore checks for operator wrapping **/
public boolean isIgnoreOpWrap()
{
return mIgnoreOpWrap;
}
/** @return whether to ignore checks for braces **/
public boolean isIgnoreBraces()
{
@ -900,6 +911,14 @@ public class Configuration
mIgnoreCastWhitespace = aTo;
}
/**
* @param aTo whether to ignore operator wrapping
*/
public void setIgnoreOpWrap(boolean aTo)
{
mIgnoreOpWrap = aTo;
}
/**
* @param aTo whether to ignore checks for braces
*/

View File

@ -84,6 +84,8 @@ public interface Defn
String IGNORE_CAST_WHITESPACE_PROP = "checkstyle.ignore.whitespace.cast";
/** property name for ignoring braces **/
String IGNORE_BRACES_PROP = "checkstyle.ignore.braces";
/** property name for ignoring wrapping lines on operators **/
String IGNORE_OP_WRAP_PROP = "checkstyle.ignore.opwrap";
/** property name for ignoring 'public' in interface definitions **/
String IGNORE_PUBLIC_IN_INTERFACE_PROP =
"checkstyle.ignore.public.in.interface";

View File

@ -965,22 +965,18 @@ class Verifier
*/
void verifyOpBegin(int aLineNo, int aColNo, String aText)
{
if (mConfig.isIgnoreWhitespace()) {
return;
}
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 example of the check below.:-)
// if (!aText.equals(mLines[aLineNo - 1].trim())
// &&
// (mLines[aLineNo - 1].substring(aColNo + aText.length() - 1)
// .trim().length() == 0))
// {
// log(aLineNo, aColNo - 1,
// "'" + aText + "' should be on a new line.");
// }
if (!mConfig.isIgnoreOpWrap()
&& !aText.equals(mLines[aLineNo - 1].trim())
&& (mLines[aLineNo - 1].substring(aColNo + aText.length() - 1)
.trim().length() == 0))
{
log(aLineNo, aColNo - 1,
"'" + aText + "' should be on a new line.");
}
}

View File

@ -903,14 +903,14 @@ shiftExpression
// binary addition/subtraction (level 3)
additiveExpression
: multiplicativeExpression
((p:PLUS^ {ver.verifyOpBegin(p.getLine(), p.getColumn(), p.getText());}| m:MINUS^ {ver.verifyWSAroundBegin(m.getLine(), m.getColumn(), m.getText());} )
((p:PLUS^ {ver.verifyOpBegin(p.getLine(), p.getColumn(), p.getText());}| m:MINUS^ {ver.verifyOpBegin(m.getLine(), m.getColumn(), m.getText());} )
multiplicativeExpression)*
;
// multiplication/division/modulo (level 2)
multiplicativeExpression
: unaryExpression ((s:STAR^ {ver.verifyWSAroundBegin(s.getLine(), s.getColumn(), s.getText());} | DIV^ | MOD^ ) unaryExpression)*
: unaryExpression ((s:STAR^ {ver.verifyOpBegin(s.getLine(), s.getColumn(), s.getText());} | DIV^ | MOD^ ) unaryExpression)*
;
unaryExpression

View File

@ -809,4 +809,33 @@ public class CheckerTest
verify(c, filepath, expected);
}
public void testOpWrapOn()
throws Exception
{
mConfig.setJavadocScope(Scope.NOTHING);
mConfig.setIgnoreOpWrap(false);
final Checker c = createChecker();
final String filepath = getPath("InputOpWrap.java");
assertNotNull(c);
final String[] expected = {
filepath + ":15:19: '+' should be on a new line.",
filepath + ":16:15: '-' should be on a new line.",
filepath + ":24:18: '&&' should be on a new line.",
};
verify(c, filepath, expected);
}
public void testOpWrapOff()
throws Exception
{
mConfig.setJavadocScope(Scope.NOTHING);
mConfig.setIgnoreOpWrap(true);
final Checker c = createChecker();
final String filepath = getPath("InputOpWrap.java");
assertNotNull(c);
final String[] expected = {
};
verify(c, filepath, expected);
}
}