Bug fix the handling of '{'. Demonstrates the power of using findFirstToken().

This commit is contained in:
Oliver Burn 2002-11-23 00:20:17 +00:00
parent b657e696ff
commit 4a5ccfb6fe
3 changed files with 24 additions and 15 deletions

View File

@ -62,28 +62,25 @@ public class OtherLeftCurlyCheck
case TokenTypes.LITERAL_CATCH:
case TokenTypes.LITERAL_SYNCHRONIZED:
case TokenTypes.LITERAL_FOR:
brace = aAST.getLastChild();
break;
case TokenTypes.LITERAL_TRY:
case TokenTypes.LITERAL_FINALLY:
case TokenTypes.LITERAL_DO:
brace = (DetailAST) aAST.getFirstChild();
case TokenTypes.LITERAL_IF:
brace = aAST.findFirstToken(TokenTypes.SLIST);
break;
case TokenTypes.LITERAL_ELSE:
final DetailAST candidate = (DetailAST) aAST.getFirstChild();
if (candidate.getType() == TokenTypes.SLIST) {
brace = candidate;
}
else {
// silently ignore
brace = null;
}
brace =
(candidate.getType() == TokenTypes.SLIST)
? candidate
: null; // silently ignore
break;
case TokenTypes.LITERAL_SWITCH:
case TokenTypes.LITERAL_IF:
brace = (DetailAST) aAST.getFirstChild().getNextSibling()
.getNextSibling().getNextSibling();
case TokenTypes.LITERAL_SWITCH :
brace = aAST.findFirstToken(TokenTypes.LCURLY);
break;
default:
brace = null;
}

View File

@ -100,7 +100,7 @@ class InputBraces
if (condition())
testIf();
}
void whitespaceAfterSemi()
{
//reject

View File

@ -41,4 +41,16 @@ public class OtherLeftCurlyCheckTest
};
verify(c, fname, expected);
}
public void testMissingBraces()
throws Exception
{
final CheckConfiguration checkConfig = new CheckConfiguration();
checkConfig.setClassname(OtherLeftCurlyCheck.class.getName());
final Checker c = createChecker(checkConfig);
final String fname = getPath("InputBraces.java");
final String[] expected = {
};
verify(c, fname, expected);
}
}