/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4891872
* @summary Some tests for the generic core reflection api.
* @author Gilad Bracha
* @compile TestC2.java
*/
abstract class C0<T> {
public T ft;
public C0(){}
public C0(T t) {}
public abstract T mt(T t);
}
}
}
interface I3 {
}
{
public int fi;
public <T> C2(T t) {}
}
public class TestC2 {
testMethods();
testFields();
}
static void testSuperclass() {
assert
sc instanceof ParameterizedType :
"Superclass of C2 should be a parameterized type";
assert
"The raw generic superclass of C2 should be C0";
assert
"Superclass of C2 should have one type argument";
assert
t instanceof TypeVariable :
"Type argument to superclass of C2 should be a type variable";
assert
"Name of type argument to superclass of C2 should be T1";
assert
"T1 has one bound (superclass)";
t = bs[0];
assert
t instanceof ParameterizedType :
"Bound of C0 should be a parameterized type";
assert
"The raw bound of T1 should be C2";
assert
"Bound of T1 should have three type arguments";
assert
"First argument to bound of T1 is a type variable";
assert
"Second argument to bound of T1 is a type variable";
assert
"Third argument to bound of T1 is a type variable";
assert
"First type arg to bound of T1 is T1";
assert
"Seconmd type arg to bound of T1 is T2";
assert
"Third type arg to bound of T1 is T3";
}
static void testSuperInterfaces() {
assert
"C2 should have three generic superinterfaces";
assert
t instanceof ParameterizedType :
"First superinterface of C2 should be a parameterized type";
assert
"First super interface of C2 is instantiation of I1";
assert
"First super interface of C2 has 2 type arguments";
t = sis[1];
assert
t instanceof ParameterizedType :
"Second superinterface of C2 should be a parameterized type";
pt = (ParameterizedType) t;
assert
"Second super interface of C2 is instantiation of I2";
assert
"Second super interface of C2 has 3 type arguments";
t = sis[2];
assert
t == I3.class :
"Third superinterface of C2 is I3";
// Test interfaces themselves
assert
"I3 has two formal type parameters";
assert
"Name of first formal type arg of I1 is X1";
assert
"Name of second formal type arg of I1 is X2";
assert
"The generic and non-generic superclasses of an interface must be the same";
assert
"I1 has one generic superinterface";
assert
"Superinterface of I1 is I3";
assert
"I3 has three formal type parameters";
assert
"Name of first formal type arg of I2 is E1";
assert
"Name of second formal type arg of I2 is E2";
assert
"Name of third formal type arg of I2 is E3";
assert
"The generic and non-generic superclasses of an interface must be the same";
assert
"I3 has no formal type parameters";
assert
"The generic and non-generic superclasses of an interface must be the same";
}
static void testTypeParameters() {
assert
"C2 should have three type parameters";
assert
"T1 should have one bound";
assert
"The bound of T1 should be a parameterized type";
assert
"T2 should have one bound";
assert
"The bound of T2 should be a parameterized type";
assert
"T3 should have one bound";
assert
"The bound of T3 should be Throwable";
}
assert
rt_mc1t instanceof ParameterizedType :
"The return type of mc1t should be a parameterized type";
assert
"The raw return type of mc1t should be C0";
assert
"Return type of mc1t should have one type argument";
assert
"Type argument of return type of mc1t is a type variable";
assert
"Return type of mc1 is C0";
assert
rt_mt instanceof TypeVariable :
"Return type of mt is a type variable";
assert
"C0.mc1t has three parameters";
assert
p1_mc1t instanceof TypeVariable :
"Generic type of the 1st parameter of mc1t(T) is a type variable";
assert
assert
"T3 should have one bound (mc1t)";
assert
"The bound of T3 should be Throwable(mc1t)";
assert
p2_mc1t instanceof ParameterizedType :
"The type of parameter 2 of mc1t is a parameterized type";
assert
"Type of parameter 2 of mc1t is instantiation of C0";
assert
"Type of parameter 2 of mc1t is has null owner";
assert
"The type of parameter 2 of mc1t has one type argument";
assert
ta instanceof TypeVariable :
"The actual type arg of C0<T> is a type variable (mc1t)";
assert
assert
"mc1t: The type argument of C0<T> should have one bound";
assert
"mc1t: The bound of the type arg of C0<T> should be Object";
assert
"Type of parameter 3 of mc1t is C0";
assert
"C2.mc1 has one parameter";
assert
"C2.mt has one parameter";
assert
p_mt instanceof TypeVariable :
"The generic type of the parameter of mt(T) is a type variable";
assert
assert
"T2 should have one bound";
assert
"The bound of T2 should be parameterized type";
assert
"Method C0.mc1t should have no generic exception types";
assert
"Method C0.mc1 should have no generic exception types";
assert
"Method C0.mt should have no generic exception types";
assert
"Method C2.mc1t should have one type parameter";
assert
"Method C2.mc1 should have two type parameters";
assert
"Method C2.mt should have no type parameters";
}
assert
gt_ft instanceof TypeVariable :
"The generic type of C0.ft is a type variable";
assert
assert
"The type of ft should have one bound";
assert
gt_fc1t instanceof ParameterizedType :
"The generic type of C0.fc1t is a parameterized type";
assert
"Type of C2.fc1t is an instantiation of C0";
assert
"Type of C2.fc1t is has null owner";
assert
"The type of fc1t has one type argument";
assert
"The actual type arg of C0<String> is String";
assert
" Type of C2.fc1 should be C0";
assert
gt_fi == int.class:
" Type of C2.fi should be int";
}
assert
"Constructor C0(T) should have one generic parameter type";
assert
pt instanceof TypeVariable :
"The generic type of the parameter of C0(T2) is a type variable";
assert
assert
"T should have one bound";
assert
"Constructor C2(T2) should have no generic exception types";
assert
"Constructor C2(T2) should have no type parameters";
assert
"Constructor C0(T) should have one generic parameter type";
assert
pt instanceof TypeVariable :
"The generic type of the parameter of C2(T) is a type variable";
assert
assert
"T should have one bound";
assert
"Constructor C2(T) should have no generic exception types";
assert
"Constructor C2(T) should have one type parameter";
assert
"Constructor C2(T1,T2,T4) should have three generic parameter types";
assert
pt instanceof TypeVariable :
"The generic type of the first parameter of C2(T1,T2,T4) is a type variable";
assert
assert
"T should have one bound";
assert
"Constructor C2(T1,T2,T4) should have no generic exception types";
assert
"Constructor C2(T1,T2,T4) should have four type parameters";
assert
"Constructor C2() should have no generic parameter types";
assert
"Constructor C2() should have one generic exception type";
assert
"Constructor C2() should have no type parameters";
}
}