1 /*******************************************************************************
2  * Copyright (c) 2000, 2009 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 package org.eclipse.jdt.core;
15 
16 /**
17  * Represents a member-value pair of an annotation.
18  * The {@link #getValue() value} is represented by an {@link Object}. To get the exact
19  * type of this object, use its {@link #getValueKind() value kind}. If this value is an array,
20  * {@link #getValue()} returns an instance of {@link Object}[] and the value kind returns
21  * the kind of the elements in this array.
22  * <p>
23  * This interface is not intended to be implemented or extended by clients.
24  * </p>
25  *
26  * @since 3.4
27  */
28 public interface IMemberValuePair {
29 	/**
30 	 * Constant indicating that the value kind is an <code>int</code> represented by
31 	 * an instance of {@link Integer}.
32 	 */
33 	int K_INT = 1;
34 
35 	/**
36 	 * Constant indicating that the value kind is a <code>byte</code> represented by
37 	 * an instance of {@link Byte}.
38 	 */
39 	int K_BYTE = 2;
40 
41 	/**
42 	 * Constant indicating that the value kind is a <code>short</code> represented by
43 	 * an instance of {@link Short}.
44 	 */
45 	int K_SHORT = 3;
46 
47 	/**
48 	 * Constant indicating that the value kind is a <code>char</code> represented by
49 	 * an instance of {@link Character}.
50 	 */
51 	int K_CHAR = 4;
52 
53 	/**
54 	 * Constant indicating that the value kind is a <code>float</code> represented by
55 	 * an instance of {@link Float}.
56 	 */
57 	int K_FLOAT = 5;
58 
59 	/**
60 	 * Constant indicating that the value kind is a <code>double</code> represented by
61 	 * an instance of {@link Double}.
62 	 */
63 	int K_DOUBLE = 6;
64 
65 	/**
66 	 * Constant indicating that the value kind is a <code>long</code> represented by
67 	 * an instance of {@link Long}.
68 	 */
69 	int K_LONG = 7;
70 
71 	/**
72 	 * Constant indicating that the value kind is a <code>boolean</code> represented by
73 	 * an instance of {@link Boolean}.
74 	 */
75 	int K_BOOLEAN = 8;
76 
77 	/**
78 	 * Constant indicating that the value kind is a {@link String} represented by
79 	 * the corresponding {@link String}.
80 	 */
81 	int K_STRING = 9;
82 
83 	/**
84 	 * Constant indicating that the value kind is an annotation represented by
85 	 * an instance of {@link IAnnotation}.
86 	 */
87 	int K_ANNOTATION = 10;
88 
89 	/**
90 	 * Constant indicating that the value kind is a {@link Class} represented by
91 	 * the name of the class (i.e. a {@link String}. If the member-value pair is coming from
92 	 * a compilation unit, this is either a simple name (e.g. for <code>MyType.class</code>,
93 	 * the name is "MyType"), or a qualified name  (e.g. for <code>x.y.MyType.MyNestedType.class</code>,
94 	 * the name is "x.y.MyType.MyNestedType"). If the member-value pair is coming from a class file, this is
95 	 * always a fully qualified name.
96 	 * <p>
97 	 * Note that one can use {@link IType#resolveType(String)} and e.g.
98 	 * {@link IJavaProject#findType(String, String, org.eclipse.core.runtime.IProgressMonitor)}
99 	 * to find the corresponding {@link IType}.
100 	 * </p>
101 	 */
102 	int K_CLASS = 11;
103 
104 	/**
105 	 * Constant indicating that the value is a qualified name represented by a
106 	 * {@link String}. The qualified name refers to an enum constant or another
107 	 * compile-time constant if the code is correct (e.g. "MyEnum.FIRST").
108 	 */
109 	int K_QUALIFIED_NAME = 12;
110 
111 	/**
112 	 * Constant indicating that the value is a simple name represented by a
113 	 * {@link String}. The simple name refers to an enum constant or another
114 	 * compile-time constant if the code is correct (e.g. "FIRST" when there is
115 	 * a static import for "MyEnum.FIRST").
116 	 */
117 	int K_SIMPLE_NAME = 13;
118 
119 	/**
120 	 * Constant indicating that the value kind is unknown at this stage. The value is unknown in the
121 	 * following cases:
122 	 * <ul>
123 	 * <li>the value is an expression that would need to be further analyzed to determine its kind. For
124 	 * example, in <code>@MyAnnot(1 + 2.3)</code> the kind of the expression "1 + 2.3" is
125 	 * unknown</li>
126 	 * <li>the value is an array of size 0, e.g. <code>@MyAnnot({})</code></li>
127 	 * <li>the value is an array that contains at least one expression that would need to be further
128 	 *      analyzed to determine its kind. For example, in <code>@MyAnnot({3.4, 1 + 2.3})</code>,
129 	 *      the kind of the second element "1 + 2.3" is unknown.</li>
130 	 * <li>the value is an array that contains heterogeneous values, e.g.
131 	 *      <code>@MyAnnot({1, 2.3, "abc"})</code></li>
132 	 * </ul>
133 	 * If the value kind is unknown, the returned value is always either <code>null</code>, or an
134 	 * array containing {@link Object}s and/or <code>null</code>s for unknown elements.
135 	 */
136 	int K_UNKNOWN = 14;
137 
138 	/**
139 	 * Returns the member's name of this member-value pair.
140 	 *
141 	 * @return the member's name of this member-value pair.
142 	 */
getMemberName()143 	String getMemberName();
144 
145 	/**
146 	 * Returns the value of this member-value pair. The type of this value
147 	 * is function of this member-value pair's {@link #getValueKind() value kind}. It is an
148 	 * instance of {@link Object}[] if the value is an array.
149 	 * <p>
150 	 * If the value kind is {@link #K_UNKNOWN} and the value is not an array, then the
151 	 * value is <code>null</code>.
152 	 * If the value kind is {@link #K_UNKNOWN} and the value is an array, then the
153 	 * value is an array containing {@link Object}s and/or <code>null</code>s for
154 	 * unknown elements.
155 	 * See {@link #K_UNKNOWN} for more details.
156 	 * </p>
157 	 * @return the value of this member-value pair.
158 	 */
getValue()159 	Object getValue();
160 
161 	/**
162 	 * Returns the value kind of this member-value pair. This indicates the instance of
163 	 * the returned {@link #getValue() value}, or the instance of the elements if the value
164 	 * is an array. The value kind is one of the following constants:
165 	 * {@link #K_ANNOTATION}, {@link #K_BOOLEAN}, {@link #K_BYTE}, {@link #K_CHAR},
166 	 * {@link #K_CLASS}, {@link #K_DOUBLE}, {@link #K_FLOAT}, {@link #K_INT}, {@link #K_LONG},
167 	 * {@link #K_QUALIFIED_NAME}, {@link #K_SIMPLE_NAME}, {@link #K_SHORT}, {@link #K_STRING},
168 	 * {@link #K_UNKNOWN}.
169 	 *
170 	 * @return the value kind of this member-value pair
171 	 */
getValueKind()172 	int getValueKind();
173 
174 }
175