Documentation for Indentation check.

This commit is contained in:
Oleg Sukhodolsky 2003-09-27 05:26:28 +00:00
parent b1123e96e4
commit 60d0673dcc
4 changed files with 95 additions and 19 deletions

View File

@ -34,6 +34,9 @@
<li>
<a href="#GenericIllegalRegexp">GenericIllegalRegexp</a>
</li>
<li>
<a href="#Indentation">Indentation</a>
</li>
<li>
<a href="#NewlineAtEndOfFile">NewlineAtEndOfFile</a>
</li>
@ -679,6 +682,7 @@ like <span class="code">1</span>.
&lt;property name="maximumDepth" value="2"/&gt;
&lt;property name="maximumNumber" value="10"/&gt;
&lt;/module&gt;
</pre>
<h4>Package</h4>
<p class="body">
com.puppycrawl.tools.checkstyle.checks
@ -688,6 +692,78 @@ like <span class="code">1</span>.
<a href="config.html#treewalker">TreeWalker</a>
</p>
<!-- --> <a name="Indentation">Indentation</a>
<h2>Indentation</h2> <h4>Description</h4>
<p class="body">
Checks correct indentation of Java Code.
</p>
<p class="body">
The basic idea behind this is that while
pretty printers are sometimes convienent for bulk reformats of
legacy code, they often either aren't configurable enough or
just can't anticipate how format should be done. Sometimes this is
personal preference, other times it is practical experience. In any
case, this check should just ensure that a minimal set of indentation
rules are followed.
</p>
<h4>Properties</h4>
<table width="100%" border="1" cellpadding="5" class="body">
<tr class="header">
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
</tr>
<tr>
<td>basicOffset</td>
<td>how many spaces to use for new indentation level</td>
<td><a href="property_types.html#String">String</a></td>
<td>&quot;4&quot;</td>
</tr>
<tr>
<td>braceAdjustment</td>
<td>how far brace should be indented when on next line</td>
<td><a href="property_types.html#String">String</a></td>
<td>&quot;0&quot;</td>
</tr>
<tr>
<td>caseIndent</td>
<td>how much to indent a case label</td>
<td><a href="property_types.html#String">String</a></td>
<td>&quot;4&quot;</td>
</tr>
</table>
<u>NOTE</u>: although all properties have a String type
currently they must be a string representation of ineger
numbers. This were made to be able enhance these properties in
next releases in compatible manner.
<h4>Examples</h4>
<p class="body">
To configure the check:
<pre class="body">
&lt;module name=&quot;Indentation&quot;/&gt;
</pre>
</p>
<p class="body">
To configure the check to enforce indentation style recommended
by Sun:
<pre class="body">
&lt;module name=&quot;Indentation&quot;&gt;
&lt;property name=&quot;braceAdjustment&quot; value=&quot;0&quot;/&gt;
&lt;/module&gt;
</pre>
</p>
<h4>Package</h4>
<p class="body">
com.puppycrawl.tools.checkstyle.checks.indentation
</p>
<h4>Parent Module</h4>
<p class="body">
<a href="config.html#treewalker">TreeWalker</a>
</p>
</td>
</tr>
</table>

View File

@ -57,8 +57,8 @@ public class CaseHandler extends ExpressionHandler
*/
public IndentLevel getLevelImpl()
{
return new IndentLevel(getParent().getLevel(),
getIndentCheck().getCaseIndent());
int caseIndent = Integer.parseInt(getIndentCheck().getCaseIndent());
return new IndentLevel(getParent().getLevel(), caseIndent);
}
/**

View File

@ -568,7 +568,7 @@ public abstract class ExpressionHandler
*/
protected final int getBasicOffset()
{
return getIndentCheck().getBasicOffset();
return Integer.parseInt(getIndentCheck().getBasicOffset());
}
/**
@ -578,6 +578,6 @@ public abstract class ExpressionHandler
*/
protected final int getBraceAdjustement()
{
return getIndentCheck().getBraceAdjustement();
return Integer.parseInt(getIndentCheck().getBraceAdjustement());
}
}

View File

@ -103,10 +103,10 @@ import org.apache.commons.collections.ArrayStack;
* </pre>
*
* @author jrichard
* @author o_sukhodolsky
*/
public class IndentationCheck
extends Check
public class IndentationCheck extends Check
{
/** Default indentation amount - based on Sun */
private static final int DEFAULT_INDENTATION = 4;
@ -115,7 +115,7 @@ public class IndentationCheck
private int mBasicOffset = DEFAULT_INDENTATION;
/** how much to indent a case label */
private int mCaseIndentationAmount = mBasicOffset;
private int mCaseIndentationAmount = DEFAULT_INDENTATION;
/** how far brace should be indented when on next line */
private int mBraceAdjustment = 0;
@ -136,9 +136,9 @@ public class IndentationCheck
*
* @param aBasicOffset the number of tabs or spaces to indent
*/
public void setBasicOffset(int aBasicOffset)
public void setBasicOffset(String aBasicOffset)
{
mBasicOffset = aBasicOffset;
mBasicOffset = Integer.parseInt(aBasicOffset);
}
/**
@ -146,9 +146,9 @@ public class IndentationCheck
*
* @return the number of tabs or spaces to indent
*/
public int getBasicOffset()
public String getBasicOffset()
{
return mBasicOffset;
return String.valueOf(mBasicOffset);
}
/**
@ -156,9 +156,9 @@ public class IndentationCheck
*
* @param aAdjustmentAmount the brace offset
*/
public void setBraceAdjustment(int aAdjustmentAmount)
public void setBraceAdjustment(String aAdjustmentAmount)
{
mBraceAdjustment = aAdjustmentAmount;
mBraceAdjustment = Integer.parseInt(aAdjustmentAmount);
}
/**
@ -166,9 +166,9 @@ public class IndentationCheck
*
* @return the positive offset to adjust braces
*/
public int getBraceAdjustement()
public String getBraceAdjustement()
{
return mBraceAdjustment;
return String.valueOf(mBraceAdjustment);
}
/**
@ -176,9 +176,9 @@ public class IndentationCheck
*
* @param aAmount the case indentation level
*/
public void setCaseIndent(int aAmount)
public void setCaseIndent(String aAmount)
{
mCaseIndentationAmount = aAmount;
mCaseIndentationAmount = Integer.parseInt(aAmount);
}
/**
@ -186,9 +186,9 @@ public class IndentationCheck
*
* @return the case indentation level
*/
public int getCaseIndent()
public String getCaseIndent()
{
return mCaseIndentationAmount;
return String.valueOf(mCaseIndentationAmount);
}
/**