@@ -1048,6 +1048,7 @@ protected void runPhase(Env<AttrContext> env) {
1048
1048
if ((sym .flags_field & RECORD ) != 0 ) {
1049
1049
List <JCVariableDecl > fields = TreeInfo .recordFields (tree );
1050
1050
1051
+ int fieldPos = 0 ;
1051
1052
for (JCVariableDecl field : fields ) {
1052
1053
/** Some notes regarding the code below. Annotations applied to elements of a record header are propagated
1053
1054
* to other elements which, when applicable, not explicitly declared by the user: the canonical constructor,
@@ -1063,24 +1064,24 @@ protected void runPhase(Env<AttrContext> env) {
1063
1064
* copying the original annotations from the record component to the corresponding field, again this applies
1064
1065
* only if APs are present.
1065
1066
*
1066
- * First, we find the record component by comparing its name and position with current field,
1067
- * if any, and we mark it. Then we copy the annotations to the field so that annotations applicable only to the record component
1067
+ * First, we get the record component matching the field position. Then we copy the annotations
1068
+ * to the field so that annotations applicable only to the record component
1068
1069
* can be attributed, as if declared in the field, and then stored in the metadata associated to the record
1069
1070
* component. The invariance we need to keep here is that record components must be scheduled for
1070
1071
* annotation only once during this process.
1071
1072
*/
1072
- RecordComponent rc = sym . findRecordComponentToRemove ( field );
1073
+ RecordComponent rc = getRecordComponentAt ( sym , fieldPos );
1073
1074
1074
1075
if (rc != null && (rc .getOriginalAnnos ().length () != field .mods .annotations .length ())) {
1075
1076
TreeCopier <JCTree > tc = new TreeCopier <>(make .at (field .pos ));
1076
- List <JCAnnotation > originalAnnos = tc .copy (rc .getOriginalAnnos ());
1077
- field .mods .annotations = originalAnnos ;
1077
+ field .mods .annotations = tc .copy (rc .getOriginalAnnos ());
1078
1078
}
1079
1079
1080
1080
memberEnter .memberEnter (field , env );
1081
1081
1082
1082
JCVariableDecl rcDecl = new TreeCopier <JCTree >(make .at (field .pos )).copy (field );
1083
1083
sym .createRecordComponent (rc , rcDecl , field .sym );
1084
+ fieldPos ++;
1084
1085
}
1085
1086
1086
1087
enterThisAndSuper (sym , env );
@@ -1095,6 +1096,18 @@ protected void runPhase(Env<AttrContext> env) {
1095
1096
}
1096
1097
}
1097
1098
1099
+ // where
1100
+ private RecordComponent getRecordComponentAt (ClassSymbol sym , int componentPos ) {
1101
+ int i = 0 ;
1102
+ for (RecordComponent rc : sym .getRecordComponents ()) {
1103
+ if (i == componentPos ) {
1104
+ return rc ;
1105
+ }
1106
+ i ++;
1107
+ }
1108
+ return null ;
1109
+ }
1110
+
1098
1111
/** Enter member fields and methods of a class
1099
1112
*/
1100
1113
private final class MembersPhase extends AbstractMembersPhase {
0 commit comments