This commit is contained in:
Oliver Burn 2009-03-30 12:31:04 +00:00
parent b29e7a4c49
commit d868a951ca
6 changed files with 186 additions and 153 deletions

View File

@ -164,11 +164,7 @@
</module>
<module name="NestedTryDepth"/>
<module name="ExplicitInitialization"/>
<module name="AnnotationUseStyle">
<property name="closingParens" value="MIXED"/>
<property name="elementStyle" value="MIXED"/>
<property name="trailingArrayComma" value="MIXED"/>
</module>
<module name="AnnotationUseStyle"/>
<module name="MissingDeprecated"/>
<module name="MissingOverride">
<property name="javaFiveCompatibility" value="true"/>

View File

@ -35,7 +35,7 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes;
* <li>{@link ElementStyle#EXPANDED EXPANDED}</li>
* </ul>
* To not enforce an element style
* a {@link ElementStyle#MIXED MIXED} type is provided. The desired style
* a {@link ElementStyle#IGNORE IGNORE} type is provided. The desired style
* can be set through the <code>elementStyle</code> property.
* </p>
*
@ -64,7 +64,7 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes;
* To always require ending parenthesis use the
* {@link ClosingParens#ALWAYS ALWAYS} type. To never have ending parenthesis
* use the {@link ClosingParens#NEVER NEVER} type. To not enforce a
* closing parenthesis preference a {@link ClosingParens#MIXED MIXED} type is
* closing parenthesis preference a {@link ClosingParens#IGNORE IGNORE} type is
* provided. Set this through the <code>closingParens</code> property.
* </p>
*
@ -74,7 +74,7 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes;
* require a trailing comma use the {@link TrailingArrayComma#ALWAYS ALWAYS}
* type. To never have a trailing comma use the
* {@link TrailingArrayComma#NEVER NEVER} type. To not enforce a trailing
* array comma preference a {@link TrailingArrayComma#MIXED MIXED} type
* array comma preference a {@link TrailingArrayComma#IGNORE IGNORE} type
* is provided. Set this through the <code>trailingArrayComma</code> property.
* </p>
*
@ -129,14 +129,14 @@ public final class AnnotationUseStyleCheck extends Check
//has more than one option type.
/** @see #setElementStyle(String) */
private ElementStyle mStyle = ElementStyle.EXPANDED;
private ElementStyle mStyle = ElementStyle.COMPACT_NO_ARRAY;
//defaulting to NEVER because of the strange compiler behavior
/** @see #setTrailingArrayComma(String) */
private TrailingArrayComma mComma = TrailingArrayComma.NEVER;
/** @see #setClosingParans(String) */
private ClosingParens mParens = ClosingParens.ALWAYS;
private ClosingParens mParens = ClosingParens.NEVER;
/**
* Sets the ElementStyle from a string.
@ -230,7 +230,7 @@ public final class AnnotationUseStyleCheck extends Check
*/
private void checkStyleType(final DetailAST aAnnotation)
{
if (ElementStyle.MIXED.equals(this.mStyle)
if (ElementStyle.IGNORE.equals(this.mStyle)
|| this.mStyle == null)
{
return;
@ -337,7 +337,7 @@ public final class AnnotationUseStyleCheck extends Check
*/
private void checkTrailingComma(final DetailAST aAnnotation)
{
if (TrailingArrayComma.MIXED.equals(this.mComma)
if (TrailingArrayComma.IGNORE.equals(this.mComma)
|| this.mComma == null)
{
return;
@ -400,7 +400,7 @@ public final class AnnotationUseStyleCheck extends Check
*/
private void checkCheckClosingParens(final DetailAST aAST)
{
if (ClosingParens.MIXED.equals(this.mParens)
if (ClosingParens.IGNORE.equals(this.mParens)
|| this.mParens == null)
{
return;
@ -423,9 +423,7 @@ public final class AnnotationUseStyleCheck extends Check
}
/**
* Defines the styles for defining
* elements in an annotation.
*
* Defines the styles for defining elements in an annotation.
* @author Travis Schneeberger
*/
public static enum ElementStyle {
@ -456,7 +454,7 @@ public final class AnnotationUseStyleCheck extends Check
/**
* mixed styles.
*/
MIXED,
IGNORE,
}
/**
@ -484,7 +482,7 @@ public final class AnnotationUseStyleCheck extends Check
/**
* mixed styles.
*/
MIXED,
IGNORE,
}
/**
@ -512,6 +510,6 @@ public final class AnnotationUseStyleCheck extends Check
/**
* mixed styles.
*/
MIXED,
IGNORE,
}
}

View File

@ -1,5 +1,7 @@
package com.puppycrawl.tools.checkstyle;
import com.puppycrawl.tools.checkstyle.checks.annotation.AllAnnotationTests;
import com.puppycrawl.tools.checkstyle.api.AllApiTests;
import com.puppycrawl.tools.checkstyle.checks.AllChecksTests;
import com.puppycrawl.tools.checkstyle.checks.blocks.AllBlocksTests;
@ -31,7 +33,7 @@ import org.junit.runners.Suite;
AllImportsTests.class, AllIndentationTests.class, AllJavadocTests.class,
AllMetricsTests.class, AllModifierTests.class, AllNamingTests.class,
AllSizesTests.class, AllWhitespaceTests.class, AllFilterTests.class,
AllGrammarTests.class, AllRegexpTests.class})
AllGrammarTests.class, AllRegexpTests.class, AllAnnotationTests.class})
public class AllCheckstyleTests
{
}

View File

@ -18,8 +18,8 @@ public class AnnotationUseStyleTest extends BaseCheckTestSupport
public void testParansAlways() throws Exception {
DefaultConfiguration checkConfig = createCheckConfig(AnnotationUseStyleCheck.class);
checkConfig.addAttribute("closingParens", "ALWAYS");
checkConfig.addAttribute("elementStyle", "MIXED");
checkConfig.addAttribute("trailingArrayComma", "MIXED");
checkConfig.addAttribute("elementStyle", "ignore");
checkConfig.addAttribute("trailingArrayComma", "ignore");
final String[] expected = {
"3: Annotation must have closing parenthesis.",
"18: Annotation must have closing parenthesis.",
@ -37,8 +37,8 @@ public class AnnotationUseStyleTest extends BaseCheckTestSupport
public void testParansNever() throws Exception {
DefaultConfiguration checkConfig = createCheckConfig(AnnotationUseStyleCheck.class);
checkConfig.addAttribute("closingParens", "NEVER");
checkConfig.addAttribute("elementStyle", "MIXED");
checkConfig.addAttribute("trailingArrayComma", "MIXED");
checkConfig.addAttribute("elementStyle", "ignore");
checkConfig.addAttribute("trailingArrayComma", "ignore");
final String[] expected = {
"13: Annotation cannot have closing parenthesis.",
"30: Annotation cannot have closing parenthesis.",
@ -56,9 +56,9 @@ public class AnnotationUseStyleTest extends BaseCheckTestSupport
public void testStyleExpanded() throws Exception {
DefaultConfiguration checkConfig = createCheckConfig(AnnotationUseStyleCheck.class);
checkConfig.addAttribute("closingParens", "MIXED");
checkConfig.addAttribute("closingParens", "ignore");
checkConfig.addAttribute("elementStyle", "EXPANDED");
checkConfig.addAttribute("trailingArrayComma", "MIXED");
checkConfig.addAttribute("trailingArrayComma", "ignore");
final String[] expected = {
"5: Annotation style must be 'EXPANDED'.",
"12: Annotation style must be 'EXPANDED'.",
@ -79,9 +79,9 @@ public class AnnotationUseStyleTest extends BaseCheckTestSupport
@Test
public void testStyleCompact() throws Exception {
DefaultConfiguration checkConfig = createCheckConfig(AnnotationUseStyleCheck.class);
checkConfig.addAttribute("closingParens", "MIXED");
checkConfig.addAttribute("closingParens", "ignore");
checkConfig.addAttribute("elementStyle", "COMPACT");
checkConfig.addAttribute("trailingArrayComma", "MIXED");
checkConfig.addAttribute("trailingArrayComma", "ignore");
final String[] expected = {
"43: Annotation style must be 'COMPACT'.",
"47: Annotation style must be 'COMPACT'.",
@ -97,9 +97,9 @@ public class AnnotationUseStyleTest extends BaseCheckTestSupport
@Test
public void testStyleCompactNoArray() throws Exception {
DefaultConfiguration checkConfig = createCheckConfig(AnnotationUseStyleCheck.class);
checkConfig.addAttribute("closingParens", "MIXED");
checkConfig.addAttribute("closingParens", "ignore");
checkConfig.addAttribute("elementStyle", "COMPACT_NO_ARRAY");
checkConfig.addAttribute("trailingArrayComma", "MIXED");
checkConfig.addAttribute("trailingArrayComma", "ignore");
final String[] expected = {
"5: Annotation style must be 'COMPACT_NO_ARRAY'.",
"20: Annotation style must be 'COMPACT_NO_ARRAY'.",
@ -114,8 +114,8 @@ public class AnnotationUseStyleTest extends BaseCheckTestSupport
@Test
public void testCommaAlwaysViolations() throws Exception {
DefaultConfiguration checkConfig = createCheckConfig(AnnotationUseStyleCheck.class);
checkConfig.addAttribute("closingParens", "MIXED");
checkConfig.addAttribute("elementStyle", "MIXED");
checkConfig.addAttribute("closingParens", "ignore");
checkConfig.addAttribute("elementStyle", "ignore");
checkConfig.addAttribute("trailingArrayComma", "ALWAYS");
final String[] expected = {
"3:20: Annotation array values must contain trailing comma.",
@ -139,8 +139,8 @@ public class AnnotationUseStyleTest extends BaseCheckTestSupport
@Test
public void testCommaAlwaysNoViolations() throws Exception {
DefaultConfiguration checkConfig = createCheckConfig(AnnotationUseStyleCheck.class);
checkConfig.addAttribute("closingParens", "MIXED");
checkConfig.addAttribute("elementStyle", "MIXED");
checkConfig.addAttribute("closingParens", "ignore");
checkConfig.addAttribute("elementStyle", "ignore");
checkConfig.addAttribute("trailingArrayComma", "ALWAYS");
final String[] expected = {
};
@ -151,8 +151,8 @@ public class AnnotationUseStyleTest extends BaseCheckTestSupport
@Test
public void testCommaNeverViolations() throws Exception {
DefaultConfiguration checkConfig = createCheckConfig(AnnotationUseStyleCheck.class);
checkConfig.addAttribute("closingParens", "MIXED");
checkConfig.addAttribute("elementStyle", "MIXED");
checkConfig.addAttribute("closingParens", "ignore");
checkConfig.addAttribute("elementStyle", "ignore");
checkConfig.addAttribute("trailingArrayComma", "NEVER");
final String[] expected = {
"9:32: Annotation array values cannot contain trailing comma.",
@ -171,8 +171,8 @@ public class AnnotationUseStyleTest extends BaseCheckTestSupport
@Test
public void testCommaNeverNoViolations() throws Exception {
DefaultConfiguration checkConfig = createCheckConfig(AnnotationUseStyleCheck.class);
checkConfig.addAttribute("closingParens", "MIXED");
checkConfig.addAttribute("elementStyle", "MIXED");
checkConfig.addAttribute("closingParens", "ignore");
checkConfig.addAttribute("elementStyle", "ignore");
checkConfig.addAttribute("trailingArrayComma", "NEVER");
final String[] expected = {
};
@ -183,9 +183,9 @@ public class AnnotationUseStyleTest extends BaseCheckTestSupport
@Test
public void testEverythingMixed() throws Exception {
DefaultConfiguration checkConfig = createCheckConfig(AnnotationUseStyleCheck.class);
checkConfig.addAttribute("closingParens", "MIXED");
checkConfig.addAttribute("elementStyle", "MIXED");
checkConfig.addAttribute("trailingArrayComma", "MIXED");
checkConfig.addAttribute("closingParens", "ignore");
checkConfig.addAttribute("elementStyle", "ignore");
checkConfig.addAttribute("trailingArrayComma", "ignore");
final String[] expected = {
};

View File

@ -22,104 +22,38 @@
<td>elementStyle</td>
<td>
<p>
Annotations have three element styles starting with the
least verbose.
<ul>
<li>
<span class="code">COMPACT_NO_ARRAY
</span>
</li>
<li>
<span class="code">COMPACT COMPACT</span>
</li>
<li>
<span class="code">EXPANDED EXPANDED</span>
</li>
</ul>
To not enforce an element style a
<span class="code">MIXED</span>
type is provided. The desired style can be set through
the
<span class="code">elementStyle</span>
property.
</p>
<p>
Using the
<span class="code">EXPANDED</span>
style is more verbose. The expanded version is sometimes
referred to as "named parameters" in other languages.
</p>
<p>
Using the
<span class="code">COMPACT</span>
style is less verbose. This style can only be used when
there is an element called 'value' which is either the
sole element or all other elements have default values.
</p>
<p>
Using the
<span class="code">COMPACT_NO_ARRAY</span>
style is less verbose. It is similar to the
<span class="code">COMPACT</span>
style but single value arrays are flagged. With
annotations a single value array does not need to be
placed in an array initializer. This style can only be
used when there is an element called 'value' which is
either the sole element or all other elements have
default values.
Defines the annotation element styles.
</p>
</td>
<td>
<a href="property_types.html#elementStyle">element style</a>
</td>
<td>
<span class="default">EXPANDED</span>
<span class="default">compact_no_array</span>
</td>
</tr>
<tr>
<td>closingParens</td>
<td>
The ending parenthesis are optional when using annotations
with no elements. To always require ending parenthesis use
the
<span class="code">ALWAYS</span>
type. To never have ending parenthesis use the
<span class="code">NEVER</span>
type. To not enforce a closing parenthesis preference a
<span class="code">MIXED</span>
type is provided. Set this through the
<span class="code">closingParens</span>
property.
Defines the policy for ending parenthesis.
</td>
<td>
<a href="property_types.html#closingParens">closing parens</a>
</td>
<td>
<span class="default">ALWAYS</span>
<span class="default">never</span>
</td>
</tr>
<tr>
<td>trailingArrayComma</td>
<td>
Annotations also allow you to specify arrays of elements
in a standard format. As with normal arrays, a trailing
comma is optional. To always require a trailing comma use
the
<span class="code">ALWAYS</span>
type. To never have a trailing comma use the
<span class="code">NEVER</span>
type. To not enforce a trailing array comma preference a
<span class="code">MIXED type</span>
is provided. Set this through the
<span class="code">trailingArrayComma
</span>
property.
Defines the policy for trailing comma in arrays.
</td>
<td>
<a href="property_types.html#trailingArrayComma">trailing comma</a>
</td>
<td>
<span class="default">NEVER</span>
<span class="default">never</span>
</td>
</tr>
</table>
@ -130,18 +64,20 @@
</source>
<p>
To configure the check to enforce an EXPANDED style, with a
trailing array comma set to NEVER and always including the closing
To configure the check to enforce an
<span class="code">expanded</span> style, with a
trailing array comma set to <span class="code">never</span>
and always including the closing
parenthesis.
</p>
<source>
&lt;module name=&quot;AnnotationUseStyle&quot;&gt;
&lt;property name=&quot;ElementStyle&quot;
value=&quot;EXPANDED&quot;/&gt;
value=&quot;expanded&quot;/&gt;
&lt;property name=&quot;TrailingArrayComma&quot;
value=&quot;NEVER&quot;/&gt;
value=&quot;never&quot;/&gt;
&lt;property name=&quot;ClosingParens&quot;
value=&quot;ALWAYS&quot;/&gt;
value=&quot;always&quot;/&gt;
&lt;/module&gt;
</source>
</subsection>
@ -159,7 +95,7 @@
<section name="MissingDeprecated">
<subsection name="Description">
<p> Verifies that both the java.lang.Deprecated annotation is
present and the @deprecated javadoc tag is present when
present and the @deprecated Javadoc tag is present when
either is present.</p>
</subsection>
<subsection name="Examples">

View File

@ -298,39 +298,6 @@
</ul>
</section>
<section name="persistence">
<p>
This property represents the policy for checking entity beans
according to whether the beans have bean-managed persistence,
container-managed persistence, or mixed persistence:
</p>
<table summary="right curly options">
<tr>
<td>Option</td>
<td>Definition</td>
</tr>
<tr>
<td><span class="code">bean</span></td>
<td>The beans have bean-managed persistence.</td>
</tr>
<tr>
<td><span class="code">container</span></td>
<td>The beans have container-managed persistence.</td>
</tr>
<tr>
<td><span class="code">mixed</span></td>
<td>
The beans have mixed bean-managed and container-managed
persistence.
</td>
</tr>
</table>
</section>
<section name="importOrder">
<p>
This property represents the policy for checking imports order.
@ -357,7 +324,7 @@
<tr>
<td><span class="code">above</span></td>
<td>All static imports are above the local group.. For example:
<td>All static imports are above the local group. For example:
<pre>
import static a.b.C.*;
import a.b.D;
@ -405,5 +372,139 @@
</tr>
</table>
</section>
<section name="elementStyle">
<p>
This property represents the policy for the styles for defining
elements in an annotation. The following table
describes the valid options:
</p>
<table summary="elementStyle options">
<tr>
<td>Option</td>
<td>Definition</td>
</tr>
<tr>
<td><span class="code">expanded</span></td>
<td>
The expanded version is sometimes referred to as "named parameters"
in other languages. Example:
<pre>@SuppressWarnings(value={"unchecked","unused",})</pre>
</td>
</tr>
<tr>
<td><span class="code">compact</span></td>
<td>
This style can only be used when there is an element called 'value'
which is either the sole element or all other elements have default
values. Examples:
<pre>@SuppressWarnings({"unchecked","unused",})</pre>
and:
<pre>@SuppressWarnings("unchecked")</pre>
</td>
</tr>
<tr>
<td><span class="code">compact_no_array</span></td>
<td>
It is similar to the <span class="code">compact</span> style but
single value arrays are flagged. With annotations a single value
array does not need to be placed in an array initializer.
This style can only be used when there is an element called 'value'
which is either the sole element or all other elements have
default values.
Example: <pre>@SuppressWarnings("unchecked")</pre>
</td>
</tr>
<tr>
<td><span class="code">ignore</span></td>
<td>
Anything goes.
</td>
</tr>
</table>
</section>
<section name="closingParens">
<p>
This property represents the policy for the styles for the ending
parenthesis. The following table describes the valid options:
</p>
<table summary="closingParens options">
<tr>
<td>Option</td>
<td>Definition</td>
</tr>
<tr>
<td><span class="code">always</span></td>
<td>
Example:
<pre>@Deprecated()</pre>
</td>
</tr>
<tr>
<td><span class="code">never</span></td>
<td>
Example:
<pre>@Deprecated</pre>
</td>
</tr>
<tr>
<td><span class="code">ignore</span></td>
<td>
Anything goes.
</td>
</tr>
</table>
</section>
<section name="trailingArrayComma">
<p>
This property represents the policy for the styles for the trailing
array comma. The following table describes the valid options:
</p>
<table summary="trailingArrayComma options">
<tr>
<td>Option</td>
<td>Definition</td>
</tr>
<tr>
<td><span class="code">always</span></td>
<td>
Example:
<pre>@SuppressWarnings(value={"unchecked","unused",})</pre>
</td>
</tr>
<tr>
<td><span class="code">never</span></td>
<td>
Example:
<pre>@SuppressWarnings(value={"unchecked","unused"})</pre>
</td>
</tr>
<tr>
<td><span class="code">ignore</span></td>
<td>
Anything goes.
</td>
</tr>
</table>
</section>
</body>
</document>