author | vromero |
Thu, 29 Jun 2017 07:19:44 -0700 | |
changeset 45753 | 567c159ce16f |
parent 45504 | ea7475564d07 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
43143
a8f5cdfa330a
8171528: Crash in Annotate with duplicate package-info declarations
vromero
parents:
42828
diff
changeset
|
2 |
* Copyright (c) 2003, 2017, 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 |
||
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
28 |
import com.sun.tools.javac.code.*; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
29 |
import com.sun.tools.javac.code.Attribute.Compound; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
30 |
import com.sun.tools.javac.code.Attribute.TypeCompound; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
31 |
import com.sun.tools.javac.code.Scope.WriteableScope; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
32 |
import com.sun.tools.javac.code.Symbol.*; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
33 |
import com.sun.tools.javac.code.TypeMetadata.Entry.Kind; |
29960
d20c04ed8ffe
8043984: Confusing (incorrect) error message on repeatable annotations
alundblad
parents:
29842
diff
changeset
|
34 |
import com.sun.tools.javac.resources.CompilerProperties.Errors; |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
35 |
import com.sun.tools.javac.tree.JCTree; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
36 |
import com.sun.tools.javac.tree.JCTree.*; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
37 |
import com.sun.tools.javac.tree.TreeInfo; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
38 |
import com.sun.tools.javac.tree.TreeMaker; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
39 |
import com.sun.tools.javac.tree.TreeScanner; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
40 |
import com.sun.tools.javac.util.*; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
41 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
42 |
import com.sun.tools.javac.util.List; |
15385 | 43 |
|
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
44 |
import javax.tools.JavaFileObject; |
45500
365640343c55
8181464: Invalid lambda in annotation causes NPE in Lint.augment
vromero
parents:
43269
diff
changeset
|
45 |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
46 |
import java.util.*; |
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
47 |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
48 |
import static com.sun.tools.javac.code.Flags.SYNTHETIC; |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41637
diff
changeset
|
49 |
import static com.sun.tools.javac.code.Kinds.Kind.MDL; |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
50 |
import static com.sun.tools.javac.code.Kinds.Kind.MTH; |
43143
a8f5cdfa330a
8171528: Crash in Annotate with duplicate package-info declarations
vromero
parents:
42828
diff
changeset
|
51 |
import static com.sun.tools.javac.code.Kinds.Kind.PCK; |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
52 |
import static com.sun.tools.javac.code.Kinds.Kind.VAR; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
53 |
import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14054
diff
changeset
|
54 |
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
|
55 |
import static com.sun.tools.javac.code.TypeTag.CLASS; |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
56 |
import static com.sun.tools.javac.tree.JCTree.Tag.ANNOTATION; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
57 |
import static com.sun.tools.javac.tree.JCTree.Tag.ASSIGN; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
58 |
import static com.sun.tools.javac.tree.JCTree.Tag.IDENT; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
59 |
import static com.sun.tools.javac.tree.JCTree.Tag.NEWARRAY; |
45500
365640343c55
8181464: Invalid lambda in annotation causes NPE in Lint.augment
vromero
parents:
43269
diff
changeset
|
60 |
|
40504
0a01f6710c84
8078561: Error message should be generated once when -source 6 is specified
jlahoda
parents:
34762
diff
changeset
|
61 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag; |
10950 | 62 |
|
45500
365640343c55
8181464: Invalid lambda in annotation causes NPE in Lint.augment
vromero
parents:
43269
diff
changeset
|
63 |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
64 |
/** Enter annotations onto symbols and types (and trees). |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
65 |
* |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
66 |
* This is also a pseudo stage in the compiler taking care of scheduling when annotations are |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
67 |
* entered. |
10 | 68 |
* |
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
69 |
* <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
|
70 |
* If you write code that depends on this, you do so at your own risk. |
10 | 71 |
* This code and its internal interfaces are subject to change or |
72 |
* deletion without notice.</b> |
|
73 |
*/ |
|
74 |
public class Annotate { |
|
22163 | 75 |
protected static final Context.Key<Annotate> annotateKey = new Context.Key<>(); |
10 | 76 |
|
77 |
public static Annotate instance(Context context) { |
|
78 |
Annotate instance = context.get(annotateKey); |
|
79 |
if (instance == null) |
|
80 |
instance = new Annotate(context); |
|
81 |
return instance; |
|
82 |
} |
|
83 |
||
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
84 |
private final Attr attr; |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
85 |
private final Check chk; |
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
86 |
private final ConstFold cfolder; |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
87 |
private final DeferredLintHandler deferredLintHandler; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
88 |
private final Enter enter; |
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
89 |
private final Lint lint; |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
90 |
private final Log log; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
91 |
private final Names names; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
92 |
private final Resolve resolve; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
93 |
private final TreeMaker make; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
94 |
private final Symtab syms; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
95 |
private final TypeEnvs typeEnvs; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
96 |
private final Types types; |
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
97 |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
98 |
private final Attribute theUnfinishedDefaultValue; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
99 |
private final boolean allowRepeatedAnnos; |
41031
9075bf88387b
8138822: Source version error missing version number
dlsmith
parents:
40504
diff
changeset
|
100 |
private final String sourceName; |
10 | 101 |
|
102 |
protected Annotate(Context context) { |
|
103 |
context.put(annotateKey, this); |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
104 |
|
10 | 105 |
attr = Attr.instance(context); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
106 |
chk = Check.instance(context); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
107 |
cfolder = ConstFold.instance(context); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
108 |
deferredLintHandler = DeferredLintHandler.instance(context); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
109 |
enter = Enter.instance(context); |
10 | 110 |
log = Log.instance(context); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
111 |
lint = Lint.instance(context); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
112 |
make = TreeMaker.instance(context); |
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
113 |
names = Names.instance(context); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
114 |
resolve = Resolve.instance(context); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
115 |
syms = Symtab.instance(context); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
116 |
typeEnvs = TypeEnvs.instance(context); |
10 | 117 |
types = Types.instance(context); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
118 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
119 |
theUnfinishedDefaultValue = new Attribute.Error(syms.errType); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
120 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
121 |
Source source = Source.instance(context); |
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
122 |
allowRepeatedAnnos = source.allowRepeatedAnnotations(); |
41031
9075bf88387b
8138822: Source version error missing version number
dlsmith
parents:
40504
diff
changeset
|
123 |
sourceName = source.name; |
43269
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43143
diff
changeset
|
124 |
|
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43143
diff
changeset
|
125 |
blockCount = 1; |
10 | 126 |
} |
127 |
||
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
128 |
/** Semaphore to delay annotation processing */ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
129 |
private int blockCount = 0; |
10 | 130 |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
131 |
/** Called when annotations processing needs to be postponed. */ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
132 |
public void blockAnnotations() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
133 |
blockCount++; |
10 | 134 |
} |
135 |
||
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
136 |
/** Called when annotation processing can be resumed. */ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
137 |
public void unblockAnnotations() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
138 |
blockCount--; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
139 |
if (blockCount == 0) |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
140 |
flush(); |
10 | 141 |
} |
142 |
||
21043
3b000be15694
8026286: Improper locking of annotation queues causes assertion failures.
emc
parents:
21041
diff
changeset
|
143 |
/** Variant which allows for a delayed flush of annotations. |
3b000be15694
8026286: Improper locking of annotation queues causes assertion failures.
emc
parents:
21041
diff
changeset
|
144 |
* Needed by ClassReader */ |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
145 |
public void unblockAnnotationsNoFlush() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
146 |
blockCount--; |
21043
3b000be15694
8026286: Improper locking of annotation queues causes assertion failures.
emc
parents:
21041
diff
changeset
|
147 |
} |
3b000be15694
8026286: Improper locking of annotation queues causes assertion failures.
emc
parents:
21041
diff
changeset
|
148 |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
149 |
/** are we blocking annotation processing? */ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
150 |
public boolean annotationsBlocked() {return blockCount > 0; } |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
151 |
|
43269
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43143
diff
changeset
|
152 |
public void enterDone() { |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43143
diff
changeset
|
153 |
unblockAnnotations(); |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43143
diff
changeset
|
154 |
} |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43143
diff
changeset
|
155 |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
156 |
public List<TypeCompound> fromAnnotations(List<JCAnnotation> annotations) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
157 |
if (annotations.isEmpty()) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
158 |
return List.nil(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
159 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
160 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
161 |
ListBuffer<TypeCompound> buf = new ListBuffer<>(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
162 |
for (JCAnnotation anno : annotations) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
163 |
Assert.checkNonNull(anno.attribute); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
164 |
buf.append((TypeCompound) anno.attribute); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
165 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
166 |
return buf.toList(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
167 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
168 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
169 |
/** Annotate (used for everything else) */ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
170 |
public void normal(Runnable r) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
171 |
q.append(r); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
172 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
173 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
174 |
/** Validate, triggers after 'normal' */ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
175 |
public void validate(Runnable a) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
176 |
validateQ.append(a); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
177 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
178 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
179 |
/** Flush all annotation queues */ |
10 | 180 |
public void flush() { |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
181 |
if (annotationsBlocked()) return; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
182 |
if (isFlushing()) return; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
183 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
184 |
startFlushing(); |
10 | 185 |
try { |
15385 | 186 |
while (q.nonEmpty()) { |
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
187 |
q.next().run(); |
15385 | 188 |
} |
189 |
while (typesQ.nonEmpty()) { |
|
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
190 |
typesQ.next().run(); |
15385 | 191 |
} |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
192 |
while (afterTypesQ.nonEmpty()) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
193 |
afterTypesQ.next().run(); |
15385 | 194 |
} |
21018
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
195 |
while (validateQ.nonEmpty()) { |
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
196 |
validateQ.next().run(); |
21018
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
197 |
} |
10 | 198 |
} finally { |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
199 |
doneFlushing(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
200 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
201 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
202 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
203 |
private ListBuffer<Runnable> q = new ListBuffer<>(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
204 |
private ListBuffer<Runnable> validateQ = new ListBuffer<>(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
205 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
206 |
private int flushCount = 0; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
207 |
private boolean isFlushing() { return flushCount > 0; } |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
208 |
private void startFlushing() { flushCount++; } |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
209 |
private void doneFlushing() { flushCount--; } |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
210 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
211 |
ListBuffer<Runnable> typesQ = new ListBuffer<>(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
212 |
ListBuffer<Runnable> afterTypesQ = new ListBuffer<>(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
213 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
214 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
215 |
public void typeAnnotation(Runnable a) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
216 |
typesQ.append(a); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
217 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
218 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
219 |
public void afterTypes(Runnable a) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
220 |
afterTypesQ.append(a); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
221 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
222 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
223 |
/** |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
224 |
* Queue annotations for later attribution and entering. This is probably the method you are looking for. |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
225 |
* |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
226 |
* @param annotations the list of JCAnnotations to attribute and enter |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
227 |
* @param localEnv the enclosing env |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
228 |
* @param s ths Symbol on which to enter the annotations |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
229 |
* @param deferPos report errors here |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
230 |
*/ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
231 |
public void annotateLater(List<JCAnnotation> annotations, Env<AttrContext> localEnv, |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
232 |
Symbol s, DiagnosticPosition deferPos) |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
233 |
{ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
234 |
if (annotations.isEmpty()) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
235 |
return; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
236 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
237 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
238 |
s.resetAnnotations(); // mark Annotations as incomplete for now |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
239 |
|
34762
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
240 |
normal(() -> { |
43143
a8f5cdfa330a
8171528: Crash in Annotate with duplicate package-info declarations
vromero
parents:
42828
diff
changeset
|
241 |
// Packages are unusual, in that they are the only type of declaration that can legally appear |
a8f5cdfa330a
8171528: Crash in Annotate with duplicate package-info declarations
vromero
parents:
42828
diff
changeset
|
242 |
// more than once in a compilation, and in all cases refer to the same underlying symbol. |
a8f5cdfa330a
8171528: Crash in Annotate with duplicate package-info declarations
vromero
parents:
42828
diff
changeset
|
243 |
// This means they are the only kind of declaration that syntactically may have multiple sets |
a8f5cdfa330a
8171528: Crash in Annotate with duplicate package-info declarations
vromero
parents:
42828
diff
changeset
|
244 |
// of annotations, each on a different package declaration, even though that is ultimately |
a8f5cdfa330a
8171528: Crash in Annotate with duplicate package-info declarations
vromero
parents:
42828
diff
changeset
|
245 |
// forbidden by JLS 8 section 7.4. |
a8f5cdfa330a
8171528: Crash in Annotate with duplicate package-info declarations
vromero
parents:
42828
diff
changeset
|
246 |
// The corollary here is that all of the annotations on a package symbol may have already |
a8f5cdfa330a
8171528: Crash in Annotate with duplicate package-info declarations
vromero
parents:
42828
diff
changeset
|
247 |
// been handled, meaning that the set of annotations pending completion is now empty. |
a8f5cdfa330a
8171528: Crash in Annotate with duplicate package-info declarations
vromero
parents:
42828
diff
changeset
|
248 |
Assert.check(s.kind == PCK || s.annotationsPendingCompletion()); |
34762
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
249 |
JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
250 |
DiagnosticPosition prevLintPos = |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
251 |
deferPos != null |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
252 |
? deferredLintHandler.setPos(deferPos) |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
253 |
: deferredLintHandler.immediate(); |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
254 |
Lint prevLint = deferPos != null ? null : chk.setLint(lint); |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
255 |
try { |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
256 |
if (s.hasAnnotations() && annotations.nonEmpty()) |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45500
diff
changeset
|
257 |
log.error(annotations.head.pos, Errors.AlreadyAnnotated(Kinds.kindName(s), s)); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
258 |
|
34762
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
259 |
Assert.checkNonNull(s, "Symbol argument to actualEnterAnnotations is null"); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
260 |
|
34762
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
261 |
// false is passed as fifth parameter since annotateLater is |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
262 |
// never called for a type parameter |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
263 |
annotateNow(s, annotations, localEnv, false, false); |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
264 |
} finally { |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
265 |
if (prevLint != null) |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
266 |
chk.setLint(prevLint); |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
267 |
deferredLintHandler.setPos(prevLintPos); |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
268 |
log.useSource(prev); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
269 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
270 |
}); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
271 |
|
34762
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
272 |
validate(() -> { //validate annotations |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
273 |
JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
274 |
try { |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
275 |
chk.validateAnnotations(annotations, s); |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
276 |
} finally { |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
277 |
log.useSource(prev); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
278 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
279 |
}); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
280 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
281 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
282 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
283 |
/** Queue processing of an attribute default value. */ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
284 |
public void annotateDefaultValueLater(JCExpression defaultValue, Env<AttrContext> localEnv, |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
285 |
MethodSymbol m, DiagnosticPosition deferPos) |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
286 |
{ |
34762
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
287 |
normal(() -> { |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
288 |
JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
289 |
DiagnosticPosition prevLintPos = deferredLintHandler.setPos(deferPos); |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
290 |
try { |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
291 |
enterDefaultValue(defaultValue, localEnv, m); |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
292 |
} finally { |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
293 |
deferredLintHandler.setPos(prevLintPos); |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
294 |
log.useSource(prev); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
295 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
296 |
}); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
297 |
|
34762
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
298 |
validate(() -> { //validate annotations |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
299 |
JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
300 |
try { |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
301 |
// if default value is an annotation, check it is a well-formed |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
302 |
// annotation value (e.g. no duplicate values, no missing values, etc.) |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
303 |
chk.validateAnnotationTree(defaultValue); |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
304 |
} finally { |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
305 |
log.useSource(prev); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
306 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
307 |
}); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
308 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
309 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
310 |
/** Enter a default value for an annotation element. */ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
311 |
private void enterDefaultValue(JCExpression defaultValue, |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
312 |
Env<AttrContext> localEnv, MethodSymbol m) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
313 |
m.defaultValue = attributeAnnotationValue(m.type.getReturnType(), defaultValue, localEnv); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
314 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
315 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
316 |
/** |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
317 |
* Gather up annotations into a map from type symbols to lists of Compound attributes, |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
318 |
* then continue on with repeating annotations processing. |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
319 |
*/ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
320 |
private <T extends Attribute.Compound> void annotateNow(Symbol toAnnotate, |
30069
5686d5e44a83
8044196: Incorrect applying of repeatable annotations with incompatible target to type parameter
alundblad
parents:
30066
diff
changeset
|
321 |
List<JCAnnotation> withAnnotations, Env<AttrContext> env, boolean typeAnnotations, |
5686d5e44a83
8044196: Incorrect applying of repeatable annotations with incompatible target to type parameter
alundblad
parents:
30066
diff
changeset
|
322 |
boolean isTypeParam) |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
323 |
{ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
324 |
Map<TypeSymbol, ListBuffer<T>> annotated = new LinkedHashMap<>(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
325 |
Map<T, DiagnosticPosition> pos = new HashMap<>(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
326 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
327 |
for (List<JCAnnotation> al = withAnnotations; !al.isEmpty(); al = al.tail) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
328 |
JCAnnotation a = al.head; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
329 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
330 |
T c; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
331 |
if (typeAnnotations) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
332 |
@SuppressWarnings("unchecked") |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
333 |
T tmp = (T)attributeTypeAnnotation(a, syms.annotationType, env); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
334 |
c = tmp; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
335 |
} else { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
336 |
@SuppressWarnings("unchecked") |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
337 |
T tmp = (T)attributeAnnotation(a, syms.annotationType, env); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
338 |
c = tmp; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
339 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
340 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
341 |
Assert.checkNonNull(c, "Failed to create annotation"); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
342 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
343 |
if (annotated.containsKey(a.type.tsym)) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
344 |
if (!allowRepeatedAnnos) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45500
diff
changeset
|
345 |
log.error(DiagnosticFlag.SOURCE_LEVEL, a.pos(), Errors.RepeatableAnnotationsNotSupportedInSource(sourceName)); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
346 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
347 |
ListBuffer<T> l = annotated.get(a.type.tsym); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
348 |
l = l.append(c); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
349 |
annotated.put(a.type.tsym, l); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
350 |
pos.put(c, a.pos()); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
351 |
} else { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
352 |
annotated.put(a.type.tsym, ListBuffer.of(c)); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
353 |
pos.put(c, a.pos()); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
354 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
355 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
356 |
// Note: @Deprecated has no effect on local variables and parameters |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
357 |
if (!c.type.isErroneous() |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41637
diff
changeset
|
358 |
&& (toAnnotate.kind == MDL || toAnnotate.owner.kind != MTH) |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
359 |
&& types.isSameType(c.type, syms.deprecatedType)) { |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41637
diff
changeset
|
360 |
toAnnotate.flags_field |= (Flags.DEPRECATED | Flags.DEPRECATED_ANNOTATION); |
41637 | 361 |
Attribute fr = c.member(names.forRemoval); |
362 |
if (fr instanceof Attribute.Constant) { |
|
363 |
Attribute.Constant v = (Attribute.Constant) fr; |
|
364 |
if (v.type == syms.booleanType && ((Integer) v.value) != 0) { |
|
365 |
toAnnotate.flags_field |= Flags.DEPRECATED_REMOVAL; |
|
366 |
} |
|
367 |
} |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
368 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
369 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
370 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
371 |
List<T> buf = List.nil(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
372 |
for (ListBuffer<T> lb : annotated.values()) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
373 |
if (lb.size() == 1) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
374 |
buf = buf.prepend(lb.first()); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
375 |
} else { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
376 |
AnnotationContext<T> ctx = new AnnotationContext<>(env, annotated, pos, typeAnnotations); |
30069
5686d5e44a83
8044196: Incorrect applying of repeatable annotations with incompatible target to type parameter
alundblad
parents:
30066
diff
changeset
|
377 |
T res = makeContainerAnnotation(lb.toList(), ctx, toAnnotate, isTypeParam); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
378 |
if (res != null) |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
379 |
buf = buf.prepend(res); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
380 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
381 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
382 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
383 |
if (typeAnnotations) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
384 |
@SuppressWarnings("unchecked") |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
385 |
List<TypeCompound> attrs = (List<TypeCompound>)buf.reverse(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
386 |
toAnnotate.appendUniqueTypeAttributes(attrs); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
387 |
} else { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
388 |
@SuppressWarnings("unchecked") |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
389 |
List<Attribute.Compound> attrs = (List<Attribute.Compound>)buf.reverse(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
390 |
toAnnotate.resetAnnotations(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
391 |
toAnnotate.setDeclarationAttributes(attrs); |
10 | 392 |
} |
393 |
} |
|
394 |
||
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
395 |
/** |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
396 |
* Attribute and store a semantic representation of the annotation tree {@code tree} into the |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
397 |
* tree.attribute field. |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
398 |
* |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
399 |
* @param tree the tree representing an annotation |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
400 |
* @param expectedAnnotationType the expected (super)type of the annotation |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
401 |
* @param env the current env in where the annotation instance is found |
10 | 402 |
*/ |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
403 |
public Attribute.Compound attributeAnnotation(JCAnnotation tree, Type expectedAnnotationType, |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
404 |
Env<AttrContext> env) |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
405 |
{ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
406 |
// The attribute might have been entered if it is Target or Repetable |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
407 |
// Because TreeCopier does not copy type, redo this if type is null |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
408 |
if (tree.attribute != null && tree.type != null) |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
409 |
return tree.attribute; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
410 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
411 |
List<Pair<MethodSymbol, Attribute>> elems = attributeAnnotationValues(tree, expectedAnnotationType, env); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
412 |
Attribute.Compound ac = new Attribute.Compound(tree.type, elems); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
413 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
414 |
return tree.attribute = ac; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
415 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
416 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
417 |
/** Attribute and store a semantic representation of the type annotation tree {@code tree} into |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
418 |
* the tree.attribute field. |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
419 |
* |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
420 |
* @param a the tree representing an annotation |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
421 |
* @param expectedAnnotationType the expected (super)type of the annotation |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
422 |
* @param env the the current env in where the annotation instance is found |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
423 |
*/ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
424 |
public Attribute.TypeCompound attributeTypeAnnotation(JCAnnotation a, Type expectedAnnotationType, |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
425 |
Env<AttrContext> env) |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
426 |
{ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
427 |
// The attribute might have been entered if it is Target or Repetable |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
428 |
// Because TreeCopier does not copy type, redo this if type is null |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
429 |
if (a.attribute == null || a.type == null || !(a.attribute instanceof Attribute.TypeCompound)) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
430 |
// Create a new TypeCompound |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
431 |
List<Pair<MethodSymbol,Attribute>> elems = |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
432 |
attributeAnnotationValues(a, expectedAnnotationType, env); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
433 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
434 |
Attribute.TypeCompound tc = |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
435 |
new Attribute.TypeCompound(a.type, elems, TypeAnnotationPosition.unknown); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
436 |
a.attribute = tc; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
437 |
return tc; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
438 |
} else { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
439 |
// Use an existing TypeCompound |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
440 |
return (Attribute.TypeCompound)a.attribute; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
441 |
} |
10 | 442 |
} |
443 |
||
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
444 |
/** |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
445 |
* Attribute annotation elements creating a list of pairs of the Symbol representing that |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
446 |
* element and the value of that element as an Attribute. */ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
447 |
private List<Pair<MethodSymbol, Attribute>> attributeAnnotationValues(JCAnnotation a, |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
448 |
Type expected, Env<AttrContext> env) |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
449 |
{ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
450 |
// The annotation might have had its type attributed (but not |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
451 |
// checked) by attr.attribAnnotationTypes during MemberEnter, |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
452 |
// in which case we do not need to do it again. |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
453 |
Type at = (a.annotationType.type != null ? |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
454 |
a.annotationType.type : attr.attribType(a.annotationType, env)); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
455 |
a.type = chk.checkType(a.annotationType.pos(), at, expected); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
456 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
457 |
boolean isError = a.type.isErroneous(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
458 |
if (!a.type.tsym.isAnnotationType() && !isError) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45500
diff
changeset
|
459 |
log.error(a.annotationType.pos(), Errors.NotAnnotationType(a.type)); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
460 |
isError = true; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
461 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
462 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
463 |
// List of name=value pairs (or implicit "value=" if size 1) |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
464 |
List<JCExpression> args = a.args; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
465 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
466 |
boolean elidedValue = false; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
467 |
// special case: elided "value=" assumed |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
468 |
if (args.length() == 1 && !args.head.hasTag(ASSIGN)) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
469 |
args.head = make.at(args.head.pos). |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
470 |
Assign(make.Ident(names.value), args.head); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
471 |
elidedValue = true; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
472 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
473 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
474 |
ListBuffer<Pair<MethodSymbol,Attribute>> buf = new ListBuffer<>(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
475 |
for (List<JCExpression> tl = args; tl.nonEmpty(); tl = tl.tail) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
476 |
Pair<MethodSymbol, Attribute> p = attributeAnnotationNameValuePair(tl.head, a.type, isError, env, elidedValue); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
477 |
if (p != null && !p.fst.type.isErroneous()) |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
478 |
buf.append(p); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
479 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
480 |
return buf.toList(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
481 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
482 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
483 |
// where |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
484 |
private Pair<MethodSymbol, Attribute> attributeAnnotationNameValuePair(JCExpression nameValuePair, |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
485 |
Type thisAnnotationType, boolean badAnnotation, Env<AttrContext> env, boolean elidedValue) |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
486 |
{ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
487 |
if (!nameValuePair.hasTag(ASSIGN)) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45500
diff
changeset
|
488 |
log.error(nameValuePair.pos(), Errors.AnnotationValueMustBeNameValue); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
489 |
attributeAnnotationValue(nameValuePair.type = syms.errType, nameValuePair, env); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
490 |
return null; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
491 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
492 |
JCAssign assign = (JCAssign)nameValuePair; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
493 |
if (!assign.lhs.hasTag(IDENT)) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45500
diff
changeset
|
494 |
log.error(nameValuePair.pos(), Errors.AnnotationValueMustBeNameValue); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
495 |
attributeAnnotationValue(nameValuePair.type = syms.errType, nameValuePair, env); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
496 |
return null; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
497 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
498 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
499 |
// Resolve element to MethodSym |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
500 |
JCIdent left = (JCIdent)assign.lhs; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
501 |
Symbol method = resolve.resolveQualifiedMethod(elidedValue ? assign.rhs.pos() : left.pos(), |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
502 |
env, thisAnnotationType, |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42407
diff
changeset
|
503 |
left.name, List.nil(), null); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
504 |
left.sym = method; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
505 |
left.type = method.type; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
506 |
if (method.owner != thisAnnotationType.tsym && !badAnnotation) |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45500
diff
changeset
|
507 |
log.error(left.pos(), Errors.NoAnnotationMember(left.name, thisAnnotationType)); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
508 |
Type resultType = method.type.getReturnType(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
509 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
510 |
// Compute value part |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
511 |
Attribute value = attributeAnnotationValue(resultType, assign.rhs, env); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
512 |
nameValuePair.type = resultType; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
513 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
514 |
return method.type.isErroneous() ? null : new Pair<>((MethodSymbol)method, value); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
515 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
516 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
517 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
518 |
/** Attribute an annotation element value */ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
519 |
private Attribute attributeAnnotationValue(Type expectedElementType, JCExpression tree, |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
520 |
Env<AttrContext> env) |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
521 |
{ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
522 |
//first, try completing the symbol for the annotation value - if acompletion |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
523 |
//error is thrown, we should recover gracefully, and display an |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
524 |
//ordinary resolution diagnostic. |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
525 |
try { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
526 |
expectedElementType.tsym.complete(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
527 |
} catch(CompletionFailure e) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45500
diff
changeset
|
528 |
log.error(tree.pos(), Errors.CantResolve(Kinds.kindName(e.sym), e.sym.getQualifiedName(), null, null)); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
529 |
expectedElementType = syms.errType; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
530 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
531 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
532 |
if (expectedElementType.hasTag(ARRAY)) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
533 |
return getAnnotationArrayValue(expectedElementType, tree, env); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
534 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
535 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
536 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
537 |
//error recovery |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
538 |
if (tree.hasTag(NEWARRAY)) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
539 |
if (!expectedElementType.isErroneous()) |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45500
diff
changeset
|
540 |
log.error(tree.pos(), Errors.AnnotationValueNotAllowableType); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
541 |
JCNewArray na = (JCNewArray)tree; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
542 |
if (na.elemtype != null) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45500
diff
changeset
|
543 |
log.error(na.elemtype.pos(), Errors.NewNotAllowedInAnnotation); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
544 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
545 |
for (List<JCExpression> l = na.elems; l.nonEmpty(); l=l.tail) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
546 |
attributeAnnotationValue(syms.errType, |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
547 |
l.head, |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
548 |
env); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
549 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
550 |
return new Attribute.Error(syms.errType); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
551 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
552 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
553 |
if (expectedElementType.tsym.isAnnotationType()) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
554 |
if (tree.hasTag(ANNOTATION)) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
555 |
return attributeAnnotation((JCAnnotation)tree, expectedElementType, env); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
556 |
} else { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45500
diff
changeset
|
557 |
log.error(tree.pos(), Errors.AnnotationValueMustBeAnnotation); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
558 |
expectedElementType = syms.errType; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
559 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
560 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
561 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
562 |
//error recovery |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
563 |
if (tree.hasTag(ANNOTATION)) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
564 |
if (!expectedElementType.isErroneous()) |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45500
diff
changeset
|
565 |
log.error(tree.pos(), Errors.AnnotationNotValidForType(expectedElementType)); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
566 |
attributeAnnotation((JCAnnotation)tree, syms.errType, env); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
567 |
return new Attribute.Error(((JCAnnotation)tree).annotationType.type); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
568 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
569 |
|
45500
365640343c55
8181464: Invalid lambda in annotation causes NPE in Lint.augment
vromero
parents:
43269
diff
changeset
|
570 |
MemberEnter.InitTreeVisitor initTreeVisitor = new MemberEnter.InitTreeVisitor() { |
365640343c55
8181464: Invalid lambda in annotation causes NPE in Lint.augment
vromero
parents:
43269
diff
changeset
|
571 |
// the methods below are added to allow class literals on top of constant expressions |
365640343c55
8181464: Invalid lambda in annotation causes NPE in Lint.augment
vromero
parents:
43269
diff
changeset
|
572 |
@Override |
365640343c55
8181464: Invalid lambda in annotation causes NPE in Lint.augment
vromero
parents:
43269
diff
changeset
|
573 |
public void visitTypeIdent(JCPrimitiveTypeTree that) {} |
365640343c55
8181464: Invalid lambda in annotation causes NPE in Lint.augment
vromero
parents:
43269
diff
changeset
|
574 |
|
365640343c55
8181464: Invalid lambda in annotation causes NPE in Lint.augment
vromero
parents:
43269
diff
changeset
|
575 |
@Override |
365640343c55
8181464: Invalid lambda in annotation causes NPE in Lint.augment
vromero
parents:
43269
diff
changeset
|
576 |
public void visitTypeArray(JCArrayTypeTree that) {} |
365640343c55
8181464: Invalid lambda in annotation causes NPE in Lint.augment
vromero
parents:
43269
diff
changeset
|
577 |
}; |
365640343c55
8181464: Invalid lambda in annotation causes NPE in Lint.augment
vromero
parents:
43269
diff
changeset
|
578 |
tree.accept(initTreeVisitor); |
365640343c55
8181464: Invalid lambda in annotation causes NPE in Lint.augment
vromero
parents:
43269
diff
changeset
|
579 |
if (!initTreeVisitor.result) { |
365640343c55
8181464: Invalid lambda in annotation causes NPE in Lint.augment
vromero
parents:
43269
diff
changeset
|
580 |
log.error(tree.pos(), Errors.ExpressionNotAllowableAsAnnotationValue); |
365640343c55
8181464: Invalid lambda in annotation causes NPE in Lint.augment
vromero
parents:
43269
diff
changeset
|
581 |
return new Attribute.Error(syms.errType); |
365640343c55
8181464: Invalid lambda in annotation causes NPE in Lint.augment
vromero
parents:
43269
diff
changeset
|
582 |
} |
365640343c55
8181464: Invalid lambda in annotation causes NPE in Lint.augment
vromero
parents:
43269
diff
changeset
|
583 |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
584 |
if (expectedElementType.isPrimitive() || |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
585 |
(types.isSameType(expectedElementType, syms.stringType) && !expectedElementType.hasTag(TypeTag.ERROR))) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
586 |
return getAnnotationPrimitiveValue(expectedElementType, tree, env); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
587 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
588 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
589 |
if (expectedElementType.tsym == syms.classType.tsym) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
590 |
return getAnnotationClassValue(expectedElementType, tree, env); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
591 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
592 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
593 |
if (expectedElementType.hasTag(CLASS) && |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
594 |
(expectedElementType.tsym.flags() & Flags.ENUM) != 0) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
595 |
return getAnnotationEnumValue(expectedElementType, tree, env); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
596 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
597 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
598 |
//error recovery: |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
599 |
if (!expectedElementType.isErroneous()) |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45500
diff
changeset
|
600 |
log.error(tree.pos(), Errors.AnnotationValueNotAllowableType); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
601 |
return new Attribute.Error(attr.attribExpr(tree, env, expectedElementType)); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
602 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
603 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
604 |
private Attribute getAnnotationEnumValue(Type expectedElementType, JCExpression tree, Env<AttrContext> env) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
605 |
Type result = attr.attribExpr(tree, env, expectedElementType); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
606 |
Symbol sym = TreeInfo.symbol(tree); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
607 |
if (sym == null || |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
608 |
TreeInfo.nonstaticSelect(tree) || |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
609 |
sym.kind != VAR || |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
610 |
(sym.flags() & Flags.ENUM) == 0) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45500
diff
changeset
|
611 |
log.error(tree.pos(), Errors.EnumAnnotationMustBeEnumConstant); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
612 |
return new Attribute.Error(result.getOriginalType()); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
613 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
614 |
VarSymbol enumerator = (VarSymbol) sym; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
615 |
return new Attribute.Enum(expectedElementType, enumerator); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
616 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
617 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
618 |
private Attribute getAnnotationClassValue(Type expectedElementType, JCExpression tree, Env<AttrContext> env) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
619 |
Type result = attr.attribExpr(tree, env, expectedElementType); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
620 |
if (result.isErroneous()) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
621 |
// Does it look like an unresolved class literal? |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
622 |
if (TreeInfo.name(tree) == names._class && |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
623 |
((JCFieldAccess) tree).selected.type.isErroneous()) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
624 |
Name n = (((JCFieldAccess) tree).selected).type.tsym.flatName(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
625 |
return new Attribute.UnresolvedClass(expectedElementType, |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
626 |
types.createErrorType(n, |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
627 |
syms.unknownSymbol, syms.classType)); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
628 |
} else { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
629 |
return new Attribute.Error(result.getOriginalType()); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
630 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
631 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
632 |
|
45753 | 633 |
// Class literals look like field accesses of a field named class |
634 |
// at the tree level |
|
635 |
if (TreeInfo.name(tree) != names._class) { |
|
636 |
log.error(tree.pos(), Errors.AnnotationValueMustBeClassLiteral); |
|
637 |
return new Attribute.Error(syms.errType); |
|
638 |
} |
|
639 |
||
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
640 |
return new Attribute.Class(types, |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
641 |
(((JCFieldAccess) tree).selected).type); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
642 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
643 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
644 |
private Attribute getAnnotationPrimitiveValue(Type expectedElementType, JCExpression tree, Env<AttrContext> env) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
645 |
Type result = attr.attribExpr(tree, env, expectedElementType); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
646 |
if (result.isErroneous()) |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
647 |
return new Attribute.Error(result.getOriginalType()); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
648 |
if (result.constValue() == null) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45500
diff
changeset
|
649 |
log.error(tree.pos(), Errors.AttributeValueMustBeConstant); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
650 |
return new Attribute.Error(expectedElementType); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
651 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
652 |
result = cfolder.coerce(result, expectedElementType); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
653 |
return new Attribute.Constant(expectedElementType, result.constValue()); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
654 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
655 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
656 |
private Attribute getAnnotationArrayValue(Type expectedElementType, JCExpression tree, Env<AttrContext> env) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
657 |
// Special case, implicit array |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
658 |
if (!tree.hasTag(NEWARRAY)) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
659 |
tree = make.at(tree.pos). |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42407
diff
changeset
|
660 |
NewArray(null, List.nil(), List.of(tree)); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
661 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
662 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
663 |
JCNewArray na = (JCNewArray)tree; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
664 |
if (na.elemtype != null) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45500
diff
changeset
|
665 |
log.error(na.elemtype.pos(), Errors.NewNotAllowedInAnnotation); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
666 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
667 |
ListBuffer<Attribute> buf = new ListBuffer<>(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
668 |
for (List<JCExpression> l = na.elems; l.nonEmpty(); l=l.tail) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
669 |
buf.append(attributeAnnotationValue(types.elemtype(expectedElementType), |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
670 |
l.head, |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
671 |
env)); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
672 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
673 |
na.type = expectedElementType; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
674 |
return new Attribute. |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
675 |
Array(expectedElementType, buf.toArray(new Attribute[buf.length()])); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
676 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
677 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
678 |
/* ********************************* |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
679 |
* Support for repeating annotations |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
680 |
***********************************/ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
681 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
682 |
/** |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
683 |
* This context contains all the information needed to synthesize new |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
684 |
* annotations trees for repeating annotations. |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
685 |
*/ |
23814
06ab27895804
8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents:
23397
diff
changeset
|
686 |
private class AnnotationContext<T extends Attribute.Compound> { |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
687 |
public final Env<AttrContext> env; |
15385 | 688 |
public final Map<Symbol.TypeSymbol, ListBuffer<T>> annotated; |
689 |
public final Map<T, JCDiagnostic.DiagnosticPosition> pos; |
|
690 |
public final boolean isTypeCompound; |
|
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
691 |
|
23814
06ab27895804
8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents:
23397
diff
changeset
|
692 |
public AnnotationContext(Env<AttrContext> env, |
06ab27895804
8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents:
23397
diff
changeset
|
693 |
Map<Symbol.TypeSymbol, ListBuffer<T>> annotated, |
06ab27895804
8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents:
23397
diff
changeset
|
694 |
Map<T, JCDiagnostic.DiagnosticPosition> pos, |
06ab27895804
8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents:
23397
diff
changeset
|
695 |
boolean isTypeCompound) { |
13840
a365c561f4de
7196774: javac cannot be built with JDK 6 after 7151010
jjg
parents:
13689
diff
changeset
|
696 |
Assert.checkNonNull(env); |
a365c561f4de
7196774: javac cannot be built with JDK 6 after 7151010
jjg
parents:
13689
diff
changeset
|
697 |
Assert.checkNonNull(annotated); |
a365c561f4de
7196774: javac cannot be built with JDK 6 after 7151010
jjg
parents:
13689
diff
changeset
|
698 |
Assert.checkNonNull(pos); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
699 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
700 |
this.env = env; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
701 |
this.annotated = annotated; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
702 |
this.pos = pos; |
15385 | 703 |
this.isTypeCompound = isTypeCompound; |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
704 |
} |
23814
06ab27895804
8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents:
23397
diff
changeset
|
705 |
} |
06ab27895804
8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents:
23397
diff
changeset
|
706 |
|
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
707 |
/* Process repeated annotations. This method returns the |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
708 |
* synthesized container annotation or null IFF all repeating |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
709 |
* annotation are invalid. This method reports errors/warnings. |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
710 |
*/ |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
711 |
private <T extends Attribute.Compound> T processRepeatedAnnotations(List<T> annotations, |
30069
5686d5e44a83
8044196: Incorrect applying of repeatable annotations with incompatible target to type parameter
alundblad
parents:
30066
diff
changeset
|
712 |
AnnotationContext<T> ctx, Symbol on, boolean isTypeParam) |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
713 |
{ |
15385 | 714 |
T firstOccurrence = annotations.head; |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
715 |
List<Attribute> repeated = List.nil(); |
14804
f93a8d60b9a4
8001114: Container annotation is not checked for semantic correctness
jfranck
parents:
14359
diff
changeset
|
716 |
Type origAnnoType = null; |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
717 |
Type arrayOfOrigAnnoType = null; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
718 |
Type targetContainerType = null; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
719 |
MethodSymbol containerValueSymbol = null; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
720 |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
721 |
Assert.check(!annotations.isEmpty() && !annotations.tail.isEmpty()); // i.e. size() > 1 |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
722 |
|
16342
28d6ae9ed67c
7196531: Duplicate error messages on repeating annotations
jfranck
parents:
15385
diff
changeset
|
723 |
int count = 0; |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
724 |
for (List<T> al = annotations; !al.isEmpty(); al = al.tail) { |
16342
28d6ae9ed67c
7196531: Duplicate error messages on repeating annotations
jfranck
parents:
15385
diff
changeset
|
725 |
count++; |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
726 |
|
16342
28d6ae9ed67c
7196531: Duplicate error messages on repeating annotations
jfranck
parents:
15385
diff
changeset
|
727 |
// 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
|
728 |
Assert.check(count > 1 || !al.tail.isEmpty()); |
28d6ae9ed67c
7196531: Duplicate error messages on repeating annotations
jfranck
parents:
15385
diff
changeset
|
729 |
|
15385 | 730 |
T currentAnno = al.head; |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
731 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
732 |
origAnnoType = currentAnno.type; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
733 |
if (arrayOfOrigAnnoType == null) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
734 |
arrayOfOrigAnnoType = types.makeArrayType(origAnnoType); |
15385 | 735 |
} |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
736 |
|
16342
28d6ae9ed67c
7196531: Duplicate error messages on repeating annotations
jfranck
parents:
15385
diff
changeset
|
737 |
// 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
|
738 |
boolean reportError = count > 1; |
28d6ae9ed67c
7196531: Duplicate error messages on repeating annotations
jfranck
parents:
15385
diff
changeset
|
739 |
Type currentContainerType = getContainingType(currentAnno, ctx.pos.get(currentAnno), reportError); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
740 |
if (currentContainerType == null) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
741 |
continue; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
742 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
743 |
// Assert that the target Container is == for all repeated |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
744 |
// annos of the same annotation type, the types should |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
745 |
// come from the same Symbol, i.e. be '==' |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
746 |
Assert.check(targetContainerType == null || currentContainerType == targetContainerType); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
747 |
targetContainerType = currentContainerType; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
748 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
749 |
containerValueSymbol = validateContainer(targetContainerType, origAnnoType, ctx.pos.get(currentAnno)); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
750 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
751 |
if (containerValueSymbol == null) { // Check of CA type failed |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
752 |
// errors are already reported |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
753 |
continue; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
754 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
755 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
756 |
repeated = repeated.prepend(currentAnno); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
757 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
758 |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
759 |
if (!repeated.isEmpty() && targetContainerType == null) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45500
diff
changeset
|
760 |
log.error(ctx.pos.get(annotations.head), Errors.DuplicateAnnotationInvalidRepeated(origAnnoType)); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
761 |
return null; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
762 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
763 |
|
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
764 |
if (!repeated.isEmpty()) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
765 |
repeated = repeated.reverse(); |
30069
5686d5e44a83
8044196: Incorrect applying of repeatable annotations with incompatible target to type parameter
alundblad
parents:
30066
diff
changeset
|
766 |
DiagnosticPosition pos = ctx.pos.get(firstOccurrence); |
5686d5e44a83
8044196: Incorrect applying of repeatable annotations with incompatible target to type parameter
alundblad
parents:
30066
diff
changeset
|
767 |
TreeMaker m = make.at(pos); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
768 |
Pair<MethodSymbol, Attribute> p = |
22165
ec53c8946fc2
8030807: langtools should still build using jdk 7
vromero
parents:
22163
diff
changeset
|
769 |
new Pair<MethodSymbol, Attribute>(containerValueSymbol, |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
770 |
new Attribute.Array(arrayOfOrigAnnoType, repeated)); |
15385 | 771 |
if (ctx.isTypeCompound) { |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
772 |
/* TODO: the following code would be cleaner: |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
773 |
Attribute.TypeCompound at = new Attribute.TypeCompound(targetContainerType, List.of(p), |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
774 |
((Attribute.TypeCompound)annotations.head).position); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
775 |
JCTypeAnnotation annoTree = m.TypeAnnotation(at); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
776 |
at = attributeTypeAnnotation(annoTree, targetContainerType, ctx.env); |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
777 |
*/ |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
778 |
// However, we directly construct the TypeCompound to keep the |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
779 |
// direct relation to the contained TypeCompounds. |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
780 |
Attribute.TypeCompound at = new Attribute.TypeCompound(targetContainerType, List.of(p), |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
781 |
((Attribute.TypeCompound)annotations.head).position); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
782 |
|
30069
5686d5e44a83
8044196: Incorrect applying of repeatable annotations with incompatible target to type parameter
alundblad
parents:
30066
diff
changeset
|
783 |
JCAnnotation annoTree = m.TypeAnnotation(at); |
5686d5e44a83
8044196: Incorrect applying of repeatable annotations with incompatible target to type parameter
alundblad
parents:
30066
diff
changeset
|
784 |
if (!chk.validateAnnotationDeferErrors(annoTree)) |
5686d5e44a83
8044196: Incorrect applying of repeatable annotations with incompatible target to type parameter
alundblad
parents:
30066
diff
changeset
|
785 |
log.error(annoTree.pos(), Errors.DuplicateAnnotationInvalidRepeated(origAnnoType)); |
5686d5e44a83
8044196: Incorrect applying of repeatable annotations with incompatible target to type parameter
alundblad
parents:
30066
diff
changeset
|
786 |
|
5686d5e44a83
8044196: Incorrect applying of repeatable annotations with incompatible target to type parameter
alundblad
parents:
30066
diff
changeset
|
787 |
if (!chk.isTypeAnnotation(annoTree, isTypeParam)) { |
5686d5e44a83
8044196: Incorrect applying of repeatable annotations with incompatible target to type parameter
alundblad
parents:
30066
diff
changeset
|
788 |
log.error(pos, isTypeParam ? Errors.InvalidRepeatableAnnotationNotApplicable(targetContainerType, on) |
5686d5e44a83
8044196: Incorrect applying of repeatable annotations with incompatible target to type parameter
alundblad
parents:
30066
diff
changeset
|
789 |
: Errors.InvalidRepeatableAnnotationNotApplicableInContext(targetContainerType)); |
5686d5e44a83
8044196: Incorrect applying of repeatable annotations with incompatible target to type parameter
alundblad
parents:
30066
diff
changeset
|
790 |
} |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
791 |
|
15385 | 792 |
at.setSynthesized(true); |
14804
f93a8d60b9a4
8001114: Container annotation is not checked for semantic correctness
jfranck
parents:
14359
diff
changeset
|
793 |
|
15385 | 794 |
@SuppressWarnings("unchecked") |
795 |
T x = (T) at; |
|
796 |
return x; |
|
797 |
} else { |
|
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
798 |
Attribute.Compound c = new Attribute.Compound(targetContainerType, List.of(p)); |
15385 | 799 |
JCAnnotation annoTree = m.Annotation(c); |
800 |
||
29960
d20c04ed8ffe
8043984: Confusing (incorrect) error message on repeatable annotations
alundblad
parents:
29842
diff
changeset
|
801 |
if (!chk.annotationApplicable(annoTree, on)) { |
d20c04ed8ffe
8043984: Confusing (incorrect) error message on repeatable annotations
alundblad
parents:
29842
diff
changeset
|
802 |
log.error(annoTree.pos(), |
d20c04ed8ffe
8043984: Confusing (incorrect) error message on repeatable annotations
alundblad
parents:
29842
diff
changeset
|
803 |
Errors.InvalidRepeatableAnnotationNotApplicable(targetContainerType, on)); |
d20c04ed8ffe
8043984: Confusing (incorrect) error message on repeatable annotations
alundblad
parents:
29842
diff
changeset
|
804 |
} |
14804
f93a8d60b9a4
8001114: Container annotation is not checked for semantic correctness
jfranck
parents:
14359
diff
changeset
|
805 |
|
15385 | 806 |
if (!chk.validateAnnotationDeferErrors(annoTree)) |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45500
diff
changeset
|
807 |
log.error(annoTree.pos(), Errors.DuplicateAnnotationInvalidRepeated(origAnnoType)); |
15385 | 808 |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
809 |
c = attributeAnnotation(annoTree, targetContainerType, ctx.env); |
15385 | 810 |
c.setSynthesized(true); |
811 |
||
812 |
@SuppressWarnings("unchecked") |
|
813 |
T x = (T) c; |
|
814 |
return x; |
|
815 |
} |
|
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
816 |
} else { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
817 |
return null; // errors should have been reported elsewhere |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
818 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
819 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
820 |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
821 |
/** |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
822 |
* Fetches the actual Type that should be the containing annotation. |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
823 |
*/ |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
824 |
private Type getContainingType(Attribute.Compound currentAnno, |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
825 |
DiagnosticPosition pos, |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
826 |
boolean reportError) |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
827 |
{ |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
828 |
Type origAnnoType = currentAnno.type; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
829 |
TypeSymbol origAnnoDecl = origAnnoType.tsym; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
830 |
|
15356
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14961
diff
changeset
|
831 |
// Fetch the Repeatable annotation from the current |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
832 |
// annotation's declaration, or null if it has none |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
833 |
Attribute.Compound ca = origAnnoDecl.getAnnotationTypeMetadata().getRepeatable(); |
15356
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14961
diff
changeset
|
834 |
if (ca == null) { // has no Repeatable annotation |
16342
28d6ae9ed67c
7196531: Duplicate error messages on repeating annotations
jfranck
parents:
15385
diff
changeset
|
835 |
if (reportError) |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45500
diff
changeset
|
836 |
log.error(pos, Errors.DuplicateAnnotationMissingContainer(origAnnoType)); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
837 |
return null; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
838 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
839 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
840 |
return filterSame(extractContainingType(ca, pos, origAnnoDecl), |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
841 |
origAnnoType); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
842 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
843 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
844 |
// returns null if t is same as 's', returns 't' otherwise |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
845 |
private Type filterSame(Type t, Type s) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
846 |
if (t == null || s == null) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
847 |
return t; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
848 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
849 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
850 |
return types.isSameType(t, s) ? null : t; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
851 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
852 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
853 |
/** Extract the actual Type to be used for a containing annotation. */ |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
854 |
private Type extractContainingType(Attribute.Compound ca, |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
855 |
DiagnosticPosition pos, |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
856 |
TypeSymbol annoDecl) |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
857 |
{ |
15356
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14961
diff
changeset
|
858 |
// The next three checks check that the Repeatable annotation |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
859 |
// on the declaration of the annotation type that is repeating is |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
860 |
// valid. |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
861 |
|
15356
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14961
diff
changeset
|
862 |
// Repeatable must have at least one element |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
863 |
if (ca.values.isEmpty()) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45500
diff
changeset
|
864 |
log.error(pos, Errors.InvalidRepeatableAnnotation(annoDecl)); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
865 |
return null; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
866 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
867 |
Pair<MethodSymbol,Attribute> p = ca.values.head; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
868 |
Name name = p.fst.name; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
869 |
if (name != names.value) { // should contain only one element, named "value" |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45500
diff
changeset
|
870 |
log.error(pos, Errors.InvalidRepeatableAnnotation(annoDecl)); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
871 |
return null; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
872 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
873 |
if (!(p.snd instanceof Attribute.Class)) { // check that the value of "value" is an Attribute.Class |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45500
diff
changeset
|
874 |
log.error(pos, Errors.InvalidRepeatableAnnotation(annoDecl)); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
875 |
return null; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
876 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
877 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
878 |
return ((Attribute.Class)p.snd).getValue(); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
879 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
880 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
881 |
/* Validate that the suggested targetContainerType Type is a valid |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
882 |
* container type for repeated instances of originalAnnoType |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
883 |
* annotations. Return null and report errors if this is not the |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
884 |
* case, return the MethodSymbol of the value element in |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
885 |
* targetContainerType if it is suitable (this is needed to |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
886 |
* synthesize the container). */ |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
887 |
private MethodSymbol validateContainer(Type targetContainerType, |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
888 |
Type originalAnnoType, |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
889 |
DiagnosticPosition pos) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
890 |
MethodSymbol containerValueSymbol = null; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
891 |
boolean fatalError = false; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
892 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
893 |
// Validate that there is a (and only 1) value method |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
894 |
Scope scope = targetContainerType.tsym.members(); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
895 |
int nr_value_elems = 0; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
896 |
boolean error = false; |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
24895
diff
changeset
|
897 |
for(Symbol elm : scope.getSymbolsByName(names.value)) { |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
898 |
nr_value_elems++; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
899 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
900 |
if (nr_value_elems == 1 && |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
901 |
elm.kind == MTH) { |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
902 |
containerValueSymbol = (MethodSymbol)elm; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
903 |
} else { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
904 |
error = true; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
905 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
906 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
907 |
if (error) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
908 |
log.error(pos, |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45500
diff
changeset
|
909 |
Errors.InvalidRepeatableAnnotationMultipleValues(targetContainerType, |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45500
diff
changeset
|
910 |
nr_value_elems)); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
911 |
return null; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
912 |
} else if (nr_value_elems == 0) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
913 |
log.error(pos, |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45500
diff
changeset
|
914 |
Errors.InvalidRepeatableAnnotationNoValue(targetContainerType)); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
915 |
return null; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
916 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
917 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
918 |
// validate that the 'value' element is a method |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
919 |
// probably "impossible" to fail this |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
27121
diff
changeset
|
920 |
if (containerValueSymbol.kind != MTH) { |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
921 |
log.error(pos, |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45500
diff
changeset
|
922 |
Errors.InvalidRepeatableAnnotationInvalidValue(targetContainerType)); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
923 |
fatalError = true; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
924 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
925 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
926 |
// validate that the 'value' element has the correct return type |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
927 |
// i.e. array of original anno |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
928 |
Type valueRetType = containerValueSymbol.type.getReturnType(); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
929 |
Type expectedType = types.makeArrayType(originalAnnoType); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
930 |
if (!(types.isArray(valueRetType) && |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
931 |
types.isSameType(expectedType, valueRetType))) { |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
932 |
log.error(pos, |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45500
diff
changeset
|
933 |
Errors.InvalidRepeatableAnnotationValueReturn(targetContainerType, |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45500
diff
changeset
|
934 |
valueRetType, |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45500
diff
changeset
|
935 |
expectedType)); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
936 |
fatalError = true; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
937 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
938 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
939 |
return fatalError ? null : containerValueSymbol; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
940 |
} |
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
941 |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
942 |
private <T extends Attribute.Compound> T makeContainerAnnotation(List<T> toBeReplaced, |
30069
5686d5e44a83
8044196: Incorrect applying of repeatable annotations with incompatible target to type parameter
alundblad
parents:
30066
diff
changeset
|
943 |
AnnotationContext<T> ctx, Symbol sym, boolean isTypeParam) |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
944 |
{ |
23814
06ab27895804
8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents:
23397
diff
changeset
|
945 |
// Process repeated annotations |
06ab27895804
8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents:
23397
diff
changeset
|
946 |
T validRepeated = |
30069
5686d5e44a83
8044196: Incorrect applying of repeatable annotations with incompatible target to type parameter
alundblad
parents:
30066
diff
changeset
|
947 |
processRepeatedAnnotations(toBeReplaced, ctx, sym, isTypeParam); |
23814
06ab27895804
8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents:
23397
diff
changeset
|
948 |
|
06ab27895804
8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents:
23397
diff
changeset
|
949 |
if (validRepeated != null) { |
06ab27895804
8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents:
23397
diff
changeset
|
950 |
// Check that the container isn't manually |
06ab27895804
8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents:
23397
diff
changeset
|
951 |
// present along with repeated instances of |
06ab27895804
8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents:
23397
diff
changeset
|
952 |
// its contained annotation. |
06ab27895804
8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents:
23397
diff
changeset
|
953 |
ListBuffer<T> manualContainer = ctx.annotated.get(validRepeated.type.tsym); |
06ab27895804
8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents:
23397
diff
changeset
|
954 |
if (manualContainer != null) { |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
955 |
log.error(ctx.pos.get(manualContainer.first()), |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45500
diff
changeset
|
956 |
Errors.InvalidRepeatableAnnotationRepeatedAndContainerPresent(manualContainer.first().type.tsym)); |
23814
06ab27895804
8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents:
23397
diff
changeset
|
957 |
} |
06ab27895804
8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents:
23397
diff
changeset
|
958 |
} |
06ab27895804
8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents:
23397
diff
changeset
|
959 |
|
06ab27895804
8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents:
23397
diff
changeset
|
960 |
// A null return will delete the Placeholder |
06ab27895804
8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents:
23397
diff
changeset
|
961 |
return validRepeated; |
06ab27895804
8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents:
23397
diff
changeset
|
962 |
} |
06ab27895804
8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents:
23397
diff
changeset
|
963 |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
964 |
/******************** |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
965 |
* Type annotations * |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
966 |
********************/ |
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
967 |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
968 |
/** |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
969 |
* Attribute the list of annotations and enter them onto s. |
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
970 |
*/ |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
971 |
public void enterTypeAnnotations(List<JCAnnotation> annotations, Env<AttrContext> env, |
30069
5686d5e44a83
8044196: Incorrect applying of repeatable annotations with incompatible target to type parameter
alundblad
parents:
30066
diff
changeset
|
972 |
Symbol s, DiagnosticPosition deferPos, boolean isTypeParam) |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
973 |
{ |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
974 |
Assert.checkNonNull(s, "Symbol argument to actualEnterTypeAnnotations is nul/"); |
23129
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
975 |
JavaFileObject prev = log.useSource(env.toplevel.sourcefile); |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
976 |
DiagnosticPosition prevLintPos = null; |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
977 |
|
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
978 |
if (deferPos != null) { |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
979 |
prevLintPos = deferredLintHandler.setPos(deferPos); |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
980 |
} |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
981 |
try { |
30069
5686d5e44a83
8044196: Incorrect applying of repeatable annotations with incompatible target to type parameter
alundblad
parents:
30066
diff
changeset
|
982 |
annotateNow(s, annotations, env, true, isTypeParam); |
23129
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
983 |
} finally { |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
984 |
if (prevLintPos != null) |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
985 |
deferredLintHandler.setPos(prevLintPos); |
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
986 |
log.useSource(prev); |
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
987 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
988 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
989 |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
990 |
/** |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
991 |
* Enqueue tree for scanning of type annotations, attaching to the Symbol sym. |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
992 |
*/ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
993 |
public void queueScanTreeAndTypeAnnotate(JCTree tree, Env<AttrContext> env, Symbol sym, |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
994 |
DiagnosticPosition deferPos) |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
995 |
{ |
23134
010b1b0d25fb
8036142: Remove redundant call to annotateTypeLater with null Symbol
emc
parents:
23129
diff
changeset
|
996 |
Assert.checkNonNull(sym); |
34762
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
997 |
normal(() -> tree.accept(new TypeAnnotate(env, sym, deferPos))); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
998 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
999 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1000 |
/** |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1001 |
* Apply the annotations to the particular type. |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1002 |
*/ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1003 |
public void annotateTypeSecondStage(JCTree tree, List<JCAnnotation> annotations, Type storeAt) { |
34762
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
1004 |
typeAnnotation(() -> { |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
1005 |
List<Attribute.TypeCompound> compounds = fromAnnotations(annotations); |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
1006 |
Assert.check(annotations.size() == compounds.size()); |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
1007 |
storeAt.getMetadataOfKind(Kind.ANNOTATIONS).combine(new TypeMetadata.Annotations(compounds)); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1008 |
}); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1009 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1010 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1011 |
/** |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1012 |
* Apply the annotations to the particular type. |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1013 |
*/ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1014 |
public void annotateTypeParameterSecondStage(JCTree tree, List<JCAnnotation> annotations) { |
34762
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
1015 |
typeAnnotation(() -> { |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
1016 |
List<Attribute.TypeCompound> compounds = fromAnnotations(annotations); |
d68b7daca533
8057548: Annotate.Worker should be replaced with lambdas
alundblad
parents:
33370
diff
changeset
|
1017 |
Assert.check(annotations.size() == compounds.size()); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1018 |
}); |
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
1019 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
1020 |
|
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 |
* 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
|
1023 |
* 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
|
1024 |
*/ |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1025 |
private class TypeAnnotate extends TreeScanner { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1026 |
private final Env<AttrContext> env; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1027 |
private final Symbol sym; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1028 |
private DiagnosticPosition deferPos; |
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
1029 |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1030 |
public TypeAnnotate(Env<AttrContext> env, Symbol sym, DiagnosticPosition deferPos) { |
23129
6d3b2e246dac
8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents:
23126
diff
changeset
|
1031 |
|
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1032 |
this.env = env; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1033 |
this.sym = sym; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1034 |
this.deferPos = deferPos; |
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 |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1038 |
public void visitAnnotatedType(JCAnnotatedType tree) { |
30069
5686d5e44a83
8044196: Incorrect applying of repeatable annotations with incompatible target to type parameter
alundblad
parents:
30066
diff
changeset
|
1039 |
enterTypeAnnotations(tree.annotations, env, sym, deferPos, false); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1040 |
scan(tree.underlyingType); |
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 |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1044 |
public void visitTypeParameter(JCTypeParameter tree) { |
30069
5686d5e44a83
8044196: Incorrect applying of repeatable annotations with incompatible target to type parameter
alundblad
parents:
30066
diff
changeset
|
1045 |
enterTypeAnnotations(tree.annotations, env, sym, deferPos, true); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1046 |
scan(tree.bounds); |
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
1047 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
1048 |
|
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
1049 |
@Override |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1050 |
public void visitNewArray(JCNewArray tree) { |
30069
5686d5e44a83
8044196: Incorrect applying of repeatable annotations with incompatible target to type parameter
alundblad
parents:
30066
diff
changeset
|
1051 |
enterTypeAnnotations(tree.annotations, env, sym, deferPos, false); |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1052 |
for (List<JCAnnotation> dimAnnos : tree.dimAnnotations) |
30069
5686d5e44a83
8044196: Incorrect applying of repeatable annotations with incompatible target to type parameter
alundblad
parents:
30066
diff
changeset
|
1053 |
enterTypeAnnotations(dimAnnos, env, sym, deferPos, false); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1054 |
scan(tree.elemtype); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1055 |
scan(tree.elems); |
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
1056 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
1057 |
|
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1058 |
@Override |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1059 |
public void visitMethodDef(JCMethodDecl tree) { |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1060 |
scan(tree.mods); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1061 |
scan(tree.restype); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1062 |
scan(tree.typarams); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1063 |
scan(tree.recvparam); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1064 |
scan(tree.params); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1065 |
scan(tree.thrown); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1066 |
scan(tree.defaultValue); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1067 |
// Do not annotate the body, just the signature. |
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
1068 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
1069 |
|
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1070 |
@Override |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1071 |
public void visitVarDef(JCVariableDecl tree) { |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1072 |
DiagnosticPosition prevPos = deferPos; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1073 |
deferPos = tree.pos(); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1074 |
try { |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
27121
diff
changeset
|
1075 |
if (sym != null && sym.kind == VAR) { |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1076 |
// 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
|
1077 |
// and once when the sym is the parameter. |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1078 |
scan(tree.mods); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1079 |
scan(tree.vartype); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1080 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1081 |
scan(tree.init); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1082 |
} finally { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1083 |
deferPos = prevPos; |
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
1084 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
1085 |
} |
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 |
@Override |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
1088 |
public void visitClassDef(JCClassDecl tree) { |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1089 |
// 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
|
1090 |
// a method. Ignore it - the class will be visited |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1091 |
// separately later. |
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
1092 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
1093 |
|
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
1094 |
@Override |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
1095 |
public void visitNewClass(JCNewClass tree) { |
33370
f563e436a81f
8057685: javac should not crash compiling type annotations
sadayapalam
parents:
30069
diff
changeset
|
1096 |
scan(tree.encl); |
f563e436a81f
8057685: javac should not crash compiling type annotations
sadayapalam
parents:
30069
diff
changeset
|
1097 |
scan(tree.typeargs); |
f563e436a81f
8057685: javac should not crash compiling type annotations
sadayapalam
parents:
30069
diff
changeset
|
1098 |
scan(tree.clazz); |
f563e436a81f
8057685: javac should not crash compiling type annotations
sadayapalam
parents:
30069
diff
changeset
|
1099 |
scan(tree.args); |
f563e436a81f
8057685: javac should not crash compiling type annotations
sadayapalam
parents:
30069
diff
changeset
|
1100 |
// the anonymous class instantiation if any will be visited separately. |
23126
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
1101 |
} |
1994a0d3b8de
8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents:
22702
diff
changeset
|
1102 |
} |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1103 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1104 |
/********************* |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1105 |
* Completer support * |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1106 |
*********************/ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1107 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1108 |
private AnnotationTypeCompleter theSourceCompleter = new AnnotationTypeCompleter() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1109 |
@Override |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1110 |
public void complete(ClassSymbol sym) throws CompletionFailure { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1111 |
Env<AttrContext> context = typeEnvs.get(sym); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1112 |
Annotate.this.attributeAnnotationType(context); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1113 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1114 |
}; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1115 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1116 |
/* Last stage completer to enter just enough annotations to have a prototype annotation type. |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1117 |
* This currently means entering @Target and @Repetable. |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1118 |
*/ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1119 |
public AnnotationTypeCompleter annotationTypeSourceCompleter() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1120 |
return theSourceCompleter; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1121 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1122 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1123 |
private void attributeAnnotationType(Env<AttrContext> env) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1124 |
Assert.check(((JCClassDecl)env.tree).sym.isAnnotationType(), |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1125 |
"Trying to annotation type complete a non-annotation type"); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1126 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1127 |
JavaFileObject prev = log.useSource(env.toplevel.sourcefile); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1128 |
try { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1129 |
JCClassDecl tree = (JCClassDecl)env.tree; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1130 |
AnnotationTypeVisitor v = new AnnotationTypeVisitor(attr, chk, syms, typeEnvs); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1131 |
v.scanAnnotationType(tree); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1132 |
tree.sym.getAnnotationTypeMetadata().setRepeatable(v.repeatable); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1133 |
tree.sym.getAnnotationTypeMetadata().setTarget(v.target); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1134 |
} finally { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1135 |
log.useSource(prev); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1136 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1137 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1138 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1139 |
public Attribute unfinishedDefaultValue() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1140 |
return theUnfinishedDefaultValue; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1141 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1142 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1143 |
public static interface AnnotationTypeCompleter { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1144 |
void complete(ClassSymbol sym) throws CompletionFailure; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1145 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1146 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1147 |
/** Visitor to determine a prototype annotation type for a class declaring an annotation type. |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1148 |
* |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1149 |
* <p><b>This is NOT part of any supported API. |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1150 |
* If you write code that depends on this, you do so at your own risk. |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1151 |
* This code and its internal interfaces are subject to change or |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1152 |
* deletion without notice.</b> |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1153 |
*/ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1154 |
public class AnnotationTypeVisitor extends TreeScanner { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1155 |
private Env<AttrContext> env; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1156 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1157 |
private final Attr attr; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1158 |
private final Check check; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1159 |
private final Symtab tab; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1160 |
private final TypeEnvs typeEnvs; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1161 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1162 |
private Compound target; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1163 |
private Compound repeatable; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1164 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1165 |
public AnnotationTypeVisitor(Attr attr, Check check, Symtab tab, TypeEnvs typeEnvs) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1166 |
this.attr = attr; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1167 |
this.check = check; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1168 |
this.tab = tab; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1169 |
this.typeEnvs = typeEnvs; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1170 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1171 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1172 |
public Compound getRepeatable() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1173 |
return repeatable; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1174 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1175 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1176 |
public Compound getTarget() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1177 |
return target; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1178 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1179 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1180 |
public void scanAnnotationType(JCClassDecl decl) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1181 |
visitClassDef(decl); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1182 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1183 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1184 |
@Override |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1185 |
public void visitClassDef(JCClassDecl tree) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1186 |
Env<AttrContext> prevEnv = env; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1187 |
env = typeEnvs.get(tree.sym); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1188 |
try { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1189 |
scan(tree.mods); // look for repeatable and target |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1190 |
// don't descend into body |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1191 |
} finally { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1192 |
env = prevEnv; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1193 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1194 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1195 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1196 |
@Override |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1197 |
public void visitAnnotation(JCAnnotation tree) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1198 |
Type t = tree.annotationType.type; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1199 |
if (t == null) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1200 |
t = attr.attribType(tree.annotationType, env); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1201 |
tree.annotationType.type = t = check.checkType(tree.annotationType.pos(), t, tab.annotationType); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1202 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1203 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1204 |
if (t == tab.annotationTargetType) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1205 |
target = Annotate.this.attributeAnnotation(tree, tab.annotationTargetType, env); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1206 |
} else if (t == tab.repeatableType) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1207 |
repeatable = Annotate.this.attributeAnnotation(tree, tab.repeatableType, env); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1208 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1209 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1210 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1211 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1212 |
/** Represents the semantics of an Annotation Type. |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1213 |
* |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1214 |
* <p><b>This is NOT part of any supported API. |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1215 |
* If you write code that depends on this, you do so at your own risk. |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1216 |
* This code and its internal interfaces are subject to change or |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1217 |
* deletion without notice.</b> |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1218 |
*/ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1219 |
public static class AnnotationTypeMetadata { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1220 |
final ClassSymbol metaDataFor; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1221 |
private Compound target; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1222 |
private Compound repeatable; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1223 |
private AnnotationTypeCompleter annotationTypeCompleter; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1224 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1225 |
public AnnotationTypeMetadata(ClassSymbol metaDataFor, AnnotationTypeCompleter annotationTypeCompleter) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1226 |
this.metaDataFor = metaDataFor; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1227 |
this.annotationTypeCompleter = annotationTypeCompleter; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1228 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1229 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1230 |
private void init() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1231 |
// Make sure metaDataFor is member entered |
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29960
diff
changeset
|
1232 |
while (!metaDataFor.isCompleted()) |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1233 |
metaDataFor.complete(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1234 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1235 |
if (annotationTypeCompleter != null) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1236 |
AnnotationTypeCompleter c = annotationTypeCompleter; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1237 |
annotationTypeCompleter = null; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1238 |
c.complete(metaDataFor); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1239 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1240 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1241 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1242 |
public void complete() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1243 |
init(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1244 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1245 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1246 |
public Compound getRepeatable() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1247 |
init(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1248 |
return repeatable; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1249 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1250 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1251 |
public void setRepeatable(Compound repeatable) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1252 |
Assert.checkNull(this.repeatable); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1253 |
this.repeatable = repeatable; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1254 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1255 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1256 |
public Compound getTarget() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1257 |
init(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1258 |
return target; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1259 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1260 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1261 |
public void setTarget(Compound target) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1262 |
Assert.checkNull(this.target); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1263 |
this.target = target; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1264 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1265 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1266 |
public Set<MethodSymbol> getAnnotationElements() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1267 |
init(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1268 |
Set<MethodSymbol> members = new LinkedHashSet<>(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1269 |
WriteableScope s = metaDataFor.members(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1270 |
Iterable<Symbol> ss = s.getSymbols(NON_RECURSIVE); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1271 |
for (Symbol sym : ss) |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1272 |
if (sym.kind == MTH && |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1273 |
sym.name != sym.name.table.names.clinit && |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1274 |
(sym.flags() & SYNTHETIC) == 0) |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1275 |
members.add((MethodSymbol)sym); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1276 |
return members; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1277 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1278 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1279 |
public Set<MethodSymbol> getAnnotationElementsWithDefault() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1280 |
init(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1281 |
Set<MethodSymbol> members = getAnnotationElements(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1282 |
Set<MethodSymbol> res = new LinkedHashSet<>(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1283 |
for (MethodSymbol m : members) |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1284 |
if (m.defaultValue != null) |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1285 |
res.add(m); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1286 |
return res; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1287 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1288 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1289 |
@Override |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1290 |
public String toString() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1291 |
return "Annotation type for: " + metaDataFor; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1292 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1293 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1294 |
public boolean isMetadataForAnnotationType() { return true; } |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1295 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1296 |
public static AnnotationTypeMetadata notAnAnnotationType() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1297 |
return NOT_AN_ANNOTATION_TYPE; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1298 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1299 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1300 |
private static final AnnotationTypeMetadata NOT_AN_ANNOTATION_TYPE = |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1301 |
new AnnotationTypeMetadata(null, null) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1302 |
@Override |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1303 |
public void complete() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1304 |
} // do nothing |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1305 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1306 |
@Override |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1307 |
public String toString() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1308 |
return "Not an annotation type"; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1309 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1310 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1311 |
@Override |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1312 |
public Set<MethodSymbol> getAnnotationElements() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1313 |
return new LinkedHashSet<>(0); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1314 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1315 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1316 |
@Override |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1317 |
public Set<MethodSymbol> getAnnotationElementsWithDefault() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1318 |
return new LinkedHashSet<>(0); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1319 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1320 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1321 |
@Override |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1322 |
public boolean isMetadataForAnnotationType() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1323 |
return false; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1324 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1325 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1326 |
@Override |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1327 |
public Compound getTarget() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1328 |
return null; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1329 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1330 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1331 |
@Override |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1332 |
public Compound getRepeatable() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1333 |
return null; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1334 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1335 |
}; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27224
diff
changeset
|
1336 |
} |
43269
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43143
diff
changeset
|
1337 |
|
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43143
diff
changeset
|
1338 |
public void newRound() { |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43143
diff
changeset
|
1339 |
blockCount = 1; |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43143
diff
changeset
|
1340 |
} |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
10950
diff
changeset
|
1341 |
} |