author | emc |
Wed, 16 Oct 2013 16:33:04 -0400 | |
changeset 21043 | 3b000be15694 |
parent 21041 | 99f5e5e97425 |
child 21713 | b3fcc9c0fea3 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
15356
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14961
diff
changeset
|
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.comp; |
|
27 |
||
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
28 |
import java.util.Map; |
15385 | 29 |
|
10 | 30 |
import com.sun.tools.javac.util.*; |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
31 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
10 | 32 |
import com.sun.tools.javac.code.*; |
33 |
import com.sun.tools.javac.code.Symbol.*; |
|
34 |
import com.sun.tools.javac.tree.*; |
|
35 |
import com.sun.tools.javac.tree.JCTree.*; |
|
36 |
||
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14054
diff
changeset
|
37 |
import static com.sun.tools.javac.code.TypeTag.ARRAY; |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14054
diff
changeset
|
38 |
import static com.sun.tools.javac.code.TypeTag.CLASS; |
10950 | 39 |
import static com.sun.tools.javac.tree.JCTree.Tag.*; |
21015
f3bec12a63e7
6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents:
20599
diff
changeset
|
40 |
import javax.lang.model.type.ErrorType; |
10950 | 41 |
|
10 | 42 |
/** Enter annotations on symbols. Annotations accumulate in a queue, |
43 |
* which is processed at the top level of any set of recursive calls |
|
44 |
* requesting it be processed. |
|
45 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
46 |
* <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
|
47 |
* If you write code that depends on this, you do so at your own risk. |
10 | 48 |
* This code and its internal interfaces are subject to change or |
49 |
* deletion without notice.</b> |
|
50 |
*/ |
|
51 |
public class Annotate { |
|
52 |
protected static final Context.Key<Annotate> annotateKey = |
|
53 |
new Context.Key<Annotate>(); |
|
54 |
||
55 |
public static Annotate instance(Context context) { |
|
56 |
Annotate instance = context.get(annotateKey); |
|
57 |
if (instance == null) |
|
58 |
instance = new Annotate(context); |
|
59 |
return instance; |
|
60 |
} |
|
61 |
||
62 |
final Attr attr; |
|
63 |
final TreeMaker make; |
|
64 |
final Log log; |
|
65 |
final Symtab syms; |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
66 |
final Names names; |
10 | 67 |
final Resolve rs; |
68 |
final Types types; |
|
69 |
final ConstFold cfolder; |
|
70 |
final Check chk; |
|
71 |
||
72 |
protected Annotate(Context context) { |
|
73 |
context.put(annotateKey, this); |
|
74 |
attr = Attr.instance(context); |
|
75 |
make = TreeMaker.instance(context); |
|
76 |
log = Log.instance(context); |
|
77 |
syms = Symtab.instance(context); |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
78 |
names = Names.instance(context); |
10 | 79 |
rs = Resolve.instance(context); |
80 |
types = Types.instance(context); |
|
81 |
cfolder = ConstFold.instance(context); |
|
82 |
chk = Check.instance(context); |
|
83 |
} |
|
84 |
||
85 |
/* ******************************************************************** |
|
86 |
* Queue maintenance |
|
87 |
*********************************************************************/ |
|
88 |
||
89 |
private int enterCount = 0; |
|
90 |
||
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
91 |
ListBuffer<Worker> q = new ListBuffer<Worker>(); |
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
92 |
ListBuffer<Worker> typesQ = new ListBuffer<Worker>(); |
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
93 |
ListBuffer<Worker> repeatedQ = new ListBuffer<Worker>(); |
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
94 |
ListBuffer<Worker> afterRepeatedQ = new ListBuffer<Worker>(); |
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
95 |
ListBuffer<Worker> validateQ = new ListBuffer<Worker>(); |
15385 | 96 |
|
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
97 |
public void earlier(Worker a) { |
15385 | 98 |
q.prepend(a); |
99 |
} |
|
10 | 100 |
|
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
101 |
public void normal(Worker a) { |
10 | 102 |
q.append(a); |
103 |
} |
|
104 |
||
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
105 |
public void typeAnnotation(Worker a) { |
15385 | 106 |
typesQ.append(a); |
10 | 107 |
} |
108 |
||
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
109 |
public void repeated(Worker a) { |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
110 |
repeatedQ.append(a); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
111 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
112 |
|
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
113 |
public void afterRepeated(Worker a) { |
15385 | 114 |
afterRepeatedQ.append(a); |
115 |
} |
|
116 |
||
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
117 |
public void validate(Worker a) { |
21018
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
118 |
validateQ.append(a); |
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
119 |
} |
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
120 |
|
10 | 121 |
/** Called when the Enter phase starts. */ |
122 |
public void enterStart() { |
|
123 |
enterCount++; |
|
124 |
} |
|
125 |
||
126 |
/** Called after the Enter phase completes. */ |
|
127 |
public void enterDone() { |
|
128 |
enterCount--; |
|
129 |
flush(); |
|
130 |
} |
|
131 |
||
21043
3b000be15694
8026286: Improper locking of annotation queues causes assertion failures.
emc
parents:
21041
diff
changeset
|
132 |
/** Variant which allows for a delayed flush of annotations. |
3b000be15694
8026286: Improper locking of annotation queues causes assertion failures.
emc
parents:
21041
diff
changeset
|
133 |
* Needed by ClassReader */ |
3b000be15694
8026286: Improper locking of annotation queues causes assertion failures.
emc
parents:
21041
diff
changeset
|
134 |
public void enterDoneWithoutFlush() { |
3b000be15694
8026286: Improper locking of annotation queues causes assertion failures.
emc
parents:
21041
diff
changeset
|
135 |
enterCount--; |
3b000be15694
8026286: Improper locking of annotation queues causes assertion failures.
emc
parents:
21041
diff
changeset
|
136 |
} |
3b000be15694
8026286: Improper locking of annotation queues causes assertion failures.
emc
parents:
21041
diff
changeset
|
137 |
|
10 | 138 |
public void flush() { |
139 |
if (enterCount != 0) return; |
|
140 |
enterCount++; |
|
141 |
try { |
|
15385 | 142 |
while (q.nonEmpty()) { |
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
143 |
q.next().run(); |
15385 | 144 |
} |
145 |
while (typesQ.nonEmpty()) { |
|
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
146 |
typesQ.next().run(); |
15385 | 147 |
} |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
148 |
while (repeatedQ.nonEmpty()) { |
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
149 |
repeatedQ.next().run(); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
150 |
} |
15385 | 151 |
while (afterRepeatedQ.nonEmpty()) { |
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
152 |
afterRepeatedQ.next().run(); |
15385 | 153 |
} |
21018
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
154 |
while (validateQ.nonEmpty()) { |
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
155 |
validateQ.next().run(); |
21018
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
156 |
} |
10 | 157 |
} finally { |
158 |
enterCount--; |
|
159 |
} |
|
160 |
} |
|
161 |
||
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
162 |
/** A client that needs to run during {@link #flush()} registers an worker |
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
163 |
* into one of the queues defined in this class. The queues are: {@link #earlier(Worker)}, |
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
164 |
* {@link #normal(Worker)}, {@link #typeAnnotation(Worker)}, {@link #repeated(Worker)}, |
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
165 |
* {@link #afterRepeated(Worker)}, {@link #validate(Worker)}. |
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
166 |
* The {@link Worker#run()} method will called inside the {@link #flush()} |
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
167 |
* call. Queues are empties in the abovementioned order. |
10 | 168 |
*/ |
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
169 |
public interface Worker { |
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
170 |
void run(); |
10 | 171 |
String toString(); |
172 |
} |
|
173 |
||
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
174 |
/** |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
175 |
* This context contains all the information needed to synthesize new |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
176 |
* annotations trees by the completer for repeating annotations. |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
177 |
*/ |
15385 | 178 |
public class AnnotateRepeatedContext<T extends Attribute.Compound> { |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
179 |
public final Env<AttrContext> env; |
15385 | 180 |
public final Map<Symbol.TypeSymbol, ListBuffer<T>> annotated; |
181 |
public final Map<T, JCDiagnostic.DiagnosticPosition> pos; |
|
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
182 |
public final Log log; |
15385 | 183 |
public final boolean isTypeCompound; |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
184 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
185 |
public AnnotateRepeatedContext(Env<AttrContext> env, |
15385 | 186 |
Map<Symbol.TypeSymbol, ListBuffer<T>> annotated, |
187 |
Map<T, JCDiagnostic.DiagnosticPosition> pos, |
|
188 |
Log log, |
|
189 |
boolean isTypeCompound) { |
|
13840
a365c561f4de
7196774: javac cannot be built with JDK 6 after 7151010
jjg
parents:
13689
diff
changeset
|
190 |
Assert.checkNonNull(env); |
a365c561f4de
7196774: javac cannot be built with JDK 6 after 7151010
jjg
parents:
13689
diff
changeset
|
191 |
Assert.checkNonNull(annotated); |
a365c561f4de
7196774: javac cannot be built with JDK 6 after 7151010
jjg
parents:
13689
diff
changeset
|
192 |
Assert.checkNonNull(pos); |
a365c561f4de
7196774: javac cannot be built with JDK 6 after 7151010
jjg
parents:
13689
diff
changeset
|
193 |
Assert.checkNonNull(log); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
194 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
195 |
this.env = env; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
196 |
this.annotated = annotated; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
197 |
this.pos = pos; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
198 |
this.log = log; |
15385 | 199 |
this.isTypeCompound = isTypeCompound; |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
200 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
201 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
202 |
/** |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
203 |
* Process a list of repeating annotations returning a new |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
204 |
* Attribute.Compound that is the attribute for the synthesized tree |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
205 |
* for the container. |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
206 |
* |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
207 |
* @param repeatingAnnotations a List of repeating annotations |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
208 |
* @return a new Attribute.Compound that is the container for the repeatingAnnotations |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
209 |
*/ |
15385 | 210 |
public T processRepeatedAnnotations(List<T> repeatingAnnotations, Symbol sym) { |
14804
f93a8d60b9a4
8001114: Container annotation is not checked for semantic correctness
jfranck
parents:
14359
diff
changeset
|
211 |
return Annotate.this.processRepeatedAnnotations(repeatingAnnotations, this, sym); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
212 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
213 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
214 |
/** |
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
215 |
* Queue the Worker a on the repeating annotations queue of the |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
216 |
* Annotate instance this context belongs to. |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
217 |
* |
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
218 |
* @param a the Worker to enqueue for repeating annotation annotating |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
219 |
*/ |
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
220 |
public void annotateRepeated(Worker a) { |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
221 |
Annotate.this.repeated(a); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
222 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
223 |
} |
10 | 224 |
|
225 |
/* ******************************************************************** |
|
226 |
* Compute an attribute from its annotation. |
|
227 |
*********************************************************************/ |
|
228 |
||
229 |
/** Process a single compound annotation, returning its |
|
230 |
* Attribute. Used from MemberEnter for attaching the attributes |
|
231 |
* to the annotated symbol. |
|
232 |
*/ |
|
233 |
Attribute.Compound enterAnnotation(JCAnnotation a, |
|
234 |
Type expected, |
|
235 |
Env<AttrContext> env) { |
|
17578 | 236 |
return enterAnnotation(a, expected, env, false); |
237 |
} |
|
238 |
||
239 |
Attribute.TypeCompound enterTypeAnnotation(JCAnnotation a, |
|
240 |
Type expected, |
|
241 |
Env<AttrContext> env) { |
|
242 |
return (Attribute.TypeCompound) enterAnnotation(a, expected, env, true); |
|
243 |
} |
|
244 |
||
245 |
// boolean typeAnnotation determines whether the method returns |
|
246 |
// a Compound (false) or TypeCompound (true). |
|
247 |
Attribute.Compound enterAnnotation(JCAnnotation a, |
|
248 |
Type expected, |
|
249 |
Env<AttrContext> env, |
|
250 |
boolean typeAnnotation) { |
|
10 | 251 |
// The annotation might have had its type attributed (but not checked) |
252 |
// by attr.attribAnnotationTypes during MemberEnter, in which case we do not |
|
253 |
// need to do it again. |
|
254 |
Type at = (a.annotationType.type != null ? a.annotationType.type |
|
255 |
: attr.attribType(a.annotationType, env)); |
|
256 |
a.type = chk.checkType(a.annotationType.pos(), at, expected); |
|
17578 | 257 |
if (a.type.isErroneous()) { |
258 |
if (typeAnnotation) { |
|
21041 | 259 |
return new Attribute.TypeCompound(a.type, List.<Pair<MethodSymbol,Attribute>>nil(), |
260 |
new TypeAnnotationPosition()); |
|
17578 | 261 |
} else { |
262 |
return new Attribute.Compound(a.type, List.<Pair<MethodSymbol,Attribute>>nil()); |
|
263 |
} |
|
264 |
} |
|
10 | 265 |
if ((a.type.tsym.flags() & Flags.ANNOTATION) == 0) { |
266 |
log.error(a.annotationType.pos(), |
|
267 |
"not.annotation.type", a.type.toString()); |
|
17578 | 268 |
if (typeAnnotation) { |
269 |
return new Attribute.TypeCompound(a.type, List.<Pair<MethodSymbol,Attribute>>nil(), null); |
|
270 |
} else { |
|
271 |
return new Attribute.Compound(a.type, List.<Pair<MethodSymbol,Attribute>>nil()); |
|
272 |
} |
|
10 | 273 |
} |
274 |
List<JCExpression> args = a.args; |
|
10950 | 275 |
if (args.length() == 1 && !args.head.hasTag(ASSIGN)) { |
10 | 276 |
// special case: elided "value=" assumed |
277 |
args.head = make.at(args.head.pos). |
|
278 |
Assign(make.Ident(names.value), args.head); |
|
279 |
} |
|
280 |
ListBuffer<Pair<MethodSymbol,Attribute>> buf = |
|
281 |
new ListBuffer<Pair<MethodSymbol,Attribute>>(); |
|
282 |
for (List<JCExpression> tl = args; tl.nonEmpty(); tl = tl.tail) { |
|
283 |
JCExpression t = tl.head; |
|
10950 | 284 |
if (!t.hasTag(ASSIGN)) { |
10 | 285 |
log.error(t.pos(), "annotation.value.must.be.name.value"); |
286 |
continue; |
|
287 |
} |
|
288 |
JCAssign assign = (JCAssign)t; |
|
10950 | 289 |
if (!assign.lhs.hasTag(IDENT)) { |
10 | 290 |
log.error(t.pos(), "annotation.value.must.be.name.value"); |
291 |
continue; |
|
292 |
} |
|
293 |
JCIdent left = (JCIdent)assign.lhs; |
|
19122
1841f2fa76de
8017216: javac doesn't fill in end position for some errors of type not found
ksrini
parents:
17578
diff
changeset
|
294 |
Symbol method = rs.resolveQualifiedMethod(assign.rhs.pos(), |
9603
fa337b87574b
6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents:
7681
diff
changeset
|
295 |
env, |
fa337b87574b
6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents:
7681
diff
changeset
|
296 |
a.type, |
fa337b87574b
6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents:
7681
diff
changeset
|
297 |
left.name, |
fa337b87574b
6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents:
7681
diff
changeset
|
298 |
List.<Type>nil(), |
fa337b87574b
6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents:
7681
diff
changeset
|
299 |
null); |
10 | 300 |
left.sym = method; |
301 |
left.type = method.type; |
|
302 |
if (method.owner != a.type.tsym) |
|
303 |
log.error(left.pos(), "no.annotation.member", left.name, a.type); |
|
304 |
Type result = method.type.getReturnType(); |
|
305 |
Attribute value = enterAttributeValue(result, assign.rhs, env); |
|
306 |
if (!method.type.isErroneous()) |
|
307 |
buf.append(new Pair<MethodSymbol,Attribute> |
|
308 |
((MethodSymbol)method, value)); |
|
6594
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
5847
diff
changeset
|
309 |
t.type = result; |
10 | 310 |
} |
17578 | 311 |
if (typeAnnotation) { |
312 |
if (a.attribute == null || !(a.attribute instanceof Attribute.TypeCompound)) { |
|
313 |
// Create a new TypeCompound |
|
314 |
Attribute.TypeCompound tc = new Attribute.TypeCompound(a.type, buf.toList(), new TypeAnnotationPosition()); |
|
315 |
a.attribute = tc; |
|
316 |
return tc; |
|
317 |
} else { |
|
318 |
// Use an existing TypeCompound |
|
319 |
return a.attribute; |
|
320 |
} |
|
321 |
} else { |
|
322 |
Attribute.Compound ac = new Attribute.Compound(a.type, buf.toList()); |
|
323 |
a.attribute = ac; |
|
324 |
return ac; |
|
325 |
} |
|
10 | 326 |
} |
327 |
||
328 |
Attribute enterAttributeValue(Type expected, |
|
329 |
JCExpression tree, |
|
330 |
Env<AttrContext> env) { |
|
9603
fa337b87574b
6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents:
7681
diff
changeset
|
331 |
//first, try completing the attribution value sym - if a completion |
fa337b87574b
6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents:
7681
diff
changeset
|
332 |
//error is thrown, we should recover gracefully, and display an |
fa337b87574b
6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents:
7681
diff
changeset
|
333 |
//ordinary resolution diagnostic. |
fa337b87574b
6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents:
7681
diff
changeset
|
334 |
try { |
fa337b87574b
6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents:
7681
diff
changeset
|
335 |
expected.tsym.complete(); |
fa337b87574b
6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents:
7681
diff
changeset
|
336 |
} catch(CompletionFailure e) { |
fa337b87574b
6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents:
7681
diff
changeset
|
337 |
log.error(tree.pos(), "cant.resolve", Kinds.kindName(e.sym), e.sym); |
20599
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
338 |
expected = syms.errType; |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
339 |
} |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
340 |
if (expected.hasTag(ARRAY)) { |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
341 |
if (!tree.hasTag(NEWARRAY)) { |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
342 |
tree = make.at(tree.pos). |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
343 |
NewArray(null, List.<JCExpression>nil(), List.of(tree)); |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
344 |
} |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
345 |
JCNewArray na = (JCNewArray)tree; |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
346 |
if (na.elemtype != null) { |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
347 |
log.error(na.elemtype.pos(), "new.not.allowed.in.annotation"); |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
348 |
} |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
349 |
ListBuffer<Attribute> buf = new ListBuffer<Attribute>(); |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
350 |
for (List<JCExpression> l = na.elems; l.nonEmpty(); l=l.tail) { |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
351 |
buf.append(enterAttributeValue(types.elemtype(expected), |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
352 |
l.head, |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
353 |
env)); |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
354 |
} |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
355 |
na.type = expected; |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
356 |
return new Attribute. |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
357 |
Array(expected, buf.toArray(new Attribute[buf.length()])); |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
358 |
} |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
359 |
if (tree.hasTag(NEWARRAY)) { //error recovery |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
360 |
if (!expected.isErroneous()) |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
361 |
log.error(tree.pos(), "annotation.value.not.allowable.type"); |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
362 |
JCNewArray na = (JCNewArray)tree; |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
363 |
if (na.elemtype != null) { |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
364 |
log.error(na.elemtype.pos(), "new.not.allowed.in.annotation"); |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
365 |
} |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
366 |
for (List<JCExpression> l = na.elems; l.nonEmpty(); l=l.tail) { |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
367 |
enterAttributeValue(syms.errType, |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
368 |
l.head, |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
369 |
env); |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
370 |
} |
21015
f3bec12a63e7
6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents:
20599
diff
changeset
|
371 |
return new Attribute.Error(syms.errType); |
20599
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
372 |
} |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
373 |
if ((expected.tsym.flags() & Flags.ANNOTATION) != 0) { |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
374 |
if (tree.hasTag(ANNOTATION)) { |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
375 |
return enterAnnotation((JCAnnotation)tree, expected, env); |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
376 |
} else { |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
377 |
log.error(tree.pos(), "annotation.value.must.be.annotation"); |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
378 |
expected = syms.errType; |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
379 |
} |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
380 |
} |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
381 |
if (tree.hasTag(ANNOTATION)) { //error recovery |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
382 |
if (!expected.isErroneous()) |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
383 |
log.error(tree.pos(), "annotation.not.valid.for.type", expected); |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
384 |
enterAnnotation((JCAnnotation)tree, syms.errType, env); |
21015
f3bec12a63e7
6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents:
20599
diff
changeset
|
385 |
return new Attribute.Error(((JCAnnotation)tree).annotationType.type); |
9603
fa337b87574b
6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents:
7681
diff
changeset
|
386 |
} |
10 | 387 |
if (expected.isPrimitive() || types.isSameType(expected, syms.stringType)) { |
388 |
Type result = attr.attribExpr(tree, env, expected); |
|
389 |
if (result.isErroneous()) |
|
21015
f3bec12a63e7
6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents:
20599
diff
changeset
|
390 |
return new Attribute.Error(result.getOriginalType()); |
10 | 391 |
if (result.constValue() == null) { |
392 |
log.error(tree.pos(), "attribute.value.must.be.constant"); |
|
393 |
return new Attribute.Error(expected); |
|
394 |
} |
|
395 |
result = cfolder.coerce(result, expected); |
|
396 |
return new Attribute.Constant(expected, result.constValue()); |
|
397 |
} |
|
398 |
if (expected.tsym == syms.classType.tsym) { |
|
399 |
Type result = attr.attribExpr(tree, env, expected); |
|
19507
323f001d6be1
8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents:
19122
diff
changeset
|
400 |
if (result.isErroneous()) { |
21015
f3bec12a63e7
6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents:
20599
diff
changeset
|
401 |
// Does it look like an unresolved class literal? |
f3bec12a63e7
6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents:
20599
diff
changeset
|
402 |
if (TreeInfo.name(tree) == names._class && |
f3bec12a63e7
6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents:
20599
diff
changeset
|
403 |
((JCFieldAccess) tree).selected.type.isErroneous()) { |
19507
323f001d6be1
8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents:
19122
diff
changeset
|
404 |
Name n = (((JCFieldAccess) tree).selected).type.tsym.flatName(); |
323f001d6be1
8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents:
19122
diff
changeset
|
405 |
return new Attribute.UnresolvedClass(expected, |
323f001d6be1
8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents:
19122
diff
changeset
|
406 |
types.createErrorType(n, |
323f001d6be1
8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents:
19122
diff
changeset
|
407 |
syms.unknownSymbol, syms.classType)); |
323f001d6be1
8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents:
19122
diff
changeset
|
408 |
} else { |
21015
f3bec12a63e7
6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents:
20599
diff
changeset
|
409 |
return new Attribute.Error(result.getOriginalType()); |
19507
323f001d6be1
8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents:
19122
diff
changeset
|
410 |
} |
323f001d6be1
8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents:
19122
diff
changeset
|
411 |
} |
323f001d6be1
8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents:
19122
diff
changeset
|
412 |
|
323f001d6be1
8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents:
19122
diff
changeset
|
413 |
// Class literals look like field accesses of a field named class |
323f001d6be1
8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents:
19122
diff
changeset
|
414 |
// at the tree level |
10 | 415 |
if (TreeInfo.name(tree) != names._class) { |
416 |
log.error(tree.pos(), "annotation.value.must.be.class.literal"); |
|
21015
f3bec12a63e7
6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents:
20599
diff
changeset
|
417 |
return new Attribute.Error(syms.errType); |
10 | 418 |
} |
419 |
return new Attribute.Class(types, |
|
420 |
(((JCFieldAccess) tree).selected).type); |
|
421 |
} |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14054
diff
changeset
|
422 |
if (expected.hasTag(CLASS) && |
10 | 423 |
(expected.tsym.flags() & Flags.ENUM) != 0) { |
21015
f3bec12a63e7
6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents:
20599
diff
changeset
|
424 |
Type result = attr.attribExpr(tree, env, expected); |
10 | 425 |
Symbol sym = TreeInfo.symbol(tree); |
426 |
if (sym == null || |
|
427 |
TreeInfo.nonstaticSelect(tree) || |
|
428 |
sym.kind != Kinds.VAR || |
|
429 |
(sym.flags() & Flags.ENUM) == 0) { |
|
430 |
log.error(tree.pos(), "enum.annotation.must.be.enum.constant"); |
|
21015
f3bec12a63e7
6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents:
20599
diff
changeset
|
431 |
return new Attribute.Error(result.getOriginalType()); |
10 | 432 |
} |
433 |
VarSymbol enumerator = (VarSymbol) sym; |
|
434 |
return new Attribute.Enum(expected, enumerator); |
|
435 |
} |
|
20599
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
436 |
//error recovery: |
10 | 437 |
if (!expected.isErroneous()) |
438 |
log.error(tree.pos(), "annotation.value.not.allowable.type"); |
|
439 |
return new Attribute.Error(attr.attribExpr(tree, env, expected)); |
|
440 |
} |
|
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
441 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
442 |
/* ********************************* |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
443 |
* Support for repeating annotations |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
444 |
***********************************/ |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
445 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
446 |
/* Process repeated annotations. This method returns the |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
447 |
* synthesized container annotation or null IFF all repeating |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
448 |
* annotation are invalid. This method reports errors/warnings. |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
449 |
*/ |
15385 | 450 |
private <T extends Attribute.Compound> T processRepeatedAnnotations(List<T> annotations, |
451 |
AnnotateRepeatedContext<T> ctx, |
|
452 |
Symbol on) { |
|
453 |
T firstOccurrence = annotations.head; |
|
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
454 |
List<Attribute> repeated = List.nil(); |
14804
f93a8d60b9a4
8001114: Container annotation is not checked for semantic correctness
jfranck
parents:
14359
diff
changeset
|
455 |
Type origAnnoType = null; |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
456 |
Type arrayOfOrigAnnoType = null; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
457 |
Type targetContainerType = null; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
458 |
MethodSymbol containerValueSymbol = null; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
459 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
460 |
Assert.check(!annotations.isEmpty() && |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
461 |
!annotations.tail.isEmpty()); // i.e. size() > 1 |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
462 |
|
16342
28d6ae9ed67c
7196531: Duplicate error messages on repeating annotations
jfranck
parents:
15385
diff
changeset
|
463 |
int count = 0; |
15385 | 464 |
for (List<T> al = annotations; |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
465 |
!al.isEmpty(); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
466 |
al = al.tail) |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
467 |
{ |
16342
28d6ae9ed67c
7196531: Duplicate error messages on repeating annotations
jfranck
parents:
15385
diff
changeset
|
468 |
count++; |
28d6ae9ed67c
7196531: Duplicate error messages on repeating annotations
jfranck
parents:
15385
diff
changeset
|
469 |
|
28d6ae9ed67c
7196531: Duplicate error messages on repeating annotations
jfranck
parents:
15385
diff
changeset
|
470 |
// There must be more than a single anno in the annotation list |
28d6ae9ed67c
7196531: Duplicate error messages on repeating annotations
jfranck
parents:
15385
diff
changeset
|
471 |
Assert.check(count > 1 || !al.tail.isEmpty()); |
28d6ae9ed67c
7196531: Duplicate error messages on repeating annotations
jfranck
parents:
15385
diff
changeset
|
472 |
|
15385 | 473 |
T currentAnno = al.head; |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
474 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
475 |
origAnnoType = currentAnno.type; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
476 |
if (arrayOfOrigAnnoType == null) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
477 |
arrayOfOrigAnnoType = types.makeArrayType(origAnnoType); |
15385 | 478 |
} |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
479 |
|
16342
28d6ae9ed67c
7196531: Duplicate error messages on repeating annotations
jfranck
parents:
15385
diff
changeset
|
480 |
// Only report errors if this isn't the first occurrence I.E. count > 1 |
28d6ae9ed67c
7196531: Duplicate error messages on repeating annotations
jfranck
parents:
15385
diff
changeset
|
481 |
boolean reportError = count > 1; |
28d6ae9ed67c
7196531: Duplicate error messages on repeating annotations
jfranck
parents:
15385
diff
changeset
|
482 |
Type currentContainerType = getContainingType(currentAnno, ctx.pos.get(currentAnno), reportError); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
483 |
if (currentContainerType == null) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
484 |
continue; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
485 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
486 |
// Assert that the target Container is == for all repeated |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
487 |
// annos of the same annotation type, the types should |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
488 |
// come from the same Symbol, i.e. be '==' |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
489 |
Assert.check(targetContainerType == null || currentContainerType == targetContainerType); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
490 |
targetContainerType = currentContainerType; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
491 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
492 |
containerValueSymbol = validateContainer(targetContainerType, origAnnoType, ctx.pos.get(currentAnno)); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
493 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
494 |
if (containerValueSymbol == null) { // Check of CA type failed |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
495 |
// errors are already reported |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
496 |
continue; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
497 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
498 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
499 |
repeated = repeated.prepend(currentAnno); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
500 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
501 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
502 |
if (!repeated.isEmpty()) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
503 |
repeated = repeated.reverse(); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
504 |
TreeMaker m = make.at(ctx.pos.get(firstOccurrence)); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
505 |
Pair<MethodSymbol, Attribute> p = |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
506 |
new Pair<MethodSymbol, Attribute>(containerValueSymbol, |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
507 |
new Attribute.Array(arrayOfOrigAnnoType, repeated)); |
15385 | 508 |
if (ctx.isTypeCompound) { |
509 |
/* TODO: the following code would be cleaner: |
|
510 |
Attribute.TypeCompound at = new Attribute.TypeCompound(targetContainerType, List.of(p), |
|
511 |
((Attribute.TypeCompound)annotations.head).position); |
|
512 |
JCTypeAnnotation annoTree = m.TypeAnnotation(at); |
|
513 |
at = enterTypeAnnotation(annoTree, targetContainerType, ctx.env); |
|
514 |
*/ |
|
515 |
// However, we directly construct the TypeCompound to keep the |
|
516 |
// direct relation to the contained TypeCompounds. |
|
517 |
Attribute.TypeCompound at = new Attribute.TypeCompound(targetContainerType, List.of(p), |
|
518 |
((Attribute.TypeCompound)annotations.head).position); |
|
14804
f93a8d60b9a4
8001114: Container annotation is not checked for semantic correctness
jfranck
parents:
14359
diff
changeset
|
519 |
|
15385 | 520 |
// TODO: annotation applicability checks from below? |
521 |
||
522 |
at.setSynthesized(true); |
|
14804
f93a8d60b9a4
8001114: Container annotation is not checked for semantic correctness
jfranck
parents:
14359
diff
changeset
|
523 |
|
15385 | 524 |
@SuppressWarnings("unchecked") |
525 |
T x = (T) at; |
|
526 |
return x; |
|
527 |
} else { |
|
528 |
Attribute.Compound c = new Attribute.Compound(targetContainerType, List.of(p)); |
|
529 |
JCAnnotation annoTree = m.Annotation(c); |
|
530 |
||
531 |
if (!chk.annotationApplicable(annoTree, on)) |
|
532 |
log.error(annoTree.pos(), "invalid.repeatable.annotation.incompatible.target", targetContainerType, origAnnoType); |
|
14804
f93a8d60b9a4
8001114: Container annotation is not checked for semantic correctness
jfranck
parents:
14359
diff
changeset
|
533 |
|
15385 | 534 |
if (!chk.validateAnnotationDeferErrors(annoTree)) |
535 |
log.error(annoTree.pos(), "duplicate.annotation.invalid.repeated", origAnnoType); |
|
536 |
||
537 |
c = enterAnnotation(annoTree, targetContainerType, ctx.env); |
|
538 |
c.setSynthesized(true); |
|
539 |
||
540 |
@SuppressWarnings("unchecked") |
|
541 |
T x = (T) c; |
|
542 |
return x; |
|
543 |
} |
|
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
544 |
} else { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
545 |
return null; // errors should have been reported elsewhere |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
546 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
547 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
548 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
549 |
/** Fetches the actual Type that should be the containing annotation. */ |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
550 |
private Type getContainingType(Attribute.Compound currentAnno, |
16342
28d6ae9ed67c
7196531: Duplicate error messages on repeating annotations
jfranck
parents:
15385
diff
changeset
|
551 |
DiagnosticPosition pos, |
28d6ae9ed67c
7196531: Duplicate error messages on repeating annotations
jfranck
parents:
15385
diff
changeset
|
552 |
boolean reportError) |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
553 |
{ |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
554 |
Type origAnnoType = currentAnno.type; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
555 |
TypeSymbol origAnnoDecl = origAnnoType.tsym; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
556 |
|
15356
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14961
diff
changeset
|
557 |
// Fetch the Repeatable annotation from the current |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
558 |
// annotation's declaration, or null if it has none |
15356
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14961
diff
changeset
|
559 |
Attribute.Compound ca = origAnnoDecl.attribute(syms.repeatableType.tsym); |
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14961
diff
changeset
|
560 |
if (ca == null) { // has no Repeatable annotation |
16342
28d6ae9ed67c
7196531: Duplicate error messages on repeating annotations
jfranck
parents:
15385
diff
changeset
|
561 |
if (reportError) |
28d6ae9ed67c
7196531: Duplicate error messages on repeating annotations
jfranck
parents:
15385
diff
changeset
|
562 |
log.error(pos, "duplicate.annotation.missing.container", origAnnoType, syms.repeatableType); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
563 |
return null; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
564 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
565 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
566 |
return filterSame(extractContainingType(ca, pos, origAnnoDecl), |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
567 |
origAnnoType); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
568 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
569 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
570 |
// returns null if t is same as 's', returns 't' otherwise |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
571 |
private Type filterSame(Type t, Type s) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
572 |
if (t == null || s == null) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
573 |
return t; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
574 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
575 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
576 |
return types.isSameType(t, s) ? null : t; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
577 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
578 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
579 |
/** Extract the actual Type to be used for a containing annotation. */ |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
580 |
private Type extractContainingType(Attribute.Compound ca, |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
581 |
DiagnosticPosition pos, |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
582 |
TypeSymbol annoDecl) |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
583 |
{ |
15356
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14961
diff
changeset
|
584 |
// The next three checks check that the Repeatable annotation |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
585 |
// on the declaration of the annotation type that is repeating is |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
586 |
// valid. |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
587 |
|
15356
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14961
diff
changeset
|
588 |
// Repeatable must have at least one element |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
589 |
if (ca.values.isEmpty()) { |
15356
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14961
diff
changeset
|
590 |
log.error(pos, "invalid.repeatable.annotation", annoDecl); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
591 |
return null; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
592 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
593 |
Pair<MethodSymbol,Attribute> p = ca.values.head; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
594 |
Name name = p.fst.name; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
595 |
if (name != names.value) { // should contain only one element, named "value" |
15356
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14961
diff
changeset
|
596 |
log.error(pos, "invalid.repeatable.annotation", annoDecl); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
597 |
return null; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
598 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
599 |
if (!(p.snd instanceof Attribute.Class)) { // check that the value of "value" is an Attribute.Class |
15356
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14961
diff
changeset
|
600 |
log.error(pos, "invalid.repeatable.annotation", annoDecl); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
601 |
return null; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
602 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
603 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
604 |
return ((Attribute.Class)p.snd).getValue(); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
605 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
606 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
607 |
/* Validate that the suggested targetContainerType Type is a valid |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
608 |
* container type for repeated instances of originalAnnoType |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
609 |
* annotations. Return null and report errors if this is not the |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
610 |
* case, return the MethodSymbol of the value element in |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
611 |
* targetContainerType if it is suitable (this is needed to |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
612 |
* synthesize the container). */ |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
613 |
private MethodSymbol validateContainer(Type targetContainerType, |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
614 |
Type originalAnnoType, |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
615 |
DiagnosticPosition pos) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
616 |
MethodSymbol containerValueSymbol = null; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
617 |
boolean fatalError = false; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
618 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
619 |
// Validate that there is a (and only 1) value method |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
620 |
Scope scope = targetContainerType.tsym.members(); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
621 |
int nr_value_elems = 0; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
622 |
boolean error = false; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
623 |
for(Symbol elm : scope.getElementsByName(names.value)) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
624 |
nr_value_elems++; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
625 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
626 |
if (nr_value_elems == 1 && |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
627 |
elm.kind == Kinds.MTH) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
628 |
containerValueSymbol = (MethodSymbol)elm; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
629 |
} else { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
630 |
error = true; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
631 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
632 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
633 |
if (error) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
634 |
log.error(pos, |
15356
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14961
diff
changeset
|
635 |
"invalid.repeatable.annotation.multiple.values", |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
636 |
targetContainerType, |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
637 |
nr_value_elems); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
638 |
return null; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
639 |
} else if (nr_value_elems == 0) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
640 |
log.error(pos, |
15356
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14961
diff
changeset
|
641 |
"invalid.repeatable.annotation.no.value", |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
642 |
targetContainerType); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
643 |
return null; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
644 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
645 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
646 |
// validate that the 'value' element is a method |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
647 |
// probably "impossible" to fail this |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
648 |
if (containerValueSymbol.kind != Kinds.MTH) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
649 |
log.error(pos, |
15356
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14961
diff
changeset
|
650 |
"invalid.repeatable.annotation.invalid.value", |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
651 |
targetContainerType); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
652 |
fatalError = true; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
653 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
654 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
655 |
// validate that the 'value' element has the correct return type |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
656 |
// i.e. array of original anno |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
657 |
Type valueRetType = containerValueSymbol.type.getReturnType(); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
658 |
Type expectedType = types.makeArrayType(originalAnnoType); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
659 |
if (!(types.isArray(valueRetType) && |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
660 |
types.isSameType(expectedType, valueRetType))) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
661 |
log.error(pos, |
15356
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14961
diff
changeset
|
662 |
"invalid.repeatable.annotation.value.return", |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
663 |
targetContainerType, |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
664 |
valueRetType, |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
665 |
expectedType); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
666 |
fatalError = true; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
667 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
668 |
if (error) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
669 |
fatalError = true; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
670 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
671 |
|
15356
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14961
diff
changeset
|
672 |
// The conditions for a valid containing annotation are made |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
673 |
// in Check.validateRepeatedAnnotaton(); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
674 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
675 |
return fatalError ? null : containerValueSymbol; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
676 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
677 |
} |