Skip to content

Commit e8db074

Browse files
committed
Merge remote-tracking branch 'origin/master' into BETA_JAVA25
2 parents cc26c86 + 85f1797 commit e8db074

File tree

20 files changed

+684
-46
lines changed

20 files changed

+684
-46
lines changed

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/core/compiler/IProblem.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2490,8 +2490,6 @@ public interface IProblem {
24902490
/** @since 3.22 */
24912491
int SwitchExpressionsReturnWithinSwitchExpression = Syntax + 1724;
24922492

2493-
/* Java 14 errors end */
2494-
/* Java 15 errors begin */
24952493
/* records - begin */
24962494

24972495
/** @since 3.26 */
@@ -2597,8 +2595,6 @@ public interface IProblem {
25972595
*/
25982596
int SafeVarargsOnSyntheticRecordAccessor = TypeRelated + 1764;
25992597

2600-
2601-
/* records - end */
26022598
/* Local and Nested Static Declarations - Begin */
26032599
/** @since 3.28 */
26042600
int LocalStaticsIllegalVisibilityModifierForInterfaceLocalType = TypeRelated + 1765;
@@ -2610,6 +2606,8 @@ public interface IProblem {
26102606
int RecordErasureIncompatibilityInCanonicalConstructor = TypeRelated + 1768;
26112607
/** @since 3.41 */
26122608
int CompactConstructorOnlyInRecords = TypeRelated + 1769;
2609+
/** @since 3.42 */
2610+
int RecordAccessorMissingOverrideAnnotation = TypeRelated + 1770;
26132611
/* records - end */
26142612

26152613

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,21 +118,32 @@ public void abort(int abortLevel, CategorizedProblem problem) {
118118
return this.arguments; // overridden in compact constructor.
119119
}
120120

121+
public LocalVariableBinding [] argumentBindings() {
122+
int length = this.arguments == null ? 0 : this.arguments.length;
123+
LocalVariableBinding [] argumentBindings = new LocalVariableBinding[length];
124+
for(int i = 0; i < length; i++)
125+
argumentBindings[i] = this.arguments[i].binding;
126+
return argumentBindings;
127+
}
128+
121129
/**
122130
* When a method is accessed via SourceTypeBinding.resolveTypesFor(MethodBinding)
123131
* we create the argument binding and resolve annotations in order to compute null annotation tagbits.
124132
*/
125133
public void createArgumentBindings() {
126-
createArgumentBindings(this.arguments, this.binding, this.scope);
134+
createArgumentBindings(this.arguments(true), this.binding, this.scope);
127135
}
128136
// version for invocation from LambdaExpression:
129-
static void createArgumentBindings(Argument[] arguments, MethodBinding binding, MethodScope scope) {
137+
static void createArgumentBindings(AbstractVariableDeclaration[] arguments, MethodBinding binding, MethodScope scope) {
130138
boolean useTypeAnnotations = scope.environment().usesNullTypeAnnotations();
131139
if (arguments != null && binding != null) {
132-
for (int i = 0, length = arguments.length; i < length; i++) {
133-
Argument argument = arguments[i];
134-
binding.parameters[i] = argument.createBinding(scope, binding.parameters[i]);
135-
long argumentTagBits = argument.binding.tagBits;
140+
LocalVariableBinding [] argumentBindings = binding.isCompactConstructor() ? scope.argumentBindings() : new LocalVariableBinding[arguments.length];
141+
int length = Math.min(binding.parameters.length, arguments.length);
142+
for (int i = 0; i < length; i++) {
143+
if (arguments[i] instanceof Argument argument)
144+
argumentBindings[i] = argument.createBinding(scope, binding.parameters[i]);
145+
binding.parameters[i] = argumentBindings[i].type;
146+
long argumentTagBits = argumentBindings[i].tagBits;
136147
if ((argumentTagBits & TagBits.AnnotationOwning) != 0) {
137148
if (binding.parameterFlowBits == null) {
138149
binding.parameterFlowBits = new byte[arguments.length];
@@ -245,15 +256,16 @@ public void bindThrownExceptions() {
245256
* <li>NotOwning - for resource leak analysis
246257
* </ul>
247258
*/
248-
static void analyseArguments(LookupEnvironment environment, FlowInfo flowInfo, FlowContext flowContext, Argument[] methodArguments, MethodBinding methodBinding) {
259+
static void analyseArguments(LookupEnvironment environment, FlowInfo flowInfo, FlowContext flowContext, AbstractVariableDeclaration[] methodArguments, MethodBinding methodBinding, MethodScope scope) {
249260
if (methodArguments != null) {
250261
boolean usesNullTypeAnnotations = environment.usesNullTypeAnnotations();
251262
boolean usesOwningAnnotations = environment.usesOwningAnnotations();
252263

264+
LocalVariableBinding [] methodArgumentBindings = scope.argumentBindings();
253265
int length = Math.min(methodBinding.parameters.length, methodArguments.length);
254266
for (int i = 0; i < length; i++) {
255267
TypeBinding parameterBinding = methodBinding.parameters[i];
256-
LocalVariableBinding local = methodArguments[i].binding;
268+
LocalVariableBinding local = methodArgumentBindings[i];
257269
if (usesNullTypeAnnotations) {
258270
// leverage null type annotations:
259271
long tagBits = parameterBinding.tagBits & TagBits.AnnotationNullMASK;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public boolean isRecoveredFromLoneIdentifier() {
6464
return false;
6565
}
6666

67-
public TypeBinding createBinding(MethodScope scope, TypeBinding typeBinding) {
67+
public LocalVariableBinding createBinding(MethodScope scope, TypeBinding typeBinding) {
6868
if (this.binding == null) {
6969
// for default constructors and fake implementation of abstract methods
7070
this.binding = new LocalVariableBinding(this, typeBinding, this.modifiers, scope);
@@ -85,15 +85,15 @@ public TypeBinding createBinding(MethodScope scope, TypeBinding typeBinding) {
8585
scope.validateNullAnnotation(this.binding.tagBits, this.type, annots);
8686
}
8787
this.binding.declaration = this;
88-
return this.binding.type; // might have been updated during resolveAnnotations (for typeAnnotations)
88+
return this.binding; // type might have been updated during resolveAnnotations (for typeAnnotations)
8989
}
9090

9191
public TypeBinding bind(MethodScope scope, TypeBinding typeBinding, boolean used) {
9292
if (this.isUnnamed(scope) && !scope.isLambdaScope()) {
9393
scope.problemReporter().illegalUseOfUnderscoreAsAnIdentifier(this.sourceStart, this.sourceEnd, scope.compilerOptions().sourceLevel > ClassFileConstants.JDK1_8, true);
9494
}
9595

96-
TypeBinding newTypeBinding = createBinding(scope, typeBinding); // basically a no-op if createBinding() was called before
96+
TypeBinding newTypeBinding = createBinding(scope, typeBinding).type; // basically a no-op if createBinding() was called before
9797

9898
// record the resolved type into the type reference
9999
Binding existingVariable = scope.getBinding(this.name, Binding.VARIABLE, this, false /*do not resolve hidden field*/);

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,7 @@ public void analyseCode(ClassScope classScope, InitializationFlowContext initial
197197
}
198198

199199
// nullity, owning and mark as assigned
200-
analyseArguments(classScope.environment(), flowInfo, initializerFlowContext, this.arguments, this.binding);
201-
202-
if (this.isCompactConstructor()) {
203-
for (LocalVariableBinding local : this.scope.locals) {
204-
if (local != null && local.isParameter())
205-
flowInfo.markAsDefinitelyAssigned(local);
206-
}
207-
}
200+
analyseArguments(classScope.environment(), flowInfo, initializerFlowContext, this.arguments(true), this.binding, this.scope);
208201

209202
if (JavaFeature.FLEXIBLE_CONSTRUCTOR_BODIES.matchesCompliance(this.scope.compilerOptions())) {
210203
this.scope.enterEarlyConstructionContext();
@@ -301,6 +294,11 @@ public AbstractVariableDeclaration[] arguments(boolean includedElided) {
301294
return includedElided && this.isCompactConstructor() ? this.protoArguments : super.arguments(includedElided);
302295
}
303296

297+
@Override
298+
public LocalVariableBinding[] argumentBindings() {
299+
return this.isCompactConstructor() ? this.scope == null ? Binding.NO_ARGUMENT_BINDINGS : this.scope.argumentBindings() : super.argumentBindings();
300+
}
301+
304302
protected void doFieldReachAnalysis(FlowInfo flowInfo, FieldBinding[] fields) {
305303
for (FieldBinding field : fields) {
306304
if (!field.isStatic() && !flowInfo.isDefinitelyAssigned(field)) {
@@ -710,6 +708,9 @@ public void resolve(ClassScope upperScope) {
710708

711709
if (this.binding != null && this.binding.isCanonicalConstructor()) {
712710
RecordComponentBinding[] rcbs = upperScope.referenceContext.binding.components();
711+
boolean lastComponentVarargs = rcbs.length > 0 && rcbs[rcbs.length - 1].sourceRecordComponent().isVarArgs();
712+
if (this.binding.isVarargs() != lastComponentVarargs)
713+
upperScope.problemReporter().recordErasureIncompatibilityInCanonicalConstructor(this.arguments[this.arguments.length - 1].type);
713714
for (int i = 0; i < rcbs.length; ++i) {
714715
TypeBinding mpt = this.binding.parameters[i];
715716
TypeBinding rct = rcbs[i].type;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, fi
569569

570570
// nullity, owning and mark as assigned
571571
MethodBinding methodWithParameterDeclaration = argumentsTypeElided() ? this.descriptor : this.binding;
572-
AbstractMethodDeclaration.analyseArguments(currentScope.environment(), lambdaInfo, flowContext, this.arguments, methodWithParameterDeclaration);
572+
AbstractMethodDeclaration.analyseArguments(currentScope.environment(), lambdaInfo, flowContext, this.arguments, methodWithParameterDeclaration, this.scope);
573573

574574
if (this.arguments != null) {
575575
for (Argument argument : this.arguments) {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public void analyseCode(ClassScope classScope, FlowContext flowContext, FlowInfo
104104
FlowInfo.DEAD_END);
105105

106106
// nullity, owning and mark as assigned
107-
analyseArguments(classScope.environment(), flowInfo, flowContext, this.arguments, this.binding);
107+
analyseArguments(classScope.environment(), flowInfo, flowContext, this.arguments, this.binding, this.scope);
108108

109109
BiPredicate<TypeBinding, ReferenceBinding> condition = (argType, declClass) -> {
110110
ReferenceBinding enclosingType = argType.enclosingType();
@@ -288,6 +288,9 @@ public void resolveStatements() {
288288
this.scope.problemReporter().recordAccessorMethodShouldBePublic(this);
289289
if (this.binding.isStatic())
290290
this.scope.problemReporter().recordAccessorMethodShouldNotBeStatic(this);
291+
if ((this.binding.modifiers & ExtraCompilerModifiers.AccOverriding) == 0) {
292+
this.scope.problemReporter().recordAccessorMissingOverrideAnnotation(this);
293+
}
291294
}
292295
if (this.thrownExceptions != null)
293296
this.scope.problemReporter().recordAccessorMethodHasThrowsClause(this);

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/flow/ExceptionHandlingFlowContext.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ public class ExceptionHandlingFlowContext extends FlowContext {
6060
// for dealing with anonymous constructor thrown exceptions
6161
public List<TypeBinding> extendedExceptions;
6262

63-
private static final Argument[] NO_ARGUMENTS = new Argument[0];
6463
public Argument [] catchArguments;
6564

6665
private final int[] exceptionToCatchBlockMap;
@@ -72,7 +71,7 @@ public ExceptionHandlingFlowContext(
7271
FlowContext initializationParent,
7372
BlockScope scope,
7473
UnconditionalFlowInfo flowInfo) {
75-
this(parent, associatedNode, handledExceptions, null, NO_ARGUMENTS, initializationParent, scope, flowInfo);
74+
this(parent, associatedNode, handledExceptions, null, ASTNode.NO_ARGUMENTS, initializationParent, scope, flowInfo);
7675
}
7776
public ExceptionHandlingFlowContext(
7877
FlowContext parent,

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/Binding.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ public abstract class Binding {
7070
public static final ElementValuePair[] NO_ELEMENT_VALUE_PAIRS = new ElementValuePair[0];
7171
public static final char[][] NO_PARAMETER_NAMES = new char[0][];
7272
public static final RecordComponentBinding[] NO_COMPONENTS = new RecordComponentBinding[0];
73+
public static final LocalVariableBinding[] NO_ARGUMENT_BINDINGS = new LocalVariableBinding[0];
74+
7375

7476
public static final RecordComponentBinding[] UNINITIALIZED_COMPONENTS = new RecordComponentBinding[0];
7577
public static final FieldBinding[] UNINITIALIZED_FIELDS = new FieldBinding[0];

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ protected void fillInDefaultNonNullness(AbstractMethodDeclaration sourceMethod,
519519
this.parameterFlowBits = new byte[this.parameters.length];
520520
boolean added = false;
521521
int length = this.parameterFlowBits.length;
522+
LocalVariableBinding [] argumentBindings = sourceMethod == null ? Binding.NO_ARGUMENT_BINDINGS : sourceMethod.argumentBindings();
522523
for (int i = 0; i < length; i++) {
523524
if(!needToApplyParameterNonNullDefault.hasNonNullDefaultForParam(i)) {
524525
continue;
@@ -530,10 +531,11 @@ protected void fillInDefaultNonNullness(AbstractMethodDeclaration sourceMethod,
530531
added = true;
531532
this.parameterFlowBits[i] |= PARAM_NONNULL;
532533
if (sourceMethod != null) {
533-
sourceMethod.arguments[i].binding.tagBits |= TagBits.AnnotationNonNull;
534+
argumentBindings[i].tagBits |= TagBits.AnnotationNonNull;
534535
}
535536
} else if (sourceMethod != null && (this.parameterFlowBits[i] & PARAM_NONNULL) != 0) {
536-
sourceMethod.scope.problemReporter().nullAnnotationIsRedundant(sourceMethod, i);
537+
if (!sourceMethod.isCompactConstructor()) // Don't complain about implicit parameter. Also component nullity applies to more than just the parameter.
538+
sourceMethod.scope.problemReporter().nullAnnotationIsRedundant(sourceMethod, i);
537539
}
538540
}
539541
if (added)
@@ -560,6 +562,7 @@ protected void fillInDefaultNonNullness18(AbstractMethodDeclaration sourceMethod
560562
if (hasNonNullDefaultForParameter.hasAnyNonNullDefault()) {
561563
boolean added = false;
562564
int length = this.parameters.length;
565+
LocalVariableBinding [] argumentBindings = sourceMethod == null ? Binding.NO_ARGUMENT_BINDINGS : sourceMethod.argumentBindings();
563566
for (int i = 0; i < length; i++) {
564567
if (!hasNonNullDefaultForParameter.hasNonNullDefaultForParam(i))
565568
continue;
@@ -572,7 +575,7 @@ protected void fillInDefaultNonNullness18(AbstractMethodDeclaration sourceMethod
572575
if (!parameter.isBaseType()) {
573576
this.parameters[i] = env.createNonNullAnnotatedType(parameter);
574577
if (sourceMethod != null)
575-
sourceMethod.arguments[i].binding.type = this.parameters[i];
578+
argumentBindings[i].type = this.parameters[i];
576579
}
577580
}
578581
}

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import static org.eclipse.jdt.internal.compiler.impl.JavaFeature.FLEXIBLE_CONSTRUCTOR_BODIES;
2626

27+
import java.util.Arrays;
2728
import java.util.Map;
2829
import org.eclipse.jdt.core.compiler.CharOperation;
2930
import org.eclipse.jdt.internal.compiler.ASTVisitor;
@@ -91,6 +92,15 @@ public MethodScope(Scope parent, ReferenceContext context, boolean isStatic, int
9192
this.lastVisibleFieldID = lastVisibleFieldID;
9293
}
9394

95+
public LocalVariableBinding [] argumentBindings() {
96+
int i = 0;
97+
while (i < this.localIndex) {
98+
LocalVariableBinding local = this.locals[i++];
99+
if (local == null || !local.isParameter()) break; // done with arguments
100+
}
101+
return Arrays.copyOf(this.locals, i);
102+
}
103+
94104
@Override
95105
String basicToString(int tab) {
96106
String newLine = "\n"; //$NON-NLS-1$

0 commit comments

Comments
 (0)