test/tools/apt/mirror/type/ArrayTyp.java

Thu, 15 Dec 2011 15:47:47 -0800

author
katleman
date
Thu, 15 Dec 2011 15:47:47 -0800
changeset 1153
29a512337b79
parent 554
9d9f26857129
permissions
-rw-r--r--

Added tag jdk8-b16 for changeset ec2c0973cc31

     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  */
    25 /*
    26  * @test
    27  * @bug 4853450 5009357
    28  * @summary ArrayType tests
    29  * @library ../../lib
    30  * @compile -source 1.5 ArrayTyp.java
    31  * @run main/othervm ArrayTyp
    32  */
    35 import java.util.*;
    36 import com.sun.mirror.declaration.*;
    37 import com.sun.mirror.type.*;
    38 import com.sun.mirror.util.*;
    41 public class ArrayTyp extends Tester {
    43     public static void main(String[] args) {
    44         (new ArrayTyp()).run();
    45     }
    48     // Declaration used by tests
    50     private boolean[] bs;
    51     private String[][] bss;
    54     private ArrayType arr;              // an array type
    55     private ArrayType arrarr;           // a multi-dimensional array type
    57     protected void init() {
    58         arr = (ArrayType) getField("bs").getType();
    59         arrarr = (ArrayType) getField("bss").getType();
    60     }
    63     // TypeMirror methods
    65     @Test(result="array")
    66     Collection<String> accept() {
    67         final Collection<String> res = new ArrayList<String>();
    69         arr.accept(new SimpleTypeVisitor() {
    70             public void visitTypeMirror(TypeMirror t) {
    71                 res.add("type");
    72             }
    73             public void visitArrayType(ArrayType t) {
    74                 res.add("array");
    75             }
    76             public void visitReferenceType(ReferenceType t) {
    77                 res.add("ref type");
    78             }
    79         });
    80         return res;
    81     }
    83     @Test(result="boolean[]")
    84     String toStringTest() {
    85         return arr.toString();
    86     }
    88     @Test(result="java.lang.String[][]")
    89     String toStringTestMulti() {
    90         return arrarr.toString();
    91     }
    94     // ArrayType method
    96     @Test(result="boolean")
    97     TypeMirror getComponentType() {
    98         return (PrimitiveType) arr.getComponentType();
    99     }
   101     @Test(result="java.lang.String[]")
   102     TypeMirror getComponentTypeMulti() {
   103         return (ArrayType) arrarr.getComponentType();
   104     }
   105 }

mercurial