Skip to content

Commit

Permalink
Issue checkstyle#3575: changed module setters for scope
Browse files Browse the repository at this point in the history
  • Loading branch information
rnveach committed Nov 29, 2016
1 parent f5a211e commit 0751fbf
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ private static BeanUtilsBean createBeanUtilsBean() {
short[].class);
cub.register(new PatternConverter(), Pattern.class);
cub.register(new ServerityLevelConverter(), SeverityLevel.class);
cub.register(new ScopeConverter(), Scope.class);
cub.register(new RelaxedStringArrayConverter(), String[].class);

// BigDecimal, BigInteger, Class, Date, String, Time, TimeStamp
Expand Down Expand Up @@ -264,6 +265,15 @@ public Object convert(Class type, Object value) {
}
}

/** A converter that converts strings to scope. */
private static class ScopeConverter implements Converter {
@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public Object convert(Class type, Object value) {
return Scope.getInstance(value.toString());
}
}

/**
* A converter that does not care whether the array elements contain String
* characters like '*' or '_'. The normal ArrayConverter class has problems
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,19 +229,19 @@ public void setAllowedAnnotations(String... userAnnotations) {
/**
* Set the scope.
*
* @param from a {@code String} value
* @param scope a scope.
*/
public void setScope(String from) {
scope = Scope.getInstance(from);
public void setScope(Scope scope) {
this.scope = scope;
}

/**
* Set the excludeScope.
*
* @param excludeScope a {@code String} value
* @param scope a scope.
*/
public void setExcludeScope(String excludeScope) {
this.excludeScope = Scope.getInstance(excludeScope);
public void setExcludeScope(Scope scope) {
excludeScope = scope;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,18 +489,18 @@ private static boolean isExtraHtml(String token, Deque<HtmlTag> htmlStack) {

/**
* Sets the scope to check.
* @param from string to get the scope from
* @param scope a scope.
*/
public void setScope(String from) {
scope = Scope.getInstance(from);
public void setScope(Scope scope) {
this.scope = scope;
}

/**
* Set the excludeScope.
* @param excludeScope a {@code String} value
* @param scope a scope.
*/
public void setExcludeScope(String excludeScope) {
this.excludeScope = Scope.getInstance(excludeScope);
public void setExcludeScope(Scope scope) {
excludeScope = scope;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,18 @@ public class JavadocTypeCheck

/**
* Sets the scope to check.
* @param from string to set scope from
* @param scope a scope.
*/
public void setScope(String from) {
scope = Scope.getInstance(from);
public void setScope(Scope scope) {
this.scope = scope;
}

/**
* Set the excludeScope.
* @param excludeScope a {@code String} value
* @param scope a scope.
*/
public void setExcludeScope(String excludeScope) {
this.excludeScope = Scope.getInstance(excludeScope);
public void setExcludeScope(Scope scope) {
excludeScope = scope;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,18 @@ public class JavadocVariableCheck

/**
* Sets the scope to check.
* @param from string to get the scope from
* @param scope a scope.
*/
public void setScope(String from) {
scope = Scope.getInstance(from);
public void setScope(Scope scope) {
this.scope = scope;
}

/**
* Set the excludeScope.
* @param excludeScope a {@code String} value
* @param scope a scope.
*/
public void setExcludeScope(String excludeScope) {
this.excludeScope = Scope.getInstance(excludeScope);
public void setExcludeScope(Scope scope) {
excludeScope = scope;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,18 @@ public void setIgnoreOverridden(boolean ignoreOverridden) {

/**
* Set the scope.
* @param from a {@code String} value
* @param from a scope.
*/
public void setScope(String from) {
scope = Scope.getInstance(from);
public void setScope(Scope from) {
scope = from;
}

/**
* Set the excludeScope.
* @param excludeScope a {@code String} value
* @param excludeScope a scope.
*/
public void setExcludeScope(String excludeScope) {
this.excludeScope = Scope.getInstance(excludeScope);
public void setExcludeScope(Scope excludeScope) {
this.excludeScope = excludeScope;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck;
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.javadoc.AbstractJavadocCheck;

Expand Down Expand Up @@ -583,6 +584,7 @@ private static String getCheckPropertyExpectedTypeName(Class<?> clss, Object ins
final String instanceName = instance.getClass().getSimpleName();
String result = null;

// noinspection IfStatementWithTooManyBranches
if (clss == boolean.class) {
result = "Boolean";
}
Expand Down Expand Up @@ -612,6 +614,9 @@ else if (clss == Pattern.class) {
else if (clss == SeverityLevel.class) {
result = "Severity";
}
else if (clss == Scope.class) {
result = "Scope Policy";
}
else if (clss != String.class) {
Assert.fail("Unknown property type: " + clss.getSimpleName());
}
Expand Down Expand Up @@ -666,8 +671,10 @@ else if (clss == Pattern.class) {
result += " (empty)";
}
}
else if (clss == SeverityLevel.class) {
result = value.toString().toLowerCase(Locale.ENGLISH);
else if (clss == SeverityLevel.class || clss == Scope.class) {
if (value != null) {
result = value.toString().toLowerCase(Locale.ENGLISH);
}
}

if (clss != String.class && clss != String[].class && result == null) {
Expand Down
16 changes: 8 additions & 8 deletions src/xdocs/config_javadoc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,13 @@ public int checkReturnTag(final int aTagIndex,
<tr>
<td>scope</td>
<td>visibility scope where Javadoc comments are checked</td>
<td><a href="property_types.html#scope">scope</a></td>
<td><a href="property_types.html#scope">Scope Policy</a></td>
<td><code>private</code></td>
</tr>
<tr>
<td>excludeScope</td>
<td>visibility scope where Javadoc comments are not checked</td>
<td><a href="property_types.html#scope">scope</a></td>
<td><a href="property_types.html#scope">Scope Policy</a></td>
<td><code>null</code></td>
</tr>
<tr>
Expand Down Expand Up @@ -778,13 +778,13 @@ public boolean isSomething()
<tr>
<td>scope</td>
<td>visibility scope where Javadoc comments are checked</td>
<td><a href="property_types.html#scope">scope</a></td>
<td><a href="property_types.html#scope">Scope Policy</a></td>
<td><code>private</code></td>
</tr>
<tr>
<td>excludeScope</td>
<td>visibility scope where Javadoc comments are not checked</td>
<td><a href="property_types.html#scope">scope</a></td>
<td><a href="property_types.html#scope">Scope Policy</a></td>
<td><code>null</code></td>
</tr>
<tr>
Expand Down Expand Up @@ -1079,13 +1079,13 @@ public boolean isSomething()
<tr>
<td>scope</td>
<td>visibility scope where Javadoc comments are checked</td>
<td><a href="property_types.html#scope">scope</a></td>
<td><a href="property_types.html#scope">Scope Policy</a></td>
<td><code>private</code></td>
</tr>
<tr>
<td>excludeScope</td>
<td>visibility scope where Javadoc comments are not checked</td>
<td><a href="property_types.html#scope">scope</a></td>
<td><a href="property_types.html#scope">Scope Policy</a></td>
<td><code>null</code></td>
</tr>
<tr>
Expand Down Expand Up @@ -1257,13 +1257,13 @@ public boolean isSomething()
<tr>
<td>scope</td>
<td>visibility scope where Javadoc comments are checked</td>
<td><a href="property_types.html#scope">scope</a></td>
<td><a href="property_types.html#scope">Scope Policy</a></td>
<td><code>private</code></td>
</tr>
<tr>
<td>excludeScope</td>
<td>visibility scope where Javadoc comments are not checked</td>
<td><a href="property_types.html#scope">scope</a></td>
<td><a href="property_types.html#scope">Scope Policy</a></td>
<td><code>null</code></td>
</tr>
<tr>
Expand Down
4 changes: 2 additions & 2 deletions src/xdocs/config_naming.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1183,13 +1183,13 @@ public boolean equals(Object o) {
<tr>
<td>scope</td>
<td>Visibility scope of methods where parameters are checked.</td>
<td><a href="property_types.html#scope">scope</a></td>
<td><a href="property_types.html#scope">Scope Policy</a></td>
<td><code>anoninner</code></td>
</tr>
<tr>
<td>excludeScope</td>
<td>Visibility scope of methods where parameters are not checked.</td>
<td><a href="property_types.html#scope">scope</a></td>
<td><a href="property_types.html#scope">Scope Policy</a></td>
<td><code>null</code></td>
</tr>
</table>
Expand Down

0 comments on commit 0751fbf

Please sign in to comment.