0N/A/*
553N/A * Copyright (c) 2004, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
553N/A * or visit www.oracle.com if you need additional information or have any
553N/A * questions.
0N/A */
0N/A
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 4853450 5014539 5034991
0N/A * @summary Tests AnnotationValue methods.
0N/A * @library ../../lib
0N/A * @compile -source 1.5 AnnoVal.java
131N/A * @run main/othervm AnnoVal
0N/A */
0N/A
0N/A
0N/Aimport java.util.*;
0N/Aimport com.sun.mirror.declaration.*;
0N/Aimport com.sun.mirror.type.*;
0N/A
0N/A
0N/Apublic class AnnoVal extends Tester {
0N/A
0N/A public static void main(String[] args) {
0N/A (new AnnoVal()).run();
0N/A }
0N/A
0N/A @Test(result={
0N/A "i Integer 2",
0N/A "l Long 4294967296",
0N/A "d Double 3.14",
0N/A "b Boolean true",
0N/A "c Character @",
0N/A "s String sigh",
0N/A // The following results reflect some implementation details.
0N/A "k ClassTypeImpl java.lang.Boolean",
0N/A "kb PrimitiveTypeImpl boolean",
0N/A "ka ArrayTypeImpl java.lang.Boolean[]",
0N/A "kab ArrayTypeImpl int[][]",
0N/A "w ClassTypeImpl java.lang.Long",
0N/A "e EnumConstantDeclarationImpl TYPE",
0N/A "sa ArrayList [\"up\", \"down\"]",
0N/A "a AnnotationMirrorImpl @AT1"})
0N/A @AT2(i = 1 + 1,
0N/A l = 1024 * 1024 * 1024 * 4L,
0N/A d = 3.14,
0N/A b = true,
0N/A c = '@',
0N/A s = "sigh",
0N/A k = Boolean.class,
0N/A kb = boolean.class,
0N/A ka = Boolean[].class, // bugid 5020899
0N/A kab = int[][].class, // "
0N/A w = Long.class,
0N/A e = java.lang.annotation.ElementType.TYPE,
0N/A sa = {"up", "down"},
0N/A a = @AT1)
0N/A Collection<String> getValue() {
0N/A Collection<String> res = new ArrayList<String>();
0N/A AnnotationMirror anno = getAnno("getValue", "AT2");
0N/A
0N/A for (Map.Entry<AnnotationTypeElementDeclaration, AnnotationValue> e :
0N/A anno.getElementValues().entrySet()) {
0N/A Object val = e.getValue().getValue();
0N/A res.add(String.format("%s %s %s",
0N/A e.getKey().getSimpleName(),
0N/A simpleClassName(val),
0N/A val));
0N/A }
0N/A return res;
0N/A }
0N/A
0N/A @Test(result={
0N/A "int i 2",
0N/A "long l 4294967296L",
0N/A "double d 3.14",
0N/A "boolean b true",
0N/A "char c '@'",
0N/A "java.lang.String s \"sigh\"",
0N/A "java.lang.Class k java.lang.Boolean.class",
0N/A "java.lang.Class kb boolean.class",
0N/A "java.lang.Class ka java.lang.Boolean[].class",
0N/A "java.lang.Class kab int[][].class",
0N/A "java.lang.Class<? extends java.lang.Number> w java.lang.Long.class",
0N/A "java.lang.annotation.ElementType e java.lang.annotation.ElementType.TYPE",
0N/A "java.lang.String[] sa {\"up\", \"down\"}",
0N/A "AT1 a @AT1"})
0N/A Collection<String> toStringTests() {
0N/A Collection<String> res = new ArrayList<String>();
0N/A AnnotationMirror anno = getAnno("getValue", "AT2");
0N/A
0N/A for (Map.Entry<AnnotationTypeElementDeclaration,AnnotationValue> e :
0N/A anno.getElementValues().entrySet()) {
0N/A res.add(String.format("%s %s %s",
0N/A e.getKey().getReturnType(),
0N/A e.getKey().getSimpleName(),
0N/A e.getValue().toString()));
0N/A }
0N/A return res;
0N/A }
0N/A
0N/A @Test(result={
0N/A "byte b 0x0b",
0N/A "float f 3.0f",
0N/A "double nan 0.0/0.0",
0N/A "double hi 1.0/0.0",
0N/A "float lo -1.0f/0.0f",
0N/A "char newline '\\n'",
0N/A "char ff '\\u00ff'",
0N/A "java.lang.String s \"\\\"high\\tlow\\\"\"",
0N/A "java.lang.String smiley \"\\u263a\""})
0N/A @AT3(b = 11,
0N/A f = 3,
0N/A nan = 0.0/0.0,
0N/A hi = 1.0/0.0,
0N/A lo = -1.0f/0.0f,
0N/A newline = '\n',
0N/A ff = '\u00FF',
0N/A s = "\"high\tlow\"",
0N/A smiley = "\u263A")
0N/A Collection<String> toStringFancy() {
0N/A Collection<String> res = new ArrayList<String>();
0N/A AnnotationMirror anno = getAnno("toStringFancy", "AT3");
0N/A
0N/A for (Map.Entry<AnnotationTypeElementDeclaration,AnnotationValue> e :
0N/A anno.getElementValues().entrySet()) {
0N/A res.add(String.format("%s %s %s",
0N/A e.getKey().getReturnType(),
0N/A e.getKey().getSimpleName(),
0N/A e.getValue().toString()));
0N/A }
0N/A return res;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the simple name of an object's class.
0N/A */
0N/A private String simpleClassName(Object o) {
0N/A return (o == null)
0N/A ? "null"
0N/A : o.getClass().getName().replaceFirst(".*\\.", "");
0N/A }
0N/A}
0N/A
0N/A
0N/A/*
0N/A * Annotations used for testing.
0N/A */
0N/A
0N/A@interface AT1 {
0N/A String value() default "";
0N/A}
0N/A
0N/A@interface AT2 {
0N/A int i();
0N/A long l();
0N/A double d();
0N/A boolean b();
0N/A char c();
0N/A String s();
0N/A Class k();
0N/A Class kb();
0N/A Class ka();
0N/A Class kab();
0N/A Class<? extends Number> w();
0N/A java.lang.annotation.ElementType e();
0N/A String[] sa();
0N/A AT1 a();
0N/A}
0N/A
0N/A@interface AT3 {
0N/A byte b();
0N/A float f();
0N/A double nan();
0N/A double hi();
0N/A float lo();
0N/A char newline();
0N/A char ff();
0N/A String s();
0N/A String smiley();
0N/A}