From d2fb67faae0b56340678abef1d1ecedf1df8bb95 Mon Sep 17 00:00:00 2001 From: Oleg Sukhodolsky Date: Mon, 5 Jan 2004 07:38:33 +0000 Subject: [PATCH] Fix for 866501 (Inconsistent lcurly new line on wrap). Some grammar changes made to fix this problem. --- docs/releasenotes.html | 3 +++ .../tools/checkstyle/api/TokenTypes.java | 15 +++++++++------ .../checks/blocks/LeftCurlyCheck.java | 3 +-- .../puppycrawl/tools/checkstyle/grammars/java.g | 16 ++++++++++------ .../checkstyle/InputScopeInnerInterfaces.java | 17 +++++++++++++++++ .../checks/blocks/LeftCurlyCheckTest.java | 8 ++++++++ 6 files changed, 48 insertions(+), 14 deletions(-) diff --git a/docs/releasenotes.html b/docs/releasenotes.html index 7d7f0f7c5..01f5993fa 100644 --- a/docs/releasenotes.html +++ b/docs/releasenotes.html @@ -96,6 +96,9 @@
  • FinalParameter now reports column of start of parameter declaration. (bug 864900)
  • +
  • Fixed inconsistent handling of NLOW (new + line on wrap) option by LeftCurly check. (bug 866501)
  • + diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/api/TokenTypes.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/api/TokenTypes.java index b9e25bd51..240584ad2 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/api/TokenTypes.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/api/TokenTypes.java @@ -338,6 +338,7 @@ public final class TokenTypes * +--MODIFIERS * | * +--LITERAL_PUBLIC (public) + * +--LITERAL_CLASS (class) * +--IDENT (MyClass) * +--EXTENDS_CLAUSE * +--IMPLEMENTS_CLAUSE @@ -380,6 +381,7 @@ public final class TokenTypes * +--MODIFIERS * | * +--LITERAL_PUBLIC (public) + * +--LITERAL_INTERFACE (interface) * +--IDENT (MyInterface) * +--EXTENDS_CLAUSE * +--OBJBLOCK @@ -1310,8 +1312,8 @@ public final class TokenTypes GeneratedJava14TokenTypes.LITERAL_volatile; /** - * The class keyword. This element does not appear - * as part of a class declaration, but only inline to reference a + * The class keyword. This element appears both + * as part of a class declaration, and inline to reference a * class object. * *

    For example:

    @@ -1345,13 +1347,14 @@ public final class TokenTypes //public static final int LITERAL_EXTENDS = // GeneratedJava14TokenTypes.LITERAL_extends; - /* * - * This token does not appear in the tree. + /** + * The interface keyword. This token appears in + * interface definition. * * @see #INTERFACE_DEF **/ - //public static final int LITERAL_INTERFACE = - // GeneratedJava14TokenTypes.LITERAL_interface; + public static final int LITERAL_INTERFACE = + GeneratedJava14TokenTypes.LITERAL_interface; /** * A left (curly) brace ({). diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/blocks/LeftCurlyCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/blocks/LeftCurlyCheck.java index 591dcb163..58c38f178 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/blocks/LeftCurlyCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/blocks/LeftCurlyCheck.java @@ -128,8 +128,7 @@ public class LeftCurlyCheck case TokenTypes.INTERFACE_DEF : case TokenTypes.CLASS_DEF : - // TODO: should check for modifiers - startToken = (DetailAST) aAST.getFirstChild().getNextSibling(); + startToken = (DetailAST) aAST.getFirstChild(); brace = (DetailAST) aAST.getLastChild().getFirstChild(); break; diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/grammars/java.g b/src/checkstyle/com/puppycrawl/tools/checkstyle/grammars/java.g index f59df3ff2..9054e12fa 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/grammars/java.g +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/grammars/java.g @@ -188,15 +188,17 @@ modifier // Definition of a Java class classDefinition![AST modifiers] - : "class" IDENT + : c:"class" IDENT // it _might_ have a superclass... sc:superClassClause // it might implement some interfaces... ic:implementsClause // now parse the body of the class cb:classBlock - {#classDefinition = #(#[CLASS_DEF,"CLASS_DEF"], - modifiers,IDENT,sc,ic,cb);} + { + #classDefinition = #(#[CLASS_DEF,"CLASS_DEF"], + modifiers, c, IDENT, sc, ic, cb); + } ; superClassClause! @@ -206,13 +208,15 @@ superClassClause! // Definition of a Java Interface interfaceDefinition![AST modifiers] - : "interface" IDENT + : i:"interface" IDENT // it might extend some other interfaces ie:interfaceExtends // now parse the body of the interface (looks like a class...) cb:classBlock - {#interfaceDefinition = #(#[INTERFACE_DEF,"INTERFACE_DEF"], - modifiers,IDENT,ie,cb);} + { + #interfaceDefinition = #(#[INTERFACE_DEF,"INTERFACE_DEF"], + modifiers, i, IDENT, ie, cb); + } ; diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/InputScopeInnerInterfaces.java b/src/testinputs/com/puppycrawl/tools/checkstyle/InputScopeInnerInterfaces.java index db1c73eae..ada7a559a 100644 --- a/src/testinputs/com/puppycrawl/tools/checkstyle/InputScopeInnerInterfaces.java +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/InputScopeInnerInterfaces.java @@ -44,4 +44,21 @@ public class InputScopeInnerInterfaces void mb(); } + private + class + MyClass1 { + } + + class + MyClass2 { + } + + private + interface + MyInterface1 { + } + + interface + MyInterface2 { + } } diff --git a/src/tests/com/puppycrawl/tools/checkstyle/checks/blocks/LeftCurlyCheckTest.java b/src/tests/com/puppycrawl/tools/checkstyle/checks/blocks/LeftCurlyCheckTest.java index d29e6a398..6b3619456 100644 --- a/src/tests/com/puppycrawl/tools/checkstyle/checks/blocks/LeftCurlyCheckTest.java +++ b/src/tests/com/puppycrawl/tools/checkstyle/checks/blocks/LeftCurlyCheckTest.java @@ -28,6 +28,10 @@ public class LeftCurlyCheckTest createCheckConfig(LeftCurlyCheck.class); checkConfig.addAttribute("option", LeftCurlyOption.NL.toString()); final String[] expected = { + "49:14: '{' should be on a new line.", + "53:14: '{' should be on a new line.", + "58:18: '{' should be on a new line.", + "62:18: '{' should be on a new line.", }; verify(checkConfig, getPath("InputScopeInnerInterfaces.java"), expected); } @@ -44,6 +48,10 @@ public class LeftCurlyCheckTest "21:5: '{' should be on the previous line.", "30:5: '{' should be on the previous line.", "39:5: '{' should be on the previous line.", + "49:14: '{' should be on a new line.", + "53:14: '{' should be on a new line.", + "58:18: '{' should be on a new line.", + "62:18: '{' should be on a new line.", }; verify(checkConfig, getPath("InputScopeInnerInterfaces.java"), expected); }