diff --git a/checkstyle_checks.xml b/checkstyle_checks.xml index 87b29b5e9..3454f211d 100755 --- a/checkstyle_checks.xml +++ b/checkstyle_checks.xml @@ -164,11 +164,7 @@ - - - - - + diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationUseStyleCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationUseStyleCheck.java index 5016a232c..bf7e7010d 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationUseStyleCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationUseStyleCheck.java @@ -35,7 +35,7 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes; *
  • {@link ElementStyle#EXPANDED EXPANDED}
  • * * 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 elementStyle property. *

    * @@ -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 closingParens property. *

    * @@ -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 trailingArrayComma property. *

    * @@ -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, } } diff --git a/src/tests/com/puppycrawl/tools/checkstyle/AllCheckstyleTests.java b/src/tests/com/puppycrawl/tools/checkstyle/AllCheckstyleTests.java index 1881955c9..cab2114a1 100644 --- a/src/tests/com/puppycrawl/tools/checkstyle/AllCheckstyleTests.java +++ b/src/tests/com/puppycrawl/tools/checkstyle/AllCheckstyleTests.java @@ -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 { } diff --git a/src/tests/com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationUseStyleTest.java b/src/tests/com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationUseStyleTest.java index 4feb93041..9abdb0172 100644 --- a/src/tests/com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationUseStyleTest.java +++ b/src/tests/com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationUseStyleTest.java @@ -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 = { }; diff --git a/src/xdocs/config_annotations.xml b/src/xdocs/config_annotations.xml index fac556a9c..084803dc9 100644 --- a/src/xdocs/config_annotations.xml +++ b/src/xdocs/config_annotations.xml @@ -22,104 +22,38 @@ elementStyle

    - Annotations have three element styles starting with the - least verbose. -

      -
    • - COMPACT_NO_ARRAY - -
    • -
    • - COMPACT COMPACT -
    • -
    • - EXPANDED EXPANDED -
    • -
    - To not enforce an element style a - MIXED - type is provided. The desired style can be set through - the - elementStyle - property. -

    -

    - Using the - EXPANDED - style is more verbose. The expanded version is sometimes - referred to as "named parameters" in other languages. -

    -

    - Using the - COMPACT - 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. -

    -

    - Using the - COMPACT_NO_ARRAY - style is less verbose. It is similar to the - COMPACT - 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.

    element style - EXPANDED + compact_no_array closingParens - The ending parenthesis are optional when using annotations - with no elements. To always require ending parenthesis use - the - ALWAYS - type. To never have ending parenthesis use the - NEVER - type. To not enforce a closing parenthesis preference a - MIXED - type is provided. Set this through the - closingParens - property. + Defines the policy for ending parenthesis. closing parens - ALWAYS + never trailingArrayComma - 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 - ALWAYS - type. To never have a trailing comma use the - NEVER - type. To not enforce a trailing array comma preference a - MIXED type - is provided. Set this through the - trailingArrayComma - - property. + Defines the policy for trailing comma in arrays. trailing comma - NEVER + never @@ -130,18 +64,20 @@

    - 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 + expanded style, with a + trailing array comma set to never + and always including the closing parenthesis.

    <module name="AnnotationUseStyle"> <property name="ElementStyle" - value="EXPANDED"/> + value="expanded"/> <property name="TrailingArrayComma" - value="NEVER"/> + value="never"/> <property name="ClosingParens" - value="ALWAYS"/> + value="always"/> </module> @@ -159,7 +95,7 @@

    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.

    diff --git a/src/xdocs/property_types.xml b/src/xdocs/property_types.xml index 45a659dcd..3e081f813 100755 --- a/src/xdocs/property_types.xml +++ b/src/xdocs/property_types.xml @@ -298,39 +298,6 @@
    -
    -

    - This property represents the policy for checking entity beans - according to whether the beans have bean-managed persistence, - container-managed persistence, or mixed persistence: -

    - - - - - - - - - - - - - - - - - - - - - -
    OptionDefinition
    beanThe beans have bean-managed persistence.
    containerThe beans have container-managed persistence.
    mixed - The beans have mixed bean-managed and container-managed - persistence. -
    -
    -

    This property represents the policy for checking imports order. @@ -357,7 +324,7 @@ above - All static imports are above the local group.. For example: + All static imports are above the local group. For example:

         import static a.b.C.*;
         import a.b.D;
    @@ -405,5 +372,139 @@
             
           
         
    + + +
    +

    + This property represents the policy for the styles for defining + elements in an annotation. The following table + describes the valid options: +

    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    OptionDefinition
    expanded + The expanded version is sometimes referred to as "named parameters" + in other languages. Example: +
    @SuppressWarnings(value={"unchecked","unused",})
    +
    compact + 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: +
    @SuppressWarnings({"unchecked","unused",})
    + and: +
    @SuppressWarnings("unchecked")
    +
    compact_no_array + It is similar to the compact 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:
    @SuppressWarnings("unchecked")
    +
    ignore + Anything goes. +
    +
    + + +
    +

    + This property represents the policy for the styles for the ending + parenthesis. The following table describes the valid options: +

    + + + + + + + + + + + + + + + + + + + + + +
    OptionDefinition
    always + Example: +
    @Deprecated()
    +
    never + Example: +
    @Deprecated
    +
    ignore + Anything goes. +
    +
    + + +
    +

    + This property represents the policy for the styles for the trailing + array comma. The following table describes the valid options: +

    + + + + + + + + + + + + + + + + + + + + + +
    OptionDefinition
    always + Example: +
    @SuppressWarnings(value={"unchecked","unused",})
    +
    never + Example: +
    @SuppressWarnings(value={"unchecked","unused"})
    +
    ignore + Anything goes. +
    +
    +