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