Skip to content

Commit

Permalink
Small tweaks while doing other work. (square#2685)
Browse files Browse the repository at this point in the history
* Add missing nullability annotations.

* Inline single-use utility methods.

* Remove redundant throws.

* Inline method only called once.
  • Loading branch information
JakeWharton authored and swankjesse committed Mar 7, 2018
1 parent 98ddee4 commit 0b56d38
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 28 deletions.
6 changes: 3 additions & 3 deletions retrofit/src/main/java/retrofit2/BuiltInConverters.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public Converter<?, RequestBody> requestBodyConverter(Type type,
static final class VoidResponseBodyConverter implements Converter<ResponseBody, Void> {
static final VoidResponseBodyConverter INSTANCE = new VoidResponseBodyConverter();

@Override public Void convert(ResponseBody value) throws IOException {
@Override public Void convert(ResponseBody value) {
value.close();
return null;
}
Expand All @@ -58,7 +58,7 @@ static final class VoidResponseBodyConverter implements Converter<ResponseBody,
static final class RequestBodyConverter implements Converter<RequestBody, RequestBody> {
static final RequestBodyConverter INSTANCE = new RequestBodyConverter();

@Override public RequestBody convert(RequestBody value) throws IOException {
@Override public RequestBody convert(RequestBody value) {
return value;
}
}
Expand All @@ -67,7 +67,7 @@ static final class StreamingResponseBodyConverter
implements Converter<ResponseBody, ResponseBody> {
static final StreamingResponseBodyConverter INSTANCE = new StreamingResponseBodyConverter();

@Override public ResponseBody convert(ResponseBody value) throws IOException {
@Override public ResponseBody convert(ResponseBody value) {
return value;
}
}
Expand Down
18 changes: 7 additions & 11 deletions retrofit/src/main/java/retrofit2/OkHttpCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,20 @@ final class OkHttpCall<T> implements Call<T> {
}

call.enqueue(new okhttp3.Callback() {
@Override public void onResponse(okhttp3.Call call, okhttp3.Response rawResponse)
throws IOException {
@Override public void onResponse(okhttp3.Call call, okhttp3.Response rawResponse) {
Response<T> response;
try {
response = parseResponse(rawResponse);
} catch (Throwable e) {
callFailure(e);
return;
}
callSuccess(response);

try {
callback.onResponse(OkHttpCall.this, response);
} catch (Throwable t) {
t.printStackTrace();
}
}

@Override public void onFailure(okhttp3.Call call, IOException e) {
Expand All @@ -133,14 +137,6 @@ private void callFailure(Throwable e) {
t.printStackTrace();
}
}

private void callSuccess(Response<T> response) {
try {
callback.onResponse(OkHttpCall.this, response);
} catch (Throwable t) {
t.printStackTrace();
}
}
});
}

Expand Down
3 changes: 1 addition & 2 deletions retrofit/src/main/java/retrofit2/ParameterHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,7 @@ static final class RawPart extends ParameterHandler<MultipartBody.Part> {
private RawPart() {
}

@Override void apply(RequestBuilder builder, @Nullable MultipartBody.Part value)
throws IOException {
@Override void apply(RequestBuilder builder, @Nullable MultipartBody.Part value) {
if (value != null) { // Skip null values.
builder.addPart(value);
}
Expand Down
20 changes: 8 additions & 12 deletions retrofit/src/main/java/retrofit2/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ static boolean equals(Type a, Type b) {
if (!(b instanceof ParameterizedType)) return false;
ParameterizedType pa = (ParameterizedType) a;
ParameterizedType pb = (ParameterizedType) b;
return equal(pa.getOwnerType(), pb.getOwnerType())
Object ownerA = pa.getOwnerType();
Object ownerB = pb.getOwnerType();
return (ownerA == ownerB || (ownerA != null && ownerA.equals(ownerB)))
&& pa.getRawType().equals(pb.getRawType())
&& Arrays.equals(pa.getActualTypeArguments(), pb.getActualTypeArguments());

Expand Down Expand Up @@ -155,14 +157,6 @@ private static int indexOf(Object[] array, Object toFind) {
throw new NoSuchElementException();
}

private static boolean equal(Object a, Object b) {
return a == b || (a != null && a.equals(b));
}

static int hashCodeOrZero(Object o) {
return o != null ? o.hashCode() : 0;
}

static String typeToString(Type type) {
return type instanceof Class ? ((Class<?>) type).getName() : type.toString();
}
Expand Down Expand Up @@ -330,7 +324,7 @@ static Type getParameterUpperBound(int index, ParameterizedType type) {
return paramType;
}

static boolean hasUnresolvableType(Type type) {
static boolean hasUnresolvableType(@Nullable Type type) {
if (type instanceof Class<?>) {
return false;
}
Expand Down Expand Up @@ -370,7 +364,7 @@ private static final class ParameterizedTypeImpl implements ParameterizedType {
private final Type rawType;
private final Type[] typeArguments;

ParameterizedTypeImpl(Type ownerType, Type rawType, Type... typeArguments) {
ParameterizedTypeImpl(@Nullable Type ownerType, Type rawType, Type... typeArguments) {
// Require an owner type if the raw type needs it.
if (rawType instanceof Class<?>
&& (ownerType == null) != (((Class<?>) rawType).getEnclosingClass() == null)) {
Expand Down Expand Up @@ -404,7 +398,9 @@ private static final class ParameterizedTypeImpl implements ParameterizedType {
}

@Override public int hashCode() {
return Arrays.hashCode(typeArguments) ^ rawType.hashCode() ^ hashCodeOrZero(ownerType);
return Arrays.hashCode(typeArguments)
^ rawType.hashCode()
^ (ownerType != null ? ownerType.hashCode() : 0);
}

@Override public String toString() {
Expand Down

0 comments on commit 0b56d38

Please sign in to comment.