IsSameTypeWildcardTest.java revision 3549:8150eeaf8c24
1/*
2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/*
25 * @test
26 * @bug 8161277
27 * @summary javax.lang.model.util.Types.isSameType(...) returns true on wildcards
28 * @library /tools/lib/types
29 * @modules jdk.compiler/com.sun.tools.javac.api
30 *          jdk.compiler/com.sun.tools.javac.main
31 *          jdk.compiler/com.sun.tools.javac.code
32 *          jdk.compiler/com.sun.tools.javac.comp
33 *          jdk.compiler/com.sun.tools.javac.tree
34 *          jdk.compiler/com.sun.tools.javac.util
35 *          jdk.compiler/com.sun.tools.javac.file
36 *          jdk.compiler/com.sun.tools.javac.model
37 * @build TypeHarness
38 * @run main IsSameTypeWildcardTest
39 */
40
41import java.util.ArrayList;
42import java.util.List;
43
44import com.sun.tools.javac.code.Type;
45import com.sun.tools.javac.util.Assert;
46import com.sun.tools.javac.model.JavacTypes;
47
48public class IsSameTypeWildcardTest extends TypeHarness {
49    StrToTypeFactory strToTypeFactory;
50    JavacTypes javacTypes;
51
52    public static void main(String... args) throws Exception {
53        new IsSameTypeWildcardTest().runTest();
54    }
55
56    public IsSameTypeWildcardTest() {
57        javacTypes = JavacTypes.instance(context);
58    }
59
60    void runTest() {
61        List<String> imports = new ArrayList<>();
62        imports.add("java.util.*");
63        strToTypeFactory = new StrToTypeFactory(null, imports, null);
64
65        Type listOfWildcard = strToTypeFactory.getType("List<?>");
66        com.sun.tools.javac.util.List<Type> arguments = listOfWildcard.getTypeArguments();
67        Assert.check(!javacTypes.isSameType(arguments.head, arguments.head),
68                "if any argument is a wildcard then result must be false");
69    }
70}
71