Added support for brace checking on the keywords try, catch, finally, static.

What are not covered deliberately are labels and instance initializers.
This commit is contained in:
Oliver Burn 2002-02-22 04:12:04 +00:00
parent 41e2089574
commit 59ce3f31d7
5 changed files with 43 additions and 20 deletions

View File

@ -142,7 +142,7 @@
</tr>
</table>
<p>The check can be tailored for types, methods and others. What is included in others are: <span class="code">switch, while, for, do, if, else, synchronized </span>. It does not include array initializers, .</p>
<p>The check can be tailored for types, methods and others. What is included in others are the keywords <span class="code">switch, while, for, do, if, else, synchronized, try, catch, finally, static</span>.</p>
<h3><a name="length">Long Lines</a></h3>
<p>Checks for lines that are longer than a specified length. The default is <span class="default">&quot;80&quot;</span>. This can be turned off for <code>import</code> statements.</p>

View File

@ -84,8 +84,7 @@ public final class Scope implements Comparable
/** map from scope names to the respective Scope */
private static final Map NAME_TO_SCOPE = new HashMap();
static
{
static {
NAME_TO_SCOPE.put(SCOPENAME_NOTHING, NOTHING);
NAME_TO_SCOPE.put(SCOPENAME_PUBLIC, PUBLIC);
NAME_TO_SCOPE.put(SCOPENAME_PROTECTED, PROTECTED);

View File

@ -307,7 +307,7 @@ field!
{
java.util.List exs = new java.util.ArrayList();
MethodSignature msig = new MethodSignature();
final MyCommonAST[] lcurls = new MyCommonAST[2];
final MyCommonAST[] stmtBraces = new MyCommonAST[2];
}
: // method, constructor, or variable declaration
mods:modifiers[msig.getModSet()]
@ -347,9 +347,9 @@ field!
ver.reportStartMethodBlock();
}
(
s2:compoundStatement[lcurls]
s2:compoundStatement[stmtBraces]
{
ver.verifyLCurlyMethod(msig.getLineNo(), lcurls[0]);
ver.verifyLCurlyMethod(msig.getLineNo(), stmtBraces[0]);
ver.verifyMethodLength(#s2.getLineNo(),
sCompoundLength);
}
@ -370,8 +370,12 @@ field!
)
// "static { ... }" class initializer
| "static" {ver.reportStartMethodBlock();} s3:compoundStatement[sIgnoreAST] {ver.reportEndMethodBlock();}
{#field = #(#[STATIC_INIT,"STATIC_INIT"], s3);}
| st:"static" {ver.reportStartMethodBlock();} s3:compoundStatement[stmtBraces]
{
#field = #(#[STATIC_INIT,"STATIC_INIT"], s3);
ver.reportEndMethodBlock();
ver.verifyLCurlyOther(st.getLine(), stmtBraces[0]);
}
// "{ ... }" instance initializer
| {ver.reportStartMethodBlock();} s4:compoundStatement[sIgnoreAST] {ver.reportEndMethodBlock();}
@ -561,7 +565,7 @@ statement[int[] aType, MyCommonAST[] aCurlies]
// Attach a label to the front of a statement
| IDENT c:COLON^ {#c.setType(LABELED_STAT);} statement[sIgnoreType, sIgnoreAST]
// If-else statement
// If-else statement
| ii:"if"^ LPAREN! expression RPAREN! statement[stmtType, stmtBraces]
{
aType[0] = STMT_IF;
@ -720,17 +724,32 @@ forIter
// an exception handler try/catch block
tryBlock
: t:"try"^ compoundStatement[sIgnoreAST]
{ ver.verifyWSAroundBegin(t.getLine(), t.getColumn(), t.getText()); }
{
final MyCommonAST[] stmtBraces = new MyCommonAST[2];
}
: t:"try"^ compoundStatement[stmtBraces]
{
ver.verifyWSAroundBegin(t.getLine(), t.getColumn(), t.getText());
ver.verifyLCurlyOther(t.getLine(), stmtBraces[0]);
}
(handler)*
( "finally"^ compoundStatement[sIgnoreAST] )?
(
f:"finally"^ compoundStatement[stmtBraces]
{ ver.verifyLCurlyOther(f.getLine(), stmtBraces[0]); }
)?
;
// an exception handler
handler
: c:"catch"^ LPAREN! parameterDeclaration[new MethodSignature()] RPAREN! compoundStatement[sIgnoreAST]
{ver.verifyWSAroundBegin(c.getLine(), c.getColumn(), c.getText());}
{
final MyCommonAST[] stmtBraces = new MyCommonAST[2];
}
: c:"catch"^ LPAREN! parameterDeclaration[new MethodSignature()] RPAREN! compoundStatement[stmtBraces]
{
ver.verifyWSAroundBegin(c.getLine(), c.getColumn(), c.getText());
ver.verifyLCurlyOther(c.getLine(), stmtBraces[0]);
}
;

View File

@ -297,6 +297,7 @@ public class CheckerTest
filepath + ":109: Expected @param tag for 'aOne'.",
filepath + ":109: Expected @param tag for 'aFour'.",
filepath + ":109: Expected @param tag for 'aFive'.",
filepath + ":129: '{' should be on the previous line.",
};
verify(c, filepath, expected);
@ -647,11 +648,14 @@ public class CheckerTest
assertNotNull(c);
final String[] expected = {
filepath + ":19: '{' should be on the previous line.",
filepath + ":22: '{' should be on the previous line.",
filepath + ":29: '{' should be on the previous line.",
filepath + ":33: '{' should be on the previous line.",
filepath + ":51: '{' should be on the previous line.",
filepath + ":53: '{' should be on the previous line.",
filepath + ":21: '{' should be on the previous line.",
filepath + ":23: '{' should be on the previous line.",
filepath + ":30: '{' should be on the previous line.",
filepath + ":34: '{' should be on the previous line.",
filepath + ":42: '{' should be on the previous line.",
filepath + ":46: '{' should be on the previous line.",
filepath + ":52: '{' should be on the previous line.",
filepath + ":54: '{' should be on the previous line.",
};
verify(c, filepath, expected);
}

View File

@ -17,7 +17,8 @@ class InputLeftCurlyOther
int a = 2;
while (true)
{
try {
try
{
if (x > 0)
{
break;