Skip to content

Commit

Permalink
Issue #8328: Change name of checkstyle types to be close to real java…
Browse files Browse the repository at this point in the history
… types - enums
  • Loading branch information
gaurabdg committed Jun 28, 2020
1 parent 0a47921 commit c2ffb7f
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 151 deletions.
Expand Up @@ -35,52 +35,54 @@
* </p>
* <ul>
* <li>
* {@code ElementStyle.COMPACT_NO_ARRAY}
* {@code ElementStyleOption.COMPACT_NO_ARRAY}
* </li>
* <li>
* {@code ElementStyle.COMPACT}
* {@code ElementStyleOption.COMPACT}
* </li>
* <li>
* {@code ElementStyle.EXPANDED}
* {@code ElementStyleOption.EXPANDED}
* </li>
* </ul>
* <p>
* To not enforce an element style a {@code ElementStyle.IGNORE} type is provided.
* To not enforce an element style a {@code ElementStyleOption.IGNORE} type is provided.
* The desired style can be set through the {@code elementStyle} property.
* </p>
* <p>
* Using the {@code ElementStyle.EXPANDED} style is more verbose.
* Using the {@code ElementStyleOption.EXPANDED} style is more verbose.
* The expanded version is sometimes referred to as "named parameters" in other languages.
* </p>
* <p>
* Using the {@code ElementStyle.COMPACT} style is less verbose.
* Using the {@code ElementStyleOption.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.
* </p>
* <p>
* Using the {@code ElementStyle.COMPACT_NO_ARRAY} style is less verbose.
* It is similar to the {@code ElementStyle.COMPACT} style but single value arrays are flagged.
* Using the {@code ElementStyleOption.COMPACT_NO_ARRAY} style is less verbose.
* It is similar to the {@code ElementStyleOption.COMPACT} style but single value arrays are
* flagged.
* With annotations a single value array does not need to be placed in an array initializer.
* </p>
* <p>
* The ending parenthesis are optional when using annotations with no elements.
* To always require ending parenthesis use the {@code ClosingParens.ALWAYS} type.
* To never have ending parenthesis use the {@code ClosingParens.NEVER} type.
* To not enforce a closing parenthesis preference a {@code ClosingParens.IGNORE} type is provided.
* To always require ending parenthesis use the {@code ClosingParensOption.ALWAYS} type.
* To never have ending parenthesis use the {@code ClosingParensOption.NEVER} type.
* To not enforce a closing parenthesis preference a {@code ClosingParensOption.IGNORE} type is
* provided.
* Set this through the {@code closingParens} property.
* </p>
* <p>
* 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 {@code TrailingArrayComma.ALWAYS} type.
* To never have a trailing comma use the {@code TrailingArrayComma.NEVER} type.
* To not enforce a trailing array comma preference a {@code TrailingArrayComma.IGNORE} type
* To always require a trailing comma use the {@code TrailingArrayCommaOption.ALWAYS} type.
* To never have a trailing comma use the {@code TrailingArrayCommaOption.NEVER} type.
* To not enforce a trailing array comma preference a {@code TrailingArrayCommaOption.IGNORE} type
* is provided. Set this through the {@code trailingArrayComma} property.
* </p>
* <p>
* By default the {@code ElementStyle} is set to {@code COMPACT_NO_ARRAY},
* the {@code TrailingArrayComma} is set to {@code NEVER},
* and the {@code ClosingParens} is set to {@code NEVER}.
* By default the {@code ElementStyleOption} is set to {@code COMPACT_NO_ARRAY},
* the {@code TrailingArrayCommaOption} is set to {@code NEVER},
* and the {@code ClosingParensOption} is set to {@code NEVER}.
* </p>
* <p>
* According to the JLS, it is legal to include a trailing comma
Expand Down Expand Up @@ -136,7 +138,7 @@ public final class AnnotationUseStyleCheck extends AbstractCheck {
/**
* Defines the styles for defining elements in an annotation.
*/
public enum ElementStyle {
public enum ElementStyleOption {

/**
* Expanded example
Expand Down Expand Up @@ -173,7 +175,7 @@ public enum ElementStyle {
* elements in an annotation.
*
*/
public enum TrailingArrayComma {
public enum TrailingArrayCommaOption {

/**
* With comma example
Expand Down Expand Up @@ -201,7 +203,7 @@ public enum TrailingArrayComma {
* elements in an annotation.
*
*/
public enum ClosingParens {
public enum ClosingParensOption {

/**
* With parens example
Expand Down Expand Up @@ -269,26 +271,26 @@ public enum ClosingParens {
/**
* Define the annotation element styles.
*/
private ElementStyle elementStyle = ElementStyle.COMPACT_NO_ARRAY;
private ElementStyleOption elementStyle = ElementStyleOption.COMPACT_NO_ARRAY;

// defaulting to NEVER because of the strange compiler behavior
/**
* Define the policy for trailing comma in arrays.
*/
private TrailingArrayComma trailingArrayComma = TrailingArrayComma.NEVER;
private TrailingArrayCommaOption trailingArrayComma = TrailingArrayCommaOption.NEVER;

/**
* Define the policy for ending parenthesis.
*/
private ClosingParens closingParens = ClosingParens.NEVER;
private ClosingParensOption closingParens = ClosingParensOption.NEVER;

/**
* Setter to define the annotation element styles.
*
* @param style string representation
*/
public void setElementStyle(final String style) {
elementStyle = getOption(ElementStyle.class, style);
elementStyle = getOption(ElementStyleOption.class, style);
}

/**
Expand All @@ -297,7 +299,7 @@ public void setElementStyle(final String style) {
* @param comma string representation
*/
public void setTrailingArrayComma(final String comma) {
trailingArrayComma = getOption(TrailingArrayComma.class, comma);
trailingArrayComma = getOption(TrailingArrayCommaOption.class, comma);
}

/**
Expand All @@ -306,7 +308,7 @@ public void setTrailingArrayComma(final String comma) {
* @param parens string representation
*/
public void setClosingParens(final String parens) {
closingParens = getOption(ClosingParens.class, parens);
closingParens = getOption(ClosingParensOption.class, parens);
}

/**
Expand Down Expand Up @@ -348,13 +350,13 @@ public int[] getAcceptableTokens() {
@Override
public void visitToken(final DetailAST ast) {
checkStyleType(ast);
checkCheckClosingParens(ast);
checkCheckClosingParensOption(ast);
checkTrailingComma(ast);
}

/**
* Checks to see if the
* {@link ElementStyle AnnotationElementStyle}
* {@link ElementStyleOption AnnotationElementStyleOption}
* is correct.
*
* @param annotation the annotation token
Expand Down Expand Up @@ -386,7 +388,7 @@ private void checkExpandedStyle(final DetailAST annotation) {
annotation.getChildCount(TokenTypes.ANNOTATION_MEMBER_VALUE_PAIR);

if (valuePairCount == 0 && hasArguments(annotation)) {
log(annotation, MSG_KEY_ANNOTATION_INCORRECT_STYLE, ElementStyle.EXPANDED);
log(annotation, MSG_KEY_ANNOTATION_INCORRECT_STYLE, ElementStyleOption.EXPANDED);
}
}

Expand Down Expand Up @@ -419,7 +421,7 @@ private void checkCompactStyle(final DetailAST annotation) {
&& ANNOTATION_ELEMENT_SINGLE_NAME.equals(
valuePair.getFirstChild().getText())) {
log(annotation, MSG_KEY_ANNOTATION_INCORRECT_STYLE,
ElementStyle.COMPACT);
ElementStyleOption.COMPACT);
}
}

Expand All @@ -436,7 +438,7 @@ private void checkCompactNoArrayStyle(final DetailAST annotation) {
if (arrayInit != null
&& arrayInit.getChildCount(TokenTypes.EXPR) == 1) {
log(annotation, MSG_KEY_ANNOTATION_INCORRECT_STYLE,
ElementStyle.COMPACT_NO_ARRAY);
ElementStyleOption.COMPACT_NO_ARRAY);
}
// in expanded style with pairs
else {
Expand All @@ -447,7 +449,7 @@ private void checkCompactNoArrayStyle(final DetailAST annotation) {
if (nestedArrayInit != null
&& nestedArrayInit.getChildCount(TokenTypes.EXPR) == 1) {
log(annotation, MSG_KEY_ANNOTATION_INCORRECT_STYLE,
ElementStyle.COMPACT_NO_ARRAY);
ElementStyleOption.COMPACT_NO_ARRAY);
}
ast = ast.getNextSibling();
}
Expand All @@ -461,7 +463,7 @@ private void checkCompactNoArrayStyle(final DetailAST annotation) {
* @param annotation the annotation token
*/
private void checkTrailingComma(final DetailAST annotation) {
if (trailingArrayComma != TrailingArrayComma.IGNORE) {
if (trailingArrayComma != TrailingArrayCommaOption.IGNORE) {
DetailAST child = annotation.getFirstChild();

while (child != null) {
Expand Down Expand Up @@ -494,7 +496,7 @@ private void logCommaViolation(final DetailAST ast) {
// comma can be null if array is empty
final DetailAST comma = rCurly.getPreviousSibling();

if (trailingArrayComma == TrailingArrayComma.ALWAYS) {
if (trailingArrayComma == TrailingArrayCommaOption.ALWAYS) {
if (comma == null || comma.getType() != TokenTypes.COMMA) {
log(rCurly, MSG_KEY_ANNOTATION_TRAILING_COMMA_MISSING);
}
Expand All @@ -510,11 +512,11 @@ else if (comma != null && comma.getType() == TokenTypes.COMMA) {
*
* @param ast the annotation token
*/
private void checkCheckClosingParens(final DetailAST ast) {
if (closingParens != ClosingParens.IGNORE) {
private void checkCheckClosingParensOption(final DetailAST ast) {
if (closingParens != ClosingParensOption.IGNORE) {
final DetailAST paren = ast.getLastChild();

if (closingParens == ClosingParens.ALWAYS) {
if (closingParens == ClosingParensOption.ALWAYS) {
if (paren.getType() != TokenTypes.RPAREN) {
log(ast, MSG_KEY_ANNOTATION_PARENS_MISSING);
}
Expand Down
Expand Up @@ -56,7 +56,8 @@
* </li>
* <li>
* arrange static imports: ensures the relative order between type imports and static imports
* (see <a href="https://checkstyle.org/property_types.html#importOrder">import orders</a>)
* (see
* <a href="https://checkstyle.org/property_types.html#ImportOrderOption">ImportOrderOption</a>)
* </li>
* </ul>
* <ul>
Expand Down
Expand Up @@ -48,10 +48,10 @@ protected String getPackageLocation() {
* valueOf() is uncovered.
*/
@Test
public void testElementStyleValueOf() {
final AnnotationUseStyleCheck.ElementStyle option =
AnnotationUseStyleCheck.ElementStyle.valueOf("COMPACT");
assertEquals(AnnotationUseStyleCheck.ElementStyle.COMPACT, option,
public void testElementStyleOptionValueOf() {
final AnnotationUseStyleCheck.ElementStyleOption option =
AnnotationUseStyleCheck.ElementStyleOption.valueOf("COMPACT");
assertEquals(AnnotationUseStyleCheck.ElementStyleOption.COMPACT, option,
"Invalid valueOf result");
}

Expand All @@ -60,10 +60,10 @@ public void testElementStyleValueOf() {
* valueOf() is uncovered.
*/
@Test
public void testTrailingArrayCommaValueOf() {
final AnnotationUseStyleCheck.TrailingArrayComma option =
AnnotationUseStyleCheck.TrailingArrayComma.valueOf("ALWAYS");
assertEquals(AnnotationUseStyleCheck.TrailingArrayComma.ALWAYS, option,
public void testTrailingArrayCommaOptionValueOf() {
final AnnotationUseStyleCheck.TrailingArrayCommaOption option =
AnnotationUseStyleCheck.TrailingArrayCommaOption.valueOf("ALWAYS");
assertEquals(AnnotationUseStyleCheck.TrailingArrayCommaOption.ALWAYS, option,
"Invalid valueOf result");
}

Expand All @@ -72,10 +72,10 @@ public void testTrailingArrayCommaValueOf() {
* valueOf() is uncovered.
*/
@Test
public void testClosingParensValueOf() {
final AnnotationUseStyleCheck.ClosingParens option =
AnnotationUseStyleCheck.ClosingParens.valueOf("ALWAYS");
assertEquals(AnnotationUseStyleCheck.ClosingParens.ALWAYS, option,
public void testClosingParensOptionValueOf() {
final AnnotationUseStyleCheck.ClosingParensOption option =
AnnotationUseStyleCheck.ClosingParensOption.valueOf("ALWAYS");
assertEquals(AnnotationUseStyleCheck.ClosingParensOption.ALWAYS, option,
"Invalid valueOf result");
}

Expand Down
Expand Up @@ -82,20 +82,8 @@
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
import com.puppycrawl.tools.checkstyle.api.Configuration;
import com.puppycrawl.tools.checkstyle.api.Scope;
import com.puppycrawl.tools.checkstyle.api.SeverityLevel;
import com.puppycrawl.tools.checkstyle.checks.LineSeparatorOption;
import com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck.ClosingParens;
import com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck.ElementStyle;
import com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck.TrailingArrayComma;
import com.puppycrawl.tools.checkstyle.checks.blocks.BlockOption;
import com.puppycrawl.tools.checkstyle.checks.blocks.LeftCurlyOption;
import com.puppycrawl.tools.checkstyle.checks.blocks.RightCurlyOption;
import com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderOption;
import com.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheck;
import com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocContentLocationOption;
import com.puppycrawl.tools.checkstyle.checks.naming.AccessModifier;
import com.puppycrawl.tools.checkstyle.checks.whitespace.PadOption;
import com.puppycrawl.tools.checkstyle.checks.whitespace.WrapOption;
import com.puppycrawl.tools.checkstyle.internal.utils.CheckUtil;
import com.puppycrawl.tools.checkstyle.internal.utils.TestUtil;
import com.puppycrawl.tools.checkstyle.internal.utils.XdocUtil;
Expand Down Expand Up @@ -1028,51 +1016,18 @@ else if (fieldClass == Pattern.class) {
else if (fieldClass == Pattern[].class) {
result = "Regular Expressions";
}
else if (fieldClass == SeverityLevel.class) {
result = "Severity";
}
else if (fieldClass == Scope.class) {
result = "Scope";
}
else if (fieldClass == ElementStyle.class) {
result = "Element Style";
}
else if (fieldClass == ClosingParens.class) {
result = "Closing Parens";
}
else if (fieldClass == TrailingArrayComma.class) {
result = "Trailing Comma";
}
else if (fieldClass == PadOption.class) {
result = "Pad Policy";
}
else if (fieldClass == WrapOption.class) {
result = "Wrap Operator Policy";
}
else if (fieldClass == BlockOption.class) {
result = "Block Policy";
}
else if (fieldClass == LeftCurlyOption.class) {
result = "Left Curly Brace Policy";
}
else if (fieldClass == RightCurlyOption.class) {
result = "Right Curly Brace Policy";
}
else if (fieldClass == LineSeparatorOption.class) {
result = "Line Separator Policy";
}
else if (fieldClass == ImportOrderOption.class) {
result = "Import Order Policy";
}
else if (fieldClass == AccessModifier[].class) {
result = "Access Modifier Set";
}
else if (fieldClass == JavadocContentLocationOption.class) {
result = "Javadoc Content Location";
}
else if ("PropertyCacheFile".equals(fieldClass.getSimpleName())) {
result = "File";
}
else if (fieldClass.isEnum()) {
result = fieldClass.getSimpleName();
}
else {
fail("Unknown property type: " + fieldClass.getSimpleName());
}
Expand Down
4 changes: 2 additions & 2 deletions src/xdocs/config.xml
Expand Up @@ -359,7 +359,7 @@
<tr>
<td>severity</td>
<td>the default severity level of all violations</td>
<td><a href="property_types.html#severity">Severity</a></td>
<td><a href="property_types.html#SeverityLevel">SeverityLevel</a></td>
<td><code>error</code></td>
<td>3.1</td>
</tr>
Expand Down Expand Up @@ -713,7 +713,7 @@
<section name="Severity">
<p>
Each module has a <a
href="property_types.html#severity">severity</a> property that a
href="property_types.html#SeverityLevel">severity</a> property that a
Checkstyle audit assigns to all violations of the check. The
default severity level of a check is <code>error</code>.
</p>
Expand Down

0 comments on commit c2ffb7f

Please sign in to comment.