return wildcardType().withUpperBounds(unrollBounds(typeArguments, wild.getUpperBounds())) .withLowerBounds(unrollBounds(typeArguments, wild.getLowerBounds())).build();
@Test public void testLowerBoundedWildcardType() { final WildcardType lowerBounded = TypeUtils.wildcardType().withLowerBounds(java.sql.Date.class).build(); assertEquals(String.format("? super %s", java.sql.Date.class.getName()), TypeUtils.toString(lowerBounded)); assertEquals(String.format("? super %s", java.sql.Date.class.getName()), lowerBounded.toString()); final TypeVariable<Class<Iterable>> iterableT0 = Iterable.class.getTypeParameters()[0]; final WildcardType lowerTypeVariable = TypeUtils.wildcardType().withLowerBounds(iterableT0).build(); assertEquals(String.format("? super %s", iterableT0.getName()), TypeUtils.toString(lowerTypeVariable)); assertEquals(String.format("? super %s", iterableT0.getName()), lowerTypeVariable.toString()); }
@Test public void testWildcardType() throws Exception { final WildcardType simpleWildcard = TypeUtils.wildcardType().withUpperBounds(String.class).build(); final Field cClass = AClass.class.getField("cClass"); assertTrue(TypeUtils.equals(((ParameterizedType) cClass.getGenericType()).getActualTypeArguments()[0], simpleWildcard)); assertEquals(String.format("? extends %s", String.class.getName()), TypeUtils.toString(simpleWildcard)); assertEquals(String.format("? extends %s", String.class.getName()), simpleWildcard.toString()); }
@Test public void testLANG1190() throws Exception { final Type fromType = ClassWithSuperClassWithGenericType.class.getDeclaredMethod("methodWithGenericReturnType").getGenericReturnType(); final Type failingToType = TypeUtils.wildcardType().withLowerBounds(ClassWithSuperClassWithGenericType.class).build(); assertTrue(TypeUtils.isAssignable(fromType, failingToType)); }
@Test public void testGenericArrayType() throws Exception { final Type expected = getClass().getField("intWildcardComparable").getGenericType(); final GenericArrayType actual = TypeUtils.genericArrayType(TypeUtils.parameterize(Comparable.class, TypeUtils.wildcardType() .withUpperBounds(Integer.class).build())); assertTrue(TypeUtils.equals(expected, actual)); assertEquals("java.lang.Comparable<? extends java.lang.Integer>[]", actual.toString()); }
@Test public void testUnboundedWildcardType() { final WildcardType unbounded = TypeUtils.wildcardType().withLowerBounds((Type) null).withUpperBounds().build(); assertTrue(TypeUtils.equals(TypeUtils.WILDCARD_ALL, unbounded)); assertArrayEquals(new Type[] { Object.class }, TypeUtils.getImplicitUpperBounds(unbounded)); assertArrayEquals(new Type[] { null }, TypeUtils.getImplicitLowerBounds(unbounded)); assertEquals("?", TypeUtils.toString(unbounded)); assertEquals("?", unbounded.toString()); }
return wildcardType().withUpperBounds(unrollBounds(typeArguments, wild.getUpperBounds())) .withLowerBounds(unrollBounds(typeArguments, wild.getLowerBounds())).build();
return wildcardType().withUpperBounds(unrollBounds(typeArguments, wild.getUpperBounds())) .withLowerBounds(unrollBounds(typeArguments, wild.getLowerBounds())).build();
return wildcardType().withUpperBounds(unrollBounds(typeArguments, wild.getUpperBounds())) .withLowerBounds(unrollBounds(typeArguments, wild.getLowerBounds())).build();