Skip to content

Commit b94f572

Browse files
Revert #3896 until full analysis and resolution of resulting causes I-Build failure (#3926)
1 parent 7a29182 commit b94f572

File tree

37 files changed

+633
-756
lines changed

37 files changed

+633
-756
lines changed

org.eclipse.jdt.apt.tests/forceQualifierUpdate.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ Bug 420446 - APT tests don't run
44
Bug 566471 - I20200828-0150 - Comparator Errors Found
55
https://github.com/eclipse-platform/eclipse.platform.releng.aggregator/issues/1184
66
https://github.com/eclipse-platform/eclipse.platform.releng.aggregator/issues/1659
7-
https://github.com/eclipse-platform/eclipse.platform.releng.aggregator/issues/1923
8-
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1090
7+
https://github.com/eclipse-platform/eclipse.platform.releng.aggregator/issues/1923
-20 Bytes
Binary file not shown.

org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/RecordElementProcessor.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,17 +368,15 @@ public void testRecords4a() {
368368
assertEquals("incorrect parameters", 6, parameters.size());
369369
for (VariableElement v : parameters) {
370370
if (v.getSimpleName().toString().equals("comp_")) {
371-
verifyAnnotations(v, new String[]{"@MyAnnot()"});
371+
verifyAnnotations(v, new String[]{"@MyAnnot()"}); // ECJ fails
372372
} else if (v.getSimpleName().toString().equals("comp2_")) {
373373
verifyAnnotations(v, new String[]{"@MyAnnot2()"});
374374
} else if (v.getSimpleName().toString().equals("comp3_")) {
375-
verifyAnnotations(v, new String[]{"@MyAnnot5()"});
375+
verifyAnnotations(v, new String[]{}); // ECJ fails
376376
} else if (v.getSimpleName().toString().equals("comp4_")) {
377-
verifyAnnotations(v, new String[]{});
377+
verifyAnnotations(v, new String[]{}); // ECJ fails
378378
} else if (v.getSimpleName().toString().equals("comp5_")) {
379-
verifyAnnotations(v, new String[]{"@MyAnnot5()"});
380-
} else if (v.getSimpleName().toString().equals("comp6_")) {
381-
verifyAnnotations(v, new String[]{"@MyAnnot6()"});
379+
verifyAnnotations(v, new String[]{});
382380
}
383381
}
384382
}

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ClassFile.java

Lines changed: 49 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
6464
import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;
6565
import org.eclipse.jdt.internal.compiler.problem.ShouldNotImplement;
66-
import org.eclipse.jdt.internal.compiler.tool.EclipseCompiler;
6766
import org.eclipse.jdt.internal.compiler.util.Messages;
6867
import 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
}

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ASTNode.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public abstract class ASTNode implements TypeConstants, TypeIds {
7676
public final static int Bit7 = 0x40; // depth (name ref, msg) | need runtime checkcast (cast expression) | label used (labelStatement) | needFreeReturn (AbstractMethodDeclaration) | Used in Pattern Guard expression (NameReference)
7777
public final static int Bit8 = 0x80; // depth (name ref, msg) | unsafe cast (cast expression) | is default constructor (constructor declaration) | isElseStatementUnreachable (if statement)
7878
public final static int Bit9 = 0x100; // depth (name ref, msg) | operator (operator) | is local type (type decl) | isThenStatementUnreachable (if statement) | can be static
79-
public final static int Bit10= 0x200; // depth (name ref, msg) | operator (operator) | is anonymous type (type decl)
79+
public final static int Bit10= 0x200; // depth (name ref, msg) | operator (operator) | is anonymous type (type decl) | is implicit constructor (constructor)
8080
public final static int Bit11 = 0x400; // depth (name ref, msg) | operator (operator) | is member type (type decl)
8181
public final static int Bit12 = 0x800; // depth (name ref, msg) | operator (operator) | has abstract methods (type decl)
8282
public final static int Bit13 = 0x1000; // depth (name ref, msg) | operator (operator) | is secondary type (type decl)
@@ -177,6 +177,7 @@ public abstract class ASTNode implements TypeConstants, TypeIds {
177177
public static final int IsSecretYieldValueUsage = Bit5;
178178

179179
// for statements
180+
// public static final int IsImplicit = Bit11; // record declaration
180181
public static final int IsReachable = Bit32;
181182
public static final int LabelUsed = Bit7;
182183
public static final int DocumentedFallthrough = Bit30; // switch statement
@@ -236,6 +237,7 @@ public abstract class ASTNode implements TypeConstants, TypeIds {
236237
// for constructor declaration
237238
public static final int IsDefaultConstructor = Bit8;
238239
public static final int IsCanonicalConstructor = Bit10; // record declaration
240+
public static final int IsImplicit = Bit11; // record declaration / generated statements in compact constructor
239241

240242
// for compilation unit
241243
public static final int HasAllMethodBodies = Bit5;
@@ -309,6 +311,7 @@ public abstract class ASTNode implements TypeConstants, TypeIds {
309311
public static final int InsideExpressionStatement = Bit21;
310312

311313
// for annotation reference, signal if annotation was created from a default:
314+
// also used for implicit method creation of records Java 14
312315
public static final int IsSynthetic = ASTNode.Bit7;
313316

314317
// for all reference context entries.
@@ -319,7 +322,6 @@ public abstract class ASTNode implements TypeConstants, TypeIds {
319322
public static final RecordComponent [] NO_RECORD_COMPONENTS = new RecordComponent [0];
320323
public static final TypePattern[] NO_TYPE_PATTERNS = new TypePattern[0];
321324
public static final LocalVariableBinding[] NO_VARIABLES = new LocalVariableBinding[0];
322-
public static final Annotation[] NO_ANNOTATIONS = new Annotation[0];
323325

324326
public ASTNode() {
325327

0 commit comments

Comments
 (0)