Type annotations on inner type that is an array components
B. Blaser
bsrbnd at gmail.com
Wed Jul 25 12:00:03 UTC 2018
Hi,
On 20 July 2018 at 03:40, Alex Buckley <alex.buckley at oracle.com> wrote:
> Hi Mike,
>
> javac's generation of target_path items for annotated nested types is
> clearly sub-par, and fixing this particular issue may tickle (or even
> create) related issues. I'd therefore lean towards this issue being a P3
> rather than a P4, although javac developers would govern.
>
> The rampdown schedule is at http://openjdk.java.net/projects/jdk/11/. I
> doubt that this P3 can be reported, fixed, tested, and reviewed by the start
> of RDP2, which is when a P3 (or P4) would expect to be dropped or deferred.
> Do you have a fix ready to go?
Currently, inner types within arrays don't seem to be addressed for
type annotations in declaration positions ('@TA(6)' for example, but
not '@TA(4)').
Does anyone already try to fix this?
If not, the following patch strives to fill this gap, tier1 is OK.
Is there any open issue about that?
Being not an expert in this area of the compiler, any comment or
subsequent explanation would be welcome.
Thanks,
Bernard
> (Please note that LTS is a non-factor in JEP 3, which describes the release
> process and is linked from the URL above.)
>
> Alex
diff -r b0fcf59be391
src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeAnnotations.java
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeAnnotations.java
Fri Jul 20 14:48:41 2018 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeAnnotations.java
Wed Jul 25 12:32:00 2018 +0200
@@ -423,9 +423,6 @@
return type;
}
- if (type.hasTag(TypeTag.ARRAY))
- return rewriteArrayType((ArrayType)type, annotations, pos);
-
if (type.hasTag(TypeTag.TYPEVAR)) {
return type.annotatedType(onlyTypeAnnotations);
} else if (type.getKind() == TypeKind.UNION) {
@@ -443,6 +440,14 @@
Element enclEl = type.asElement();
JCTree enclTr = typetree;
+ if (type.hasTag(TypeTag.ARRAY) && enclTr.getKind() !=
JCTree.Kind.ANNOTATED_TYPE) {
+ while (enclTy.hasTag(TypeTag.ARRAY)) {
+ enclTy = ((ArrayType)enclTy).elemtype;
+ }
+ enclEl = enclTy.asElement();
+ enclTr = ((JCArrayTypeTree)typetree).elemtype;
+ }
+
while (enclEl != null &&
enclEl.getKind() != ElementKind.PACKAGE &&
enclTy != null &&
@@ -523,9 +528,13 @@
p.location = p.location.appendList(depth.toList());
}
- Type ret = typeWithAnnotations(type, enclTy, annotations);
- typetree.type = ret;
- return ret;
+ if (type.hasTag(TypeTag.ARRAY))
+ return rewriteArrayType((ArrayType)type,
annotations, pos, depth.toList());
+ else {
+ Type ret = typeWithAnnotations(type, enclTy, annotations);
+ typetree.type = ret;
+ return ret;
+ }
}
}
@@ -536,7 +545,7 @@
*
* SIDE EFFECT: Update position for the annotations to be {@code pos}.
*/
- private Type rewriteArrayType(ArrayType type,
List<TypeCompound> annotations, TypeAnnotationPosition pos) {
+ private Type rewriteArrayType(ArrayType type,
List<TypeCompound> annotations, TypeAnnotationPosition pos,
List<TypePathEntry> depth) {
ArrayType tomodify = new ArrayType(type);
ArrayType res = tomodify;
@@ -581,7 +590,7 @@
for (TypeCompound tc : annotations) {
if (tc.position == null)
tc.position = pos;
- tc.position.location = loc;
+ tc.position.location = depth.prependList(loc);
}
return res;
More information about the compiler-dev
mailing list