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

Tue, 25 May 2010 15:54:51 -0700

author
ohair
date
Tue, 25 May 2010 15:54:51 -0700
changeset 554
9d9f26857129
parent 174
fdfed22db054
permissions
-rw-r--r--

6943119: Rebrand source copyright notices
Reviewed-by: darcy

     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 4993299 5010385 5014539
    28  * @summary AnnotationTypeElementDeclaration tests
    29  * @library ../../lib
    30  * @compile -source 1.5 AnnoTypeElemDecl.java
    31  * @run main/othervm AnnoTypeElemDecl
    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 AnnoTypeElemDecl extends Tester {
    43     public static void main(String[] args) {
    44         (new AnnoTypeElemDecl()).run();
    45     }
    48     // Some annotation type elements to use.
    49     private AnnotationTypeElementDeclaration elem1 = null;      // s()
    50     private AnnotationTypeElementDeclaration elem2 = null;      // i()
    51     private AnnotationTypeElementDeclaration elem3 = null;      // b()
    53     protected void init() {
    54         for (TypeDeclaration at : thisClassDecl.getNestedTypes()) {
    55             for (MethodDeclaration meth : at.getMethods()) {
    56                 AnnotationTypeElementDeclaration elem =
    57                     (AnnotationTypeElementDeclaration) meth;
    58                 if (elem.getSimpleName().equals("s")) {
    59                     elem1 = elem;       // s()
    60                 } else if (elem.getSimpleName().equals("i")) {
    61                     elem2 = elem;       // i()
    62                 } else {
    63                     elem3 = elem;       // b()
    64                 }
    65             }
    66         }
    67     }
    70     // Declaration methods
    72     @Test(result="anno type element")
    73     Collection<String> accept() {
    74         final Collection<String> res = new ArrayList<String>();
    76         elem1.accept(new SimpleDeclarationVisitor() {
    77             public void visitTypeDeclaration(TypeDeclaration t) {
    78                 res.add("type");
    79             }
    80             public void visitExecutableDeclaration(ExecutableDeclaration e) {
    81                 res.add("executable");
    82             }
    83             public void visitMethodDeclaration(MethodDeclaration m) {
    84                 res.add("method");
    85             }
    86             public void visitAnnotationTypeElementDeclaration(
    87                                         AnnotationTypeElementDeclaration a) {
    88                 res.add("anno type element");
    89             }
    90         });
    91         return res;
    92     }
    94     @Test(result={"@AnnoTypeElemDecl.AT2"})
    95     Collection<AnnotationMirror> getAnnotationMirrors() {
    96         return elem1.getAnnotationMirrors();
    97     }
    99     @Test(result=" Sed Quis custodiet ipsos custodes?\n")
   100     String getDocComment() {
   101         return elem1.getDocComment();
   102     }
   104     @Test(result={"public", "abstract"})
   105     Collection<Modifier> getModifiers() {
   106         return elem1.getModifiers();
   107     }
   109     @Test(result="AnnoTypeElemDecl.java")
   110     String getPosition() {
   111         return elem1.getPosition().file().getName();
   112     }
   114     @Test(result="s")
   115     String getSimpleName() {
   116         return elem1.getSimpleName();
   117     }
   120     // MemberDeclaration method
   122     @Test(result="AnnoTypeElemDecl.AT1")
   123     TypeDeclaration getDeclaringType() {
   124         return elem1.getDeclaringType();
   125     }
   128     // ExecutableDeclaration methods
   130     @Test(result={})
   131     Collection<TypeParameterDeclaration> getFormalTypeParameters() {
   132         return elem1.getFormalTypeParameters();
   133     }
   135     @Test(result={})
   136     Collection<ParameterDeclaration> getParameters() {
   137         return elem1.getParameters();
   138     }
   140     @Test(result={})
   141     Collection<ReferenceType> getThrownTypes() {
   142         return elem1.getThrownTypes();
   143     }
   145     @Test(result="false")
   146     Boolean isVarArgs() {
   147         return elem1.isVarArgs();
   148     }
   151     // AnnotationTypeElementDeclaration method
   153     @Test(result="\"default\"")
   154     AnnotationValue getDefaultValue1() {
   155         return elem1.getDefaultValue();
   156     }
   158     @Test(result="null")
   159     AnnotationValue getDefaultValue2() {
   160         return elem2.getDefaultValue();
   161     }
   163     // 5010385: getValue() returns null for boolean type elements
   164     @Test(result="false")
   165     Boolean getDefaultValue3() {
   166         return (Boolean) elem3.getDefaultValue().getValue();
   167     }
   170     // toString
   172     @Test(result="s()")
   173     String toStringTest() {
   174         return elem1.toString();
   175     }
   178     // Declarations used by tests.
   180     @interface AT1 {
   181         /**
   182          * Sed Quis custodiet ipsos custodes?
   183          */
   184         @AT2
   185         String s() default "default";
   187         int i();
   189         boolean b() default false;
   190     }
   192     @interface AT2 {
   193     }
   194 }

mercurial