From 0ea1959b7e43a26e072888227c997602b043c2af Mon Sep 17 00:00:00 2001 From: jwilson Date: Sat, 6 May 2017 14:48:55 -0400 Subject: [PATCH] Enable Checkstyle 7.7. --- checkstyle.xml | 30 ++++++++++++++----- .../moshi/recipes/CustomFieldName.java | 2 +- .../moshi/recipes/FromJsonWithoutStrings.java | 9 +++--- .../com/squareup/moshi/recipes/ReadJson.java | 2 +- .../com/squareup/moshi/recipes/Unwrap.java | 3 ++ .../moshi/recipes/models/BlackjackHand.java | 7 +++-- .../squareup/moshi/AdapterMethodsFactory.java | 6 ++-- .../com/squareup/moshi/ClassJsonAdapter.java | 2 +- .../java/com/squareup/moshi/JsonAdapter.java | 2 +- .../java/com/squareup/moshi/JsonReader.java | 2 +- .../java/com/squareup/moshi/JsonScope.java | 2 ++ .../com/squareup/moshi/JsonValueReader.java | 2 +- .../com/squareup/moshi/LinkedHashTreeMap.java | 14 +++++---- .../com/squareup/moshi/MapJsonAdapter.java | 2 +- .../squareup/moshi/StandardJsonAdapters.java | 7 +++-- .../main/java/com/squareup/moshi/Types.java | 6 ++-- .../main/java/com/squareup/moshi/Util.java | 3 ++ pom.xml | 26 ++++++++++++++++ 18 files changed, 92 insertions(+), 35 deletions(-) diff --git a/checkstyle.xml b/checkstyle.xml index 794af42..1e4d8e6 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -1,9 +1,10 @@ + "-//Puppy Crawl//DTD Check Configuration 1.3//EN" + "http://www.puppycrawl.com/dtds/configuration_1_3.dtd"> + @@ -44,7 +45,7 @@ - + @@ -56,7 +57,9 @@ - + + + @@ -64,7 +67,9 @@ - + + + @@ -78,7 +83,15 @@ - + + + @@ -108,7 +121,7 @@ - + @@ -127,5 +140,8 @@ + + + diff --git a/examples/src/main/java/com/squareup/moshi/recipes/CustomFieldName.java b/examples/src/main/java/com/squareup/moshi/recipes/CustomFieldName.java index a500a87..d6ea8cd 100644 --- a/examples/src/main/java/com/squareup/moshi/recipes/CustomFieldName.java +++ b/examples/src/main/java/com/squareup/moshi/recipes/CustomFieldName.java @@ -21,7 +21,7 @@ import com.squareup.moshi.recipes.models.Player; public final class CustomFieldName { public void run() throws Exception { - String json = "" + String json = "" + "{" + " \"username\": \"jesse\"," + " \"lucky number\": 32" diff --git a/examples/src/main/java/com/squareup/moshi/recipes/FromJsonWithoutStrings.java b/examples/src/main/java/com/squareup/moshi/recipes/FromJsonWithoutStrings.java index 5a8394c..cdb6f56 100644 --- a/examples/src/main/java/com/squareup/moshi/recipes/FromJsonWithoutStrings.java +++ b/examples/src/main/java/com/squareup/moshi/recipes/FromJsonWithoutStrings.java @@ -44,6 +44,7 @@ public final class FromJsonWithoutStrings { new FromJsonWithoutStrings().run(); } + @SuppressWarnings("checkstyle:membername") private static final class EventJson { String title; String begin_date; @@ -55,10 +56,10 @@ public final class FromJsonWithoutStrings { String beginDateAndTime; @Override public String toString() { - return "Event{" + - "title='" + title + '\'' + - ", beginDateAndTime='" + beginDateAndTime + '\'' + - '}'; + return "Event{" + + "title='" + title + '\'' + + ", beginDateAndTime='" + beginDateAndTime + '\'' + + '}'; } } diff --git a/examples/src/main/java/com/squareup/moshi/recipes/ReadJson.java b/examples/src/main/java/com/squareup/moshi/recipes/ReadJson.java index b8d459c..047d7d8 100644 --- a/examples/src/main/java/com/squareup/moshi/recipes/ReadJson.java +++ b/examples/src/main/java/com/squareup/moshi/recipes/ReadJson.java @@ -21,7 +21,7 @@ import com.squareup.moshi.recipes.models.BlackjackHand; public final class ReadJson { public void run() throws Exception { - String json = "" + String json = "" + "{\n" + " \"hidden_card\": {\n" + " \"rank\": \"6\",\n" diff --git a/examples/src/main/java/com/squareup/moshi/recipes/Unwrap.java b/examples/src/main/java/com/squareup/moshi/recipes/Unwrap.java index 32c54af..3ac14cf 100644 --- a/examples/src/main/java/com/squareup/moshi/recipes/Unwrap.java +++ b/examples/src/main/java/com/squareup/moshi/recipes/Unwrap.java @@ -32,6 +32,9 @@ import java.util.Set; import static java.lang.annotation.RetentionPolicy.RUNTIME; final class Unwrap { + private Unwrap() { + } + public static void main(String[] args) throws Exception { String json = "" + "{\"data\":" diff --git a/examples/src/main/java/com/squareup/moshi/recipes/models/BlackjackHand.java b/examples/src/main/java/com/squareup/moshi/recipes/models/BlackjackHand.java index ad785d6..b8a9be0 100644 --- a/examples/src/main/java/com/squareup/moshi/recipes/models/BlackjackHand.java +++ b/examples/src/main/java/com/squareup/moshi/recipes/models/BlackjackHand.java @@ -17,13 +17,14 @@ package com.squareup.moshi.recipes.models; import java.util.List; +@SuppressWarnings("checkstyle:membername") public final class BlackjackHand { public final Card hidden_card; public final List visible_cards; - public BlackjackHand(Card hidden_card, List visible_cards) { - this.hidden_card = hidden_card; - this.visible_cards = visible_cards; + public BlackjackHand(Card hiddenCard, List visibleCards) { + this.hidden_card = hiddenCard; + this.visible_cards = visibleCards; } @Override public String toString() { diff --git a/moshi/src/main/java/com/squareup/moshi/AdapterMethodsFactory.java b/moshi/src/main/java/com/squareup/moshi/AdapterMethodsFactory.java index 88157d1..e14d7c4 100644 --- a/moshi/src/main/java/com/squareup/moshi/AdapterMethodsFactory.java +++ b/moshi/src/main/java/com/squareup/moshi/AdapterMethodsFactory.java @@ -31,7 +31,7 @@ final class AdapterMethodsFactory implements JsonAdapter.Factory { private final List toAdapters; private final List fromAdapters; - public AdapterMethodsFactory(List toAdapters, List fromAdapters) { + AdapterMethodsFactory(List toAdapters, List fromAdapters) { this.toAdapters = toAdapters; this.fromAdapters = fromAdapters; } @@ -271,7 +271,7 @@ final class AdapterMethodsFactory implements JsonAdapter.Factory { return null; } - static abstract class AdapterMethod { + abstract static class AdapterMethod { final Type type; final Set annotations; final Object adapter; @@ -280,7 +280,7 @@ final class AdapterMethodsFactory implements JsonAdapter.Factory { final JsonAdapter[] jsonAdapters; final boolean nullable; - public AdapterMethod(Type type, Set annotations, Object adapter, + AdapterMethod(Type type, Set annotations, Object adapter, Method method, int parameterCount, int adaptersOffset, boolean nullable) { this.type = Types.canonicalize(type); this.annotations = annotations; diff --git a/moshi/src/main/java/com/squareup/moshi/ClassJsonAdapter.java b/moshi/src/main/java/com/squareup/moshi/ClassJsonAdapter.java index e364bb6..74aab3b 100644 --- a/moshi/src/main/java/com/squareup/moshi/ClassJsonAdapter.java +++ b/moshi/src/main/java/com/squareup/moshi/ClassJsonAdapter.java @@ -194,7 +194,7 @@ final class ClassJsonAdapter extends JsonAdapter { final Field field; final JsonAdapter adapter; - public FieldBinding(String name, Field field, JsonAdapter adapter) { + FieldBinding(String name, Field field, JsonAdapter adapter) { this.name = name; this.field = field; this.adapter = adapter; diff --git a/moshi/src/main/java/com/squareup/moshi/JsonAdapter.java b/moshi/src/main/java/com/squareup/moshi/JsonAdapter.java index a7e3f2a..b60a1d2 100644 --- a/moshi/src/main/java/com/squareup/moshi/JsonAdapter.java +++ b/moshi/src/main/java/com/squareup/moshi/JsonAdapter.java @@ -58,7 +58,7 @@ public abstract class JsonAdapter { /** * Encodes {@code value} as a Java value object comprised of maps, lists, strings, numbers, * booleans, and nulls. - * + * *

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 * {@link Long} for boxed integer types ({@link Byte}, {@link Short}, {@link Integer}, and {@link diff --git a/moshi/src/main/java/com/squareup/moshi/JsonReader.java b/moshi/src/main/java/com/squareup/moshi/JsonReader.java index fb908ce..90c04f8 100644 --- a/moshi/src/main/java/com/squareup/moshi/JsonReader.java +++ b/moshi/src/main/java/com/squareup/moshi/JsonReader.java @@ -182,7 +182,7 @@ public abstract class JsonReader implements Closeable { final String[] pathNames = new String[32]; final int[] pathIndices = new int[32]; - /** True to accept non-spec compliant JSON */ + /** True to accept non-spec compliant JSON. */ boolean lenient; /** True to throw a {@link JsonDataException} on any attempt to call {@link #skipValue()}. */ diff --git a/moshi/src/main/java/com/squareup/moshi/JsonScope.java b/moshi/src/main/java/com/squareup/moshi/JsonScope.java index 0ee4920..05f47ad 100644 --- a/moshi/src/main/java/com/squareup/moshi/JsonScope.java +++ b/moshi/src/main/java/com/squareup/moshi/JsonScope.java @@ -17,6 +17,8 @@ package com.squareup.moshi; /** Lexical scoping elements within a JSON reader or writer. */ final class JsonScope { + private JsonScope() { + } /** An array with no elements requires no separators or newlines before it is closed. */ static final int EMPTY_ARRAY = 1; diff --git a/moshi/src/main/java/com/squareup/moshi/JsonValueReader.java b/moshi/src/main/java/com/squareup/moshi/JsonValueReader.java index e78bfe7..2111757 100644 --- a/moshi/src/main/java/com/squareup/moshi/JsonValueReader.java +++ b/moshi/src/main/java/com/squareup/moshi/JsonValueReader.java @@ -50,7 +50,7 @@ final class JsonValueReader extends JsonReader { private final Object[] stack = new Object[32]; - public JsonValueReader(Object root) { + JsonValueReader(Object root) { scopes[stackSize] = JsonScope.NONEMPTY_DOCUMENT; stack[stackSize++] = root; } diff --git a/moshi/src/main/java/com/squareup/moshi/LinkedHashTreeMap.java b/moshi/src/main/java/com/squareup/moshi/LinkedHashTreeMap.java index 00d6aeb..536afb8 100644 --- a/moshi/src/main/java/com/squareup/moshi/LinkedHashTreeMap.java +++ b/moshi/src/main/java/com/squareup/moshi/LinkedHashTreeMap.java @@ -55,7 +55,7 @@ final class LinkedHashTreeMap extends AbstractMap implements Seriali * Create a natural order, empty tree map whose keys must be mutually * comparable and non-null. */ - public LinkedHashTreeMap() { + LinkedHashTreeMap() { this(null); } @@ -66,8 +66,10 @@ final class LinkedHashTreeMap extends AbstractMap implements Seriali * @param comparator the comparator to order elements with, or {@code null} to * use the natural ordering. */ - @SuppressWarnings({ "unchecked", "rawtypes" }) // unsafe! if comparator is null, this assumes K is comparable - public LinkedHashTreeMap(Comparator comparator) { + @SuppressWarnings({ + "unchecked", "rawtypes" // Unsafe! if comparator is null, this assumes K is comparable. + }) + LinkedHashTreeMap(Comparator comparator) { this.comparator = comparator != null ? comparator : (Comparator) NATURAL_ORDER; @@ -473,14 +475,14 @@ final class LinkedHashTreeMap extends AbstractMap implements Seriali V value; int height; - /** Create the header entry */ + /** Create the header entry. */ Node() { key = null; hash = -1; next = prev = this; } - /** Create a regular entry */ + /** Create a regular entry. */ Node(Node parent, K key, int hash, Node next, Node prev) { this.parent = parent; this.key = key; @@ -665,7 +667,7 @@ final class LinkedHashTreeMap extends AbstractMap implements Seriali * comparisons. Using this class to create a tree of size S is * {@code O(S)}. */ - final static class AvlBuilder { + static final class AvlBuilder { /** This stack is a singly linked list, linked by the 'parent' field. */ private Node stack; private int leavesToSkip; diff --git a/moshi/src/main/java/com/squareup/moshi/MapJsonAdapter.java b/moshi/src/main/java/com/squareup/moshi/MapJsonAdapter.java index 8cf784d..a31cf22 100644 --- a/moshi/src/main/java/com/squareup/moshi/MapJsonAdapter.java +++ b/moshi/src/main/java/com/squareup/moshi/MapJsonAdapter.java @@ -41,7 +41,7 @@ final class MapJsonAdapter extends JsonAdapter> { private final JsonAdapter keyAdapter; private final JsonAdapter valueAdapter; - public MapJsonAdapter(Moshi moshi, Type keyType, Type valueType) { + MapJsonAdapter(Moshi moshi, Type keyType, Type valueType) { this.keyAdapter = moshi.adapter(keyType); this.valueAdapter = moshi.adapter(valueType); } diff --git a/moshi/src/main/java/com/squareup/moshi/StandardJsonAdapters.java b/moshi/src/main/java/com/squareup/moshi/StandardJsonAdapters.java index 6c8b77b..bdb8da1 100644 --- a/moshi/src/main/java/com/squareup/moshi/StandardJsonAdapters.java +++ b/moshi/src/main/java/com/squareup/moshi/StandardJsonAdapters.java @@ -24,6 +24,9 @@ import java.util.Map; import java.util.Set; final class StandardJsonAdapters { + private StandardJsonAdapters() { + } + public static final JsonAdapter.Factory FACTORY = new JsonAdapter.Factory() { @Override public JsonAdapter create( Type type, Set annotations, Moshi moshi) { @@ -216,7 +219,7 @@ final class StandardJsonAdapters { private final T[] constants; private final JsonReader.Options options; - public EnumJsonAdapter(Class enumType) { + EnumJsonAdapter(Class enumType) { this.enumType = enumType; try { constants = enumType.getEnumConstants(); @@ -264,7 +267,7 @@ final class StandardJsonAdapters { static final class ObjectJsonAdapter extends JsonAdapter { private final Moshi moshi; - public ObjectJsonAdapter(Moshi moshi) { + ObjectJsonAdapter(Moshi moshi) { this.moshi = moshi; } diff --git a/moshi/src/main/java/com/squareup/moshi/Types.java b/moshi/src/main/java/com/squareup/moshi/Types.java index 350d34d..f3bf0d7 100644 --- a/moshi/src/main/java/com/squareup/moshi/Types.java +++ b/moshi/src/main/java/com/squareup/moshi/Types.java @@ -149,7 +149,7 @@ public final class Types { return (Class) rawType; } else if (type instanceof GenericArrayType) { - Type componentType = ((GenericArrayType)type).getGenericComponentType(); + Type componentType = ((GenericArrayType) type).getGenericComponentType(); return Array.newInstance(getRawType(componentType), 0).getClass(); } else if (type instanceof TypeVariable) { @@ -560,7 +560,7 @@ public final class Types { private static final class GenericArrayTypeImpl implements GenericArrayType { private final Type componentType; - public GenericArrayTypeImpl(Type componentType) { + GenericArrayTypeImpl(Type componentType) { this.componentType = canonicalize(componentType); } @@ -591,7 +591,7 @@ public final class Types { private final Type upperBound; private final Type lowerBound; - public WildcardTypeImpl(Type[] upperBounds, Type[] lowerBounds) { + WildcardTypeImpl(Type[] upperBounds, Type[] lowerBounds) { if (lowerBounds.length > 1) throw new IllegalArgumentException(); if (upperBounds.length != 1) throw new IllegalArgumentException(); diff --git a/moshi/src/main/java/com/squareup/moshi/Util.java b/moshi/src/main/java/com/squareup/moshi/Util.java index eddb6b6..0d93867 100644 --- a/moshi/src/main/java/com/squareup/moshi/Util.java +++ b/moshi/src/main/java/com/squareup/moshi/Util.java @@ -25,6 +25,9 @@ import java.util.Set; final class Util { public static final Set NO_ANNOTATIONS = Collections.emptySet(); + private Util() { + } + public static boolean typesMatch(Type pattern, Type candidate) { // TODO: permit raw types (like Set.class) to match non-raw candidates (like Set). return pattern.equals(candidate); diff --git a/pom.xml b/pom.xml index 3f7af26..cac2cd1 100644 --- a/pom.xml +++ b/pom.xml @@ -127,6 +127,32 @@ + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.17 + + + com.puppycrawl.tools + checkstyle + 7.7 + + + + true + checkstyle.xml + true + **/Iso8601Utils.java + + + + verify + + checkstyle + + + + org.apache.maven.plugins maven-release-plugin