Skip to content

Commit

Permalink
Eclipse 4.32 (M3) JDT Patch for Groovy-Eclipse
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed May 17, 2024
1 parent 972d34a commit 2b0a866
Show file tree
Hide file tree
Showing 117 changed files with 4,136 additions and 1,514 deletions.
4 changes: 3 additions & 1 deletion groovy-eclipse.setup
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,11 @@
<repositoryList
name="2024-06">
<repository
url="https://download.eclipse.org/releases/2024-05"/>
url="https://download.eclipse.org/releases/2024-06"/>
<repository
url="https://download.eclipse.org/eclipse/updates/4.32"/>
<repository
url="https://download.eclipse.org/eclipse/updates/4.32-I-builds/I20240516-1800"/>
</repositoryList>
<repositoryList
name="2024-03">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</license>

<requires>
<import feature="org.eclipse.jdt" version="3.19.500.v20240406-1929" patch="true"/>
<import feature="org.eclipse.jdt" version="3.19.500.v20240516-1803" patch="true"/>
</requires>

<plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2070,6 +2070,8 @@ public interface IProblem {
int OverrideAddingReturnOwning = Internal + 1267;
/** @since 3.38 */
int StaticResourceField = Internal + 1268;
/** @since 3.38 */
int ResourceIsNotAValue = Internal + 1269;

// terminally
/** @since 3.14 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
import org.eclipse.jdt.internal.compiler.codegen.ConstantPool;
import org.eclipse.jdt.internal.compiler.codegen.ExceptionLabel;
import org.eclipse.jdt.internal.compiler.codegen.Opcodes;
import org.eclipse.jdt.internal.compiler.codegen.OperandStack;
import org.eclipse.jdt.internal.compiler.codegen.StackMapFrame;
import org.eclipse.jdt.internal.compiler.codegen.StackMapFrameCodeStream;
import org.eclipse.jdt.internal.compiler.codegen.StackMapFrameCodeStream.ExceptionMarker;
Expand Down Expand Up @@ -814,6 +815,7 @@ private void addMissingAbstractProblemMethod(MethodDeclaration methodDeclaration

this.codeStream.init(this);
this.codeStream.preserveUnusedLocals = true;
this.codeStream.operandStack = new OperandStack.NullStack();
this.codeStream.initializeMaxLocals(methodBinding);

// return codeStream.generateCodeAttributeForProblemMethod(comp.options.runtimeExceptionNameForCompileError, "")
Expand Down Expand Up @@ -1197,7 +1199,7 @@ private void addSyntheticRecordCanonicalConstructor(TypeDeclaration typeDecl, Sy
int codeAttributeOffset = this.contentsOffset;
attributeNumber++; // add code attribute
generateCodeAttributeHeader();
this.codeStream.init(this);
this.codeStream.reset(methodBinding, this);
this.codeStream.generateSyntheticBodyForRecordCanonicalConstructor(methodBinding);
completeCodeAttributeForSyntheticMethod(
methodBinding,
Expand Down Expand Up @@ -1226,7 +1228,7 @@ private void addSyntheticRecordOverrideMethods(TypeDeclaration typeDecl, Synthet
int codeAttributeOffset = this.contentsOffset;
attributeNumber++; // add code attribute
generateCodeAttributeHeader();
this.codeStream.init(this);
this.codeStream.reset(methodBinding, this);
switch (purpose) {
case SyntheticMethodBinding.RecordCanonicalConstructor:
this.codeStream.generateSyntheticBodyForRecordCanonicalConstructor(methodBinding);
Expand Down Expand Up @@ -1265,7 +1267,7 @@ public void addSyntheticArrayConstructor(SyntheticMethodBinding methodBinding) {
int codeAttributeOffset = this.contentsOffset;
attributeNumber++; // add code attribute
generateCodeAttributeHeader();
this.codeStream.init(this);
this.codeStream.reset(methodBinding, this);
this.codeStream.generateSyntheticBodyForArrayConstructor(methodBinding);
completeCodeAttributeForSyntheticMethod(
methodBinding,
Expand All @@ -1288,7 +1290,7 @@ public void addSyntheticArrayClone(SyntheticMethodBinding methodBinding) {
int codeAttributeOffset = this.contentsOffset;
attributeNumber++; // add code attribute
generateCodeAttributeHeader();
this.codeStream.init(this);
this.codeStream.reset(methodBinding, this);
this.codeStream.generateSyntheticBodyForArrayClone(methodBinding);
completeCodeAttributeForSyntheticMethod(
methodBinding,
Expand All @@ -1311,7 +1313,7 @@ public void addSyntheticFactoryMethod(SyntheticMethodBinding methodBinding) {
int codeAttributeOffset = this.contentsOffset;
attributeNumber++; // add code attribute
generateCodeAttributeHeader();
this.codeStream.init(this);
this.codeStream.reset(methodBinding, this);
this.codeStream.generateSyntheticBodyForFactoryMethod(methodBinding);
completeCodeAttributeForSyntheticMethod(
methodBinding,
Expand Down Expand Up @@ -1340,7 +1342,7 @@ public void addSyntheticConstructorAccessMethod(SyntheticMethodBinding methodBin
int codeAttributeOffset = this.contentsOffset;
attributeNumber++; // add code attribute
generateCodeAttributeHeader();
this.codeStream.init(this);
this.codeStream.reset(methodBinding, this);
this.codeStream.generateSyntheticBodyForConstructorAccess(methodBinding);
completeCodeAttributeForSyntheticMethod(
methodBinding,
Expand Down Expand Up @@ -1370,7 +1372,7 @@ public void addSyntheticEnumValueOfMethod(SyntheticMethodBinding methodBinding)
int codeAttributeOffset = this.contentsOffset;
attributeNumber++; // add code attribute
generateCodeAttributeHeader();
this.codeStream.init(this);
this.codeStream.reset(methodBinding, this);
this.codeStream.generateSyntheticBodyForEnumValueOf(methodBinding);
completeCodeAttributeForSyntheticMethod(
methodBinding,
Expand Down Expand Up @@ -1403,7 +1405,7 @@ public void addSyntheticEnumValuesMethod(SyntheticMethodBinding methodBinding) {
int codeAttributeOffset = this.contentsOffset;
attributeNumber++; // add code attribute
generateCodeAttributeHeader();
this.codeStream.init(this);
this.codeStream.reset(methodBinding, this);
this.codeStream.generateSyntheticBodyForEnumValues(methodBinding);
completeCodeAttributeForSyntheticMethod(
methodBinding,
Expand All @@ -1427,7 +1429,7 @@ public void addSyntheticEnumInitializationMethod(SyntheticMethodBinding methodBi
int codeAttributeOffset = this.contentsOffset;
attributeNumber++; // add code attribute
generateCodeAttributeHeader();
this.codeStream.init(this);
this.codeStream.reset(methodBinding, this);
this.codeStream.generateSyntheticBodyForEnumInitializationMethod(methodBinding);
completeCodeAttributeForSyntheticMethod(
methodBinding,
Expand Down Expand Up @@ -1457,7 +1459,7 @@ public void addSyntheticFieldReadAccessMethod(SyntheticMethodBinding methodBindi
int codeAttributeOffset = this.contentsOffset;
attributeNumber++; // add code attribute
generateCodeAttributeHeader();
this.codeStream.init(this);
this.codeStream.reset(methodBinding, this);
this.codeStream.generateSyntheticBodyForFieldReadAccess(methodBinding);
completeCodeAttributeForSyntheticMethod(
methodBinding,
Expand Down Expand Up @@ -1488,7 +1490,7 @@ public void addSyntheticFieldWriteAccessMethod(SyntheticMethodBinding methodBind
int codeAttributeOffset = this.contentsOffset;
attributeNumber++; // add code attribute
generateCodeAttributeHeader();
this.codeStream.init(this);
this.codeStream.reset(methodBinding, this);
this.codeStream.generateSyntheticBodyForFieldWriteAccess(methodBinding);
completeCodeAttributeForSyntheticMethod(
methodBinding,
Expand Down Expand Up @@ -1518,7 +1520,7 @@ public void addSyntheticMethodAccessMethod(SyntheticMethodBinding methodBinding)
int codeAttributeOffset = this.contentsOffset;
attributeNumber++; // add code attribute
generateCodeAttributeHeader();
this.codeStream.init(this);
this.codeStream.reset(methodBinding, this);
this.codeStream.generateSyntheticBodyForMethodAccess(methodBinding);
completeCodeAttributeForSyntheticMethod(
methodBinding,
Expand All @@ -1542,7 +1544,7 @@ public void addSyntheticSwitchTable(SyntheticMethodBinding methodBinding) {
int codeAttributeOffset = this.contentsOffset;
attributeNumber++; // add code attribute
generateCodeAttributeHeader();
this.codeStream.init(this);
this.codeStream.reset(methodBinding, this);
this.codeStream.generateSyntheticBodyForSwitchTable(methodBinding);
int code_length = this.codeStream.position;
if (code_length > 65535) {
Expand Down Expand Up @@ -4605,7 +4607,7 @@ public void addSyntheticDeserializeLambda(SyntheticMethodBinding methodBinding,
int codeAttributeOffset = this.contentsOffset;
attributeNumber++; // add code attribute
generateCodeAttributeHeader();
this.codeStream.init(this);
this.codeStream.reset(methodBinding, this);
this.codeStream.generateSyntheticBodyForDeserializeLambda(methodBinding, syntheticMethodBindings);
int code_length = this.codeStream.position;
if (code_length > 65535) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public abstract class AbstractMethodDeclaration

AbstractMethodDeclaration(CompilationResult compilationResult){
this.compilationResult = compilationResult;
this.containsSwitchWithTry = false;
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ public void generateCode(ClassScope classScope, ClassFile classFile) {
if (referenceContext != null) {
unitResult = referenceContext.compilationResult();
problemCount = unitResult.problemCount;
if (referenceContext.clinitContainsSwitchWithTry)
this.containsSwitchWithTry = true;
}
}
boolean restart = false;
Expand Down Expand Up @@ -355,6 +357,17 @@ private void generateCode(
codeStream.recordPositionsFrom(0, declaringType.sourceStart);
classFile.completeCodeAttributeForClinit(codeAttributeOffset, classScope);
}
// the following block must happen after constantPool.resetForClinit()
if (TypeDeclaration.kind(declaringType.modifiers) != TypeDeclaration.ENUM_DECL
&& fieldDeclarations != null) {
int constantFlags = ClassFileConstants.AccStatic | ClassFileConstants.AccFinal;
for (FieldDeclaration fieldDecl : fieldDeclarations) {
if ((fieldDecl.modifiers & constantFlags) == constantFlags
&& fieldDecl.initialization != null) {
NameReference.emitDeclaringClassOfConstant(fieldDecl.initialization, codeStream);
}
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public CompactConstructorDeclaration(CompilationResult compilationResult) {
public void parseStatements(Parser parser, CompilationUnitDeclaration unit) {
this.constructorCall = SuperReference.implicitSuperConstructorCall();
parser.parse(this, unit, false);
this.containsSwitchWithTry = parser.switchWithTry;
}
@Override
public void analyseCode(ClassScope classScope, InitializationFlowContext initializerFlowContext, FlowInfo flowInfo, int initialReachMode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ public void generateCode(ClassScope classScope, ClassFile classFile) {
if (referenceContext != null) {
unitResult = referenceContext.compilationResult();
problemCount = unitResult.problemCount;
if (referenceContext.initContainsSwitchWithTry)
this.containsSwitchWithTry = true;
}
}
do {
Expand Down Expand Up @@ -601,7 +603,6 @@ public void parseStatements(Parser parser, CompilationUnitDeclaration unit) {
return;
}
parser.parse(this, unit, false);
this.containsSwitchWithTry = parser.switchWithTry;
}

@Override
Expand Down Expand Up @@ -749,6 +750,11 @@ public boolean visit(TypeDeclaration typeDeclaration, BlockScope skope) {
typeDeclaration.inPreConstructorContext = true;
return false;
}
@Override
public boolean visit(LambdaExpression lambda, BlockScope skope) {
lambda.inPreConstructorContext = true;
return true;
}
}
for (int i = 0; i <= prologueLength; ++i) {
stmts[i].traverse(new MarkAllExpressionsPreConVisitor(), this.scope);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2019 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -348,7 +348,10 @@ public void resolve(BlockScope scope) {
}
if (receiverType != null) {
// prevent (explicit) super constructor invocation from within enum
if (this.accessMode == ExplicitConstructorCall.Super && receiverType.erasure().id == TypeIds.T_JavaLangEnum) {
MethodBinding mBinding = methodScope.referenceMethod().binding;
if (this.accessMode == ExplicitConstructorCall.Super &&
(mBinding != null && (mBinding.tagBits & TagBits.HasMissingType) == 0)
&& receiverType.erasure().id == TypeIds.T_JavaLangEnum) {
scope.problemReporter().cannotInvokeSuperConstructorInEnum(this, methodScope.referenceMethod().binding);
}
// qualification should be from the type of the enclosingType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ public static FlowInfo analyseCloseableAcquisition(BlockScope scope, FlowInfo fl
}
}

private static boolean isFluentMethod(MethodBinding binding) {
static boolean isFluentMethod(MethodBinding binding) {
if (binding.isStatic())
return false;
ReferenceBinding declaringClass = binding.declaringClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public class LambdaExpression extends FunctionalExpression implements IPolyExpre
private boolean assistNode = false;
private ReferenceBinding classType;
private Set thrownExceptions;
public boolean containsSwitchWithTry = false;
private static final SyntheticArgumentBinding [] NO_SYNTHETIC_ARGUMENTS = new SyntheticArgumentBinding[0];
private static final Block NO_BODY = new Block(0);
private HashMap<TypeBinding, LambdaExpression> copiesPerTargetType;
Expand Down Expand Up @@ -1285,7 +1286,10 @@ public void generateCode(ClassFile classFile) {
}
codeStream.pushPatternAccessTrapScope(this.scope);
if (this.body instanceof Block) {
boolean prev = codeStream.stmtInPreConContext;
codeStream.stmtInPreConContext = this.inPreConstructorContext;
this.body.generateCode(this.scope, codeStream);
codeStream.stmtInPreConContext = prev;
if ((this.bits & ASTNode.NeedFreeReturn) != 0) {
codeStream.return_();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,12 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
// NullReferenceTest#test0510
}
// after having analysed exceptions above start tracking newly allocated resource:
if (analyseResources && FakedTrackingVariable.isAnyCloseable(this.resolvedType))
flowInfo = FakedTrackingVariable.analyseCloseableAcquisition(currentScope, flowInfo, flowContext, this);
if (analyseResources) {
if (FakedTrackingVariable.isAnyCloseable(this.resolvedType))
flowInfo = FakedTrackingVariable.analyseCloseableAcquisition(currentScope, flowInfo, flowContext, this);
if (!FakedTrackingVariable.isFluentMethod(this.binding))
FakedTrackingVariable.cleanUpUnassigned(currentScope, this.receiver, flowInfo, false);
}

manageSyntheticAccessIfNecessary(currentScope, flowInfo);
// account for pot. exceptions thrown by method execution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ public RecordComponent getRecordComponent() {
public void parseStatements(Parser parser, CompilationUnitDeclaration unit) {
//fill up the method body with statement
parser.parse(this, unit);
this.containsSwitchWithTry = parser.switchWithTry;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2021 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -21,6 +21,9 @@

import java.util.function.Predicate;

import org.eclipse.jdt.internal.compiler.ASTVisitor;
import org.eclipse.jdt.internal.compiler.codegen.CodeStream;
import org.eclipse.jdt.internal.compiler.impl.Constant;
import org.eclipse.jdt.internal.compiler.lookup.*;
import org.eclipse.jdt.internal.compiler.problem.AbortMethod;

Expand All @@ -41,6 +44,40 @@ public NameReference() {
this.bits |= Binding.TYPE | Binding.VARIABLE; // restrictiveFlag
}

/**
* Creates a constant pool entry which is not needed by the VM but might help tools.
* See https://bugs.openjdk.org/browse/JDK-7153958
*/
public void emitDeclaringClassOfConstant(CodeStream codeStream) {
if (this.constant != Constant.NotAConstant && this.binding instanceof FieldBinding f) {
codeStream.constantPool.literalIndexForType(f.declaringClass);
}
}
/**
* Creates a constant pool entry for each constant reference within expr.
* This is not needed by the VM but might help tools.
* See https://bugs.openjdk.org/browse/JDK-7153958
*/
public static void emitDeclaringClassOfConstant(Expression expr, CodeStream codeStream) {
if (expr instanceof Literal)
return;
expr.traverse(
new ASTVisitor() {
@Override
public boolean visit(SingleNameReference nameReference, BlockScope scope) {
nameReference.emitDeclaringClassOfConstant(codeStream);
return false;
}
@Override
public boolean visit(QualifiedNameReference nameReference, BlockScope scope) {
nameReference.emitDeclaringClassOfConstant(codeStream);
return false;
}
},
(BlockScope) null
);
}

/**
* Use this method only when sure that the current reference is <strong>not</strong>
* a chain of several fields (QualifiedNameReference with more than one field).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,26 @@ private static TypeBinding mergeTypeAnnotations(TypeBinding type, TypeBinding ot
return mainType;
}

/**
* Help Scope.mostSpecificMethodBinding(MethodBinding[], int, TypeBinding[], InvocationSite, ReferenceBinding):
* If choice between equivalent methods would otherwise be arbitrary, determine if m1 should be preferred due
* to a more specific null contract.
*/
public static boolean hasMoreSpecificNullness(MethodBinding m1, MethodBinding m2) {
long nullness1 = m1.returnType.tagBits & TagBits.AnnotationNullMASK;
long nullness2 = m2.returnType.tagBits & TagBits.AnnotationNullMASK;
if (nullness1 == TagBits.AnnotationNonNull && nullness2 != TagBits.AnnotationNonNull)
return true;
int len = Math.max(m1.parameters.length, m2.parameters.length);
for (int i=0; i<len; i++) {
nullness1 = m1.parameters[i].tagBits & TagBits.AnnotationNullMASK;
nullness2 = m2.parameters[i].tagBits & TagBits.AnnotationNullMASK;
if (nullness1 == TagBits.AnnotationNullable && nullness2 != TagBits.AnnotationNullable)
return true;
}
return false;
}

@Override
public String toString() {
if (this == NULL_ANNOTATIONS_OK) return "OK"; //$NON-NLS-1$
Expand Down
Loading

0 comments on commit 2b0a866

Please sign in to comment.