Fix for 853225 - Indentation gives false errors

This commit is contained in:
Oleg Sukhodolsky 2003-12-13 12:47:23 +00:00
parent 72be23f288
commit c75472399f
6 changed files with 48 additions and 6 deletions

View File

@ -55,13 +55,13 @@ names such as <span class="code">UnusedLocalVariable</span>.
<h2>Usage</h2>
<p>
Optional checks are distributed in jar file
<span class="code">checkstyle-@CHECKSTYLE_VERSION@-optional.jar</span> and,
<span class="code">checkstyle-optional-@CHECKSTYLE_VERSION@.jar</span> 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:
</p>
<pre>
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 .
</pre>

View File

@ -114,6 +114,10 @@
<li class="body">Fixed handling of inheritDoc in JavadocMathod
check (bug 855839).</li>
</li class="body">Fixed bug #853225 - Indentation gives false
errors.</li>
</ul>
<a name="release3_2"></a>

View File

@ -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);
}
}

View File

@ -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();
}
}

View File

@ -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;
}
/**

View File

@ -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();
}
}