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

changeset 1
9a66ca7c79fa
child 132
a54ef8459576
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/apt/mirror/declaration/AnnoMirror.java	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,124 @@
     1.4 +/*
     1.5 + * Copyright 2004-2007 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + */
    1.26 +
    1.27 +
    1.28 +/*
    1.29 + * @test
    1.30 + * @bug 4853450 5014539
    1.31 + * @summary Tests AnnotationMirror and AnnotationValue methods.
    1.32 + * @library ../../lib
    1.33 + * @compile -source 1.5 AnnoMirror.java
    1.34 + * @run main AnnoMirror
    1.35 + */
    1.36 +
    1.37 +
    1.38 +import java.util.*;
    1.39 +import com.sun.mirror.declaration.*;
    1.40 +import com.sun.mirror.type.*;
    1.41 +
    1.42 +
    1.43 +public class AnnoMirror extends Tester {
    1.44 +
    1.45 +    public static void main(String[] args) {
    1.46 +        (new AnnoMirror()).run();
    1.47 +    }
    1.48 +
    1.49 +
    1.50 +    @Test(result={"AT1"})
    1.51 +    @AT1
    1.52 +    AnnotationType getAnnotationType() {
    1.53 +        AnnotationMirror anno = getAnno("getAnnotationType", "AT1");
    1.54 +        return anno.getAnnotationType();
    1.55 +    }
    1.56 +
    1.57 +    @Test(result={})
    1.58 +    @AT1
    1.59 +    Set getElementValuesNone() {
    1.60 +        AnnotationMirror anno = getAnno("getElementValuesNone", "AT1");
    1.61 +        return anno.getElementValues().entrySet();
    1.62 +    }
    1.63 +
    1.64 +
    1.65 +    // The seemingly out-of-place parens in the following "result"
    1.66 +    // entry are needed due to the shortcut of having the test return
    1.67 +    // the entry set directly.
    1.68 +    @Test(result={"i()=2",
    1.69 +                  "b()=true",
    1.70 +                  "k()=java.lang.Boolean.class",
    1.71 +                  "a()=@AT1"})
    1.72 +    @AT2(i = 1+1,
    1.73 +         b = true,
    1.74 +         k = Boolean.class,
    1.75 +         a = @AT1)
    1.76 +    Set getElementValues() {
    1.77 +        AnnotationMirror anno = getAnno("getElementValues", "AT2");
    1.78 +        return anno.getElementValues().entrySet();
    1.79 +    }
    1.80 +
    1.81 +    @Test(result={"@AT1(\"zax\")",
    1.82 +                  "@AT2(i=2, b=true, k=java.lang.Boolean.class, a=@AT1)",
    1.83 +                  "@AT3(arr={1})",
    1.84 +                  "@AT4({2, 3, 4})"})
    1.85 +    Collection<AnnotationMirror> toStringTests() {
    1.86 +        for (MethodDeclaration m : thisClassDecl.getMethods()) {
    1.87 +            if (m.getSimpleName().equals("toStringTestsHelper")) {
    1.88 +                return m.getAnnotationMirrors();
    1.89 +            }
    1.90 +        }
    1.91 +        throw new AssertionError();
    1.92 +    }
    1.93 +
    1.94 +    @AT1("zax")
    1.95 +    @AT2(i = 1+1,
    1.96 +         b = true,
    1.97 +         k = Boolean.class,
    1.98 +         a = @AT1)
    1.99 +    @AT3(arr={1})
   1.100 +    @AT4({2,3,4})
   1.101 +    private void toStringTestsHelper() {
   1.102 +    }
   1.103 +}
   1.104 +
   1.105 +
   1.106 +/*
   1.107 + * Annotations used for testing.
   1.108 + */
   1.109 +
   1.110 +@interface AT1 {
   1.111 +    String value() default "";
   1.112 +}
   1.113 +
   1.114 +@interface AT2 {
   1.115 +    int i();
   1.116 +    boolean b();
   1.117 +    Class k();
   1.118 +    AT1 a();
   1.119 +}
   1.120 +
   1.121 +@interface AT3 {
   1.122 +    int[] arr();
   1.123 +}
   1.124 +
   1.125 +@interface AT4 {
   1.126 +    int[] value();
   1.127 +}

mercurial