diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/Verifier.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/Verifier.java index e534cda8f..73e250560 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/Verifier.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/Verifier.java @@ -18,9 +18,6 @@ //////////////////////////////////////////////////////////////////////////////// package com.puppycrawl.tools.checkstyle; -import java.util.Stack; - -import com.puppycrawl.tools.checkstyle.api.Scope; import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; import com.puppycrawl.tools.checkstyle.api.LocalizedMessages; @@ -40,12 +37,6 @@ class Verifier // Member variables //////////////////////////////////////////////////////////////////////////// - /** stack tracking the type of block currently in **/ - private final Stack mInInterface = new Stack(); - - /** tracks the level of block definitions for methods **/ - private int mMethodBlockLevel = 0; - /** the messages being logged **/ private final LocalizedMessages mMessages; @@ -92,9 +83,7 @@ class Verifier void reset() { mLines = null; - mInInterface.clear(); mMessages.reset(); - mMethodBlockLevel = 0; } /** @@ -207,51 +196,6 @@ class Verifier } - /** - * Report that the parser is entering a block that is associated with a - * class or interface. Must match up the call to this method with a call - * to the reportEndBlock(). - * @param aScope the Scope of the type block - * @param aIsInterface indicates if the block is for an interface - * @param aType the name of the type - */ - void reportStartTypeBlock(Scope aScope, - boolean aIsInterface, - MyCommonAST aType) - { - mInInterface.push(aIsInterface ? Boolean.TRUE : Boolean.FALSE); - } - - - /** - * Report that the parser is leaving a type block. - * @param aNamed is this a named type block - */ - void reportEndTypeBlock(boolean aNamed) - { - mInInterface.pop(); - } - - - /** - * Report that the parser is entering a block associated with method or - * constructor. - **/ - void reportStartMethodBlock() - { - mMethodBlockLevel++; - } - - - /** - * Report that the parser is leaving a block associated with method or - * constructor. - **/ - void reportEndMethodBlock() - { - mMethodBlockLevel--; - } - // }}} // {{{ Private methods @@ -288,19 +232,6 @@ class Verifier return retVal; } - /** @return whether currently in an interface block **/ - private boolean inInterfaceBlock() - { - return (!mInInterface.empty() - && Boolean.TRUE.equals(mInInterface.peek())); - } - - /** @return whether currently in a method block **/ - private boolean inMethodBlock() - { - return (mMethodBlockLevel > 0); - } - /** * Checks that whitespace IS after a specified column. * @param aLineNo number of line to check diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/java.g b/src/checkstyle/com/puppycrawl/tools/checkstyle/java.g index 958d7cb2c..d6b3d96da 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/java.g +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/java.g @@ -231,15 +231,9 @@ classDefinition![MyCommonAST modifiers, MyModifierSet modSet] // it might implement some interfaces... ic:implementsClause // now parse the body of the class - { - ver.reportStartTypeBlock(modSet.getVisibilityScope(), false, #IDENT); - } cb:classBlock[(modSet.size() == 0) ? #cc.getLineNo() : modSet.getFirstLineNo()] {#classDefinition = #(#[CLASS_DEF,"CLASS_DEF"], modifiers,IDENT,sc,ic,cb);} - { - ver.reportEndTypeBlock(true); - } ; superClassClause! @@ -253,15 +247,9 @@ interfaceDefinition![MyCommonAST modifiers, MyModifierSet modSet] // it might extend some other interfaces ie:interfaceExtends // now parse the body of the interface (looks like a class...) - { - ver.reportStartTypeBlock(modSet.getVisibilityScope(), true, #IDENT); - } cb:classBlock[(modSet.size() == 0) ? #ii.getLineNo() : modSet.getFirstLineNo()] {#interfaceDefinition = #(#[INTERFACE_DEF,"INTERFACE_DEF"], modifiers,IDENT,ie,cb);} - { - ver.reportEndTypeBlock(true); - } ; @@ -308,11 +296,9 @@ field! ( h:ctorHead[exs, msig] { msig.setThrows(exs); - ver.reportStartMethodBlock(); } s:constructorBody[msig.getFirstLineNo()] // constructor {#field = #(#[CTOR_DEF,"CTOR_DEF"], mods, h, s);} - {ver.reportEndMethodBlock();} | cd:classDefinition[#mods, msig.getModSet()] // inner class {#field = #cd;} @@ -336,7 +322,6 @@ field! msig.setName(#IDENT); msig.setThrows(exs); msig.setReturnType(#t); - ver.reportStartMethodBlock(); } ( s2:compoundStatement[stmtBraces, sIgnoreIsEmpty] @@ -352,21 +337,19 @@ field! param, tc, s2); } - {ver.reportEndMethodBlock();} | v:variableDefinitions[#mods,#t, msig.getModSet()] SEMI {#field = #v;} ) ) // "static { ... }" class initializer - | st:"static" {ver.reportStartMethodBlock();} s3:compoundStatement[stmtBraces, sIgnoreIsEmpty] + | st:"static" s3:compoundStatement[stmtBraces, sIgnoreIsEmpty] { #field = #(#[STATIC_INIT,"STATIC_INIT"], s3); - ver.reportEndMethodBlock(); } // "{ ... }" instance initializer - | {ver.reportStartMethodBlock();} s4:compoundStatement[sIgnoreAST, sIgnoreIsEmpty] {ver.reportEndMethodBlock();} + | s4:compoundStatement[sIgnoreAST, sIgnoreIsEmpty] {#field = #(#[INSTANCE_INIT,"INSTANCE_INIT"], s4);} ; @@ -1000,7 +983,7 @@ primaryExpression */ newExpression : n:"new"^ t:type - ( LPAREN! argList RPAREN! ({ver.reportStartTypeBlock(Scope.ANONINNER, false, null);} classBlock[-1] {ver.reportEndTypeBlock(false);})? + ( LPAREN! argList RPAREN! ( classBlock[-1] )? //java 1.1 // Note: This will allow bad constructs like