Update the tests and documentation for checking whitespace around periods.

#493383
This commit is contained in:
Oliver Burn 2002-02-09 13:18:30 +00:00
parent 241c48750b
commit db84febeb5
4 changed files with 111 additions and 85 deletions

View File

@ -184,13 +184,14 @@
<p>Container Managed Persistence EJBs require (in the EJB 1.1 specification) that managed fields are declared <span class="code">public</span>. This will cause checkstyle to complain that the fields should be declared <span class="code">private</span>. Hence checkstyle supports ignoring <span class="code">public</span> that match a specified regular expression. The default is <span class="code">^f[A-Z][a-zA-Z0-9]*$</span>.</p>
</div>
<h3>White space</h3>
<h3>Whitespace</h3>
<p>Checks for the following use of white space:</p>
<ul>
<li>Binary operators are separated from operands by spaces. For example <span class="code">x = y + 1;</span></li>
<li>Unary operators are not separated by spaces. For example <span class="code">x = --y + z++;</span></li>
<li>The keywords <span class="code">if/for/while/do/catch/synchronized/return</span> are surrounded by spaces.</li>
<li>Casts and commas (',') are followed by white space.
<li>Casts and commas (',') are followed by whitespace.</li>
<li>Periods ('.') are not surrounded by whitespace.</li>
</ul>
<p>This feature can be turned off.</p>

View File

@ -183,14 +183,14 @@ identifier
ver.reportReference(i1.getText());
sLastIdentifier = new LineText(i1.getLine(), i1.getText());
}
( DOT^ i2:IDENT {sLastIdentifier.appendText("." + i2.getText());} )*
( DOT^ i2:IDENT {ver.verifyDot(#DOT); sLastIdentifier.appendText("." + i2.getText());} )*
;
identifierStar
{ int ln = 0; String str = ""; boolean star = false; }
: i1:IDENT {ln = i1.getLine(); str = i1.getText();}
( DOT^ i2:IDENT {str += "." + i2.getText();} )*
( DOT^ i3:STAR {str += ".*"; star = true;} )?
( DOT^ i2:IDENT {str += "." + i2.getText(); ver.verifyDot(#DOT); } )*
( DOT^ i3:STAR {str += ".*"; star = true; ver.verifyDot(#DOT); } )?
{
if (star) {
ver.reportStarImport(ln, str);
@ -394,7 +394,7 @@ explicitConstructorInvocation
{#lp2.setType(SUPER_CTOR_CALL);}
// (new Outer()).super() (create enclosing instance)
| primaryExpression DOT! "super"! lp3:LPAREN^ argList RPAREN! SEMI!
| primaryExpression DOT! {ver.verifyDot(#DOT);} "super"! lp3:LPAREN^ argList RPAREN! SEMI!
{#lp3.setType(SUPER_CTOR_CALL);}
)
;
@ -884,7 +884,7 @@ postfixExpression
: primaryExpression // start with a primary
( // qualified id (id.id.id.id...) -- build the name
DOT^ ( IDENT {ver.reportReference(sFirstIdent);}
DOT^ {ver.verifyDot(#DOT);} ( IDENT {ver.reportReference(sFirstIdent);}
| "this"
| "class" {ver.reportReference(sFirstIdent);}
| newExpression
@ -895,7 +895,7 @@ postfixExpression
// allow ClassName[].class
| ( lbc:LBRACK^ {#lbc.setType(ARRAY_DECLARATOR);} RBRACK! )+
DOT^ "class"
DOT^ "class" {ver.verifyDot(#DOT);}
// an array indexing operation
| lb:LBRACK^ {#lb.setType(INDEX_OP);} expression RBRACK!
@ -935,7 +935,7 @@ primaryExpression
// look for int.class and int[].class
| builtInType
( lbt:LBRACK^ {#lbt.setType(ARRAY_DECLARATOR);} RBRACK! )*
DOT^ "class"
DOT^ "class" { ver.verifyDot(#DOT); }
;
/** object instantiation.
@ -1067,7 +1067,6 @@ LCURLY : '{' ;
RCURLY : '}' ;
COLON : ':' ;
COMMA : ',' {ver.verifyWSAfter(getLine(), getColumn() - 1, MyToken.COMMA);} ;
//DOT : '.' ;
ASSIGN : '=' {ver.verifyWSAroundEnd(getLine(), getColumn(), "=");} ;
EQUAL : "==" {ver.verifyWSAroundEnd(getLine(), getColumn(), "==");} ;
LNOT : '!' ; // check above

View File

@ -87,46 +87,52 @@ public class CheckerTest
final String filepath = getPath("InputWhitespace.java");
assertNotNull(c);
final String[] expected = {
filepath + ":11: type Javadoc comment is missing an @author tag.",
filepath + ":14: '=' is not preceeded with whitespace.",
filepath + ":14: '=' is not followed by whitespace.",
filepath + ":5: '.' is preceeded with whitespace.",
filepath + ":5: '.' is followed by whitespace.",
filepath + ":13: type Javadoc comment is missing an @author tag.",
filepath + ":16: '=' is not preceeded with whitespace.",
filepath + ":16: '=' is not followed by whitespace.",
filepath + ":24: '=' is not preceeded with whitespace.",
filepath + ":25: '=' is not preceeded with whitespace.",
filepath + ":25: '=' is not followed by whitespace.",
filepath + ":26: '+=' is not preceeded with whitespace.",
filepath + ":26: '+=' is not followed by whitespace.",
filepath + ":27: '-=' is not followed by whitespace.",
filepath + ":27: '-' is followed by whitespace.",
filepath + ":27: '+' is followed by whitespace.",
filepath + ":28: '++' is preceeded with whitespace.",
filepath + ":28: '--' is preceeded with whitespace.",
filepath + ":29: '++' is followed by whitespace.",
filepath + ":29: '--' is followed by whitespace.",
filepath + ":35: 'synchronized' is not followed by whitespace.",
filepath + ":37: 'try' is not followed by whitespace.",
filepath + ":39: 'catch' is not followed by whitespace.",
filepath + ":56: 'if' is not followed by whitespace.",
filepath + ":74: 'return' is not followed by whitespace.",
filepath + ":86: cast needs to be followed by whitespace.",
filepath + ":95: '?' is not preceeded with whitespace.",
filepath + ":95: '?' is not followed by whitespace.",
filepath + ":95: ':' is not preceeded with whitespace.",
filepath + ":95: ':' is not followed by whitespace.",
filepath + ":96: '==' is not preceeded with whitespace.",
filepath + ":96: '==' is not followed by whitespace.",
filepath + ":102: '*' is not followed by whitespace.",
filepath + ":102: '*' is not preceeded with whitespace.",
filepath + ":109: '!' is followed by whitespace.",
filepath + ":110: '~' is followed by whitespace.",
filepath + ":117: '%' is not preceeded with whitespace.",
filepath + ":118: '%' is not followed by whitespace.",
filepath + ":18: '=' is not followed by whitespace.",
filepath + ":26: '=' is not preceeded with whitespace.",
filepath + ":27: '=' is not preceeded with whitespace.",
filepath + ":27: '=' is not followed by whitespace.",
filepath + ":28: '+=' is not preceeded with whitespace.",
filepath + ":28: '+=' is not followed by whitespace.",
filepath + ":29: '-=' is not followed by whitespace.",
filepath + ":29: '-' is followed by whitespace.",
filepath + ":29: '+' is followed by whitespace.",
filepath + ":30: '++' is preceeded with whitespace.",
filepath + ":30: '--' is preceeded with whitespace.",
filepath + ":31: '++' is followed by whitespace.",
filepath + ":31: '--' is followed by whitespace.",
filepath + ":37: 'synchronized' is not followed by whitespace.",
filepath + ":39: 'try' is not followed by whitespace.",
filepath + ":41: 'catch' is not followed by whitespace.",
filepath + ":58: 'if' is not followed by whitespace.",
filepath + ":76: 'return' is not followed by whitespace.",
filepath + ":88: cast needs to be followed by whitespace.",
filepath + ":97: '?' is not preceeded with whitespace.",
filepath + ":97: '?' is not followed by whitespace.",
filepath + ":97: ':' is not preceeded with whitespace.",
filepath + ":97: ':' is not followed by whitespace.",
filepath + ":98: '==' is not preceeded with whitespace.",
filepath + ":98: '==' is not followed by whitespace.",
filepath + ":104: '*' is not followed by whitespace.",
filepath + ":104: '*' is not preceeded with whitespace.",
filepath + ":111: '!' is followed by whitespace.",
filepath + ":112: '~' is followed by whitespace.",
filepath + ":119: '%' is not preceeded with whitespace.",
filepath + ":119: '%' is not followed by whitespace.",
filepath + ":121: '/' is not preceeded with whitespace.",
filepath + ":122: '/' is not followed by whitespace.",
filepath + ":120: '%' is not followed by whitespace.",
filepath + ":121: '%' is not preceeded with whitespace.",
filepath + ":121: '%' is not followed by whitespace.",
filepath + ":123: '/' is not preceeded with whitespace.",
filepath + ":123: '/' is not followed by whitespace.",
filepath + ":124: '/' is not followed by whitespace.",
filepath + ":125: '/' is not preceeded with whitespace.",
filepath + ":125: '/' is not followed by whitespace.",
filepath + ":129: '.' is preceeded with whitespace.",
filepath + ":129: '.' is followed by whitespace.",
filepath + ":136: '.' is preceeded with whitespace.",
filepath + ":136: '.' is followed by whitespace.",
};
verify(c, filepath, expected);
}
@ -139,45 +145,51 @@ public class CheckerTest
final String filepath = getPath("InputWhitespace.java");
assertNotNull(c);
final String[] expected = {
filepath + ":11: type Javadoc comment is missing an @author tag.",
filepath + ":14: '=' is not preceeded with whitespace.",
filepath + ":14: '=' is not followed by whitespace.",
filepath + ":5: '.' is preceeded with whitespace.",
filepath + ":5: '.' is followed by whitespace.",
filepath + ":13: type Javadoc comment is missing an @author tag.",
filepath + ":16: '=' is not preceeded with whitespace.",
filepath + ":16: '=' is not followed by whitespace.",
filepath + ":24: '=' is not preceeded with whitespace.",
filepath + ":25: '=' is not preceeded with whitespace.",
filepath + ":25: '=' is not followed by whitespace.",
filepath + ":26: '+=' is not preceeded with whitespace.",
filepath + ":26: '+=' is not followed by whitespace.",
filepath + ":27: '-=' is not followed by whitespace.",
filepath + ":27: '-' is followed by whitespace.",
filepath + ":27: '+' is followed by whitespace.",
filepath + ":28: '++' is preceeded with whitespace.",
filepath + ":28: '--' is preceeded with whitespace.",
filepath + ":29: '++' is followed by whitespace.",
filepath + ":29: '--' is followed by whitespace.",
filepath + ":35: 'synchronized' is not followed by whitespace.",
filepath + ":37: 'try' is not followed by whitespace.",
filepath + ":39: 'catch' is not followed by whitespace.",
filepath + ":56: 'if' is not followed by whitespace.",
filepath + ":74: 'return' is not followed by whitespace.",
filepath + ":95: '?' is not preceeded with whitespace.",
filepath + ":95: '?' is not followed by whitespace.",
filepath + ":95: ':' is not preceeded with whitespace.",
filepath + ":95: ':' is not followed by whitespace.",
filepath + ":96: '==' is not preceeded with whitespace.",
filepath + ":96: '==' is not followed by whitespace.",
filepath + ":102: '*' is not followed by whitespace.",
filepath + ":102: '*' is not preceeded with whitespace.",
filepath + ":109: '!' is followed by whitespace.",
filepath + ":110: '~' is followed by whitespace.",
filepath + ":117: '%' is not preceeded with whitespace.",
filepath + ":118: '%' is not followed by whitespace.",
filepath + ":18: '=' is not followed by whitespace.",
filepath + ":26: '=' is not preceeded with whitespace.",
filepath + ":27: '=' is not preceeded with whitespace.",
filepath + ":27: '=' is not followed by whitespace.",
filepath + ":28: '+=' is not preceeded with whitespace.",
filepath + ":28: '+=' is not followed by whitespace.",
filepath + ":29: '-=' is not followed by whitespace.",
filepath + ":29: '-' is followed by whitespace.",
filepath + ":29: '+' is followed by whitespace.",
filepath + ":30: '++' is preceeded with whitespace.",
filepath + ":30: '--' is preceeded with whitespace.",
filepath + ":31: '++' is followed by whitespace.",
filepath + ":31: '--' is followed by whitespace.",
filepath + ":37: 'synchronized' is not followed by whitespace.",
filepath + ":39: 'try' is not followed by whitespace.",
filepath + ":41: 'catch' is not followed by whitespace.",
filepath + ":58: 'if' is not followed by whitespace.",
filepath + ":76: 'return' is not followed by whitespace.",
filepath + ":97: '?' is not preceeded with whitespace.",
filepath + ":97: '?' is not followed by whitespace.",
filepath + ":97: ':' is not preceeded with whitespace.",
filepath + ":97: ':' is not followed by whitespace.",
filepath + ":98: '==' is not preceeded with whitespace.",
filepath + ":98: '==' is not followed by whitespace.",
filepath + ":104: '*' is not followed by whitespace.",
filepath + ":104: '*' is not preceeded with whitespace.",
filepath + ":111: '!' is followed by whitespace.",
filepath + ":112: '~' is followed by whitespace.",
filepath + ":119: '%' is not preceeded with whitespace.",
filepath + ":119: '%' is not followed by whitespace.",
filepath + ":121: '/' is not preceeded with whitespace.",
filepath + ":122: '/' is not followed by whitespace.",
filepath + ":120: '%' is not followed by whitespace.",
filepath + ":121: '%' is not preceeded with whitespace.",
filepath + ":121: '%' is not followed by whitespace.",
filepath + ":123: '/' is not preceeded with whitespace.",
filepath + ":123: '/' is not followed by whitespace.",
filepath + ":124: '/' is not followed by whitespace.",
filepath + ":125: '/' is not preceeded with whitespace.",
filepath + ":125: '/' is not followed by whitespace.",
filepath + ":129: '.' is preceeded with whitespace.",
filepath + ":129: '.' is followed by whitespace.",
filepath + ":136: '.' is preceeded with whitespace.",
filepath + ":136: '.' is followed by whitespace.",
};
verify(c, filepath, expected);
}
@ -190,7 +202,7 @@ public class CheckerTest
final String filepath = getPath("InputWhitespace.java");
assertNotNull(c);
final String[] expected = {
filepath + ":11: type Javadoc comment is missing an @author tag.",
filepath + ":13: type Javadoc comment is missing an @author tag.",
};
verify(c, filepath, expected);
}

View File

@ -2,7 +2,9 @@
// Test case file for checkstyle.
// Created: 2001
////////////////////////////////////////////////////////////////////////////////
package com.puppycrawl.tools.checkstyle;
package com . puppycrawl
.tools.
checkstyle;
/**
* Class for testing whitespace issues.
@ -122,4 +124,16 @@ class InputWhitespace
int g = 4 /2;
int h = 4/2;
}
/** @return dot test **/
private java .lang. String dotTest()
{
Object o = new java.lang.Object();
o.
toString();
o
.toString();
o . toString();
return o.toString();
}
}