Enable Checkstyle 7.7.

This commit is contained in:
jwilson 2017-05-06 14:48:55 -04:00
parent 13fd0b252c
commit 0ea1959b7e
18 changed files with 92 additions and 35 deletions

View file

@ -1,9 +1,10 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<!DOCTYPE module PUBLIC <!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.2//EN" "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_2.dtd"> "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker"> <module name="Checker">
<module name="SuppressWarningsFilter"/>
<module name="NewlineAtEndOfFile"/> <module name="NewlineAtEndOfFile"/>
<module name="FileLength"/> <module name="FileLength"/>
<module name="FileTabCharacter"/> <module name="FileTabCharacter"/>
@ -44,7 +45,7 @@
<module name="LocalVariableName"/> <module name="LocalVariableName"/>
<module name="MemberName"/> <module name="MemberName"/>
<module name="MethodName"/> <module name="MethodName"/>
<module name="PackageName"/> <!--<module name="PackageName"/>-->
<module name="ParameterName"/> <module name="ParameterName"/>
<module name="StaticVariableName"/> <module name="StaticVariableName"/>
<module name="TypeName"/> <module name="TypeName"/>
@ -56,7 +57,9 @@
<module name="IllegalImport"/> <module name="IllegalImport"/>
<!-- defaults to sun.* packages --> <!-- defaults to sun.* packages -->
<module name="RedundantImport"/> <module name="RedundantImport"/>
<module name="UnusedImports"/> <module name="UnusedImports">
<property name="processJavadoc" value="true"/>
</module>
<!-- Checks for Size Violations. --> <!-- Checks for Size Violations. -->
@ -64,7 +67,9 @@
<module name="LineLength"> <module name="LineLength">
<property name="max" value="100"/> <property name="max" value="100"/>
</module> </module>
<module name="MethodLength"/> <module name="MethodLength">
<property name="max" value="200"/>
</module>
<!-- Checks for whitespace --> <!-- Checks for whitespace -->
@ -78,7 +83,15 @@
<module name="ParenPad"/> <module name="ParenPad"/>
<module name="TypecastParenPad"/> <module name="TypecastParenPad"/>
<module name="WhitespaceAfter"/> <module name="WhitespaceAfter"/>
<module name="WhitespaceAround"/> <module name="WhitespaceAround">
<property name="tokens"
value="ASSIGN, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR, BXOR_ASSIGN,
COLON, DIV, DIV_ASSIGN, DO_WHILE, EQUAL, GE, GT, LAND, LCURLY, LE, LITERAL_CATCH,
LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_RETURN,
LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS,
MINUS_ASSIGN, MOD, MOD_ASSIGN, NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION, SL, SLIST,
SL_ASSIGN, SR, SR_ASSIGN, STAR, STAR_ASSIGN, LITERAL_ASSERT, TYPE_EXTENSION_AND"/>
</module>
<!-- Modifier Checks --> <!-- Modifier Checks -->
@ -108,7 +121,7 @@
<!--module name="InnerAssignment"/--> <!--module name="InnerAssignment"/-->
<!--module name="MagicNumber"/--> <!--module name="MagicNumber"/-->
<!--module name="MissingSwitchDefault"/--> <!--module name="MissingSwitchDefault"/-->
<module name="RedundantThrows"/> <!--<module name="RedundantThrows"/>-->
<module name="SimplifyBooleanExpression"/> <module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/> <module name="SimplifyBooleanReturn"/>
@ -127,5 +140,8 @@
<!--module name="FinalParameters"/--> <!--module name="FinalParameters"/-->
<!--module name="TodoComment"/--> <!--module name="TodoComment"/-->
<module name="UpperEll"/> <module name="UpperEll"/>
<!-- Make the @SuppressWarnings annotations available to Checkstyle -->
<module name="SuppressWarningsHolder"/>
</module> </module>
</module> </module>

View file

@ -21,7 +21,7 @@ import com.squareup.moshi.recipes.models.Player;
public final class CustomFieldName { public final class CustomFieldName {
public void run() throws Exception { public void run() throws Exception {
String json = "" String json = ""
+ "{" + "{"
+ " \"username\": \"jesse\"," + " \"username\": \"jesse\","
+ " \"lucky number\": 32" + " \"lucky number\": 32"

View file

@ -44,6 +44,7 @@ public final class FromJsonWithoutStrings {
new FromJsonWithoutStrings().run(); new FromJsonWithoutStrings().run();
} }
@SuppressWarnings("checkstyle:membername")
private static final class EventJson { private static final class EventJson {
String title; String title;
String begin_date; String begin_date;
@ -55,10 +56,10 @@ public final class FromJsonWithoutStrings {
String beginDateAndTime; String beginDateAndTime;
@Override public String toString() { @Override public String toString() {
return "Event{" + return "Event{"
"title='" + title + '\'' + + "title='" + title + '\''
", beginDateAndTime='" + beginDateAndTime + '\'' + + ", beginDateAndTime='" + beginDateAndTime + '\''
'}'; + '}';
} }
} }

View file

@ -21,7 +21,7 @@ import com.squareup.moshi.recipes.models.BlackjackHand;
public final class ReadJson { public final class ReadJson {
public void run() throws Exception { public void run() throws Exception {
String json = "" String json = ""
+ "{\n" + "{\n"
+ " \"hidden_card\": {\n" + " \"hidden_card\": {\n"
+ " \"rank\": \"6\",\n" + " \"rank\": \"6\",\n"

View file

@ -32,6 +32,9 @@ import java.util.Set;
import static java.lang.annotation.RetentionPolicy.RUNTIME; import static java.lang.annotation.RetentionPolicy.RUNTIME;
final class Unwrap { final class Unwrap {
private Unwrap() {
}
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
String json = "" String json = ""
+ "{\"data\":" + "{\"data\":"

View file

@ -17,13 +17,14 @@ package com.squareup.moshi.recipes.models;
import java.util.List; import java.util.List;
@SuppressWarnings("checkstyle:membername")
public final class BlackjackHand { public final class BlackjackHand {
public final Card hidden_card; public final Card hidden_card;
public final List<Card> visible_cards; public final List<Card> visible_cards;
public BlackjackHand(Card hidden_card, List<Card> visible_cards) { public BlackjackHand(Card hiddenCard, List<Card> visibleCards) {
this.hidden_card = hidden_card; this.hidden_card = hiddenCard;
this.visible_cards = visible_cards; this.visible_cards = visibleCards;
} }
@Override public String toString() { @Override public String toString() {

View file

@ -31,7 +31,7 @@ final class AdapterMethodsFactory implements JsonAdapter.Factory {
private final List<AdapterMethod> toAdapters; private final List<AdapterMethod> toAdapters;
private final List<AdapterMethod> fromAdapters; private final List<AdapterMethod> fromAdapters;
public AdapterMethodsFactory(List<AdapterMethod> toAdapters, List<AdapterMethod> fromAdapters) { AdapterMethodsFactory(List<AdapterMethod> toAdapters, List<AdapterMethod> fromAdapters) {
this.toAdapters = toAdapters; this.toAdapters = toAdapters;
this.fromAdapters = fromAdapters; this.fromAdapters = fromAdapters;
} }
@ -271,7 +271,7 @@ final class AdapterMethodsFactory implements JsonAdapter.Factory {
return null; return null;
} }
static abstract class AdapterMethod { abstract static class AdapterMethod {
final Type type; final Type type;
final Set<? extends Annotation> annotations; final Set<? extends Annotation> annotations;
final Object adapter; final Object adapter;
@ -280,7 +280,7 @@ final class AdapterMethodsFactory implements JsonAdapter.Factory {
final JsonAdapter<?>[] jsonAdapters; final JsonAdapter<?>[] jsonAdapters;
final boolean nullable; final boolean nullable;
public AdapterMethod(Type type, Set<? extends Annotation> annotations, Object adapter, AdapterMethod(Type type, Set<? extends Annotation> annotations, Object adapter,
Method method, int parameterCount, int adaptersOffset, boolean nullable) { Method method, int parameterCount, int adaptersOffset, boolean nullable) {
this.type = Types.canonicalize(type); this.type = Types.canonicalize(type);
this.annotations = annotations; this.annotations = annotations;

View file

@ -194,7 +194,7 @@ final class ClassJsonAdapter<T> extends JsonAdapter<T> {
final Field field; final Field field;
final JsonAdapter<T> adapter; final JsonAdapter<T> adapter;
public FieldBinding(String name, Field field, JsonAdapter<T> adapter) { FieldBinding(String name, Field field, JsonAdapter<T> adapter) {
this.name = name; this.name = name;
this.field = field; this.field = field;
this.adapter = adapter; this.adapter = adapter;

View file

@ -58,7 +58,7 @@ public abstract class JsonAdapter<T> {
/** /**
* Encodes {@code value} as a Java value object comprised of maps, lists, strings, numbers, * Encodes {@code value} as a Java value object comprised of maps, lists, strings, numbers,
* booleans, and nulls. * booleans, and nulls.
* *
* <p>Values encoded using {@code value(double)} or {@code value(long)} are modeled with the * <p>Values encoded using {@code value(double)} or {@code value(long)} are modeled with the
* corresponding boxed type. Values encoded using {@code value(Number)} are modeled as a * corresponding boxed type. Values encoded using {@code value(Number)} are modeled as a
* {@link Long} for boxed integer types ({@link Byte}, {@link Short}, {@link Integer}, and {@link * {@link Long} for boxed integer types ({@link Byte}, {@link Short}, {@link Integer}, and {@link

View file

@ -182,7 +182,7 @@ public abstract class JsonReader implements Closeable {
final String[] pathNames = new String[32]; final String[] pathNames = new String[32];
final int[] pathIndices = new int[32]; final int[] pathIndices = new int[32];
/** True to accept non-spec compliant JSON */ /** True to accept non-spec compliant JSON. */
boolean lenient; boolean lenient;
/** True to throw a {@link JsonDataException} on any attempt to call {@link #skipValue()}. */ /** True to throw a {@link JsonDataException} on any attempt to call {@link #skipValue()}. */

View file

@ -17,6 +17,8 @@ package com.squareup.moshi;
/** Lexical scoping elements within a JSON reader or writer. */ /** Lexical scoping elements within a JSON reader or writer. */
final class JsonScope { final class JsonScope {
private JsonScope() {
}
/** An array with no elements requires no separators or newlines before it is closed. */ /** An array with no elements requires no separators or newlines before it is closed. */
static final int EMPTY_ARRAY = 1; static final int EMPTY_ARRAY = 1;

View file

@ -50,7 +50,7 @@ final class JsonValueReader extends JsonReader {
private final Object[] stack = new Object[32]; private final Object[] stack = new Object[32];
public JsonValueReader(Object root) { JsonValueReader(Object root) {
scopes[stackSize] = JsonScope.NONEMPTY_DOCUMENT; scopes[stackSize] = JsonScope.NONEMPTY_DOCUMENT;
stack[stackSize++] = root; stack[stackSize++] = root;
} }

View file

@ -55,7 +55,7 @@ final class LinkedHashTreeMap<K, V> extends AbstractMap<K, V> implements Seriali
* Create a natural order, empty tree map whose keys must be mutually * Create a natural order, empty tree map whose keys must be mutually
* comparable and non-null. * comparable and non-null.
*/ */
public LinkedHashTreeMap() { LinkedHashTreeMap() {
this(null); this(null);
} }
@ -66,8 +66,10 @@ final class LinkedHashTreeMap<K, V> extends AbstractMap<K, V> implements Seriali
* @param comparator the comparator to order elements with, or {@code null} to * @param comparator the comparator to order elements with, or {@code null} to
* use the natural ordering. * use the natural ordering.
*/ */
@SuppressWarnings({ "unchecked", "rawtypes" }) // unsafe! if comparator is null, this assumes K is comparable @SuppressWarnings({
public LinkedHashTreeMap(Comparator<? super K> comparator) { "unchecked", "rawtypes" // Unsafe! if comparator is null, this assumes K is comparable.
})
LinkedHashTreeMap(Comparator<? super K> comparator) {
this.comparator = comparator != null this.comparator = comparator != null
? comparator ? comparator
: (Comparator) NATURAL_ORDER; : (Comparator) NATURAL_ORDER;
@ -473,14 +475,14 @@ final class LinkedHashTreeMap<K, V> extends AbstractMap<K, V> implements Seriali
V value; V value;
int height; int height;
/** Create the header entry */ /** Create the header entry. */
Node() { Node() {
key = null; key = null;
hash = -1; hash = -1;
next = prev = this; next = prev = this;
} }
/** Create a regular entry */ /** Create a regular entry. */
Node(Node<K, V> parent, K key, int hash, Node<K, V> next, Node<K, V> prev) { Node(Node<K, V> parent, K key, int hash, Node<K, V> next, Node<K, V> prev) {
this.parent = parent; this.parent = parent;
this.key = key; this.key = key;
@ -665,7 +667,7 @@ final class LinkedHashTreeMap<K, V> extends AbstractMap<K, V> implements Seriali
* comparisons. Using this class to create a tree of size <i>S</i> is * comparisons. Using this class to create a tree of size <i>S</i> is
* {@code O(S)}. * {@code O(S)}.
*/ */
final static class AvlBuilder<K, V> { static final class AvlBuilder<K, V> {
/** This stack is a singly linked list, linked by the 'parent' field. */ /** This stack is a singly linked list, linked by the 'parent' field. */
private Node<K, V> stack; private Node<K, V> stack;
private int leavesToSkip; private int leavesToSkip;

View file

@ -41,7 +41,7 @@ final class MapJsonAdapter<K, V> extends JsonAdapter<Map<K, V>> {
private final JsonAdapter<K> keyAdapter; private final JsonAdapter<K> keyAdapter;
private final JsonAdapter<V> valueAdapter; private final JsonAdapter<V> valueAdapter;
public MapJsonAdapter(Moshi moshi, Type keyType, Type valueType) { MapJsonAdapter(Moshi moshi, Type keyType, Type valueType) {
this.keyAdapter = moshi.adapter(keyType); this.keyAdapter = moshi.adapter(keyType);
this.valueAdapter = moshi.adapter(valueType); this.valueAdapter = moshi.adapter(valueType);
} }

View file

@ -24,6 +24,9 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
final class StandardJsonAdapters { final class StandardJsonAdapters {
private StandardJsonAdapters() {
}
public static final JsonAdapter.Factory FACTORY = new JsonAdapter.Factory() { public static final JsonAdapter.Factory FACTORY = new JsonAdapter.Factory() {
@Override public JsonAdapter<?> create( @Override public JsonAdapter<?> create(
Type type, Set<? extends Annotation> annotations, Moshi moshi) { Type type, Set<? extends Annotation> annotations, Moshi moshi) {
@ -216,7 +219,7 @@ final class StandardJsonAdapters {
private final T[] constants; private final T[] constants;
private final JsonReader.Options options; private final JsonReader.Options options;
public EnumJsonAdapter(Class<T> enumType) { EnumJsonAdapter(Class<T> enumType) {
this.enumType = enumType; this.enumType = enumType;
try { try {
constants = enumType.getEnumConstants(); constants = enumType.getEnumConstants();
@ -264,7 +267,7 @@ final class StandardJsonAdapters {
static final class ObjectJsonAdapter extends JsonAdapter<Object> { static final class ObjectJsonAdapter extends JsonAdapter<Object> {
private final Moshi moshi; private final Moshi moshi;
public ObjectJsonAdapter(Moshi moshi) { ObjectJsonAdapter(Moshi moshi) {
this.moshi = moshi; this.moshi = moshi;
} }

View file

@ -149,7 +149,7 @@ public final class Types {
return (Class<?>) rawType; return (Class<?>) rawType;
} else if (type instanceof GenericArrayType) { } else if (type instanceof GenericArrayType) {
Type componentType = ((GenericArrayType)type).getGenericComponentType(); Type componentType = ((GenericArrayType) type).getGenericComponentType();
return Array.newInstance(getRawType(componentType), 0).getClass(); return Array.newInstance(getRawType(componentType), 0).getClass();
} else if (type instanceof TypeVariable) { } else if (type instanceof TypeVariable) {
@ -560,7 +560,7 @@ public final class Types {
private static final class GenericArrayTypeImpl implements GenericArrayType { private static final class GenericArrayTypeImpl implements GenericArrayType {
private final Type componentType; private final Type componentType;
public GenericArrayTypeImpl(Type componentType) { GenericArrayTypeImpl(Type componentType) {
this.componentType = canonicalize(componentType); this.componentType = canonicalize(componentType);
} }
@ -591,7 +591,7 @@ public final class Types {
private final Type upperBound; private final Type upperBound;
private final Type lowerBound; private final Type lowerBound;
public WildcardTypeImpl(Type[] upperBounds, Type[] lowerBounds) { WildcardTypeImpl(Type[] upperBounds, Type[] lowerBounds) {
if (lowerBounds.length > 1) throw new IllegalArgumentException(); if (lowerBounds.length > 1) throw new IllegalArgumentException();
if (upperBounds.length != 1) throw new IllegalArgumentException(); if (upperBounds.length != 1) throw new IllegalArgumentException();

View file

@ -25,6 +25,9 @@ import java.util.Set;
final class Util { final class Util {
public static final Set<Annotation> NO_ANNOTATIONS = Collections.emptySet(); public static final Set<Annotation> NO_ANNOTATIONS = Collections.emptySet();
private Util() {
}
public static boolean typesMatch(Type pattern, Type candidate) { public static boolean typesMatch(Type pattern, Type candidate) {
// TODO: permit raw types (like Set.class) to match non-raw candidates (like Set<Long>). // TODO: permit raw types (like Set.class) to match non-raw candidates (like Set<Long>).
return pattern.equals(candidate); return pattern.equals(candidate);

26
pom.xml
View file

@ -127,6 +127,32 @@
</pluginManagement> </pluginManagement>
<plugins> <plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>7.7</version>
</dependency>
</dependencies>
<configuration>
<failsOnError>true</failsOnError>
<configLocation>checkstyle.xml</configLocation>
<consoleOutput>true</consoleOutput>
<excludes>**/Iso8601Utils.java</excludes>
</configuration>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>checkstyle</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId> <artifactId>maven-release-plugin</artifactId>