Skip to content

Commit

Permalink
Eclipse 4.29 (M3) JDT Patch for Groovy-Eclipse
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Aug 20, 2023
1 parent c80ccf0 commit 8ef6c2c
Show file tree
Hide file tree
Showing 58 changed files with 1,367 additions and 566 deletions.
2 changes: 1 addition & 1 deletion groovy-eclipse.setup
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
<repository
url="https://download.eclipse.org/eclipse/updates/4.29"/>
<repository
url="https://download.eclipse.org/eclipse/updates/4.29-I-builds/I20230705-1800"/>
url="https://download.eclipse.org/eclipse/updates/4.29-I-builds/I20230817-0230"/>
</repositoryList>
<repositoryList
name="2023-06">
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.200.v20230705-1800" patch="true"/>
<import feature="org.eclipse.jdt" version="3.19.200.v20230817-0230" patch="true"/>
</requires>

<plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3659,8 +3659,8 @@ private int generateBootstrapMethods(List<Object> bootStrapMethodsList) {
} else {
localContentsOffset = addBootStrapTypeSwitchEntry(localContentsOffset, stmt, fPtr);
}
} else if (o instanceof StringBuilder) {
localContentsOffset = addBootStrapStringConcatEntry(localContentsOffset, (StringBuilder) o, fPtr);
} else if (o instanceof String) {
localContentsOffset = addBootStrapStringConcatEntry(localContentsOffset, (String) o, fPtr);
}
}

Expand Down Expand Up @@ -3934,7 +3934,7 @@ private int addBootStrapEnumSwitchEntry(int localContentsOffset, SwitchStatement

return localContentsOffset;
}
private int addBootStrapStringConcatEntry(int localContentsOffset, StringBuilder recipe, Map<String, Integer> fPtr) {
private int addBootStrapStringConcatEntry(int localContentsOffset, String recipe, Map<String, Integer> fPtr) {
final int contentsEntries = 10;
int indexForStringConcat = fPtr.get(ClassFile.CONCAT_CONSTANTS);
if (contentsEntries + localContentsOffset >= this.contents.length) {
Expand All @@ -3954,7 +3954,7 @@ private int addBootStrapStringConcatEntry(int localContentsOffset, StringBuilder
this.contents[localContentsOffset++] = (byte) 1;

int intValIdx =
this.constantPool.literalIndex(recipe.toString());
this.constantPool.literalIndex(recipe);
this.contents[localContentsOffset++] = (byte) (intValIdx >> 8);
this.contents[localContentsOffset++] = (byte) intValIdx;

Expand Down Expand Up @@ -6262,7 +6262,7 @@ public int recordBootstrapMethod(SwitchStatement switchStatement) {
this.bootstrapMethods.add(switchStatement);
return this.bootstrapMethods.size() - 1;
}
public int recordBootstrapMethod(StringBuilder expression) {
public int recordBootstrapMethod(String expression) {
if (this.bootstrapMethods == null) {
this.bootstrapMethods = new ArrayList<>();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// GROOVY PATCHED
/*******************************************************************************
* Copyright (c) 2000, 2017 IBM Corporation and others.
* Copyright (c) 2000, 2023 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
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public abstract class ASTNode implements TypeConstants, TypeIds {
public final static int Bit11 = 0x400; // depth (name ref, msg) | operator (operator) | is member type (type decl)
public final static int Bit12 = 0x800; // depth (name ref, msg) | operator (operator) | has abstract methods (type decl)
public final static int Bit13 = 0x1000; // depth (name ref, msg) | operator (operator) | is secondary type (type decl)
public final static int Bit14 = 0x2000; // strictly assigned (reference lhs) | operator (operator) | discard enclosing instance (explicit constr call) | hasBeenGenerated (type decl)
public final static int Bit14 = 0x2000; // strictly assigned (reference lhs) | discard enclosing instance (explicit constr call) | hasBeenGenerated (type decl)
public final static int Bit15 = 0x4000; // is unnecessary cast (expression) | is varargs (type ref) | isSubRoutineEscaping (try statement) | superAccess (javadoc allocation expression/javadoc message send/javadoc return statement)
public final static int Bit16 = 0x8000; // in javadoc comment (name ref, type ref, msg)
public final static int Bit17 = 0x10000; // compound assigned (reference lhs) | unchecked (msg, alloc, explicit constr call)
Expand Down Expand Up @@ -167,7 +167,7 @@ public abstract class ASTNode implements TypeConstants, TypeIds {
// for operators
public static final int ReturnTypeIDMASK = Bit1|Bit2|Bit3|Bit4;
public static final int OperatorSHIFT = 8; // Bit9 -> Bit14
public static final int OperatorMASK = Bit9|Bit10|Bit11|Bit12|Bit13|Bit14; // 6 bits for operator ID
public static final int OperatorMASK = Bit9|Bit10|Bit11|Bit12|Bit13; // 5 bits for operator ID - see org.eclipse.jdt.internal.compiler.ast.OperatorIds

// for binary expressions
public static final int IsReturnedValue = Bit5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.eclipse.jdt.internal.compiler.lookup.Scope;
import org.eclipse.jdt.internal.compiler.lookup.TagBits;
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
import org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding;
import org.eclipse.jdt.internal.compiler.lookup.VariableBinding;
Expand Down Expand Up @@ -931,6 +932,24 @@ public void generateOptimizedStringConcatenationCreation(BlockScope blockScope,
}
codeStream.invokeStringConcatenationStringConstructor();
}
private void addArgumentToRecipe(BlockScope blockScope, CodeStream codeStream, StringBuilder recipe, TypeBinding argType, List<TypeBinding> args) {
recipe.append(STRING_CONCAT_MARKER_1);
args.add(argType);
if (args.size() > 190) {
// StringConcatFactory#makeConcatWithConstants() can take only 200 arguments
// Commit whatever we have accumulated so far
// Get the result pushed to the stack and to be used as an operand
// for the subsequent concat operation
codeStream.invokeDynamicForStringConcat(recipe, args);
// Clear the arguments for the next batch
args.clear();
recipe.delete(0, recipe.length());
recipe.append(TypeConstants.STRING_CONCAT_MARKER_1);
args.add(blockScope.getJavaLangString());
// We popped 190 and adding 1 for the invokeDynamic
codeStream.stackDepth -= 189;
}
}
public void buildStringForConcatation(BlockScope blockScope, CodeStream codeStream, int typeID, StringBuilder recipe, List<TypeBinding> argTypes) {
if (this.constant == Constant.NotAConstant) {
switch (typeID) {
Expand All @@ -944,27 +963,23 @@ public void buildStringForConcatation(BlockScope blockScope, CodeStream codeStre
case TypeIds.T_char :
case TypeIds.T_boolean :
generateCode(blockScope, codeStream, true);
argTypes.add(this.resolvedType);
recipe.append(STRING_CONCAT_MARKER_1);
addArgumentToRecipe(blockScope, codeStream, recipe, this.resolvedType, argTypes);
break;
default :
if (this.resolvedType.id == TypeIds.T_null) {
// Optimize it, avoid aconst_null, simply append the String Literal
recipe.append((String) null);
codeStream.aconst_null();
} else {
generateCode(blockScope, codeStream, true);
codeStream.invokeStringValueOf(typeID);
argTypes.add(blockScope.getJavaLangString());
recipe.append(STRING_CONCAT_MARKER_1);
}
addArgumentToRecipe(blockScope, codeStream, recipe, blockScope.getJavaLangString(), argTypes);
break;
}
} else {
// StringLiteral and CharLiteral may contain special characters
if (this.constant.stringValue().indexOf('\u0001') != -1 || this.constant.stringValue().indexOf('\u0002') != -1) {
codeStream.ldc(this.constant.stringValue());
recipe.append(STRING_CONCAT_MARKER_1);
argTypes.add(blockScope.getJavaLangString());
addArgumentToRecipe(blockScope, codeStream, recipe, blockScope.getJavaLangString(), argTypes);
} else {
recipe.append(this.constant.stringValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ private ReferenceBinding findGroundTargetType(BlockScope blockScope, TypeBinding
freshInferenceContext.cleanUp();
}
} else {
return findGroundTargetTypeForElidedLambda(blockScope, withWildCards);
return withWildCards.getNonWildcardParameterization(blockScope);
}
}
if (targetType instanceof ReferenceBinding)
Expand All @@ -543,15 +543,6 @@ private ReferenceBinding findGroundTargetType(BlockScope blockScope, TypeBinding
return null;
}

public ReferenceBinding findGroundTargetTypeForElidedLambda(BlockScope blockScope, ParameterizedTypeBinding withWildCards) {
// non-wildcard parameterization (9.8) of the target type
TypeBinding[] types = withWildCards.getNonWildcardParameterization(blockScope);
if (types == null)
return null;
ReferenceBinding genericType = withWildCards.genericType();
return blockScope.environment().createParameterizedType(genericType, types, withWildCards.enclosingType());
}

@Override
public boolean argumentsTypeElided() {
return (this.arguments.length > 0 && this.arguments[0].hasElidedType()) || this.argumentsTypeVar;
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, 2023 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 @@ -831,6 +831,9 @@ public TypeBinding resolveType(BlockScope scope) {
return null;
}
}
if (this.argumentsHaveErrors) {
return null;
}

TypeBinding methodType = findMethodBinding(scope);
if (methodType != null && methodType.isPolyType()) {
Expand Down Expand Up @@ -1205,9 +1208,10 @@ public void registerResult(TypeBinding targetType, MethodBinding method) {

@Override
public InferenceContext18 getInferenceContext(ParameterizedMethodBinding method) {
if (this.inferenceContexts == null)
return null;
return (InferenceContext18) this.inferenceContexts.get(method);
InferenceContext18 context = null;
if (this.inferenceContexts != null)
context = (InferenceContext18) this.inferenceContexts.get(method);
return context;
}
@Override
public void cleanUpInferenceContexts() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

public abstract class OperatorExpression extends Expression implements OperatorIds {

public static int[][] OperatorSignatures = new int[NumberOfTables][];
public static int[][] OperatorSignatures = new int[UNSIGNED_RIGHT_SHIFT+1][];

static {classInitialize();}

Expand Down Expand Up @@ -1509,7 +1509,8 @@ public static final int[] get_XOR(){
}

public String operatorToString() {
switch ((this.bits & OperatorMASK) >> OperatorSHIFT) {
int op = (this.bits & OperatorMASK) >> OperatorSHIFT;
switch (op) {
case EQUAL_EQUAL :
return "=="; //$NON-NLS-1$
case LESS_EQUAL :
Expand Down Expand Up @@ -1556,8 +1557,14 @@ public String operatorToString() {
return "?:"; //$NON-NLS-1$
case EQUAL :
return "="; //$NON-NLS-1$
case INSTANCEOF :
return "instanceof"; //$NON-NLS-1$
case PLUS_PLUS :
return "++"; //$NON-NLS-1$
case MINUS_MINUS :
return "--"; //$NON-NLS-1$
}
return "unknown operator"; //$NON-NLS-1$
return "unknown operator " + op; //$NON-NLS-1$
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package org.eclipse.jdt.internal.compiler.ast;

public interface OperatorIds {
/** org.eclipse.jdt.core.dom.InfixExpression */
public static final int AND_AND = 0;
public static final int OR_OR = 1;
public static final int AND = 2;
Expand All @@ -33,14 +34,14 @@ public interface OperatorIds {
public static final int REMAINDER = 16;
public static final int RIGHT_SHIFT = 17;
public static final int EQUAL_EQUAL = 18;
public static final int UNSIGNED_RIGHT_SHIFT= 19;
public static final int NumberOfTables = 20;
public static final int UNSIGNED_RIGHT_SHIFT= 19; // last org.eclipse.jdt.internal.compiler.ast.OperatorExpression

public static final int QUESTIONCOLON = 23;

public static final int NOT_EQUAL = 29;
public static final int EQUAL = 30;
public static final int INSTANCEOF = 31;
public static final int PLUS_PLUS = 32;
public static final int MINUS_MINUS = 33;
public static final int NOT_EQUAL = 20;
public static final int EQUAL = 21;
/** others */
public static final int QUESTIONCOLON = 22;
public static final int INSTANCEOF = 23;
/** postfix */
public static final int PLUS_PLUS = 24;
public static final int MINUS_MINUS = 25;
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public void traverse(ASTVisitor visitor, ClassScope scope) {
@Override
public void updateWithAnnotations(Scope scope, int location) {
super.updateWithAnnotations(scope, location);
if (this.resolvedType instanceof TypeVariableBinding) {
if (this.resolvedType instanceof TypeVariableBinding && !this.resolvedType.hasNullTypeAnnotations()) {
// refresh this binding in case a decorated binding was created during ClassScope.connectTypeVariables()
TypeVariableBinding tvb = (TypeVariableBinding) this.resolvedType;
Binding declaringElement = tvb.declaringElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,8 @@ public TypeBinding resolveTypeInternal(BlockScope upperScope) {
for (int i = 0; i < resultExpressionsCount; i++) {
Expression resultExpr = this.resultExpressions.get(i);
TypeBinding origType = this.originalTypeMap.get(resultExpr);
if (origType == null || origType.kind() == Binding.POLY_TYPE) {
// NB: if origType == null we assume that initial resolving failed hard, rendering re-resolving impossible
if (origType != null && origType.kind() == Binding.POLY_TYPE) {
this.finalValueResultExpressionTypes[i] = this.originalValueResultExpressionTypes[i] =
resultExpr.resolveTypeExpecting(upperScope, this.expectedType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.eclipse.jdt.internal.compiler.env.IMultiModuleEntry;
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
import org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.ExternalAnnotationStatus;
import org.eclipse.jdt.internal.compiler.util.CtSym;
import org.eclipse.jdt.internal.compiler.util.JRTUtil;

@SuppressWarnings({"rawtypes", "unchecked"})
Expand Down Expand Up @@ -405,4 +406,11 @@ public IModule getModule(char[] moduleName) {
public boolean servesModule(char[] moduleName) {
return getModule(moduleName) != null;
}

public static void clearCache(String path, String releaseVersion) {
if (releaseVersion != null) {
path += '|'+ CtSym.getReleaseCode(releaseVersion);
}
ModulesCache.remove(path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2606,7 +2606,21 @@ public void generateReturnBytecode(Expression expression) {
}
}
}

public void invokeDynamicForStringConcat(StringBuilder recipe, List<TypeBinding> arguments) {
int invokeDynamicNumber = this.classFile.recordBootstrapMethod(recipe.toString());
StringBuilder signature = new StringBuilder("("); //$NON-NLS-1$
for(int i = 0; i < arguments.size(); i++) {
signature.append(arguments.get(i).signature());
}
signature.append(")Ljava/lang/String;"); //$NON-NLS-1$
this.invokeDynamic(invokeDynamicNumber,
2,
1, // int
ConstantPool.ConcatWithConstants,
signature.toString().toCharArray(),
TypeIds.T_JavaLangObject,
getPopularBinding(ConstantPool.JavaLangStringConstantPoolName));
}
/**
* The equivalent code performs a string conversion:
*
Expand All @@ -2632,19 +2646,7 @@ public void generateStringConcatenationAppend(BlockScope blockScope, Expression
oper1.buildStringForConcatation(blockScope, this, oper1.implicitConversion & TypeIds.COMPILE_TYPE_MASK, recipe, arguments);
}
oper2.buildStringForConcatation(blockScope, this, oper2.implicitConversion & TypeIds.COMPILE_TYPE_MASK, recipe, arguments);
int invokeDynamicNumber = this.classFile.recordBootstrapMethod(recipe);
StringBuilder signature = new StringBuilder("("); //$NON-NLS-1$
for(int i = 0; i < arguments.size(); i++) {
signature.append(arguments.get(i).signature());
}
signature.append(")Ljava/lang/String;"); //$NON-NLS-1$
this.invokeDynamic(invokeDynamicNumber,
2,
1, // int
ConstantPool.ConcatWithConstants,
signature.toString().toCharArray(),
TypeIds.T_JavaLangObject,
getPopularBinding(ConstantPool.JavaLangStringConstantPoolName));
invokeDynamicForStringConcat(recipe, arguments);
} else {
int pc;
if (oper1 == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.env;

import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.compiler.util.Util;

// clinit methods (synthetics too?) can be returned from IBinaryType>>getMethods()
// BUT do not have to be... the compiler will ignore them when building the binding.
// The synthetic argument of a member type's constructor (i.e. the first arg of a non-static
Expand Down Expand Up @@ -101,4 +104,36 @@ public interface IBinaryMethod extends IGenericMethod {
* Answer the type annotations on this method.
*/
IBinaryTypeAnnotation[] getTypeAnnotations();

/**
* Answer the number of method parameters based on analysis of the method descriptor.
* @return the number of parameters or {@code -1} if the descriptor was malformed.
*/
default int getParameterCount() {
// copy-adjusted from org.eclipse.jdt.core.Signature.getParameterCount(char[])
char[] methodSignature = getMethodDescriptor();
try {
int count = 0;
int i = CharOperation.indexOf(Util.C_PARAM_START, methodSignature);
if (i < 0) {
return -1;
} else {
i++;
}
for (;;) {
if (methodSignature[i] == Util.C_PARAM_END) {
return count;
}
int e= Util.scanTypeSignature(methodSignature, i);
if (e < 0) {
return -1;
} else {
i = e + 1;
}
count++;
}
} catch (ArrayIndexOutOfBoundsException e) {
return -1;
}
}
}
Loading

0 comments on commit 8ef6c2c

Please sign in to comment.