diff --git a/docs/optional.html b/docs/optional.html index 24d6f9dec..6302cc82b 100644 --- a/docs/optional.html +++ b/docs/optional.html @@ -55,13 +55,13 @@ names such as UnusedLocalVariable.

Usage

Optional checks are distributed in jar file -checkstyle-@CHECKSTYLE_VERSION@-optional.jar and, +checkstyle-optional-@CHECKSTYLE_VERSION@.jar and, in order to use an optional check, this jar file must be in the classpath. For example, this is a command to run Checkstyle with a configuration that contains optional checks:

-java -classpath checkstyle-@CHECKSTYLE_VERSION@-optional.jar:checkstyle-all-@CHECKSTYLE_VERSION@.jar \
+java -classpath checkstyle-optional-@CHECKSTYLE_VERSION@.jar:checkstyle-all-@CHECKSTYLE_VERSION@.jar \
     com.puppycrawl.tools.checkstyle.Main \
     -c config.xml -r .
 
diff --git a/docs/releasenotes.html b/docs/releasenotes.html index 1c1013ae2..94981c2db 100644 --- a/docs/releasenotes.html +++ b/docs/releasenotes.html @@ -114,6 +114,10 @@
  • Fixed handling of inheritDoc in JavadocMathod check (bug 855839).
  • + + Fixed bug #853225 - Indentation gives false + errors. + diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/AssignHandler.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/AssignHandler.java index bd4587814..ad93e0a00 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/AssignHandler.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/AssignHandler.java @@ -79,4 +79,14 @@ public class AssignHandler extends BlockParentHandler { return false; } + + /** {@inheritDoc} */ + public IndentLevel suggestedChildLevel(ExpressionHandler aChild) + { + final DetailAST assign = getMainAst(); + if (startsLine(assign)) { + return new IndentLevel(expandedTabsColumnNo(assign)); + } + return super.suggestedChildLevel(aChild); + } } diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/IndentLevel.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/IndentLevel.java index d156a5e71..18673af7c 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/IndentLevel.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/IndentLevel.java @@ -19,6 +19,7 @@ package com.puppycrawl.tools.checkstyle.checks.indentation; import java.util.Iterator; +import java.util.SortedSet; import java.util.TreeSet; /** @@ -30,7 +31,7 @@ import java.util.TreeSet; public class IndentLevel { /** set of acceptable indentation levels. */ - private TreeSet mLevels = new TreeSet(); + private SortedSet mLevels = new TreeSet(); /** * Creates new instance with one accaptable indentation level. @@ -84,6 +85,15 @@ public class IndentLevel mLevels.add(new Integer(aIndent)); } + /** + * Adds one more acceptable indentation level. + * @param aIndent new acceptable indentation. + */ + public void addAcceptedIndent(IndentLevel aIndent) + { + mLevels.addAll(aIndent.mLevels); + } + /** @return string representation of the object. */ public String toString() { @@ -91,8 +101,6 @@ public class IndentLevel return mLevels.first().toString(); } - // TODO: do we want to change representation for - // multiple acceptable levels? return mLevels.toString(); } } diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/ObjectBlockHandler.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/ObjectBlockHandler.java index e3618ee6a..a49ac8c4f 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/ObjectBlockHandler.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/ObjectBlockHandler.java @@ -89,7 +89,12 @@ public class ObjectBlockHandler extends BlockParentHandler */ public IndentLevel getLevelImpl() { - return getParent().getLevel(); + DetailAST parentAST = getMainAst().getParent(); + final IndentLevel indent = getParent().getLevel(); + if (parentAST.getType() == TokenTypes.LITERAL_NEW) { + indent.addAcceptedIndent(super.getLevelImpl()); + } + return indent; } /** diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/indentation/InputValidAssignIndent.java b/src/testinputs/com/puppycrawl/tools/checkstyle/indentation/InputValidAssignIndent.java index 906565a2e..41a5d8fdd 100644 --- a/src/testinputs/com/puppycrawl/tools/checkstyle/indentation/InputValidAssignIndent.java +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/indentation/InputValidAssignIndent.java @@ -19,7 +19,22 @@ public class InputValidAssignIndent brace = (candidate == SLIST) ? candidate : null; + + AnInterfaceFooWithALongName f = + new AnInterfaceFooWithALongName() { + public void bar() { + } + }; + + AnInterfaceFooWithALongName f1 + = new AnInterfaceFooWithALongName() { + public void bar() { + } + }; // TODO: add more testing } + private interface AnInterfaceFooWithALongName { + void bar(); + } }