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 4853450
  28  * @summary EnumType tests
  29  * @library ../../lib
  30  * @compile -source 1.5 EnumTyp.java
  31  * @run main/othervm EnumTyp
  32  */
  33 
  34 
  35 import java.util.*;
  36 import com.sun.mirror.declaration.*;
  37 import com.sun.mirror.type.*;
  38 import com.sun.mirror.util.*;
  39 
  40 
  41 public class EnumTyp extends Tester {
  42 
  43     public static void main(String[] args) {
  44         (new EnumTyp()).run();
  45     }
  46 
  47 
  48     // Declarations used by tests
  49 
  50     enum Suit {
  51         CIVIL,
  52         CRIMINAL
  53     }
  54 
  55     private Suit s;
  56 
  57 
  58     private EnumType e;         // an enum type
  59 
  60     protected void init() {
  61         e = (EnumType) getField("s").getType();
  62     }
  63 
  64 
  65     // TypeMirror methods
  66 
  67     @Test(result="enum")
  68     Collection<String> accept() {
  69         final Collection<String> res = new ArrayList<String>();
  70 
  71         e.accept(new SimpleTypeVisitor() {
  72             public void visitTypeMirror(TypeMirror t) {
  73                 res.add("type");
  74             }
  75             public void visitReferenceType(ReferenceType t) {
  76                 res.add("ref type");
  77             }
  78             public void visitClassType(ClassType t) {
  79                 res.add("class");
  80             }
  81             public void visitEnumType(EnumType t) {
  82                 res.add("enum");
  83             }
  84             public void visitInterfaceType(InterfaceType t) {
  85                 res.add("interface");
  86             }
  87         });
  88         return res;
  89     }
  90 
  91 
  92     // EnumType method
  93 
  94     @Test(result="EnumTyp.Suit")
  95     EnumDeclaration getDeclaration() {
  96         return e.getDeclaration();
  97     }
  98 }