author | vromero |
Tue, 19 Jun 2018 05:22:07 -0700 | |
changeset 50636 | 8a18bcdd75ed |
parent 47216 | 71c04702a3d5 |
child 55387 | 761b86d5563d |
permissions | -rw-r--r-- |
10 | 1 |
/* |
15385 | 2 |
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javac.code; |
|
27 |
||
28 |
import java.util.LinkedHashMap; |
|
29 |
import java.util.Map; |
|
30 |
import javax.lang.model.element.AnnotationMirror; |
|
31 |
import javax.lang.model.element.AnnotationValue; |
|
32 |
import javax.lang.model.element.AnnotationValueVisitor; |
|
33 |
import javax.lang.model.type.DeclaredType; |
|
34 |
import com.sun.tools.javac.code.Symbol.*; |
|
35 |
import com.sun.tools.javac.util.*; |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
36 |
import com.sun.tools.javac.util.DefinedBy.Api; |
10 | 37 |
|
38 |
/** An annotation value. |
|
39 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
40 |
* <p><b>This is NOT part of any supported API. |
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
41 |
* If you write code that depends on this, you do so at your own risk. |
10 | 42 |
* This code and its internal interfaces are subject to change or |
43 |
* deletion without notice.</b> |
|
44 |
*/ |
|
45 |
public abstract class Attribute implements AnnotationValue { |
|
46 |
||
47 |
/** The type of the annotation element. */ |
|
48 |
public Type type; |
|
49 |
||
50 |
public Attribute(Type type) { |
|
51 |
this.type = type; |
|
52 |
} |
|
53 |
||
54 |
public abstract void accept(Visitor v); |
|
55 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
56 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 57 |
public Object getValue() { |
58 |
throw new UnsupportedOperationException(); |
|
59 |
} |
|
60 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
61 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 62 |
public <R, P> R accept(AnnotationValueVisitor<R, P> v, P p) { |
63 |
throw new UnsupportedOperationException(); |
|
64 |
} |
|
65 |
||
14961
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14359
diff
changeset
|
66 |
public boolean isSynthesized() { |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14359
diff
changeset
|
67 |
return false; |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14359
diff
changeset
|
68 |
} |
10 | 69 |
|
22163 | 70 |
public TypeAnnotationPosition getPosition() { return null; } |
21010
5ffe0d8a5e24
8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents:
19507
diff
changeset
|
71 |
|
10 | 72 |
/** The value for an annotation element of primitive type or String. */ |
73 |
public static class Constant extends Attribute { |
|
74 |
public final Object value; |
|
75 |
public void accept(Visitor v) { v.visitConstant(this); } |
|
76 |
public Constant(Type type, Object value) { |
|
77 |
super(type); |
|
78 |
this.value = value; |
|
79 |
} |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
80 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 81 |
public String toString() { |
82 |
return Constants.format(value, type); |
|
83 |
} |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
84 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 85 |
public Object getValue() { |
86 |
return Constants.decode(value, type); |
|
87 |
} |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
88 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 89 |
public <R, P> R accept(AnnotationValueVisitor<R, P> v, P p) { |
90 |
if (value instanceof String) |
|
91 |
return v.visitString((String) value, p); |
|
92 |
if (value instanceof Integer) { |
|
93 |
int i = (Integer) value; |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
17578
diff
changeset
|
94 |
switch (type.getTag()) { |
10 | 95 |
case BOOLEAN: return v.visitBoolean(i != 0, p); |
96 |
case CHAR: return v.visitChar((char) i, p); |
|
97 |
case BYTE: return v.visitByte((byte) i, p); |
|
98 |
case SHORT: return v.visitShort((short) i, p); |
|
99 |
case INT: return v.visitInt(i, p); |
|
100 |
} |
|
101 |
} |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
17578
diff
changeset
|
102 |
switch (type.getTag()) { |
10 | 103 |
case LONG: return v.visitLong((Long) value, p); |
104 |
case FLOAT: return v.visitFloat((Float) value, p); |
|
105 |
case DOUBLE: return v.visitDouble((Double) value, p); |
|
106 |
} |
|
107 |
throw new AssertionError("Bad annotation element value: " + value); |
|
108 |
} |
|
109 |
} |
|
110 |
||
111 |
/** The value for an annotation element of type java.lang.Class, |
|
112 |
* represented as a ClassSymbol. |
|
113 |
*/ |
|
114 |
public static class Class extends Attribute { |
|
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
8032
diff
changeset
|
115 |
public final Type classType; |
10 | 116 |
public void accept(Visitor v) { v.visitClass(this); } |
117 |
public Class(Types types, Type type) { |
|
118 |
super(makeClassType(types, type)); |
|
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
8032
diff
changeset
|
119 |
this.classType = type; |
10 | 120 |
} |
121 |
static Type makeClassType(Types types, Type type) { |
|
122 |
Type arg = type.isPrimitive() |
|
123 |
? types.boxedClass(type).type |
|
124 |
: types.erasure(type); |
|
125 |
return new Type.ClassType(types.syms.classType.getEnclosingType(), |
|
126 |
List.of(arg), |
|
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26532
diff
changeset
|
127 |
types.syms.classType.tsym); |
10 | 128 |
} |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
129 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 130 |
public String toString() { |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
8032
diff
changeset
|
131 |
return classType + ".class"; |
10 | 132 |
} |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
133 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 134 |
public Type getValue() { |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
8032
diff
changeset
|
135 |
return classType; |
10 | 136 |
} |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
137 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 138 |
public <R, P> R accept(AnnotationValueVisitor<R, P> v, P p) { |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
8032
diff
changeset
|
139 |
return v.visitType(classType, p); |
10 | 140 |
} |
141 |
} |
|
142 |
||
143 |
/** A compound annotation element value, the type of which is an |
|
144 |
* attribute interface. |
|
145 |
*/ |
|
146 |
public static class Compound extends Attribute implements AnnotationMirror { |
|
147 |
/** The attributes values, as pairs. Each pair contains a |
|
148 |
* reference to the accessing method in the attribute interface |
|
149 |
* and the value to be returned when that method is called to |
|
150 |
* access this attribute. |
|
151 |
*/ |
|
152 |
public final List<Pair<MethodSymbol,Attribute>> values; |
|
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
153 |
public TypeAnnotationPosition position; |
14961
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14359
diff
changeset
|
154 |
|
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14359
diff
changeset
|
155 |
private boolean synthesized = false; |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14359
diff
changeset
|
156 |
|
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14359
diff
changeset
|
157 |
@Override |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14359
diff
changeset
|
158 |
public boolean isSynthesized() { |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14359
diff
changeset
|
159 |
return synthesized; |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14359
diff
changeset
|
160 |
} |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14359
diff
changeset
|
161 |
|
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14359
diff
changeset
|
162 |
public void setSynthesized(boolean synthesized) { |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14359
diff
changeset
|
163 |
this.synthesized = synthesized; |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14359
diff
changeset
|
164 |
} |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14359
diff
changeset
|
165 |
|
10 | 166 |
public Compound(Type type, |
23798
ca0f80391182
8035768: Move TypeAnnotationPosition from Attribute.Compound to Attribute.TypeCompound
emc
parents:
22163
diff
changeset
|
167 |
List<Pair<MethodSymbol,Attribute>> values, |
ca0f80391182
8035768: Move TypeAnnotationPosition from Attribute.Compound to Attribute.TypeCompound
emc
parents:
22163
diff
changeset
|
168 |
TypeAnnotationPosition position) { |
10 | 169 |
super(type); |
170 |
this.values = values; |
|
23798
ca0f80391182
8035768: Move TypeAnnotationPosition from Attribute.Compound to Attribute.TypeCompound
emc
parents:
22163
diff
changeset
|
171 |
this.position = position; |
10 | 172 |
} |
23798
ca0f80391182
8035768: Move TypeAnnotationPosition from Attribute.Compound to Attribute.TypeCompound
emc
parents:
22163
diff
changeset
|
173 |
|
ca0f80391182
8035768: Move TypeAnnotationPosition from Attribute.Compound to Attribute.TypeCompound
emc
parents:
22163
diff
changeset
|
174 |
public Compound(Type type, |
ca0f80391182
8035768: Move TypeAnnotationPosition from Attribute.Compound to Attribute.TypeCompound
emc
parents:
22163
diff
changeset
|
175 |
List<Pair<MethodSymbol,Attribute>> values) { |
ca0f80391182
8035768: Move TypeAnnotationPosition from Attribute.Compound to Attribute.TypeCompound
emc
parents:
22163
diff
changeset
|
176 |
this(type, values, null); |
ca0f80391182
8035768: Move TypeAnnotationPosition from Attribute.Compound to Attribute.TypeCompound
emc
parents:
22163
diff
changeset
|
177 |
} |
ca0f80391182
8035768: Move TypeAnnotationPosition from Attribute.Compound to Attribute.TypeCompound
emc
parents:
22163
diff
changeset
|
178 |
|
ca0f80391182
8035768: Move TypeAnnotationPosition from Attribute.Compound to Attribute.TypeCompound
emc
parents:
22163
diff
changeset
|
179 |
@Override |
ca0f80391182
8035768: Move TypeAnnotationPosition from Attribute.Compound to Attribute.TypeCompound
emc
parents:
22163
diff
changeset
|
180 |
public TypeAnnotationPosition getPosition() { |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
181 |
if (hasUnknownPosition()) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
182 |
if (values.size() != 0) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
183 |
Name valueName = values.head.fst.name.table.names.value; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
184 |
Pair<MethodSymbol, Attribute> res = getElemPair(valueName); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
185 |
position = res == null ? null : res.snd.getPosition(); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
186 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
187 |
} |
23798
ca0f80391182
8035768: Move TypeAnnotationPosition from Attribute.Compound to Attribute.TypeCompound
emc
parents:
22163
diff
changeset
|
188 |
return position; |
ca0f80391182
8035768: Move TypeAnnotationPosition from Attribute.Compound to Attribute.TypeCompound
emc
parents:
22163
diff
changeset
|
189 |
} |
ca0f80391182
8035768: Move TypeAnnotationPosition from Attribute.Compound to Attribute.TypeCompound
emc
parents:
22163
diff
changeset
|
190 |
|
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
191 |
public boolean isContainerTypeCompound() { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
192 |
if (isSynthesized() && values.size() == 1) |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
193 |
return getFirstEmbeddedTC() != null; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
194 |
return false; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
195 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
196 |
|
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
197 |
private Compound getFirstEmbeddedTC() { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
198 |
if (values.size() == 1) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
199 |
Pair<MethodSymbol, Attribute> val = values.get(0); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
200 |
if (val.fst.getSimpleName().contentEquals("value") |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
201 |
&& val.snd instanceof Array) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
202 |
Array arr = (Array) val.snd; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
203 |
if (arr.values.length != 0 |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
204 |
&& arr.values[0] instanceof Attribute.TypeCompound) |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
205 |
return (Attribute.TypeCompound) arr.values[0]; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
206 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
207 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
208 |
return null; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
209 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
210 |
|
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
211 |
public boolean tryFixPosition() { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
212 |
if (!isContainerTypeCompound()) |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
213 |
return false; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
214 |
|
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
215 |
Compound from = getFirstEmbeddedTC(); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
216 |
if (from != null && from.position != null && |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
217 |
from.position.type != TargetType.UNKNOWN) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
218 |
position = from.position; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
219 |
return true; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
220 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
221 |
return false; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
222 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
223 |
|
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
224 |
public boolean hasUnknownPosition() { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
225 |
return position.type == TargetType.UNKNOWN; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
226 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
227 |
|
10 | 228 |
public void accept(Visitor v) { v.visitCompound(this); } |
229 |
||
230 |
/** |
|
231 |
* Returns a string representation of this annotation. |
|
232 |
* String is of one of the forms: |
|
31751 | 233 |
* <pre> |
234 |
* {@code @com.example.foo(name1=val1, name2=val2)} |
|
235 |
* {@code @com.example.foo(val)} |
|
236 |
* {@code @com.example.foo} |
|
237 |
* </pre> |
|
10 | 238 |
* Omit parens for marker annotations, and omit "value=" when allowed. |
239 |
*/ |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
240 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 241 |
public String toString() { |
242 |
StringBuilder buf = new StringBuilder(); |
|
243 |
buf.append("@"); |
|
244 |
buf.append(type); |
|
245 |
int len = values.length(); |
|
246 |
if (len > 0) { |
|
247 |
buf.append('('); |
|
248 |
boolean first = true; |
|
249 |
for (Pair<MethodSymbol, Attribute> value : values) { |
|
250 |
if (!first) buf.append(", "); |
|
251 |
first = false; |
|
252 |
||
253 |
Name name = value.fst.name; |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1206
diff
changeset
|
254 |
if (len > 1 || name != name.table.names.value) { |
10 | 255 |
buf.append(name); |
256 |
buf.append('='); |
|
257 |
} |
|
258 |
buf.append(value.snd); |
|
259 |
} |
|
260 |
buf.append(')'); |
|
261 |
} |
|
262 |
return buf.toString(); |
|
263 |
} |
|
264 |
||
265 |
public Attribute member(Name member) { |
|
21010
5ffe0d8a5e24
8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents:
19507
diff
changeset
|
266 |
Pair<MethodSymbol,Attribute> res = getElemPair(member); |
5ffe0d8a5e24
8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents:
19507
diff
changeset
|
267 |
return res == null ? null : res.snd; |
5ffe0d8a5e24
8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents:
19507
diff
changeset
|
268 |
} |
5ffe0d8a5e24
8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents:
19507
diff
changeset
|
269 |
|
5ffe0d8a5e24
8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents:
19507
diff
changeset
|
270 |
private Pair<MethodSymbol, Attribute> getElemPair(Name member) { |
10 | 271 |
for (Pair<MethodSymbol,Attribute> pair : values) |
21010
5ffe0d8a5e24
8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents:
19507
diff
changeset
|
272 |
if (pair.fst.name == member) return pair; |
10 | 273 |
return null; |
274 |
} |
|
275 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
276 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 277 |
public Attribute.Compound getValue() { |
278 |
return this; |
|
279 |
} |
|
280 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
281 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 282 |
public <R, P> R accept(AnnotationValueVisitor<R, P> v, P p) { |
283 |
return v.visitAnnotation(this, p); |
|
284 |
} |
|
285 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
286 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 287 |
public DeclaredType getAnnotationType() { |
288 |
return (DeclaredType) type; |
|
289 |
} |
|
290 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
291 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 292 |
public Map<MethodSymbol, Attribute> getElementValues() { |
22163 | 293 |
Map<MethodSymbol, Attribute> valmap = new LinkedHashMap<>(); |
10 | 294 |
for (Pair<MethodSymbol, Attribute> value : values) |
295 |
valmap.put(value.fst, value.snd); |
|
296 |
return valmap; |
|
297 |
} |
|
298 |
} |
|
299 |
||
15385 | 300 |
public static class TypeCompound extends Compound { |
301 |
public TypeCompound(Compound compound, |
|
23798
ca0f80391182
8035768: Move TypeAnnotationPosition from Attribute.Compound to Attribute.TypeCompound
emc
parents:
22163
diff
changeset
|
302 |
TypeAnnotationPosition position) { |
ca0f80391182
8035768: Move TypeAnnotationPosition from Attribute.Compound to Attribute.TypeCompound
emc
parents:
22163
diff
changeset
|
303 |
super(compound.type, compound.values, position); |
17578 | 304 |
} |
305 |
||
23798
ca0f80391182
8035768: Move TypeAnnotationPosition from Attribute.Compound to Attribute.TypeCompound
emc
parents:
22163
diff
changeset
|
306 |
public TypeCompound(Type type, |
ca0f80391182
8035768: Move TypeAnnotationPosition from Attribute.Compound to Attribute.TypeCompound
emc
parents:
22163
diff
changeset
|
307 |
List<Pair<MethodSymbol,Attribute>> values, |
ca0f80391182
8035768: Move TypeAnnotationPosition from Attribute.Compound to Attribute.TypeCompound
emc
parents:
22163
diff
changeset
|
308 |
TypeAnnotationPosition position) { |
ca0f80391182
8035768: Move TypeAnnotationPosition from Attribute.Compound to Attribute.TypeCompound
emc
parents:
22163
diff
changeset
|
309 |
super(type, values, position); |
17578 | 310 |
} |
15385 | 311 |
} |
312 |
||
10 | 313 |
/** The value for an annotation element of an array type. |
314 |
*/ |
|
315 |
public static class Array extends Attribute { |
|
316 |
public final Attribute[] values; |
|
317 |
public Array(Type type, Attribute[] values) { |
|
318 |
super(type); |
|
319 |
this.values = values; |
|
320 |
} |
|
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
8032
diff
changeset
|
321 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
8032
diff
changeset
|
322 |
public Array(Type type, List<Attribute> values) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
8032
diff
changeset
|
323 |
super(type); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
8032
diff
changeset
|
324 |
this.values = values.toArray(new Attribute[values.size()]); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
8032
diff
changeset
|
325 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
8032
diff
changeset
|
326 |
|
10 | 327 |
public void accept(Visitor v) { v.visitArray(this); } |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
328 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 329 |
public String toString() { |
330 |
StringBuilder buf = new StringBuilder(); |
|
331 |
buf.append('{'); |
|
332 |
boolean first = true; |
|
333 |
for (Attribute value : values) { |
|
334 |
if (!first) |
|
335 |
buf.append(", "); |
|
336 |
first = false; |
|
337 |
buf.append(value); |
|
338 |
} |
|
339 |
buf.append('}'); |
|
340 |
return buf.toString(); |
|
341 |
} |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
342 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 343 |
public List<Attribute> getValue() { |
344 |
return List.from(values); |
|
345 |
} |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
346 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 347 |
public <R, P> R accept(AnnotationValueVisitor<R, P> v, P p) { |
348 |
return v.visitArray(getValue(), p); |
|
349 |
} |
|
21010
5ffe0d8a5e24
8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents:
19507
diff
changeset
|
350 |
|
5ffe0d8a5e24
8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents:
19507
diff
changeset
|
351 |
@Override |
5ffe0d8a5e24
8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents:
19507
diff
changeset
|
352 |
public TypeAnnotationPosition getPosition() { |
5ffe0d8a5e24
8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents:
19507
diff
changeset
|
353 |
if (values.length != 0) |
5ffe0d8a5e24
8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents:
19507
diff
changeset
|
354 |
return values[0].getPosition(); |
5ffe0d8a5e24
8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents:
19507
diff
changeset
|
355 |
else |
5ffe0d8a5e24
8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents:
19507
diff
changeset
|
356 |
return null; |
5ffe0d8a5e24
8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents:
19507
diff
changeset
|
357 |
} |
10 | 358 |
} |
359 |
||
360 |
/** The value for an annotation element of an enum type. |
|
361 |
*/ |
|
362 |
public static class Enum extends Attribute { |
|
363 |
public VarSymbol value; |
|
364 |
public Enum(Type type, VarSymbol value) { |
|
365 |
super(type); |
|
8032 | 366 |
this.value = Assert.checkNonNull(value); |
10 | 367 |
} |
368 |
public void accept(Visitor v) { v.visitEnum(this); } |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
369 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 370 |
public String toString() { |
371 |
return value.enclClass() + "." + value; // qualified name |
|
372 |
} |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
373 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 374 |
public VarSymbol getValue() { |
375 |
return value; |
|
376 |
} |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
377 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 378 |
public <R, P> R accept(AnnotationValueVisitor<R, P> v, P p) { |
379 |
return v.visitEnumConstant(value, p); |
|
380 |
} |
|
381 |
} |
|
382 |
||
383 |
public static class Error extends Attribute { |
|
384 |
public Error(Type type) { |
|
385 |
super(type); |
|
386 |
} |
|
387 |
public void accept(Visitor v) { v.visitError(this); } |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
388 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 389 |
public String toString() { |
390 |
return "<error>"; |
|
391 |
} |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
392 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 393 |
public String getValue() { |
394 |
return toString(); |
|
395 |
} |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
396 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 397 |
public <R, P> R accept(AnnotationValueVisitor<R, P> v, P p) { |
398 |
return v.visitString(toString(), p); |
|
399 |
} |
|
400 |
} |
|
401 |
||
19507
323f001d6be1
8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents:
18646
diff
changeset
|
402 |
public static class UnresolvedClass extends Error { |
323f001d6be1
8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents:
18646
diff
changeset
|
403 |
public Type classType; |
323f001d6be1
8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents:
18646
diff
changeset
|
404 |
public UnresolvedClass(Type type, Type classType) { |
323f001d6be1
8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents:
18646
diff
changeset
|
405 |
super(type); |
323f001d6be1
8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents:
18646
diff
changeset
|
406 |
this.classType = classType; |
323f001d6be1
8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents:
18646
diff
changeset
|
407 |
} |
323f001d6be1
8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents:
18646
diff
changeset
|
408 |
} |
323f001d6be1
8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents:
18646
diff
changeset
|
409 |
|
10 | 410 |
/** A visitor type for dynamic dispatch on the kind of attribute value. */ |
411 |
public static interface Visitor { |
|
412 |
void visitConstant(Attribute.Constant value); |
|
413 |
void visitClass(Attribute.Class clazz); |
|
414 |
void visitCompound(Attribute.Compound compound); |
|
415 |
void visitArray(Attribute.Array array); |
|
416 |
void visitEnum(Attribute.Enum e); |
|
417 |
void visitError(Attribute.Error e); |
|
418 |
} |
|
6575
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
5847
diff
changeset
|
419 |
|
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
5847
diff
changeset
|
420 |
/** A mirror of java.lang.annotation.RetentionPolicy. */ |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
5847
diff
changeset
|
421 |
public static enum RetentionPolicy { |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
5847
diff
changeset
|
422 |
SOURCE, |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
5847
diff
changeset
|
423 |
CLASS, |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
5847
diff
changeset
|
424 |
RUNTIME |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
5847
diff
changeset
|
425 |
} |
10 | 426 |
} |