test/tools/apt/mirror/declaration/EnumDecl.java

Tue, 07 Oct 2008 15:39:19 -0700

author
jjg
date
Tue, 07 Oct 2008 15:39:19 -0700
changeset 132
a54ef8459576
parent 1
9a66ca7c79fa
child 174
fdfed22db054
permissions
-rw-r--r--

6749967: regression tests for apt should be same-vm friendly
Reviewed-by: darcy

     1 /*
     2  * Copyright 2004-2007 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  */
    25 /*
    26  * @test
    27  * @bug 4853450 4989987 5010050
    28  * @summary EnumDeclaration tests
    29  * @library ../../lib
    30  * @compile -source 1.5 EnumDecl.java
    31  * @run main/othervm EnumDecl
    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 EnumDecl extends Tester {
    43     public static void main(String[] args) {
    44         (new EnumDecl()).run();
    45     }
    48     private EnumDeclaration eDecl;
    50     protected void init() {
    51         eDecl = (EnumDeclaration) env.getTypeDeclaration("E");
    52     }
    55     // Declaration methods
    57     @Test(result="enum")
    58     Collection<String> accept() {
    59         final Collection<String> res = new ArrayList<String>();
    61         eDecl.accept(new SimpleDeclarationVisitor() {
    62             public void visitTypeDeclaration(TypeDeclaration t) {
    63                 res.add("type");
    64             }
    65             public void visitClassDeclaration(ClassDeclaration c) {
    66                 res.add("class");
    67             }
    68             public void visitEnumDeclaration(EnumDeclaration e) {
    69                 res.add("enum");
    70             }
    71         });
    72         return res;
    73     }
    76     // ClassDeclaration methods
    78     // 4989987: Verify synthetic enum constructor parameters are not visible
    79     @Test(result={"E(java.lang.String)"})
    80     Collection<ConstructorDeclaration> getConstructors() {
    81         return eDecl.getConstructors();
    82     }
    84     // 4989987: Verify synthetic enum constructor parameters are not visible
    85     @Test(result={"java.lang.String color"})
    86     Collection<ParameterDeclaration> getConstructorParams() {
    87         return eDecl.getConstructors().iterator().next().getParameters();
    88     }
    90     @Test(result={"values()", "valueOf(java.lang.String)"})
    91     Collection<MethodDeclaration> getMethods() {
    92         return eDecl.getMethods();
    93     }
    95     // 5010050: Cannot find parameter names for valueOf(String name) method...
    96     @Test(result={"java.lang.String name"})
    97     Collection<ParameterDeclaration> getMethodParams() {
    98         for (MethodDeclaration m : eDecl.getMethods()) {
    99             if (m.getSimpleName().equals("valueOf")) {
   100                 return m.getParameters();
   101             }
   102         }
   103         throw new AssertionError();
   104     }
   107     // EnumDeclaration methods
   109     @Test(result={"stop", "slow", "go"})
   110     Collection<EnumConstantDeclaration> getEnumConstants() {
   111         return eDecl.getEnumConstants();
   112     }
   113 }
   116 // An enum to use for testing.
   118 enum E {
   119     stop("red"),
   120     slow("amber"),
   121     go("green");
   123     private String color;
   124     E(String color) {
   125         this.color = color;
   126     }
   127 }

mercurial