From d31d4220cc7f9cf03fe9e4cd0fe7d9e305ffe096 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20K=C3=BChne?= Date: Sun, 19 Jan 2003 13:02:30 +0000 Subject: [PATCH] changed the logic for LCURLY/RCURLY a bit fixes the problems reported on devel mailing list --- .../checks/WhitespaceAroundCheck.java | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/WhitespaceAroundCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/WhitespaceAroundCheck.java index 6a94de167..c6555cc62 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/WhitespaceAroundCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/WhitespaceAroundCheck.java @@ -154,23 +154,26 @@ public class WhitespaceAroundCheck /** @see com.puppycrawl.tools.checkstyle.api.Check */ public void visitToken(DetailAST aAST) { - // Check for RCURLY in array initializer - if ((aAST.getType() == TokenTypes.RCURLY) - && (aAST.getParent().getType() == TokenTypes.ARRAY_INIT)) + final int type = aAST.getType(); + final int parentType = aAST.getParent().getType(); + + // Check for CURLY in array initializer + if ((type == TokenTypes.RCURLY || type == TokenTypes.LCURLY) + && (parentType == TokenTypes.ARRAY_INIT)) { return; } // Check for import pkg.name.*; - if ((aAST.getType() == TokenTypes.STAR) - && (aAST.getParent().getType() == TokenTypes.DOT)) + if ((type == TokenTypes.STAR) + && (parentType == TokenTypes.DOT)) { return; } // Check for an SLIST that has a parent CASE_GROUP. It is not a '{'. - if ((aAST.getType() == TokenTypes.SLIST) - && (aAST.getParent().getType() == TokenTypes.CASE_GROUP)) + if ((type == TokenTypes.SLIST) + && (parentType == TokenTypes.CASE_GROUP)) { return; } @@ -185,15 +188,20 @@ public class WhitespaceAroundCheck "ws.notPreceeded", new Object[]{aAST.getText()}); } - if ((after < line.length()) - && !Character.isWhitespace( - line.charAt(after)) // Check for "return;" - && !((aAST.getType() == TokenTypes.LITERAL_RETURN) + if (after >= line.length()) { + return; + } + + final char nextChar = line.charAt(after); + if (!Character.isWhitespace(nextChar) + // Check for "return;" + && !((type == TokenTypes.LITERAL_RETURN) && (aAST.getFirstChild().getType() == TokenTypes.SEMI)) - // Check for "})" or "};". Happens with anon-inners - && !((aAST.getType() == TokenTypes.RCURLY) - && ((line.charAt(after) == ')') - || (line.charAt(after) == ';')))) + // Check for "})" or "};" or "},". Happens with anon-inners + && !((type == TokenTypes.RCURLY) + && ((nextChar == ')') + || (nextChar == ';') + || (nextChar == ',')))) { log( aAST.getLineNo(),