Skip to content

Commit

Permalink
new ClassName().getClass() -> ClassName.class (#751)
Browse files Browse the repository at this point in the history
  • Loading branch information
chingor13 authored Jul 23, 2019
1 parent b5379ae commit 3abca4e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -306,40 +306,26 @@ static class MedXResolve<Y extends Number, X extends Y> extends Resolve<X, Integ
public void testResolveWildcardTypeOrTypeVariable() throws Exception {
// t
TypeVariable<?> tTypeVar = (TypeVariable<?>) Resolve.class.getField("t").getGenericType();
assertEquals(
Number.class, resolveWildcardTypeOrTypeVariable(new Object().getClass(), tTypeVar));
assertEquals(
Number.class,
resolveWildcardTypeOrTypeVariable(new Resolve<Boolean, Double>().getClass(), tTypeVar));
assertEquals(
Integer.class,
resolveWildcardTypeOrTypeVariable(new IntegerResolve().getClass(), tTypeVar));
assertEquals(
Long.class, resolveWildcardTypeOrTypeVariable(new LongResolve().getClass(), tTypeVar));
assertEquals(
Double.class, resolveWildcardTypeOrTypeVariable(new DoubleResolve().getClass(), tTypeVar));
assertEquals(Number.class, resolveWildcardTypeOrTypeVariable(Object.class, tTypeVar));
assertEquals(Number.class, resolveWildcardTypeOrTypeVariable(Resolve.class, tTypeVar));
assertEquals(Integer.class, resolveWildcardTypeOrTypeVariable(IntegerResolve.class, tTypeVar));
assertEquals(Long.class, resolveWildcardTypeOrTypeVariable(LongResolve.class, tTypeVar));
assertEquals(Double.class, resolveWildcardTypeOrTypeVariable(DoubleResolve.class, tTypeVar));
// partially resolved
assertEquals(
Number.class,
resolveWildcardTypeOrTypeVariable(new MedResolve<Double>().getClass(), tTypeVar));
assertEquals(Number.class, resolveWildcardTypeOrTypeVariable(MedResolve.class, tTypeVar));
// x
TypeVariable<?> xTypeVar = (TypeVariable<?>) Resolve.class.getField("x").getGenericType();
assertEquals(
Object.class, resolveWildcardTypeOrTypeVariable(new Object().getClass(), xTypeVar));
assertEquals(Object.class, resolveWildcardTypeOrTypeVariable(Object.class, xTypeVar));
assertEquals(
Boolean.class,
Types.getArrayComponentType(
resolveWildcardTypeOrTypeVariable(new ArrayResolve().getClass(), xTypeVar)));
resolveWildcardTypeOrTypeVariable(ArrayResolve.class, xTypeVar)));
assertEquals(
Collection.class,
Types.getRawClass(
(ParameterizedType)
resolveWildcardTypeOrTypeVariable(
new ParameterizedResolve().getClass(), xTypeVar)));
assertEquals(
Number.class,
resolveWildcardTypeOrTypeVariable(
new MedXResolve<Integer, Integer>().getClass(), xTypeVar));
resolveWildcardTypeOrTypeVariable(ParameterizedResolve.class, xTypeVar)));
assertEquals(Number.class, resolveWildcardTypeOrTypeVariable(MedXResolve.class, xTypeVar));
}

private static Type resolveWildcardTypeOrTypeVariable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,27 +115,26 @@ static class ParameterizedResolve extends Resolve<Collection<Integer>, Integer>
public void testResolveTypeVariable() throws Exception {
// t
TypeVariable<?> tTypeVar = (TypeVariable<?>) Resolve.class.getField("t").getGenericType();
assertNull(resolveTypeVariable(new Object().getClass(), tTypeVar));
assertNull(resolveTypeVariable(new Resolve<Boolean, Double>().getClass(), tTypeVar));
assertEquals(Integer.class, resolveTypeVariable(new IntegerResolve().getClass(), tTypeVar));
assertEquals(Long.class, resolveTypeVariable(new LongResolve().getClass(), tTypeVar));
assertEquals(Double.class, resolveTypeVariable(new DoubleResolve().getClass(), tTypeVar));
assertNull(resolveTypeVariable(Object.class, tTypeVar));
assertNull(resolveTypeVariable(Resolve.class, tTypeVar));
assertEquals(Integer.class, resolveTypeVariable(IntegerResolve.class, tTypeVar));
assertEquals(Long.class, resolveTypeVariable(LongResolve.class, tTypeVar));
assertEquals(Double.class, resolveTypeVariable(DoubleResolve.class, tTypeVar));
// partially resolved
assertEquals(
MedResolve.class,
((TypeVariable<?>) resolveTypeVariable(new MedResolve<Double>().getClass(), tTypeVar))
((TypeVariable<?>) resolveTypeVariable(MedResolve.class, tTypeVar))
.getGenericDeclaration());
// x
TypeVariable<?> xTypeVar = (TypeVariable<?>) Resolve.class.getField("x").getGenericType();
assertNull(resolveTypeVariable(new Object().getClass(), xTypeVar));
assertNull(resolveTypeVariable(Object.class, xTypeVar));
assertEquals(
Boolean.class,
Types.getArrayComponentType(resolveTypeVariable(new ArrayResolve().getClass(), xTypeVar)));
Types.getArrayComponentType(resolveTypeVariable(ArrayResolve.class, xTypeVar)));
assertEquals(
Collection.class,
Types.getRawClass(
(ParameterizedType)
resolveTypeVariable(new ParameterizedResolve().getClass(), xTypeVar)));
(ParameterizedType) resolveTypeVariable(ParameterizedResolve.class, xTypeVar)));
}

private static Type resolveTypeVariable(Type context, TypeVariable<?> typeVariable) {
Expand Down

0 comments on commit 3abca4e

Please sign in to comment.