@@ -75,7 +75,7 @@ public class SourceTypeBinding extends ReferenceBinding {
7575 public ReferenceBinding superclass ; // MUST NOT be modified directly, use setter !
7676 public ReferenceBinding [] superInterfaces ; // MUST NOT be modified directly, use setter !
7777 private FieldBinding [] fields ; // MUST NOT be modified directly, use setter !
78- private RecordComponentBinding [] components ; // MUST NOT be modified directly, use setter !
78+ RecordComponentBinding [] components ; // MUST NOT be modified directly, use setter !
7979 private MethodBinding [] methods ; // MUST NOT be modified directly, use setter !
8080 public ReferenceBinding [] memberTypes ; // MUST NOT be modified directly, use setter !
8181 public TypeVariableBinding [] typeVariables ; // MUST NOT be modified directly, use setter !
@@ -121,6 +121,7 @@ public SourceTypeBinding(char[][] compoundName, PackageBinding fPackage, ClassSc
121121 // expect the fields & methods to be initialized correctly later
122122 this .fields = Binding .UNINITIALIZED_FIELDS ;
123123 this .methods = Binding .UNINITIALIZED_METHODS ;
124+ this .components = this .isRecord () ? Binding .UNINITIALIZED_COMPONENTS : NO_COMPONENTS ;
124125 this .prototype = this ;
125126 this .isImplicit = scope .referenceContext .isImplicitType ();
126127 computeId ();
@@ -138,6 +139,7 @@ public SourceTypeBinding(SourceTypeBinding prototype) {
138139 this .permittedTypes = prototype .permittedTypes ;
139140 this .fields = prototype .fields ;
140141 this .methods = prototype .methods ;
142+ this .components = prototype .components ;
141143 this .memberTypes = prototype .memberTypes ;
142144 this .typeVariables = prototype .typeVariables ;
143145 this .environment = prototype .environment ;
@@ -757,6 +759,11 @@ public SyntheticMethodBinding addSyntheticRecordOverrideMethod(char[] selector)
757759 }
758760 return accessMethod ;
759761}
762+ boolean areComponentsInitialized () {
763+ if (!isPrototype ())
764+ return this .prototype .areComponentsInitialized ();
765+ return this .components != Binding .UNINITIALIZED_COMPONENTS ;
766+ }
760767boolean areFieldsInitialized () {
761768 if (!isPrototype ())
762769 return this .prototype .areFieldsInitialized ();
@@ -912,7 +919,21 @@ public RecordComponentBinding[] components() {
912919 if (!isPrototype ()) {
913920 return this .components = this .prototype .components ();
914921 }
915- return this .components ;
922+ if ((this .tagBits & TagBits .HasUnresolvedComponents ) == 0 )
923+ return this .components ;
924+
925+ int length = this .components .length ;
926+ int count = 0 ;
927+ RecordComponentBinding [] rcbs = length == 0 ? Binding .NO_COMPONENTS : new RecordComponentBinding [length ];
928+ for (int i = 0 ; i < length ; i ++) {
929+ if (resolveTypeFor (this .components [i ]) != null ) {
930+ rcbs [count ++] = this .components [i ];
931+ }
932+ }
933+ if (count != rcbs .length ) // remove duplicate or broken components
934+ System .arraycopy (rcbs , 0 , rcbs = count == 0 ? Binding .NO_COMPONENTS : new RecordComponentBinding [count ], 0 , count );
935+ this .tagBits &= ~TagBits .HasUnresolvedComponents ;
936+ return setComponents (rcbs );
916937}
917938
918939private VariableBinding resolveTypeFor (VariableBinding variable ) {
@@ -923,6 +944,11 @@ private VariableBinding resolveTypeFor(VariableBinding variable) {
923944 if ((variable .modifiers & ExtraCompilerModifiers .AccUnresolved ) == 0 )
924945 return variable ;
925946
947+ if ((variable .getAnnotationTagBits () & TagBits .AnnotationDeprecated ) != 0 )
948+ variable .modifiers |= ClassFileConstants .AccDeprecated ;
949+ if (hasRestrictedAccess ())
950+ variable .modifiers |= ExtraCompilerModifiers .AccRestrictedAccess ;
951+
926952 MethodScope initializationScope = variable .isStatic ()
927953 ? this .scope .referenceContext .staticInitializerScope
928954 : this .scope .referenceContext .initializerScope ;
@@ -931,7 +957,6 @@ private VariableBinding resolveTypeFor(VariableBinding variable) {
931957 if (variable instanceof FieldBinding field )
932958 initializationScope .initializedField = field ;
933959 AbstractVariableDeclaration variableDeclaration = variable instanceof FieldBinding field ? field .sourceField () : ((RecordComponentBinding ) variable ).sourceRecordComponent ();
934- ASTNode .resolveNullDefaultAnnotations (initializationScope , variableDeclaration .annotations , variable );
935960 TypeBinding variableType =
936961 variableDeclaration .getKind () == AbstractVariableDeclaration .ENUM_CONSTANT
937962 ? initializationScope .environment ().convertToRawType (this , false /*do not force conversion of enclosing types*/ ) // enum constant is implicitly of declaring enum type
@@ -960,11 +985,6 @@ private VariableBinding resolveTypeFor(VariableBinding variable) {
960985 variable .modifiers |= ExtraCompilerModifiers .AccGenericSignature ;
961986 }
962987
963- if ((variable .getAnnotationTagBits () & TagBits .AnnotationDeprecated ) != 0 )
964- variable .modifiers |= ClassFileConstants .AccDeprecated ;
965- if (hasRestrictedAccess ())
966- variable .modifiers |= ExtraCompilerModifiers .AccRestrictedAccess ;
967-
968988 Annotation [] annotations = variableDeclaration .annotations ;
969989
970990 if (variableDeclaration instanceof RecordComponent componentDeclaration ) {
@@ -1046,6 +1066,9 @@ public FieldBinding[] fields() {
10461066 if ((this .tagBits & TagBits .AreFieldsComplete ) != 0 )
10471067 return this .fields ;
10481068
1069+ if ((this .tagBits & TagBits .HasUnresolvedComponents ) != 0 )
1070+ components ();
1071+
10491072 int failed = 0 ;
10501073 FieldBinding [] resolvedFields = this .fields ;
10511074 try {
@@ -1368,6 +1391,9 @@ public FieldBinding getField(char[] fieldName, boolean needResolve) {
13681391 if ((this .tagBits & TagBits .AreFieldsComplete ) != 0 )
13691392 return ReferenceBinding .binarySearch (fieldName , this .fields );
13701393
1394+ if ((this .tagBits & TagBits .HasUnresolvedComponents ) != 0 )
1395+ components ();
1396+
13711397 // lazily sort fields
13721398 if ((this .tagBits & TagBits .AreFieldsSorted ) == 0 ) {
13731399 int length = this .fields .length ;
@@ -1563,7 +1589,7 @@ void initializeForStaticImports() {
15631589
15641590 if (this .superInterfaces == null )
15651591 this .scope .connectTypeHierarchy ();
1566- this .scope .collateRecordComponents ();
1592+ this .scope .buildComponents ();
15671593 this .scope .buildFields ();
15681594 this .scope .buildMethods ();
15691595}
@@ -1721,6 +1747,9 @@ public MethodBinding[] methods() {
17211747 this .scope .buildMethods ();
17221748 }
17231749
1750+ if ((this .tagBits & TagBits .HasUnresolvedComponents ) != 0 )
1751+ components ();
1752+
17241753 // lazily sort methods
17251754 if ((this .tagBits & TagBits .AreMethodsSorted ) == 0 ) {
17261755 int length = this .methods .length ;
0 commit comments