0N/A/*
553N/A * Copyright (c) 2004, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
553N/A * or visit www.oracle.com if you need additional information or have any
553N/A * questions.
0N/A */
0N/A
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 4853450 5055963
0N/A * @summary InterfaceType tests
0N/A * @library ../../lib
131N/A * @run main/othervm InterfaceTyp
0N/A */
0N/A
0N/A
0N/Aimport java.util.*;
0N/Aimport com.sun.mirror.declaration.*;
0N/Aimport com.sun.mirror.type.*;
0N/Aimport com.sun.mirror.util.*;
0N/A
0N/A
0N/Apublic class InterfaceTyp<T1,T2> extends Tester {
0N/A
0N/A public static void main(String[] args) {
0N/A (new InterfaceTyp()).run();
0N/A }
0N/A
0N/A
0N/A // Declarations used by tests
0N/A
0N/A interface I1<S> extends Set<String> {
0N/A interface I2<R> {
0N/A }
0N/A }
0N/A
0N/A
0N/A // Generate some interface types to test
0N/A private I1<T1> f0;
0N/A private I1<String> f1;
0N/A private I1 f2;
0N/A private I1.I2<String> f3;
0N/A private I1.I2 f4;
0N/A private I1<T1> f5;
0N/A private I3<T1> f6;
0N/A private static final int NUMTYPES = 7;
0N/A
0N/A // Type mirrors corresponding to the types of the above fields
0N/A private InterfaceType[] t = new InterfaceType[NUMTYPES];
0N/A
0N/A protected void init() {
0N/A for (int i = 0; i < t.length; i++) {
0N/A t[i] = (InterfaceType) getField("f"+i).getType();
0N/A }
0N/A }
0N/A
0N/A
0N/A // TypeMirror methods
0N/A
0N/A @Test(result="interface")
0N/A Collection<String> accept() {
0N/A final Collection<String> res = new ArrayList<String>();
0N/A
0N/A t[0].accept(new SimpleTypeVisitor() {
0N/A public void visitReferenceType(ReferenceType t) {
0N/A res.add("ref type");
0N/A }
0N/A public void visitClassType(ClassType t) {
0N/A res.add("class");
0N/A }
0N/A public void visitInterfaceType(InterfaceType t) {
0N/A res.add("interface");
0N/A }
0N/A });
0N/A return res;
0N/A }
0N/A
0N/A @Test(result="true")
0N/A boolean equals1() {
0N/A return t[0].equals(t[0]);
0N/A }
0N/A
0N/A @Test(result="false")
0N/A boolean equals2() {
0N/A return t[0].equals(t[1]);
0N/A }
0N/A
0N/A // Raw type is not same as type instantiated with unbounded type var.
0N/A @Test(result="false")
0N/A boolean equals3() {
0N/A return t[0].equals(t[2]);
0N/A }
0N/A
0N/A // I1<T1> is same type as I1<T1>
0N/A @Test(result="true")
0N/A boolean equals4() {
0N/A return t[0].equals(t[5]);
0N/A }
0N/A
0N/A @Test(result={
0N/A "InterfaceTyp.I1<T1>",
0N/A "InterfaceTyp.I1<java.lang.String>",
0N/A "InterfaceTyp.I1",
0N/A "InterfaceTyp.I1.I2<java.lang.String>",
0N/A "InterfaceTyp.I1.I2",
0N/A "InterfaceTyp.I1<T1>",
0N/A "I3<T1>"
0N/A },
0N/A ordered=true)
0N/A Collection<String> toStringTests() {
0N/A Collection<String> res = new ArrayList<String>();
0N/A for (InterfaceType i : t) {
0N/A res.add(i.toString());
0N/A }
0N/A return res;
0N/A }
0N/A
0N/A
0N/A // DeclaredType methods
0N/A
0N/A @Test(result={"T1"})
0N/A Collection<TypeMirror> getActualTypeArguments1() {
0N/A return t[0].getActualTypeArguments();
0N/A }
0N/A
0N/A @Test(result={})
0N/A Collection<TypeMirror> getActualTypeArguments2() {
0N/A return t[2].getActualTypeArguments();
0N/A }
0N/A
0N/A @Test(result={"java.lang.String"})
0N/A Collection<TypeMirror> getActualTypeArguments3() {
0N/A return t[3].getActualTypeArguments();
0N/A }
0N/A
0N/A @Test(result="InterfaceTyp")
0N/A DeclaredType getContainingType1() {
0N/A return t[0].getContainingType();
0N/A }
0N/A
0N/A @Test(result="InterfaceTyp.I1")
0N/A DeclaredType getContainingType2() {
0N/A return t[3].getContainingType();
0N/A }
0N/A
0N/A @Test(result="null")
0N/A DeclaredType getContainingTypeTopLevel() {
0N/A return t[6].getContainingType();
0N/A }
0N/A
0N/A @Test(result={"java.util.Set<java.lang.String>"})
0N/A Collection<InterfaceType> getSuperinterfaces() {
0N/A return t[0].getSuperinterfaces();
0N/A }
0N/A
0N/A
0N/A
0N/A // InterfaceType method
0N/A
0N/A @Test(result="InterfaceTyp.I1<S>")
0N/A InterfaceDeclaration getDeclaration1() {
0N/A return t[0].getDeclaration();
0N/A }
0N/A
0N/A @Test(result="InterfaceTyp.I1.I2<R>")
0N/A InterfaceDeclaration getDeclaration2a() {
0N/A return t[3].getDeclaration();
0N/A }
0N/A
0N/A @Test(result="InterfaceTyp.I1.I2<R>")
0N/A InterfaceDeclaration getDeclaration2b() {
0N/A return t[4].getDeclaration();
0N/A }
0N/A
0N/A @Test(result="true")
0N/A boolean getDeclarationCaching() {
0N/A return t[0].getDeclaration() == t[5].getDeclaration();
0N/A }
0N/A}
0N/A
0N/A
0N/A// A top-level interface used by tests.
0N/A
0N/Ainterface I3<T> {
0N/A}