diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/ClassDefHandler.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/ClassDefHandler.java index e10b2c4d0..2ea0465a9 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/ClassDefHandler.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/ClassDefHandler.java @@ -37,10 +37,14 @@ public class ClassDefHandler extends BlockParentHandler * @param aParent the parent handler */ public ClassDefHandler(IndentationCheck aIndentCheck, - DetailAST aAst, ExpressionHandler aParent) + DetailAST aAst, + ExpressionHandler aParent) { - super(aIndentCheck, aAst.getType() == TokenTypes.CLASS_DEF - ? "class def" : "interface def", aAst, aParent); + super(aIndentCheck, + (aAst.getType() == TokenTypes.CLASS_DEF) + ? "class def" : ((aAst.getType() == TokenTypes.ENUM_DEF) + ? "enum def" : "interface def"), + aAst, aParent); } /** diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/HandlerFactory.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/HandlerFactory.java index 361343ddd..701e9b28e 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/HandlerFactory.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/HandlerFactory.java @@ -94,6 +94,7 @@ public class HandlerFactory register(TokenTypes.METHOD_DEF, MethodDefHandler.class); register(TokenTypes.CTOR_DEF, MethodDefHandler.class); register(TokenTypes.CLASS_DEF, ClassDefHandler.class); + register(TokenTypes.ENUM_DEF, ClassDefHandler.class); register(TokenTypes.OBJBLOCK, ObjectBlockHandler.class); register(TokenTypes.INTERFACE_DEF, ClassDefHandler.class); register(TokenTypes.IMPORT, ImportHandler.class); @@ -102,6 +103,7 @@ public class HandlerFactory register(TokenTypes.CTOR_CALL, MethodCallHandler.class); register(TokenTypes.LABELED_STAT, LabelHandler.class); register(TokenTypes.STATIC_INIT, StaticInitHandler.class); + register(TokenTypes.INSTANCE_INIT, SlistHandler.class); register(TokenTypes.ASSIGN, AssignHandler.class); register(TokenTypes.PLUS_ASSIGN, AssignHandler.class); register(TokenTypes.MINUS_ASSIGN, AssignHandler.class); @@ -159,6 +161,12 @@ public class HandlerFactory public ExpressionHandler getHandler(IndentationCheck aIndentCheck, DetailAST aAst, ExpressionHandler aParent) { + ExpressionHandler handler = + (ExpressionHandler) mCreatedHandlers.get(aAst); + if (handler != null) { + return handler; + } + if (aAst.getType() == TokenTypes.METHOD_CALL) { return createMethodCallHandler(aIndentCheck, aAst, aParent); } @@ -213,18 +221,12 @@ public class HandlerFactory ExpressionHandler createMethodCallHandler(IndentationCheck aIndentCheck, DetailAST aAst, ExpressionHandler aParent) { - ExpressionHandler handler = - (ExpressionHandler) mCreatedHandlers.get(aAst); - if (handler != null) { - return handler; - } - DetailAST ast = (DetailAST) aAst.getFirstChild(); while (ast != null && ast.getType() == TokenTypes.DOT) { ast = (DetailAST) ast.getFirstChild(); } - if (ast != null && ast.getType() == TokenTypes.METHOD_CALL) { - aParent = createMethodCallHandler(aIndentCheck, ast, aParent); + if (ast != null && isHandledType(ast.getType())) { + aParent = getHandler(aIndentCheck, ast, aParent); mCreatedHandlers.put(ast, aParent); } return new MethodCallHandler(aIndentCheck, aAst, aParent); diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/indentation/InputValidBlockIndent.java b/src/testinputs/com/puppycrawl/tools/checkstyle/indentation/InputValidBlockIndent.java index 972ecf611..787d555cb 100644 --- a/src/testinputs/com/puppycrawl/tools/checkstyle/indentation/InputValidBlockIndent.java +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/indentation/InputValidBlockIndent.java @@ -127,3 +127,39 @@ enum EquivalenceTester { */ public abstract int hashCode( Object target ); } + +class bug1251988 +{ + private int a; + + // non static initializer + { + if (a == 1) + { + } + } +} + +class bug1260079 +{ + public bug1260079() + { + new Thread() + { + public void run() + { + System.out.println("ran"); + } + }.start(); + } +} + +class bug1336737 { + private static enum Command { + IMPORT("import"), + LIST("list"); + private final String c; + Command(String c) { this.c = c; } + public String toString() { return c; } + } +} diff --git a/src/xdocs/releasenotes.xml b/src/xdocs/releasenotes.xml index f527a6656..b14edc308 100755 --- a/src/xdocs/releasenotes.xml +++ b/src/xdocs/releasenotes.xml @@ -61,6 +61,10 @@ Fixed bug in logic JavadocStyle check uses to get main-section of javadoc (bug 1291847). +
Other improvements: