8253385: annotation processors remove varargs information from record components
Reviewed-by: jjg
This commit is contained in:
parent
166c728300
commit
97a81cee25
src/jdk.compiler/share/classes/com/sun/tools/javac/code
test/langtools/tools/javac/records
@ -1785,6 +1785,8 @@ public abstract class Symbol extends AnnoConstruct implements PoolConstant, Elem
|
|||||||
*/
|
*/
|
||||||
private final int pos;
|
private final int pos;
|
||||||
|
|
||||||
|
private final boolean isVarargs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a record component, given its flags, name, type and owner.
|
* 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);
|
super(PUBLIC, fieldDecl.sym.name, fieldDecl.sym.type, fieldDecl.sym.owner);
|
||||||
this.originalAnnos = annotations;
|
this.originalAnnos = annotations;
|
||||||
this.pos = fieldDecl.pos;
|
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 List<JCAnnotation> getOriginalAnnos() { return originalAnnos; }
|
||||||
|
|
||||||
public boolean isVarargs() {
|
public boolean isVarargs() {
|
||||||
return type.hasTag(TypeTag.ARRAY) && ((ArrayType)type).isVarargs();
|
return isVarargs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @DefinedBy(Api.LANGUAGE_MODEL)
|
@Override @DefinedBy(Api.LANGUAGE_MODEL)
|
||||||
|
@ -1672,4 +1672,39 @@ public class RecordCompilationTests extends CompilationTestCase {
|
|||||||
removeLastCompileOptions(2);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user