01: /*
02: * Spoon - http://spoon.gforge.inria.fr/
03: * Copyright (C) 2006 INRIA Futurs <renaud.pawlak@inria.fr>
04: *
05: * This software is governed by the CeCILL-C License under French law and
06: * abiding by the rules of distribution of free software. You can use, modify
07: * and/or redistribute the software under the terms of the CeCILL-C license as
08: * circulated by CEA, CNRS and INRIA at http://www.cecill.info.
09: *
10: * This program is distributed in the hope that it will be useful, but WITHOUT
11: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12: * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details.
13: *
14: * The fact that you are presently reading this means that you have had
15: * knowledge of the CeCILL-C license and that you accept its terms.
16: */
17:
18: package spoon.reflect.declaration;
19:
20: import java.lang.annotation.Annotation;
21: import java.util.Map;
22:
23: import spoon.reflect.reference.CtTypeReference;
24:
25: /**
26: * This element defines an annotation, declared on a given annotated element.
27: *
28: * @param <A>
29: * type of represented annotation
30: */
31: public interface CtAnnotation<A extends Annotation> extends CtElement {
32:
33: /**
34: * Returns the actual annotation (a dynamic proxy for this element).
35: *
36: * <p>
37: * NOTE: before using an annotation proxy, you have to make sure that all
38: * the types referenced by the annotation have been compiled and are in the
39: * classpath so that accessed values can be converted into the actual types ({@link #getElementValue(String)}).
40: */
41: A getActualAnnotation();
42:
43: /**
44: * Returns the annotation type of this annotation.
45: *
46: * @return a reference to the type of this annotation
47: */
48: CtTypeReference<A> getAnnotationType();
49:
50: /**
51: * Gets a value for a given key (with conversion if needed).
52: *
53: * <p>
54: * NOTE: in case of a type, the value is converted to the actual type. To
55: * access the type as a reference, use {@link #getElementValues()}, which
56: * returns a map containing the raw (unconverted) values.
57: *
58: * @param key
59: * name of searched value
60: * @return the value or null if not found
61: */
62: Object getElementValue(String key);
63:
64: /**
65: * Returns this annotation's elements and their values. This is returned in
66: * the form of a map that associates element names with their corresponding
67: * values.
68: *
69: * <p>
70: * Note that <code>getElementValue("key")</code> is not completely similar
71: * to <code>getElementValues().get("key")</code> since the former converts
72: * type references into the actual types.
73: *
74: * @return this annotation's element names and their values, or an empty map
75: * if there are none
76: */
77: Map<String, Object> getElementValues();
78:
79: /**
80: * Sets the annotation's type.
81: *
82: * @param type
83: * reference to the type of this annotation
84: */
85: void setAnnotationType(CtTypeReference<? extends Annotation> type);
86:
87: /**
88: * Set's this annotation's element names and their values. This is in the
89: * form of a map that associates element names with their corresponding
90: * values. Note that type values are stored as
91: * {@link spoon.reflect.reference.CtTypeReference}.
92: */
93: void setElementValues(Map<String, Object> values);
94:
95: }
|