6363import org .eclipse .jdt .internal .compiler .problem .ProblemReporter ;
6464import org .eclipse .jdt .internal .compiler .problem .ProblemSeverities ;
6565import org .eclipse .jdt .internal .compiler .problem .ShouldNotImplement ;
66- import org .eclipse .jdt .internal .compiler .tool .EclipseCompiler ;
6766import org .eclipse .jdt .internal .compiler .util .Messages ;
6867import org .eclipse .jdt .internal .compiler .util .Util ;
6968
@@ -550,13 +549,6 @@ private RecordComponent getRecordComponent(ReferenceBinding declaringClass, char
550549 }
551550 return null ;
552551 }
553- private RecordComponent [] getRecordComponents (ReferenceBinding declaringClass ) {
554- RecordComponentBinding [] rcbs = declaringClass .components ();
555- RecordComponent [] recordComponents = new RecordComponent [rcbs .length ];
556- for (int i = 0 , length = rcbs .length ; i < length ; i ++)
557- recordComponents [i ] = rcbs [i ].sourceRecordComponent ();
558- return recordComponents ;
559- }
560552 private int addComponentAttributes (RecordComponentBinding recordComponentBinding , int componetAttributeOffset ) {
561553 // See JVMS 14 Table 4.7-C - Record Preview for allowed attributes
562554 int attributesNumber = 0 ;
@@ -1123,7 +1115,9 @@ private void addSyntheticRecordCanonicalConstructor(TypeDeclaration typeDecl, Sy
11231115 .referenceCompilationUnit ()
11241116 .compilationResult
11251117 .getLineSeparatorPositions ());
1126- completeMethodInfo (methodBinding , methodAttributeOffset , attributeNumber );
1118+ // update the number of attributes
1119+ this .contents [methodAttributeOffset ++] = (byte ) (attributeNumber >> 8 );
1120+ this .contents [methodAttributeOffset ] = (byte ) attributeNumber ;
11271121 }
11281122
11291123 private void addSyntheticRecordOverrideMethods (TypeDeclaration typeDecl , SyntheticMethodBinding methodBinding , int purpose ) {
@@ -2319,9 +2313,9 @@ public void completeCodeAttributeForSyntheticMethod(
23192313 ((SourceTypeBinding ) binding .declaringClass ).scope );
23202314 }
23212315
2322- private void completeArgumentAnnotationInfo (AbstractVariableDeclaration [] arguments , List <AnnotationContext > allAnnotationContexts ) {
2316+ private void completeArgumentAnnotationInfo (Argument [] arguments , List <AnnotationContext > allAnnotationContexts ) {
23232317 for (int i = 0 , max = arguments .length ; i < max ; i ++) {
2324- AbstractVariableDeclaration argument = arguments [i ];
2318+ Argument argument = arguments [i ];
23252319 if ((argument .bits & ASTNode .HasTypeAnnotations ) != 0 ) {
23262320 argument .getAllAnnotationContexts (AnnotationTargetTypeConstants .METHOD_FORMAL_PARAMETER , i , allAnnotationContexts );
23272321 }
@@ -2382,9 +2376,6 @@ public void completeMethodInfo(
23822376 }
23832377 }
23842378 }
2385- } else if (binding instanceof SyntheticMethodBinding syntheticMethod && syntheticMethod .isCanonicalConstructor ()) {
2386- AbstractVariableDeclaration [] parameters = getRecordComponents (syntheticMethod .declaringClass );
2387- completeArgumentAnnotationInfo (parameters , allTypeAnnotationContexts );
23882379 } else if (binding .sourceLambda () != null ) { // SyntheticMethodBinding, purpose : LambdaMethod.
23892380 LambdaExpression lambda = binding .sourceLambda ();
23902381 if ((lambda .bits & ASTNode .HasTypeAnnotations ) != 0 ) {
@@ -4182,7 +4173,7 @@ private int generateLocalVariableTableAttribute(int code_length, boolean methodD
41824173 LocalVariableBinding localVariable = this .codeStream .locals [i ];
41834174 int initializationCount = localVariable .initializationCount ;
41844175 if (initializationCount == 0 ) continue ;
4185- if (localVariable .declaration == null && !( localVariable . declaringScope != null && localVariable . declaringScope . referenceContext () instanceof ConstructorDeclaration cd && cd . isCompactConstructor ()) ) continue ;
4176+ if (localVariable .declaration == null ) continue ;
41864177 final TypeBinding localVariableTypeBinding = localVariable .type ;
41874178 boolean isParameterizedType = localVariableTypeBinding .isParameterizedType () || localVariableTypeBinding .isTypeVariable ();
41884179 if (isParameterizedType ) {
@@ -4344,10 +4335,12 @@ public int generateMethodInfoAttributes(MethodBinding methodBinding) {
43444335 attributesNumber += generateSignatureAttribute (genericSignature );
43454336 }
43464337 AbstractMethodDeclaration methodDeclaration = methodBinding .sourceMethod ();
4347- if (methodBinding instanceof SyntheticMethodBinding syntheticMethod ) {
4338+ if (methodBinding instanceof SyntheticMethodBinding ) {
4339+ SyntheticMethodBinding syntheticMethod = (SyntheticMethodBinding ) methodBinding ;
43484340 if (syntheticMethod .purpose == SyntheticMethodBinding .SuperMethodAccess && CharOperation .equals (syntheticMethod .selector , syntheticMethod .targetMethod .selector ))
43494341 methodDeclaration = ((SyntheticMethodBinding )methodBinding ).targetMethod .sourceMethod ();
43504342 if (syntheticMethod .recordComponentBinding != null ) {
4343+ assert methodDeclaration == null ;
43514344 long rcMask = TagBits .AnnotationForMethod | TagBits .AnnotationForTypeUse ;
43524345 // record component (field) accessor method
43534346 ReferenceBinding declaringClass = methodBinding .declaringClass ;
@@ -4374,9 +4367,6 @@ public int generateMethodInfoAttributes(MethodBinding methodBinding) {
43744367 () -> allTypeAnnotationContexts );
43754368 }
43764369 }
4377- } else if (syntheticMethod .isCanonicalConstructor ()) {
4378- AbstractVariableDeclaration [] parameters = getRecordComponents (syntheticMethod .declaringClass );
4379- attributesNumber += generateRuntimeAnnotationsForParameters (parameters );
43804370 }
43814371 }
43824372 if (methodDeclaration != null ) {
@@ -4385,9 +4375,9 @@ public int generateMethodInfoAttributes(MethodBinding methodBinding) {
43854375 attributesNumber += generateRuntimeAnnotations (annotations , methodBinding .isConstructor () ? TagBits .AnnotationForConstructor : TagBits .AnnotationForMethod );
43864376 }
43874377 if ((methodBinding .tagBits & TagBits .HasParameterAnnotations ) != 0 ) {
4388- AbstractVariableDeclaration [] arguments = methodBinding .isCompactConstructor () ?
4389- getRecordComponents (methodBinding .declaringClass ) : methodDeclaration .arguments ;
4378+ Argument [] arguments = methodDeclaration .arguments ;
43904379 if (arguments != null ) {
4380+ propagateRecordComponentArguments (methodDeclaration );
43914381 attributesNumber += generateRuntimeAnnotationsForParameters (arguments );
43924382 }
43934383 }
@@ -4441,6 +4431,26 @@ private int completeRuntimeTypeAnnotations(int attributesNumber,
44414431 }
44424432 return attributesNumber ;
44434433 }
4434+ private void propagateRecordComponentArguments (AbstractMethodDeclaration methodDeclaration ) {
4435+ if ((methodDeclaration .bits & ASTNode .IsImplicit ) == 0 )
4436+ return ;
4437+ ReferenceBinding declaringClass = methodDeclaration .binding .declaringClass ;
4438+ if (declaringClass instanceof SourceTypeBinding ) {
4439+ assert declaringClass .isRecord ();
4440+ RecordComponentBinding [] rcbs = ((SourceTypeBinding ) declaringClass ).components ();
4441+ Argument [] arguments = methodDeclaration .arguments ;
4442+ for (int i = 0 , length = rcbs .length ; i < length ; i ++) {
4443+ RecordComponentBinding rcb = rcbs [i ];
4444+ RecordComponent recordComponent = rcb .sourceRecordComponent ();
4445+ if ((recordComponent .bits & ASTNode .HasTypeAnnotations ) != 0 ) {
4446+ methodDeclaration .bits |= ASTNode .HasTypeAnnotations ;
4447+ arguments [i ].bits |= ASTNode .HasTypeAnnotations ;
4448+ }
4449+ long rcMask = TagBits .AnnotationForParameter | TagBits .AnnotationForTypeUse ;
4450+ arguments [i ].annotations = ASTNode .getRelevantAnnotations (recordComponent .annotations , rcMask , null );
4451+ }
4452+ }
4453+ }
44444454
44454455 public int generateMethodInfoAttributes (MethodBinding methodBinding , AnnotationMethodDeclaration declaration ) {
44464456 int attributesNumber = generateMethodInfoAttributes (methodBinding );
@@ -4756,15 +4766,15 @@ private int generateRuntimeAnnotations(final Annotation[] annotations, final lon
47564766 return attributesNumber ;
47574767 }
47584768
4759- private int generateRuntimeAnnotationsForParameters (AbstractVariableDeclaration [] arguments ) {
4769+ private int generateRuntimeAnnotationsForParameters (Argument [] arguments ) {
47604770 final int argumentsLength = arguments .length ;
47614771 final int VISIBLE_INDEX = 0 ;
47624772 final int INVISIBLE_INDEX = 1 ;
47634773 int invisibleParametersAnnotationsCounter = 0 ;
47644774 int visibleParametersAnnotationsCounter = 0 ;
47654775 int [][] annotationsCounters = new int [argumentsLength ][2 ];
47664776 for (int i = 0 ; i < argumentsLength ; i ++) {
4767- AbstractVariableDeclaration argument = arguments [i ];
4777+ Argument argument = arguments [i ];
47684778 Annotation [] annotations = argument .annotations ;
47694779 if (annotations != null ) {
47704780 for (Annotation a : annotations ) {
@@ -4811,7 +4821,7 @@ private int generateRuntimeAnnotationsForParameters(AbstractVariableDeclaration[
48114821 this .contentsOffset += 2 ;
48124822 int counter = 0 ;
48134823 if (numberOfInvisibleAnnotations != 0 ) {
4814- AbstractVariableDeclaration argument = arguments [i ];
4824+ Argument argument = arguments [i ];
48154825 Annotation [] annotations = argument .annotations ;
48164826 for (Annotation a : annotations ) {
48174827 Annotation annotation ;
@@ -4872,7 +4882,7 @@ private int generateRuntimeAnnotationsForParameters(AbstractVariableDeclaration[
48724882 this .contentsOffset += 2 ;
48734883 int counter = 0 ;
48744884 if (numberOfVisibleAnnotations != 0 ) {
4875- AbstractVariableDeclaration argument = arguments [i ];
4885+ Argument argument = arguments [i ];
48764886 Annotation [] annotations = argument .annotations ;
48774887 for (Annotation a : annotations ) {
48784888 Annotation annotation ;
@@ -5026,7 +5036,6 @@ private int generateMethodParameters(final MethodBinding binding) {
50265036 AbstractMethodDeclaration methodDeclaration = binding .sourceMethod ();
50275037
50285038 boolean isConstructor = binding .isConstructor ();
5029- boolean isCanonicalConstructor = binding .isCanonicalConstructor ();
50305039 TypeBinding [] targetParameters = binding .parameters ;
50315040 ReferenceBinding declaringClass = binding .declaringClass ;
50325041
@@ -5041,8 +5050,7 @@ private int generateMethodParameters(final MethodBinding binding) {
50415050 }
50425051 }
50435052
5044- boolean needSynthetics = isCanonicalConstructor ? false : // WYSIWYG
5045- isConstructor && !isCanonicalConstructor && declaringClass .isNestedType ();
5053+ boolean needSynthetics = isConstructor && declaringClass .isNestedType ();
50465054 if (needSynthetics ) {
50475055 // Take into account the synthetic argument names
50485056 // This tracks JLS8, paragraph 8.8.9
@@ -5070,31 +5078,19 @@ private int generateMethodParameters(final MethodBinding binding) {
50705078 }
50715079 }
50725080 if (targetParameters != Binding .NO_PARAMETERS ) {
5073- if (binding .isCompactConstructor ()) {
5074- LocalVariableBinding [] locals = binding .sourceMethod ().scope .locals ;
5075- for (LocalVariableBinding local : locals ) {
5076- if (local == null || !local .isParameter ())
5077- continue ;
5078- int modifiers = local .modifiers | ClassFileConstants .AccMandated ;
5079- length = writeArgumentName (local .name , modifiers , length );
5080- }
5081- } else if (binding .isCanonicalConstructor () && methodDeclaration == null ) { // synthetic
5082- for (RecordComponentBinding component : binding .declaringClass .components ()) {
5083- length = writeArgumentName (component .name , ClassFileConstants .AccDefault , length );
5084- }
5085- } else {
5086- Argument [] arguments = null ;
5087- if (methodDeclaration != null && methodDeclaration .arguments != null ) {
5088- arguments = methodDeclaration .arguments ;
5089- }
5090- for (int i = 0 , max = targetParameters .length , argumentsLength = arguments != null ? arguments .length : 0 ; i < max ; i ++) {
5091- if (argumentsLength > i && arguments [i ] != null ) {
5092- Argument argument = arguments [i ];
5093- int modifiers = argument .binding .modifiers ;
5094- length = writeArgumentName (argument .name , modifiers , length );
5095- } else {
5096- throw EclipseCompiler .UNEXPECTED_CONTROL_FLOW ;
5097- }
5081+ Argument [] arguments = null ;
5082+ if (methodDeclaration != null && methodDeclaration .arguments != null ) {
5083+ arguments = methodDeclaration .arguments ;
5084+ }
5085+ for (int i = 0 , max = targetParameters .length , argumentsLength = arguments != null ? arguments .length : 0 ; i < max ; i ++) {
5086+ if (argumentsLength > i && arguments [i ] != null ) {
5087+ Argument argument = arguments [i ];
5088+ int modifiers = argument .binding .modifiers ;
5089+ if (binding .isCompactConstructor ())
5090+ modifiers |= ClassFileConstants .AccMandated ;
5091+ length = writeArgumentName (argument .name , modifiers , length );
5092+ } else {
5093+ length = writeArgumentName (null , ClassFileConstants .AccSynthetic , length );
50985094 }
50995095 }
51005096 }
0 commit comments