2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
6 * The Java Pathfinder core (jpf-core) platform is licensed under the
7 * Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0.
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 package sun.reflect.annotation;
21 import java.lang.annotation.Inherited;
22 import java.lang.annotation.Retention;
23 import java.lang.annotation.RetentionPolicy;
24 import java.lang.reflect.Method;
25 import java.util.HashMap;
28 import sun.misc.SharedSecrets;
31 * this is a placeholder for a Java 6 class, which we only have here to
32 * support both Java 1.5 and 6 with the same set of env/ classes
34 * this is Java only, so it's a drag we have to add this, but since it is outside
35 * java.* and doesn't refer to Java 6 stuff outside the sun.misc.SharedSecrets
36 * we bite the bullet and add it (for now)
38 * <2do> THIS IS GOING AWAY AS SOON AS WE OFFICIALLY SWITCH TO JAVA 6
40 public class AnnotationType {
42 private RetentionPolicy retention = RetentionPolicy.RUNTIME;
43 private boolean inherited = false;
46 private final Map<String, Class<?>> memberTypes = new HashMap<String, Class<?>>();
47 private final Map<String, Object> memberDefaults = new HashMap<String, Object>();
48 private final Map<String, Method> members = new HashMap<String, Method>();
51 public static synchronized AnnotationType getInstance (Class<?> annotationClass) {
52 AnnotationType at = SharedSecrets.getJavaLangAccess().getAnnotationType(annotationClass);
54 at = new AnnotationType(annotationClass);
59 private AnnotationType(final Class<?> annoCls) {
60 if (!annoCls.isAnnotation()) {
61 throw new IllegalArgumentException("Not an annotation type");
64 Method[] methods = annoCls.getDeclaredMethods();
66 for (Method m : methods) {
67 if (m.getParameterTypes().length == 0) {
68 // cache name -> method assoc
69 String mname = m.getName();
70 members.put(mname, m);
73 Class<?> type = m.getReturnType();
74 memberTypes.put(mname, invocationHandlerReturnType(type));
76 // cache member default val (if any)
77 Object val = m.getDefaultValue();
79 memberDefaults.put(mname, val);
82 // probably an exception
86 if ((annoCls != Retention.class) && (annoCls != Inherited.class)) { // don't get recursive
87 inherited = annoCls.isAnnotationPresent(Inherited.class);
89 Retention r = annoCls.getAnnotation(Retention.class);
91 retention = RetentionPolicy.CLASS;
93 retention = r.value();
97 SharedSecrets.getJavaLangAccess().setAnnotationType(annoCls, this);
100 public static Class<?> invocationHandlerReturnType (Class<?> type) {
101 // return box types for builtins
102 if (type == boolean.class) {
103 return Boolean.class;
104 } else if (type == byte.class) {
106 } else if (type == char.class) {
107 return Character.class;
108 } else if (type == short.class) {
110 } else if (type == int.class) {
111 return Integer.class;
112 } else if (type == long.class) {
114 } else if (type == float.class) {
116 } else if (type == double.class) {
123 public Map<String, Class<?>> memberTypes() {
127 public Map<String, Method> members() {
131 public Map<String, Object> memberDefaults() {
132 return memberDefaults;
135 public RetentionPolicy retention() {
139 public boolean isInherited() {