diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/ForHandler.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/ForHandler.java index fa8a9f28a..b30563466 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/ForHandler.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/ForHandler.java @@ -50,13 +50,23 @@ public class ForHandler extends BlockParentHandler IndentLevel expected = new IndentLevel(getLevel(), getBasicOffset()); DetailAST init = getMainAst().findFirstToken(TokenTypes.FOR_INIT); - checkExpressionSubtree(init, expected, false, false); + if (init != null) { + checkExpressionSubtree(init, expected, false, false); - DetailAST cond = getMainAst().findFirstToken(TokenTypes.FOR_CONDITION); - checkExpressionSubtree(cond, expected, false, false); + DetailAST cond = + getMainAst().findFirstToken(TokenTypes.FOR_CONDITION); + checkExpressionSubtree(cond, expected, false, false); - DetailAST iter = getMainAst().findFirstToken(TokenTypes.FOR_ITERATOR); - checkExpressionSubtree(iter, expected, false, false); + DetailAST iter = + getMainAst().findFirstToken(TokenTypes.FOR_ITERATOR); + checkExpressionSubtree(iter, expected, false, false); + } + // for each + else { + DetailAST forEach = + getMainAst().findFirstToken(TokenTypes.FOR_EACH_CLAUSE); + checkExpressionSubtree(forEach, expected, false, false); + } } /** diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/indentation/InputValidBlockIndent.java b/src/testinputs/com/puppycrawl/tools/checkstyle/indentation/InputValidBlockIndent.java index bb3dd68a3..972ecf611 100644 --- a/src/testinputs/com/puppycrawl/tools/checkstyle/indentation/InputValidBlockIndent.java +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/indentation/InputValidBlockIndent.java @@ -70,7 +70,7 @@ public class InputValidBlockIndent { } -public enum EquivalenceTester { +enum EquivalenceTester { /** * An equivalence tester that decides based on {@link Object#equals(Object) equals}. */ @@ -79,14 +79,14 @@ public enum EquivalenceTester { * {@inheritDoc} */ public boolean areEqual( final Object first, final Object second ) { - return Objects.areEqual( first, second ); + return true; } /** * {@inheritDoc} */ public int hashCode( final Object target ) { - return Objects.nullSafeHashCode( target ); + return 1; } }, diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/indentation/InputValidClassDefIndent.java b/src/testinputs/com/puppycrawl/tools/checkstyle/indentation/InputValidClassDefIndent.java index 6f6be0180..3b0e2fc91 100644 --- a/src/testinputs/com/puppycrawl/tools/checkstyle/indentation/InputValidClassDefIndent.java +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/indentation/InputValidClassDefIndent.java @@ -127,3 +127,13 @@ final class InputValidClassDefIndent6 extends java.awt.event.MouseAdapter implem return 1; } } + +class HashingContainer { +// @Deprecated + public Object[] table; + + @Override + public String toString() { + return ""; + } +} diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/indentation/InputValidForIndent.java b/src/testinputs/com/puppycrawl/tools/checkstyle/indentation/InputValidForIndent.java index e5a73af7a..e80a6ac31 100644 --- a/src/testinputs/com/puppycrawl/tools/checkstyle/indentation/InputValidForIndent.java +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/indentation/InputValidForIndent.java @@ -17,7 +17,7 @@ public class InputValidForIndent { } - private void method1() + private void method1(int[] indices) { for (int i=0; i<10; i++) System.getProperty("foo"); @@ -73,6 +73,13 @@ public class InputValidForIndent { ) { System.getProperty("foo"); } - + + for ( final int index : indices ) { + System.err.println(index); + } + for ( final int index : indices ) + { + System.err.println(index); + } } } diff --git a/src/xdocs/releasenotes.xml b/src/xdocs/releasenotes.xml index b57981591..2f1586f74 100755 --- a/src/xdocs/releasenotes.xml +++ b/src/xdocs/releasenotes.xml @@ -17,8 +17,8 @@
  • DesignForExtension check skips enums now (they are final :). (bug# 1194470)
  • -
  • One more fix for Indentation check and enums (bug - 1193850)
  • +
  • Indentation check now works better with enums and + for-each statements (bugs 1193850 and 1193855)