author | emc |
Mon, 03 Mar 2014 16:17:32 -0500 | |
changeset 23134 | 010b1b0d25fb |
parent 23129 | 6d3b2e246dac |
child 23397 | 825c76b83afe |
permissions | -rw-r--r-- |
10 | 1 |
/* |
22439
4785d87cd2d6
8029376: Full attribution of unresolvable annotations
jlahoda
parents:
22165
diff
changeset
|
2 |
* Copyright (c) 2003, 2014, 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 |
||
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
28 |
import java.util.HashMap; |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
29 |
import java.util.LinkedHashMap; |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
30 |
import java.util.Map; |
15385 | 31 |
|
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
32 |
import javax.tools.JavaFileObject; |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
33 |
|
10 | 34 |
import com.sun.tools.javac.util.*; |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
35 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
10 | 36 |
import com.sun.tools.javac.code.*; |
37 |
import com.sun.tools.javac.code.Symbol.*; |
|
38 |
import com.sun.tools.javac.tree.*; |
|
39 |
import com.sun.tools.javac.tree.JCTree.*; |
|
40 |
||
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
41 |
import static com.sun.tools.javac.code.Kinds.*; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14054
diff
changeset
|
42 |
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
|
43 |
import static com.sun.tools.javac.code.TypeTag.CLASS; |
10950 | 44 |
import static com.sun.tools.javac.tree.JCTree.Tag.*; |
45 |
||
10 | 46 |
/** Enter annotations on symbols. Annotations accumulate in a queue, |
47 |
* which is processed at the top level of any set of recursive calls |
|
48 |
* requesting it be processed. |
|
49 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
50 |
* <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
|
51 |
* If you write code that depends on this, you do so at your own risk. |
10 | 52 |
* This code and its internal interfaces are subject to change or |
53 |
* deletion without notice.</b> |
|
54 |
*/ |
|
55 |
public class Annotate { |
|
22163 | 56 |
protected static final Context.Key<Annotate> annotateKey = new Context.Key<>(); |
10 | 57 |
|
58 |
public static Annotate instance(Context context) { |
|
59 |
Annotate instance = context.get(annotateKey); |
|
60 |
if (instance == null) |
|
61 |
instance = new Annotate(context); |
|
62 |
return instance; |
|
63 |
} |
|
64 |
||
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
65 |
private final Attr attr; |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
66 |
private final TreeMaker make; |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
67 |
private final Log log; |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
68 |
private final Symtab syms; |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
69 |
private final Names names; |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
70 |
private final Resolve rs; |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
71 |
private final Types types; |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
72 |
private final ConstFold cfolder; |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
73 |
private final Check chk; |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
74 |
private final Lint lint; |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
75 |
private final DeferredLintHandler deferredLintHandler; |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
76 |
private final Source source; |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
77 |
|
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
78 |
private boolean allowTypeAnnos; |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
79 |
private boolean allowRepeatedAnnos; |
10 | 80 |
|
81 |
protected Annotate(Context context) { |
|
82 |
context.put(annotateKey, this); |
|
83 |
attr = Attr.instance(context); |
|
84 |
make = TreeMaker.instance(context); |
|
85 |
log = Log.instance(context); |
|
86 |
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
|
87 |
names = Names.instance(context); |
10 | 88 |
rs = Resolve.instance(context); |
89 |
types = Types.instance(context); |
|
90 |
cfolder = ConstFold.instance(context); |
|
91 |
chk = Check.instance(context); |
|
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
92 |
source = Source.instance(context); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
93 |
lint = Lint.instance(context); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
94 |
deferredLintHandler = DeferredLintHandler.instance(context); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
95 |
allowRepeatedAnnos = source.allowRepeatedAnnotations(); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
96 |
allowTypeAnnos = source.allowTypeAnnotations(); |
10 | 97 |
} |
98 |
||
99 |
/* ******************************************************************** |
|
100 |
* Queue maintenance |
|
101 |
*********************************************************************/ |
|
102 |
||
103 |
private int enterCount = 0; |
|
104 |
||
22163 | 105 |
ListBuffer<Worker> q = new ListBuffer<>(); |
106 |
ListBuffer<Worker> typesQ = new ListBuffer<>(); |
|
107 |
ListBuffer<Worker> repeatedQ = new ListBuffer<>(); |
|
108 |
ListBuffer<Worker> afterRepeatedQ = new ListBuffer<>(); |
|
109 |
ListBuffer<Worker> validateQ = new ListBuffer<>(); |
|
15385 | 110 |
|
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
111 |
public void earlier(Worker a) { |
15385 | 112 |
q.prepend(a); |
113 |
} |
|
10 | 114 |
|
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
115 |
public void normal(Worker a) { |
10 | 116 |
q.append(a); |
117 |
} |
|
118 |
||
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
119 |
public void typeAnnotation(Worker a) { |
15385 | 120 |
typesQ.append(a); |
10 | 121 |
} |
122 |
||
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
123 |
public void repeated(Worker a) { |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
124 |
repeatedQ.append(a); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
125 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
126 |
|
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
127 |
public void afterRepeated(Worker a) { |
15385 | 128 |
afterRepeatedQ.append(a); |
129 |
} |
|
130 |
||
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
131 |
public void validate(Worker a) { |
21018
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
132 |
validateQ.append(a); |
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
133 |
} |
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
134 |
|
10 | 135 |
/** Called when the Enter phase starts. */ |
136 |
public void enterStart() { |
|
137 |
enterCount++; |
|
138 |
} |
|
139 |
||
140 |
/** Called after the Enter phase completes. */ |
|
141 |
public void enterDone() { |
|
142 |
enterCount--; |
|
143 |
flush(); |
|
144 |
} |
|
145 |
||
21043
3b000be15694
8026286: Improper locking of annotation queues causes assertion failures.
emc
parents:
21041
diff
changeset
|
146 |
/** Variant which allows for a delayed flush of annotations. |
3b000be15694
8026286: Improper locking of annotation queues causes assertion failures.
emc
parents:
21041
diff
changeset
|
147 |
* Needed by ClassReader */ |
3b000be15694
8026286: Improper locking of annotation queues causes assertion failures.
emc
parents:
21041
diff
changeset
|
148 |
public void enterDoneWithoutFlush() { |
3b000be15694
8026286: Improper locking of annotation queues causes assertion failures.
emc
parents:
21041
diff
changeset
|
149 |
enterCount--; |
3b000be15694
8026286: Improper locking of annotation queues causes assertion failures.
emc
parents:
21041
diff
changeset
|
150 |
} |
3b000be15694
8026286: Improper locking of annotation queues causes assertion failures.
emc
parents:
21041
diff
changeset
|
151 |
|
10 | 152 |
public void flush() { |
153 |
if (enterCount != 0) return; |
|
154 |
enterCount++; |
|
155 |
try { |
|
15385 | 156 |
while (q.nonEmpty()) { |
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
157 |
q.next().run(); |
15385 | 158 |
} |
159 |
while (typesQ.nonEmpty()) { |
|
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
160 |
typesQ.next().run(); |
15385 | 161 |
} |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
162 |
while (repeatedQ.nonEmpty()) { |
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
163 |
repeatedQ.next().run(); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
164 |
} |
15385 | 165 |
while (afterRepeatedQ.nonEmpty()) { |
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
166 |
afterRepeatedQ.next().run(); |
15385 | 167 |
} |
21018
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
168 |
while (validateQ.nonEmpty()) { |
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
169 |
validateQ.next().run(); |
21018
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
170 |
} |
10 | 171 |
} finally { |
172 |
enterCount--; |
|
173 |
} |
|
174 |
} |
|
175 |
||
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
176 |
/** 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
|
177 |
* 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
|
178 |
* {@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
|
179 |
* {@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
|
180 |
* 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
|
181 |
* call. Queues are empties in the abovementioned order. |
10 | 182 |
*/ |
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
183 |
public interface Worker { |
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
184 |
void run(); |
10 | 185 |
String toString(); |
186 |
} |
|
187 |
||
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
188 |
/** |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
189 |
* This context contains all the information needed to synthesize new |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
190 |
* annotations trees by the completer for repeating annotations. |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
191 |
*/ |
15385 | 192 |
public class AnnotateRepeatedContext<T extends Attribute.Compound> { |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
193 |
public final Env<AttrContext> env; |
15385 | 194 |
public final Map<Symbol.TypeSymbol, ListBuffer<T>> annotated; |
195 |
public final Map<T, JCDiagnostic.DiagnosticPosition> pos; |
|
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
196 |
public final Log log; |
15385 | 197 |
public final boolean isTypeCompound; |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
198 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
199 |
public AnnotateRepeatedContext(Env<AttrContext> env, |
15385 | 200 |
Map<Symbol.TypeSymbol, ListBuffer<T>> annotated, |
201 |
Map<T, JCDiagnostic.DiagnosticPosition> pos, |
|
202 |
Log log, |
|
203 |
boolean isTypeCompound) { |
|
13840
a365c561f4de
7196774: javac cannot be built with JDK 6 after 7151010
jjg
parents:
13689
diff
changeset
|
204 |
Assert.checkNonNull(env); |
a365c561f4de
7196774: javac cannot be built with JDK 6 after 7151010
jjg
parents:
13689
diff
changeset
|
205 |
Assert.checkNonNull(annotated); |
a365c561f4de
7196774: javac cannot be built with JDK 6 after 7151010
jjg
parents:
13689
diff
changeset
|
206 |
Assert.checkNonNull(pos); |
a365c561f4de
7196774: javac cannot be built with JDK 6 after 7151010
jjg
parents:
13689
diff
changeset
|
207 |
Assert.checkNonNull(log); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
208 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
209 |
this.env = env; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
210 |
this.annotated = annotated; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
211 |
this.pos = pos; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
212 |
this.log = log; |
15385 | 213 |
this.isTypeCompound = isTypeCompound; |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
214 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
215 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
216 |
/** |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
217 |
* Process a list of repeating annotations returning a new |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
218 |
* Attribute.Compound that is the attribute for the synthesized tree |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
219 |
* for the container. |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
220 |
* |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
221 |
* @param repeatingAnnotations a List of repeating annotations |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
222 |
* @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
|
223 |
*/ |
15385 | 224 |
public T processRepeatedAnnotations(List<T> repeatingAnnotations, Symbol sym) { |
14804
f93a8d60b9a4
8001114: Container annotation is not checked for semantic correctness
jfranck
parents:
14359
diff
changeset
|
225 |
return Annotate.this.processRepeatedAnnotations(repeatingAnnotations, this, sym); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
226 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
227 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
228 |
/** |
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
229 |
* 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
|
230 |
* Annotate instance this context belongs to. |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
231 |
* |
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
232 |
* @param a the Worker to enqueue for repeating annotation annotating |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
233 |
*/ |
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
234 |
public void annotateRepeated(Worker a) { |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
235 |
Annotate.this.repeated(a); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
236 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
237 |
} |
10 | 238 |
|
239 |
/* ******************************************************************** |
|
240 |
* Compute an attribute from its annotation. |
|
241 |
*********************************************************************/ |
|
242 |
||
243 |
/** Process a single compound annotation, returning its |
|
244 |
* Attribute. Used from MemberEnter for attaching the attributes |
|
245 |
* to the annotated symbol. |
|
246 |
*/ |
|
247 |
Attribute.Compound enterAnnotation(JCAnnotation a, |
|
248 |
Type expected, |
|
249 |
Env<AttrContext> env) { |
|
17578 | 250 |
return enterAnnotation(a, expected, env, false); |
251 |
} |
|
252 |
||
253 |
Attribute.TypeCompound enterTypeAnnotation(JCAnnotation a, |
|
254 |
Type expected, |
|
255 |
Env<AttrContext> env) { |
|
256 |
return (Attribute.TypeCompound) enterAnnotation(a, expected, env, true); |
|
257 |
} |
|
258 |
||
259 |
// boolean typeAnnotation determines whether the method returns |
|
260 |
// a Compound (false) or TypeCompound (true). |
|
261 |
Attribute.Compound enterAnnotation(JCAnnotation a, |
|
262 |
Type expected, |
|
263 |
Env<AttrContext> env, |
|
264 |
boolean typeAnnotation) { |
|
10 | 265 |
// The annotation might have had its type attributed (but not checked) |
266 |
// by attr.attribAnnotationTypes during MemberEnter, in which case we do not |
|
267 |
// need to do it again. |
|
268 |
Type at = (a.annotationType.type != null ? a.annotationType.type |
|
269 |
: attr.attribType(a.annotationType, env)); |
|
270 |
a.type = chk.checkType(a.annotationType.pos(), at, expected); |
|
22439
4785d87cd2d6
8029376: Full attribution of unresolvable annotations
jlahoda
parents:
22165
diff
changeset
|
271 |
boolean isError = a.type.isErroneous(); |
4785d87cd2d6
8029376: Full attribution of unresolvable annotations
jlahoda
parents:
22165
diff
changeset
|
272 |
if ((a.type.tsym.flags() & Flags.ANNOTATION) == 0 && !isError) { |
10 | 273 |
log.error(a.annotationType.pos(), |
274 |
"not.annotation.type", a.type.toString()); |
|
22439
4785d87cd2d6
8029376: Full attribution of unresolvable annotations
jlahoda
parents:
22165
diff
changeset
|
275 |
isError = true; |
10 | 276 |
} |
277 |
List<JCExpression> args = a.args; |
|
10950 | 278 |
if (args.length() == 1 && !args.head.hasTag(ASSIGN)) { |
10 | 279 |
// special case: elided "value=" assumed |
280 |
args.head = make.at(args.head.pos). |
|
281 |
Assign(make.Ident(names.value), args.head); |
|
282 |
} |
|
283 |
ListBuffer<Pair<MethodSymbol,Attribute>> buf = |
|
21713
b3fcc9c0fea3
8027375: javac asserts on nested erroneous annotations
jfranck
parents:
21043
diff
changeset
|
284 |
new ListBuffer<>(); |
10 | 285 |
for (List<JCExpression> tl = args; tl.nonEmpty(); tl = tl.tail) { |
286 |
JCExpression t = tl.head; |
|
10950 | 287 |
if (!t.hasTag(ASSIGN)) { |
10 | 288 |
log.error(t.pos(), "annotation.value.must.be.name.value"); |
22439
4785d87cd2d6
8029376: Full attribution of unresolvable annotations
jlahoda
parents:
22165
diff
changeset
|
289 |
enterAttributeValue(t.type = syms.errType, t, env); |
10 | 290 |
continue; |
291 |
} |
|
292 |
JCAssign assign = (JCAssign)t; |
|
10950 | 293 |
if (!assign.lhs.hasTag(IDENT)) { |
10 | 294 |
log.error(t.pos(), "annotation.value.must.be.name.value"); |
22439
4785d87cd2d6
8029376: Full attribution of unresolvable annotations
jlahoda
parents:
22165
diff
changeset
|
295 |
enterAttributeValue(t.type = syms.errType, t, env); |
10 | 296 |
continue; |
297 |
} |
|
298 |
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
|
299 |
Symbol method = rs.resolveQualifiedMethod(assign.rhs.pos(), |
9603
fa337b87574b
6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents:
7681
diff
changeset
|
300 |
env, |
fa337b87574b
6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents:
7681
diff
changeset
|
301 |
a.type, |
fa337b87574b
6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents:
7681
diff
changeset
|
302 |
left.name, |
fa337b87574b
6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents:
7681
diff
changeset
|
303 |
List.<Type>nil(), |
fa337b87574b
6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents:
7681
diff
changeset
|
304 |
null); |
10 | 305 |
left.sym = method; |
306 |
left.type = method.type; |
|
22439
4785d87cd2d6
8029376: Full attribution of unresolvable annotations
jlahoda
parents:
22165
diff
changeset
|
307 |
if (method.owner != a.type.tsym && !isError) |
10 | 308 |
log.error(left.pos(), "no.annotation.member", left.name, a.type); |
309 |
Type result = method.type.getReturnType(); |
|
310 |
Attribute value = enterAttributeValue(result, assign.rhs, env); |
|
311 |
if (!method.type.isErroneous()) |
|
21713
b3fcc9c0fea3
8027375: javac asserts on nested erroneous annotations
jfranck
parents:
21043
diff
changeset
|
312 |
buf.append(new Pair<>((MethodSymbol)method, value)); |
6594
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
5847
diff
changeset
|
313 |
t.type = result; |
10 | 314 |
} |
17578 | 315 |
if (typeAnnotation) { |
316 |
if (a.attribute == null || !(a.attribute instanceof Attribute.TypeCompound)) { |
|
317 |
// Create a new TypeCompound |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22439
diff
changeset
|
318 |
|
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22439
diff
changeset
|
319 |
Attribute.TypeCompound tc = |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22439
diff
changeset
|
320 |
new Attribute.TypeCompound(a.type, buf.toList(), |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22439
diff
changeset
|
321 |
// TODO: Eventually, we will get rid of this use of |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22439
diff
changeset
|
322 |
// unknown, because we'll get a position from |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22439
diff
changeset
|
323 |
// MemberEnter (task 8027262). |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22439
diff
changeset
|
324 |
TypeAnnotationPosition.unknown); |
17578 | 325 |
a.attribute = tc; |
326 |
return tc; |
|
327 |
} else { |
|
328 |
// Use an existing TypeCompound |
|
329 |
return a.attribute; |
|
330 |
} |
|
331 |
} else { |
|
332 |
Attribute.Compound ac = new Attribute.Compound(a.type, buf.toList()); |
|
333 |
a.attribute = ac; |
|
334 |
return ac; |
|
335 |
} |
|
10 | 336 |
} |
337 |
||
338 |
Attribute enterAttributeValue(Type expected, |
|
339 |
JCExpression tree, |
|
340 |
Env<AttrContext> env) { |
|
9603
fa337b87574b
6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents:
7681
diff
changeset
|
341 |
//first, try completing the attribution value sym - if a completion |
fa337b87574b
6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents:
7681
diff
changeset
|
342 |
//error is thrown, we should recover gracefully, and display an |
fa337b87574b
6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents:
7681
diff
changeset
|
343 |
//ordinary resolution diagnostic. |
fa337b87574b
6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents:
7681
diff
changeset
|
344 |
try { |
fa337b87574b
6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents:
7681
diff
changeset
|
345 |
expected.tsym.complete(); |
fa337b87574b
6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents:
7681
diff
changeset
|
346 |
} catch(CompletionFailure e) { |
fa337b87574b
6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents:
7681
diff
changeset
|
347 |
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
|
348 |
expected = syms.errType; |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
349 |
} |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
350 |
if (expected.hasTag(ARRAY)) { |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
351 |
if (!tree.hasTag(NEWARRAY)) { |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
352 |
tree = make.at(tree.pos). |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
353 |
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
|
354 |
} |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
355 |
JCNewArray na = (JCNewArray)tree; |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
356 |
if (na.elemtype != null) { |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
357 |
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
|
358 |
} |
22163 | 359 |
ListBuffer<Attribute> buf = new ListBuffer<>(); |
20599
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
360 |
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
|
361 |
buf.append(enterAttributeValue(types.elemtype(expected), |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
362 |
l.head, |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
363 |
env)); |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
364 |
} |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
365 |
na.type = expected; |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
366 |
return new Attribute. |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
367 |
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
|
368 |
} |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
369 |
if (tree.hasTag(NEWARRAY)) { //error recovery |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
370 |
if (!expected.isErroneous()) |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
371 |
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
|
372 |
JCNewArray na = (JCNewArray)tree; |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
373 |
if (na.elemtype != null) { |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
374 |
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
|
375 |
} |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
376 |
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
|
377 |
enterAttributeValue(syms.errType, |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
378 |
l.head, |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
379 |
env); |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
380 |
} |
21015
f3bec12a63e7
6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents:
20599
diff
changeset
|
381 |
return new Attribute.Error(syms.errType); |
20599
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
382 |
} |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
383 |
if ((expected.tsym.flags() & Flags.ANNOTATION) != 0) { |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
384 |
if (tree.hasTag(ANNOTATION)) { |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
385 |
return enterAnnotation((JCAnnotation)tree, expected, env); |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
386 |
} else { |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
387 |
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
|
388 |
expected = syms.errType; |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
389 |
} |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
390 |
} |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
391 |
if (tree.hasTag(ANNOTATION)) { //error recovery |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
392 |
if (!expected.isErroneous()) |
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
393 |
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
|
394 |
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
|
395 |
return new Attribute.Error(((JCAnnotation)tree).annotationType.type); |
9603
fa337b87574b
6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents:
7681
diff
changeset
|
396 |
} |
22439
4785d87cd2d6
8029376: Full attribution of unresolvable annotations
jlahoda
parents:
22165
diff
changeset
|
397 |
if (expected.isPrimitive() || |
4785d87cd2d6
8029376: Full attribution of unresolvable annotations
jlahoda
parents:
22165
diff
changeset
|
398 |
(types.isSameType(expected, syms.stringType) && !expected.hasTag(TypeTag.ERROR))) { |
10 | 399 |
Type result = attr.attribExpr(tree, env, expected); |
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 |
return new Attribute.Error(result.getOriginalType()); |
10 | 402 |
if (result.constValue() == null) { |
403 |
log.error(tree.pos(), "attribute.value.must.be.constant"); |
|
404 |
return new Attribute.Error(expected); |
|
405 |
} |
|
406 |
result = cfolder.coerce(result, expected); |
|
407 |
return new Attribute.Constant(expected, result.constValue()); |
|
408 |
} |
|
409 |
if (expected.tsym == syms.classType.tsym) { |
|
410 |
Type result = attr.attribExpr(tree, env, expected); |
|
19507
323f001d6be1
8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents:
19122
diff
changeset
|
411 |
if (result.isErroneous()) { |
21015
f3bec12a63e7
6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents:
20599
diff
changeset
|
412 |
// 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
|
413 |
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
|
414 |
((JCFieldAccess) tree).selected.type.isErroneous()) { |
19507
323f001d6be1
8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents:
19122
diff
changeset
|
415 |
Name n = (((JCFieldAccess) tree).selected).type.tsym.flatName(); |
323f001d6be1
8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents:
19122
diff
changeset
|
416 |
return new Attribute.UnresolvedClass(expected, |
323f001d6be1
8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents:
19122
diff
changeset
|
417 |
types.createErrorType(n, |
323f001d6be1
8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents:
19122
diff
changeset
|
418 |
syms.unknownSymbol, syms.classType)); |
323f001d6be1
8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents:
19122
diff
changeset
|
419 |
} else { |
21015
f3bec12a63e7
6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents:
20599
diff
changeset
|
420 |
return new Attribute.Error(result.getOriginalType()); |
19507
323f001d6be1
8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents:
19122
diff
changeset
|
421 |
} |
323f001d6be1
8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents:
19122
diff
changeset
|
422 |
} |
323f001d6be1
8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents:
19122
diff
changeset
|
423 |
|
323f001d6be1
8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents:
19122
diff
changeset
|
424 |
// Class literals look like field accesses of a field named class |
323f001d6be1
8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents:
19122
diff
changeset
|
425 |
// at the tree level |
10 | 426 |
if (TreeInfo.name(tree) != names._class) { |
427 |
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
|
428 |
return new Attribute.Error(syms.errType); |
10 | 429 |
} |
430 |
return new Attribute.Class(types, |
|
431 |
(((JCFieldAccess) tree).selected).type); |
|
432 |
} |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14054
diff
changeset
|
433 |
if (expected.hasTag(CLASS) && |
10 | 434 |
(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
|
435 |
Type result = attr.attribExpr(tree, env, expected); |
10 | 436 |
Symbol sym = TreeInfo.symbol(tree); |
437 |
if (sym == null || |
|
438 |
TreeInfo.nonstaticSelect(tree) || |
|
439 |
sym.kind != Kinds.VAR || |
|
440 |
(sym.flags() & Flags.ENUM) == 0) { |
|
441 |
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
|
442 |
return new Attribute.Error(result.getOriginalType()); |
10 | 443 |
} |
444 |
VarSymbol enumerator = (VarSymbol) sym; |
|
445 |
return new Attribute.Enum(expected, enumerator); |
|
446 |
} |
|
20599
5201f7144a3c
8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents:
19507
diff
changeset
|
447 |
//error recovery: |
10 | 448 |
if (!expected.isErroneous()) |
449 |
log.error(tree.pos(), "annotation.value.not.allowable.type"); |
|
450 |
return new Attribute.Error(attr.attribExpr(tree, env, expected)); |
|
451 |
} |
|
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
452 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
453 |
/* ********************************* |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
454 |
* Support for repeating annotations |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
455 |
***********************************/ |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
456 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
457 |
/* Process repeated annotations. This method returns the |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
458 |
* synthesized container annotation or null IFF all repeating |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
459 |
* annotation are invalid. This method reports errors/warnings. |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
460 |
*/ |
15385 | 461 |
private <T extends Attribute.Compound> T processRepeatedAnnotations(List<T> annotations, |
462 |
AnnotateRepeatedContext<T> ctx, |
|
463 |
Symbol on) { |
|
464 |
T firstOccurrence = annotations.head; |
|
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
465 |
List<Attribute> repeated = List.nil(); |
14804
f93a8d60b9a4
8001114: Container annotation is not checked for semantic correctness
jfranck
parents:
14359
diff
changeset
|
466 |
Type origAnnoType = null; |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
467 |
Type arrayOfOrigAnnoType = null; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
468 |
Type targetContainerType = null; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
469 |
MethodSymbol containerValueSymbol = null; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
470 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
471 |
Assert.check(!annotations.isEmpty() && |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
472 |
!annotations.tail.isEmpty()); // i.e. size() > 1 |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
473 |
|
16342
28d6ae9ed67c
7196531: Duplicate error messages on repeating annotations
jfranck
parents:
15385
diff
changeset
|
474 |
int count = 0; |
15385 | 475 |
for (List<T> al = annotations; |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
476 |
!al.isEmpty(); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
477 |
al = al.tail) |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
478 |
{ |
16342
28d6ae9ed67c
7196531: Duplicate error messages on repeating annotations
jfranck
parents:
15385
diff
changeset
|
479 |
count++; |
28d6ae9ed67c
7196531: Duplicate error messages on repeating annotations
jfranck
parents:
15385
diff
changeset
|
480 |
|
28d6ae9ed67c
7196531: Duplicate error messages on repeating annotations
jfranck
parents:
15385
diff
changeset
|
481 |
// 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
|
482 |
Assert.check(count > 1 || !al.tail.isEmpty()); |
28d6ae9ed67c
7196531: Duplicate error messages on repeating annotations
jfranck
parents:
15385
diff
changeset
|
483 |
|
15385 | 484 |
T currentAnno = al.head; |
13689
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 |
origAnnoType = currentAnno.type; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
487 |
if (arrayOfOrigAnnoType == null) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
488 |
arrayOfOrigAnnoType = types.makeArrayType(origAnnoType); |
15385 | 489 |
} |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
490 |
|
16342
28d6ae9ed67c
7196531: Duplicate error messages on repeating annotations
jfranck
parents:
15385
diff
changeset
|
491 |
// 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
|
492 |
boolean reportError = count > 1; |
28d6ae9ed67c
7196531: Duplicate error messages on repeating annotations
jfranck
parents:
15385
diff
changeset
|
493 |
Type currentContainerType = getContainingType(currentAnno, ctx.pos.get(currentAnno), reportError); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
494 |
if (currentContainerType == null) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
495 |
continue; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
496 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
497 |
// Assert that the target Container is == for all repeated |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
498 |
// annos of the same annotation type, the types should |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
499 |
// come from the same Symbol, i.e. be '==' |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
500 |
Assert.check(targetContainerType == null || currentContainerType == targetContainerType); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
501 |
targetContainerType = currentContainerType; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
502 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
503 |
containerValueSymbol = validateContainer(targetContainerType, origAnnoType, ctx.pos.get(currentAnno)); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
504 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
505 |
if (containerValueSymbol == null) { // Check of CA type failed |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
506 |
// errors are already reported |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
507 |
continue; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
508 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
509 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
510 |
repeated = repeated.prepend(currentAnno); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
511 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
512 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
513 |
if (!repeated.isEmpty()) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
514 |
repeated = repeated.reverse(); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
515 |
TreeMaker m = make.at(ctx.pos.get(firstOccurrence)); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
516 |
Pair<MethodSymbol, Attribute> p = |
22165
ec53c8946fc2
8030807: langtools should still build using jdk 7
vromero
parents:
22163
diff
changeset
|
517 |
new Pair<MethodSymbol, Attribute>(containerValueSymbol, |
22163 | 518 |
new Attribute.Array(arrayOfOrigAnnoType, repeated)); |
15385 | 519 |
if (ctx.isTypeCompound) { |
520 |
/* TODO: the following code would be cleaner: |
|
521 |
Attribute.TypeCompound at = new Attribute.TypeCompound(targetContainerType, List.of(p), |
|
522 |
((Attribute.TypeCompound)annotations.head).position); |
|
523 |
JCTypeAnnotation annoTree = m.TypeAnnotation(at); |
|
524 |
at = enterTypeAnnotation(annoTree, targetContainerType, ctx.env); |
|
525 |
*/ |
|
526 |
// However, we directly construct the TypeCompound to keep the |
|
527 |
// direct relation to the contained TypeCompounds. |
|
528 |
Attribute.TypeCompound at = new Attribute.TypeCompound(targetContainerType, List.of(p), |
|
529 |
((Attribute.TypeCompound)annotations.head).position); |
|
14804
f93a8d60b9a4
8001114: Container annotation is not checked for semantic correctness
jfranck
parents:
14359
diff
changeset
|
530 |
|
15385 | 531 |
// TODO: annotation applicability checks from below? |
532 |
||
533 |
at.setSynthesized(true); |
|
14804
f93a8d60b9a4
8001114: Container annotation is not checked for semantic correctness
jfranck
parents:
14359
diff
changeset
|
534 |
|
15385 | 535 |
@SuppressWarnings("unchecked") |
536 |
T x = (T) at; |
|
537 |
return x; |
|
538 |
} else { |
|
539 |
Attribute.Compound c = new Attribute.Compound(targetContainerType, List.of(p)); |
|
540 |
JCAnnotation annoTree = m.Annotation(c); |
|
541 |
||
542 |
if (!chk.annotationApplicable(annoTree, on)) |
|
543 |
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
|
544 |
|
15385 | 545 |
if (!chk.validateAnnotationDeferErrors(annoTree)) |
546 |
log.error(annoTree.pos(), "duplicate.annotation.invalid.repeated", origAnnoType); |
|
547 |
||
548 |
c = enterAnnotation(annoTree, targetContainerType, ctx.env); |
|
549 |
c.setSynthesized(true); |
|
550 |
||
551 |
@SuppressWarnings("unchecked") |
|
552 |
T x = (T) c; |
|
553 |
return x; |
|
554 |
} |
|
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
555 |
} else { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
556 |
return null; // errors should have been reported elsewhere |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
557 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
558 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
559 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
560 |
/** Fetches the actual Type that should be the containing annotation. */ |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
561 |
private Type getContainingType(Attribute.Compound currentAnno, |
16342
28d6ae9ed67c
7196531: Duplicate error messages on repeating annotations
jfranck
parents:
15385
diff
changeset
|
562 |
DiagnosticPosition pos, |
28d6ae9ed67c
7196531: Duplicate error messages on repeating annotations
jfranck
parents:
15385
diff
changeset
|
563 |
boolean reportError) |
13689
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 |
Type origAnnoType = currentAnno.type; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
566 |
TypeSymbol origAnnoDecl = origAnnoType.tsym; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
567 |
|
15356
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14961
diff
changeset
|
568 |
// Fetch the Repeatable annotation from the current |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
569 |
// 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
|
570 |
Attribute.Compound ca = origAnnoDecl.attribute(syms.repeatableType.tsym); |
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14961
diff
changeset
|
571 |
if (ca == null) { // has no Repeatable annotation |
16342
28d6ae9ed67c
7196531: Duplicate error messages on repeating annotations
jfranck
parents:
15385
diff
changeset
|
572 |
if (reportError) |
28d6ae9ed67c
7196531: Duplicate error messages on repeating annotations
jfranck
parents:
15385
diff
changeset
|
573 |
log.error(pos, "duplicate.annotation.missing.container", origAnnoType, syms.repeatableType); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
574 |
return null; |
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 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
577 |
return filterSame(extractContainingType(ca, pos, origAnnoDecl), |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
578 |
origAnnoType); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
579 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
580 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
581 |
// returns null if t is same as 's', returns 't' otherwise |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
582 |
private Type filterSame(Type t, Type s) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
583 |
if (t == null || s == null) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
584 |
return t; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
585 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
586 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
587 |
return types.isSameType(t, s) ? null : t; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
588 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
589 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
590 |
/** Extract the actual Type to be used for a containing annotation. */ |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
591 |
private Type extractContainingType(Attribute.Compound ca, |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
592 |
DiagnosticPosition pos, |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
593 |
TypeSymbol annoDecl) |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
594 |
{ |
15356
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14961
diff
changeset
|
595 |
// The next three checks check that the Repeatable annotation |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
596 |
// on the declaration of the annotation type that is repeating is |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
597 |
// valid. |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
598 |
|
15356
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14961
diff
changeset
|
599 |
// Repeatable must have at least one element |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
600 |
if (ca.values.isEmpty()) { |
15356
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14961
diff
changeset
|
601 |
log.error(pos, "invalid.repeatable.annotation", annoDecl); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
602 |
return null; |
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 |
Pair<MethodSymbol,Attribute> p = ca.values.head; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
605 |
Name name = p.fst.name; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
606 |
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
|
607 |
log.error(pos, "invalid.repeatable.annotation", annoDecl); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
608 |
return null; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
609 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
610 |
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
|
611 |
log.error(pos, "invalid.repeatable.annotation", annoDecl); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
612 |
return null; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
613 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
614 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
615 |
return ((Attribute.Class)p.snd).getValue(); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
616 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
617 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
618 |
/* Validate that the suggested targetContainerType Type is a valid |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
619 |
* container type for repeated instances of originalAnnoType |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
620 |
* annotations. Return null and report errors if this is not the |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
621 |
* case, return the MethodSymbol of the value element in |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
622 |
* targetContainerType if it is suitable (this is needed to |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
623 |
* synthesize the container). */ |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
624 |
private MethodSymbol validateContainer(Type targetContainerType, |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
625 |
Type originalAnnoType, |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
626 |
DiagnosticPosition pos) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
627 |
MethodSymbol containerValueSymbol = null; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
628 |
boolean fatalError = false; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
629 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
630 |
// Validate that there is a (and only 1) value method |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
631 |
Scope scope = targetContainerType.tsym.members(); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
632 |
int nr_value_elems = 0; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
633 |
boolean error = false; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
634 |
for(Symbol elm : scope.getElementsByName(names.value)) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
635 |
nr_value_elems++; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
636 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
637 |
if (nr_value_elems == 1 && |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
638 |
elm.kind == Kinds.MTH) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
639 |
containerValueSymbol = (MethodSymbol)elm; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
640 |
} else { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
641 |
error = true; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
642 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
643 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
644 |
if (error) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
645 |
log.error(pos, |
15356
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14961
diff
changeset
|
646 |
"invalid.repeatable.annotation.multiple.values", |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
647 |
targetContainerType, |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
648 |
nr_value_elems); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
649 |
return null; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
650 |
} else if (nr_value_elems == 0) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
651 |
log.error(pos, |
15356
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14961
diff
changeset
|
652 |
"invalid.repeatable.annotation.no.value", |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
653 |
targetContainerType); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
654 |
return null; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
655 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
656 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
657 |
// validate that the 'value' element is a method |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
658 |
// probably "impossible" to fail this |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
659 |
if (containerValueSymbol.kind != Kinds.MTH) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
660 |
log.error(pos, |
15356
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14961
diff
changeset
|
661 |
"invalid.repeatable.annotation.invalid.value", |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
662 |
targetContainerType); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
663 |
fatalError = true; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
664 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
665 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
666 |
// validate that the 'value' element has the correct return type |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
667 |
// i.e. array of original anno |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
668 |
Type valueRetType = containerValueSymbol.type.getReturnType(); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
669 |
Type expectedType = types.makeArrayType(originalAnnoType); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
670 |
if (!(types.isArray(valueRetType) && |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
671 |
types.isSameType(expectedType, valueRetType))) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
672 |
log.error(pos, |
15356
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14961
diff
changeset
|
673 |
"invalid.repeatable.annotation.value.return", |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
674 |
targetContainerType, |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
675 |
valueRetType, |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
676 |
expectedType); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
677 |
fatalError = true; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
678 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
679 |
if (error) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
680 |
fatalError = true; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
681 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
682 |
|
15356
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14961
diff
changeset
|
683 |
// The conditions for a valid containing annotation are made |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
684 |
// in Check.validateRepeatedAnnotaton(); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
685 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
686 |
return fatalError ? null : containerValueSymbol; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
687 |
} |
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
688 |
|
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
689 |
/* ******************************************************************** |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
690 |
* Annotation processing |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
691 |
*********************************************************************/ |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
692 |
|
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
693 |
/** Queue annotations for later processing. */ |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
694 |
void annotateLater(final List<JCAnnotation> annotations, |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
695 |
final Env<AttrContext> localEnv, |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
696 |
final Symbol s, |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
697 |
final DiagnosticPosition deferPos) { |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
698 |
if (annotations.isEmpty()) { |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
699 |
return; |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
700 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
701 |
if (s.kind != PCK) { |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
702 |
s.resetAnnotations(); // mark Annotations as incomplete for now |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
703 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
704 |
normal(new Annotate.Worker() { |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
705 |
@Override |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
706 |
public String toString() { |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
707 |
return "annotate " + annotations + " onto " + s + " in " + s.owner; |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
708 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
709 |
|
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
710 |
@Override |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
711 |
public void run() { |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
712 |
Assert.check(s.kind == PCK || s.annotationsPendingCompletion()); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
713 |
JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
714 |
DiagnosticPosition prevLintPos = |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
715 |
deferPos != null |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
716 |
? deferredLintHandler.setPos(deferPos) |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
717 |
: deferredLintHandler.immediate(); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
718 |
Lint prevLint = deferPos != null ? null : chk.setLint(lint); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
719 |
try { |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
720 |
if (s.hasAnnotations() && |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
721 |
annotations.nonEmpty()) |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
722 |
log.error(annotations.head.pos, |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
723 |
"already.annotated", |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
724 |
kindName(s), s); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
725 |
actualEnterAnnotations(annotations, localEnv, s); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
726 |
} finally { |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
727 |
if (prevLint != null) |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
728 |
chk.setLint(prevLint); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
729 |
deferredLintHandler.setPos(prevLintPos); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
730 |
log.useSource(prev); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
731 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
732 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
733 |
}); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
734 |
|
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
735 |
validate(new Annotate.Worker() { //validate annotations |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
736 |
@Override |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
737 |
public void run() { |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
738 |
JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
739 |
try { |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
740 |
chk.validateAnnotations(annotations, s); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
741 |
} finally { |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
742 |
log.useSource(prev); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
743 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
744 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
745 |
}); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
746 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
747 |
|
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
748 |
/** Enter a set of annotations. */ |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
749 |
private void actualEnterAnnotations(List<JCAnnotation> annotations, |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
750 |
Env<AttrContext> env, |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
751 |
Symbol s) { |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
752 |
Map<TypeSymbol, ListBuffer<Attribute.Compound>> annotated = new LinkedHashMap<>(); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
753 |
Map<Attribute.Compound, DiagnosticPosition> pos = new HashMap<>(); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
754 |
|
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
755 |
for (List<JCAnnotation> al = annotations; !al.isEmpty(); al = al.tail) { |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
756 |
JCAnnotation a = al.head; |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
757 |
Attribute.Compound c = enterAnnotation(a, syms.annotationType, env); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
758 |
if (c == null) { |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
759 |
continue; |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
760 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
761 |
|
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
762 |
if (annotated.containsKey(a.type.tsym)) { |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
763 |
if (!allowRepeatedAnnos) { |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
764 |
log.error(a.pos(), "repeatable.annotations.not.supported.in.source"); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
765 |
allowRepeatedAnnos = true; |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
766 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
767 |
ListBuffer<Attribute.Compound> l = annotated.get(a.type.tsym); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
768 |
l = l.append(c); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
769 |
annotated.put(a.type.tsym, l); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
770 |
pos.put(c, a.pos()); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
771 |
} else { |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
772 |
annotated.put(a.type.tsym, ListBuffer.of(c)); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
773 |
pos.put(c, a.pos()); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
774 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
775 |
|
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
776 |
// Note: @Deprecated has no effect on local variables and parameters |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
777 |
if (!c.type.isErroneous() |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
778 |
&& s.owner.kind != MTH |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
779 |
&& types.isSameType(c.type, syms.deprecatedType)) { |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
780 |
s.flags_field |= Flags.DEPRECATED; |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
781 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
782 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
783 |
|
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
784 |
s.setDeclarationAttributesWithCompletion( |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
785 |
new AnnotateRepeatedContext<>(env, annotated, pos, log, false)); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
786 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
787 |
|
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
788 |
/* |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
789 |
* If the symbol is non-null, attach the type annotation to it. |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
790 |
*/ |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
791 |
private void actualEnterTypeAnnotations(final List<JCAnnotation> annotations, |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
792 |
final Env<AttrContext> env, |
23129
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
793 |
final Symbol s, |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
794 |
final DiagnosticPosition deferPos) { |
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
795 |
Map<TypeSymbol, ListBuffer<Attribute.TypeCompound>> annotated = new LinkedHashMap<>(); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
796 |
Map<Attribute.TypeCompound, DiagnosticPosition> pos = new HashMap<>(); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
797 |
|
23129
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
798 |
JavaFileObject prev = log.useSource(env.toplevel.sourcefile); |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
799 |
DiagnosticPosition prevLintPos = null; |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
800 |
|
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
801 |
if (deferPos != null) { |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
802 |
prevLintPos = deferredLintHandler.setPos(deferPos); |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
803 |
} |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
804 |
try { |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
805 |
|
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
806 |
for (List<JCAnnotation> al = annotations; !al.isEmpty(); al = al.tail) { |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
807 |
JCAnnotation a = al.head; |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
808 |
Attribute.TypeCompound tc = |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
809 |
enterTypeAnnotation(a, syms.annotationType, env); |
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
810 |
|
23129
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
811 |
if (tc == null) { |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
812 |
continue; |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
813 |
} |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
814 |
|
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
815 |
if (annotated.containsKey(a.type.tsym)) { |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
816 |
if (!allowRepeatedAnnos) { |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
817 |
log.error(a.pos(), "repeatable.annotations.not.supported.in.source"); |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
818 |
allowRepeatedAnnos = true; |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
819 |
} |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
820 |
ListBuffer<Attribute.TypeCompound> l = annotated.get(a.type.tsym); |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
821 |
l = l.append(tc); |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
822 |
annotated.put(a.type.tsym, l); |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
823 |
pos.put(tc, a.pos()); |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
824 |
} else { |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
825 |
annotated.put(a.type.tsym, ListBuffer.of(tc)); |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
826 |
pos.put(tc, a.pos()); |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
827 |
} |
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
828 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
829 |
|
23129
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
830 |
if (s != null) { |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
831 |
s.appendTypeAttributesWithCompletion( |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
832 |
new AnnotateRepeatedContext<>(env, annotated, pos, log, true)); |
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
833 |
} |
23129
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
834 |
} finally { |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
835 |
if (prevLintPos != null) |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
836 |
deferredLintHandler.setPos(prevLintPos); |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
837 |
log.useSource(prev); |
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
838 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
839 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
840 |
|
23129
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
841 |
public void annotateTypeLater(final JCTree tree, |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
842 |
final Env<AttrContext> env, |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
843 |
final Symbol sym, |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
844 |
final DiagnosticPosition deferPos) { |
23134
010b1b0d25fb
8036142: Remove redundant call to annotateTypeLater with null Symbol
emc
parents:
23129
diff
changeset
|
845 |
Assert.checkNonNull(sym); |
23129
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
846 |
normal(new Annotate.Worker() { |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
847 |
@Override |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
848 |
public String toString() { |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
849 |
return "type annotate " + tree + " onto " + sym + " in " + sym.owner; |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
850 |
} |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
851 |
@Override |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
852 |
public void run() { |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
853 |
tree.accept(new TypeAnnotate(env, sym, deferPos)); |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
854 |
} |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
855 |
}); |
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
856 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
857 |
|
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
858 |
/** |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
859 |
* We need to use a TreeScanner, because it is not enough to visit the top-level |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
860 |
* annotations. We also need to visit type arguments, etc. |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
861 |
*/ |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
862 |
private class TypeAnnotate extends TreeScanner { |
23129
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
863 |
private final Env<AttrContext> env; |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
864 |
private final Symbol sym; |
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
865 |
private DiagnosticPosition deferPos; |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
866 |
|
23129
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
867 |
public TypeAnnotate(final Env<AttrContext> env, |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
868 |
final Symbol sym, |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
869 |
final DiagnosticPosition deferPos) { |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
870 |
|
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
871 |
this.env = env; |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
872 |
this.sym = sym; |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
873 |
this.deferPos = deferPos; |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
874 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
875 |
|
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
876 |
@Override |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
877 |
public void visitAnnotatedType(final JCAnnotatedType tree) { |
23129
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
878 |
actualEnterTypeAnnotations(tree.annotations, env, sym, deferPos); |
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
879 |
super.visitAnnotatedType(tree); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
880 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
881 |
|
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
882 |
@Override |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
883 |
public void visitTypeParameter(final JCTypeParameter tree) { |
23129
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
884 |
actualEnterTypeAnnotations(tree.annotations, env, sym, deferPos); |
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
885 |
super.visitTypeParameter(tree); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
886 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
887 |
|
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
888 |
@Override |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
889 |
public void visitNewArray(final JCNewArray tree) { |
23129
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
890 |
actualEnterTypeAnnotations(tree.annotations, env, sym, deferPos); |
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
891 |
for (List<JCAnnotation> dimAnnos : tree.dimAnnotations) |
23129
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
892 |
actualEnterTypeAnnotations(dimAnnos, env, sym, deferPos); |
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
893 |
super.visitNewArray(tree); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
894 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
895 |
|
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
896 |
@Override |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
897 |
public void visitMethodDef(final JCMethodDecl tree) { |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
898 |
scan(tree.mods); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
899 |
scan(tree.restype); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
900 |
scan(tree.typarams); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
901 |
scan(tree.recvparam); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
902 |
scan(tree.params); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
903 |
scan(tree.thrown); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
904 |
scan(tree.defaultValue); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
905 |
// Do not annotate the body, just the signature. |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
906 |
// scan(tree.body); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
907 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
908 |
|
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
909 |
@Override |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
910 |
public void visitVarDef(final JCVariableDecl tree) { |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
911 |
DiagnosticPosition prevPos = deferPos; |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
912 |
deferPos = tree.pos(); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
913 |
try { |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
914 |
if (sym != null && sym.kind == Kinds.VAR) { |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
915 |
// Don't visit a parameter once when the sym is the method |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
916 |
// and once when the sym is the parameter. |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
917 |
scan(tree.mods); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
918 |
scan(tree.vartype); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
919 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
920 |
scan(tree.init); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
921 |
} finally { |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
922 |
deferPos = prevPos; |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
923 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
924 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
925 |
|
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
926 |
@Override |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
927 |
public void visitClassDef(JCClassDecl tree) { |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
928 |
// We can only hit a classdef if it is declared within |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
929 |
// a method. Ignore it - the class will be visited |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
930 |
// separately later. |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
931 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
932 |
|
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
933 |
@Override |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
934 |
public void visitNewClass(JCNewClass tree) { |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
935 |
if (tree.def == null) { |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
936 |
// For an anonymous class instantiation the class |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
937 |
// will be visited separately. |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
938 |
super.visitNewClass(tree); |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
939 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
940 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
941 |
} |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
942 |
} |