1 /*
   2  * Copyright (c) 2004, 2008, 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 /*
  26  * @test
  27  * @bug 5033381
  28  * @summary Test the type creation methods in Types.
  29  * @library ../../lib
  30  * @run main/othervm TypeCreation
  31  */
  32 
  33 
  34 import java.util.*;
  35 import com.sun.mirror.declaration.*;
  36 import com.sun.mirror.type.*;
  37 import com.sun.mirror.util.*;
  38 
  39 import static com.sun.mirror.type.PrimitiveType.Kind.*;
  40 
  41 
  42 public class TypeCreation extends Tester {
  43 
  44     public static void main(String[] args) {
  45         (new TypeCreation()).run();
  46     }
  47 
  48 
  49     // Declarations used by tests
  50 
  51     class A {
  52     }
  53 
  54     class O<T> {
  55         class I<S> {
  56         }
  57     }
  58 
  59 
  60     private Types types;
  61 
  62     private TypeDeclaration A;
  63     private TypeDeclaration O;
  64     private TypeDeclaration I;
  65 
  66     private DeclaredType AType;
  67 
  68     protected void init() {
  69         types = env.getTypeUtils();
  70         A = env.getTypeDeclaration("TypeCreation.A");
  71         O = env.getTypeDeclaration("TypeCreation.O");
  72         I = env.getTypeDeclaration("TypeCreation.O.I");
  73 
  74         AType = types.getDeclaredType(A);
  75     }
  76 
  77 
  78     @Test(result="boolean")
  79     PrimitiveType getPrimitiveType() {
  80         return types.getPrimitiveType(BOOLEAN);
  81     }
  82 
  83     @Test(result="void")
  84     VoidType getVoidType() {
  85         return types.getVoidType();
  86     }
  87 
  88     @Test(result="boolean[]")
  89     ArrayType getArrayType1() {
  90         return types.getArrayType(
  91                 types.getPrimitiveType(BOOLEAN));
  92     }
  93 
  94     @Test(result="TypeCreation.A[]")
  95     ArrayType getArrayType2() {
  96         return types.getArrayType(AType);
  97     }
  98 
  99     @Test(result="? extends TypeCreation.A")
 100     WildcardType getWildcardType() {
 101         Collection<ReferenceType> uppers = new ArrayList<ReferenceType>();
 102         Collection<ReferenceType> downers = new ArrayList<ReferenceType>();
 103         uppers.add(AType);
 104         return types.getWildcardType(uppers, downers);
 105     }
 106 
 107     @Test(result="TypeCreation.O<java.lang.String>")
 108     DeclaredType getDeclaredType1() {
 109         TypeDeclaration stringDecl = env.getTypeDeclaration("java.lang.String");
 110         DeclaredType stringType = types.getDeclaredType(stringDecl);
 111         return types.getDeclaredType(O, stringType);
 112     }
 113 
 114     @Test(result="TypeCreation.O<java.lang.String>.I<java.lang.Number>")
 115     DeclaredType getDeclaredType2() {
 116         TypeDeclaration numDecl = env.getTypeDeclaration("java.lang.Number");
 117         DeclaredType numType = types.getDeclaredType(numDecl);
 118         DeclaredType OType = getDeclaredType1();
 119         return types.getDeclaredType(OType, I, numType);
 120     }
 121 }