JType implements Type, Type.ArrayType { @Override public List<Type> typeArguments() { if (typeArguments == null) { typeArguments = sema.types(typeBinding.getTypeArguments()); } return typeArguments; } JType(JSema sema, ITypeBinding typeBinding); @Override boolean is(String fullyQualifiedName); @Override boolean isSubtypeOf(String fullyQualifiedName); @Override boolean isSubtypeOf(Type superType); @Override boolean isArray(); @Override boolean isClass(); @Override boolean isVoid(); @Override boolean isPrimitive(); @Override boolean isPrimitive(Primitives primitive); @Override boolean isUnknown(); @Override boolean isNumerical(); @Override String fullyQualifiedName(); @Override String name(); @Override String toString(); @Override Symbol.TypeSymbol symbol(); @Override Type erasure(); @Override Type elementType(); @Override boolean equals(Object obj); @Override int hashCode(); @Override boolean isParameterized(); @Override List<Type> typeArguments();  }
@Test void typeArguments() { JavaTree.CompilationUnitTreeImpl cu = test("class C { void m() { new java.util.HashMap<Integer, String>(); } }"); ClassTreeImpl c = (ClassTreeImpl) cu.types().get(0); MethodTreeImpl m = (MethodTreeImpl) c.members().get(0); ExpressionStatementTreeImpl s = (ExpressionStatementTreeImpl) Objects.requireNonNull(m.block()).body().get(0); AbstractTypedTree e = Objects.requireNonNull((AbstractTypedTree) s.expression()); assertThat(cu.sema.type(e.typeBinding).typeArguments()) .hasToString(e.symbolType().typeArguments().toString()) .hasToString("[Integer, String]"); assertThat(cu.sema.type(c.typeBinding).typeArguments()) .isEqualTo(c.symbol().type().typeArguments()) .isEmpty(); }
@Test void wildcard() { JavaTree.CompilationUnitTreeImpl cu = test("class C<T1, T2, T3> { C<? extends String, ? extends String, ? super String> f; }"); ClassTreeImpl c = (ClassTreeImpl) cu.types().get(0); VariableTreeImpl f = (VariableTreeImpl) c.members().get(0); JavaTree.ParameterizedTypeTreeImpl p = (JavaTree.ParameterizedTypeTreeImpl) f.type(); JavaTree.WildcardTreeImpl w1 = (JavaTree.WildcardTreeImpl) p.typeArguments().get(0); JavaTree.WildcardTreeImpl w2 = (JavaTree.WildcardTreeImpl) p.typeArguments().get(1); JavaTree.WildcardTreeImpl w3 = (JavaTree.WildcardTreeImpl) p.typeArguments().get(2); JType wildcardType1 = cu.sema.type(Objects.requireNonNull(w1.typeBinding)); JType wildcardType2 = cu.sema.type(Objects.requireNonNull(w2.typeBinding)); JType wildcardType3 = cu.sema.type(Objects.requireNonNull(w3.typeBinding)); assertThat(wildcardType1) .isEqualTo(wildcardType2) .isNotEqualTo(wildcardType3); }