8253385: annotation processors remove varargs information from record components

Reviewed-by: jjg
This commit is contained in:
Vicente Romero 2020-11-04 23:30:41 +00:00
parent 166c728300
commit 97a81cee25
2 changed files with 44 additions and 1 deletions

View File

@ -1785,6 +1785,8 @@ public abstract class Symbol extends AnnoConstruct implements PoolConstant, Elem
*/
private final int pos;
private final boolean isVarargs;
/**
* Construct a record component, given its flags, name, type and owner.
*/
@ -1792,12 +1794,18 @@ public abstract class Symbol extends AnnoConstruct implements PoolConstant, Elem
super(PUBLIC, fieldDecl.sym.name, fieldDecl.sym.type, fieldDecl.sym.owner);
this.originalAnnos = annotations;
this.pos = fieldDecl.pos;
/* it is better to store the original information for this one, instead of relying
* on the info in the type of the symbol. This is because on the presence of APs
* the symbol will be blown out and we won't be able to know if the original
* record component was declared varargs or not.
*/
this.isVarargs = type.hasTag(TypeTag.ARRAY) && ((ArrayType)type).isVarargs();
}
public List<JCAnnotation> getOriginalAnnos() { return originalAnnos; }
public boolean isVarargs() {
return type.hasTag(TypeTag.ARRAY) && ((ArrayType)type).isVarargs();
return isVarargs;
}
@Override @DefinedBy(Api.LANGUAGE_MODEL)

View File

@ -1672,4 +1672,39 @@ public class RecordCompilationTests extends CompilationTestCase {
removeLastCompileOptions(2);
}
}
public void testAnnotationsOnVarargsRecComp() {
assertOK(
"""
import java.lang.annotation.*;
@Target({ElementType.TYPE_USE})
@interface Simple {}
record R(@Simple int... val) {
static void test() {
R rec = new R(10, 20);
}
}
"""
);
assertOK(
"""
import java.lang.annotation.*;
@Target({ElementType.TYPE_USE})
@interface SimpleContainer{ Simple[] value(); }
@Repeatable(SimpleContainer.class)
@Target({ElementType.TYPE_USE})
@interface Simple {}
record R(@Simple int... val) {
static void test() {
R rec = new R(10, 20);
}
}
"""
);
}
}