Skip to content

Commit

Permalink
Remove obsoleted code in CompilerOptions
Browse files Browse the repository at this point in the history
Found during the review of eclipse-jdt#2551

- CompilerOptions.originalComplianceLevel is obsoleted and can be
removed + code in TypeConverter using it should be cleaned up.
- CompilerOptions.originalSourceLevel is obsoleted and can be removed +
code in JDT that uses it should be cleaned up

Fixes eclipse-jdt#2760
  • Loading branch information
iloveeclipse committed Sep 5, 2024
1 parent 7b15979 commit dba0ef7
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.compiler.ASTVisitor;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.impl.Constant;
import org.eclipse.jdt.internal.compiler.lookup.*;

Expand Down Expand Up @@ -317,14 +316,8 @@ private TypeBinding internalResolveLeafType(Scope scope, boolean checkBounds) {

TypeVariableBinding[] typeVariables = currentOriginal.typeVariables();
if (typeVariables == Binding.NO_TYPE_VARIABLES) { // check generic
if (scope.compilerOptions().originalSourceLevel >= ClassFileConstants.JDK1_5) { // below 1.5, already reported as syntax error
scope.problemReporter().nonGenericTypeCannotBeParameterized(i, this, currentType, argTypes);
return null;
}
this.resolvedType = (qualifyingType != null && qualifyingType.isParameterizedType())
? scope.environment().createParameterizedType(currentOriginal, null, qualifyingType)
: currentType;
return this.resolvedType;
scope.problemReporter().nonGenericTypeCannotBeParameterized(i, this, currentType, argTypes);
return null;
} else if (argLength != typeVariables.length) {
if (!isDiamond) { // check arity
scope.problemReporter().incorrectArityForParameterizedType(this, currentType, argTypes, i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.compiler.ASTVisitor;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.impl.Constant;
import org.eclipse.jdt.internal.compiler.lookup.*;

Expand Down Expand Up @@ -280,19 +279,10 @@ private TypeBinding internalResolveLeafType(Scope scope, ReferenceBinding enclos

TypeVariableBinding[] typeVariables = currentOriginal.typeVariables();
if (typeVariables == Binding.NO_TYPE_VARIABLES) { // non generic invoked with arguments
boolean isCompliant15 = scope.compilerOptions().originalSourceLevel >= ClassFileConstants.JDK1_5;
if ((currentOriginal.tagBits & TagBits.HasMissingType) == 0) {
if (isCompliant15) { // below 1.5, already reported as syntax error
this.resolvedType = currentType;
scope.problemReporter().nonGenericTypeCannotBeParameterized(0, this, currentType, argTypes);
return null;
}
}
// resilience do not rebuild a parameterized type unless compliance is allowing it
if (!isCompliant15) {
if (!this.resolvedType.isValidBinding())
return currentType;
return this.resolvedType = currentType;
this.resolvedType = currentType;
scope.problemReporter().nonGenericTypeCannotBeParameterized(0, this, currentType, argTypes);
return null;
}
// if missing generic type, and compliance >= 1.5, then will rebuild a parameterized binding
} else if (argLength != typeVariables.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,18 +429,8 @@ public class CompilerOptions {
public boolean generateGenericSignatureForLambdaExpressions;
/** Compliance level for the compiler, refers to a JDK version, e.g. {@link ClassFileConstants#JDK1_4} */
public long complianceLevel;
/** Original compliance level for the compiler, refers to a JDK version, e.g. {@link ClassFileConstants#JDK1_4},
* Usually same as the field complianceLevel, though the latter could deviate to create temporary sandbox
* modes during reconcile operations. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=323633
*/
public long originalComplianceLevel;
/** Java source level, refers to a JDK version, e.g. {@link ClassFileConstants#JDK1_4} */
public long sourceLevel;
/** Original Java source level, refers to a JDK version, e.g. {@link ClassFileConstants#JDK1_4}
* Usually same as the field sourceLevel, though the latter could deviate to create temporary sandbox
* modes during reconcile operations. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=323633
* */
public long originalSourceLevel;
/** VM target level, refers to a JDK version, e.g. {@link ClassFileConstants#JDK1_4} */
public long targetJDK;
/** Source encoding format */
Expand Down Expand Up @@ -1574,8 +1564,8 @@ protected void resetDefaults() {

// by default be compliant with first supported version
final long firstSupportedJdkLevel = getFirstSupportedJdkLevel();
this.complianceLevel = this.originalComplianceLevel = firstSupportedJdkLevel;
this.sourceLevel = this.originalSourceLevel = firstSupportedJdkLevel;
this.complianceLevel = firstSupportedJdkLevel;
this.sourceLevel = firstSupportedJdkLevel;
this.targetJDK = firstSupportedJdkLevel;

this.defaultEncoding = null; // will use the platform default encoding
Expand Down Expand Up @@ -1771,11 +1761,11 @@ public void set(Map<String, String> optionsMap) {
}
if ((optionValue = optionsMap.get(OPTION_Compliance)) != null) {
long level = versionToJdkLevel(optionValue);
if (level != 0) this.complianceLevel = this.originalComplianceLevel = level;
if (level != 0) this.complianceLevel = level;
}
if ((optionValue = optionsMap.get(OPTION_Source)) != null) {
long level = versionToJdkLevel(optionValue);
if (level != 0) this.sourceLevel = this.originalSourceLevel = level;
if (level != 0) this.sourceLevel = level;
}
if ((optionValue = optionsMap.get(OPTION_TargetPlatform)) != null) {
long level = versionToJdkLevel(optionValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ void cachePartsFrom(IBinaryType binaryType, boolean needFieldsAndMethods) {
}

CompilerOptions globalOptions = this.environment.globalOptions;
long sourceLevel = globalOptions.originalSourceLevel;
long sourceLevel = globalOptions.sourceLevel;
/* https://bugs.eclipse.org/bugs/show_bug.cgi?id=324850, even in a 1.4 project, we
must internalize type variables and observe any parameterization of super class
and/or super interfaces in order to be able to detect overriding in the presence
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1679,7 +1679,7 @@ public boolean usesNullTypeAnnotations() {

private void initializeUsesNullTypeAnnotation() {
this.globalOptions.useNullTypeAnnotations = Boolean.FALSE;
if (!this.globalOptions.isAnnotationBasedNullAnalysisEnabled || this.globalOptions.originalSourceLevel < ClassFileConstants.JDK1_8)
if (!this.globalOptions.isAnnotationBasedNullAnalysisEnabled)
return;
ReferenceBinding nullable;
ReferenceBinding nonNull;
Expand Down Expand Up @@ -1733,7 +1733,7 @@ public boolean usesOwningAnnotations() {

private void initializeUsesOwningAnnotations() {
this.globalOptions.useOwningAnnotations = Boolean.FALSE;
if (!this.globalOptions.analyseResourceLeaks || this.globalOptions.originalSourceLevel < ClassFileConstants.JDK1_7)
if (!this.globalOptions.analyseResourceLeaks)
return;
ReferenceBinding owning;
ReferenceBinding notOwning;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private CompilationUnitDeclaration convert(ISourceType[] sourceTypes, Compilatio
org.eclipse.jdt.core.ICompilationUnit cuHandle = topLevelTypeInfo.getHandle().getCompilationUnit();
this.cu = (ICompilationUnit) cuHandle;
final CompilationUnitElementInfo compilationUnitElementInfo = (CompilationUnitElementInfo) ((JavaElement) this.cu).getElementInfo();
if (this.has1_5Compliance &&
if (
(compilationUnitElementInfo.annotationNumber >= CompilationUnitElementInfo.ANNOTATION_THRESHOLD_FOR_DIET_PARSE ||
(compilationUnitElementInfo.hasFunctionalTypes && (this.flags & LOCAL_TYPE) != 0) ||
couldBeVarargs)) {
Expand Down Expand Up @@ -299,11 +299,9 @@ private FieldDeclaration convert(SourceField fieldHandle, TypeDeclaration type,
field.type = createTypeReference(fieldInfo.getTypeName(), start, end);
}

// convert 1.5 specific constructs only if compliance is 1.5 or above
if (this.has1_5Compliance) {
/* convert annotations */
field.annotations = convertAnnotations(fieldHandle);
}
// convert 1.5 specific constructs
/* convert annotations */
field.annotations = convertAnnotations(fieldHandle);

/* conversion of field constant */
if ((this.flags & FIELD_INITIALIZATION) != 0) {
Expand Down Expand Up @@ -431,11 +429,9 @@ private AbstractMethodDeclaration convert(SourceMethod methodHandle, SourceMetho
method.declarationSourceStart = methodInfo.getDeclarationSourceStart();
method.declarationSourceEnd = methodInfo.getDeclarationSourceEnd();

// convert 1.5 specific constructs only if compliance is 1.5 or above
if (this.has1_5Compliance) {
/* convert annotations */
method.annotations = convertAnnotations(methodHandle);
}
// convert 1.5 specific constructs
/* convert annotations */
method.annotations = convertAnnotations(methodHandle);

/* convert arguments */
String[] argumentTypeSignatures = methodHandle.getParameterTypes();
Expand All @@ -457,11 +453,9 @@ private AbstractMethodDeclaration convert(SourceMethod methodHandle, SourceMetho
typeReference,
ClassFileConstants.AccDefault);
// do not care whether was final or not
// convert 1.5 specific constructs only if compliance is 1.5 or above
if (this.has1_5Compliance) {
/* convert annotations */
method.arguments[i].annotations = convertAnnotations(parameters[i]);
}
// convert 1.5 specific constructs
/* convert annotations */
method.arguments[i].annotations = convertAnnotations(parameters[i]);
}
}

Expand Down Expand Up @@ -546,11 +540,10 @@ private TypeDeclaration convert(SourceType typeHandle, CompilationResult compila
type.declarationSourceEnd = typeInfo.getDeclarationSourceEnd();
type.bodyEnd = type.declarationSourceEnd;

// convert 1.5 specific constructs only if compliance is 1.5 or above
if (this.has1_5Compliance) {
/* convert annotations */
type.annotations = convertAnnotations(typeHandle);
}
// convert 1.5 specific constructs
/* convert annotations */
type.annotations = convertAnnotations(typeHandle);

/* https://bugs.eclipse.org/bugs/show_bug.cgi?id=324850, even in a 1.4 project, we
must internalize type variables and observe any parameterization of super class
and/or super interfaces in order to be able to detect overriding in the presence
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.eclipse.jdt.internal.compiler.ast.TypeParameter;
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
import org.eclipse.jdt.internal.compiler.ast.Wildcard;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
Expand All @@ -39,14 +38,11 @@ public abstract class TypeConverter {
int namePos;

protected ProblemReporter problemReporter;
protected boolean has1_5Compliance;
protected boolean has14_Compliance;

private final char memberTypeSeparator;

protected TypeConverter(ProblemReporter problemReporter, char memberTypeSeparator) {
this.problemReporter = problemReporter;
this.has1_5Compliance = problemReporter.options.originalComplianceLevel >= ClassFileConstants.JDK1_5;
this.has14_Compliance = problemReporter.options.originalComplianceLevel >= ClassFileConstants.JDK14;
this.memberTypeSeparator = memberTypeSeparator;
}

Expand Down Expand Up @@ -282,9 +278,7 @@ private TypeReference decodeType(String typeSignature, int length, int start, in
break;
case Signature.C_GENERIC_START :
nameFragmentEnd = this.namePos-1;
// convert 1.5 specific constructs only if compliance is 1.5 or above
if (!this.has1_5Compliance)
break typeLoop;
// convert 1.5 specific constructs
if (fragments == null) fragments = new ArrayList(2);
addIdentifiers(typeSignature, nameFragmentStart, nameFragmentEnd + 1, identCount, fragments);
this.namePos++; // skip '<'
Expand Down Expand Up @@ -443,17 +437,17 @@ private TypeReference decodeType2(char[] typeName, int length, int start, int en
Because of the way type signatures are encoded, TypeConverter.decodeType(String, int, int, int) is immune
to this problem. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=325633
*/
if (this.has1_5Compliance || includeGenericsAnyway) {
if (includeGenericsAnyway) {
if (fragments == null) fragments = new ArrayList(2);
}
nameFragmentEnd = this.namePos-1;
if (this.has1_5Compliance || includeGenericsAnyway) {
if (includeGenericsAnyway) {
char[][] identifiers = CharOperation.splitOn('.', typeName, nameFragmentStart, this.namePos);
fragments.add(identifiers);
}
this.namePos++; // skip '<'
TypeReference[] arguments = decodeTypeArguments(typeName, length, start, end, includeGenericsAnyway); // positionned on '>' at end
if (this.has1_5Compliance || includeGenericsAnyway) {
if (includeGenericsAnyway) {
fragments.add(arguments);
identCount = 0;
nameFragmentStart = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,22 +143,20 @@ private AbstractMethodDeclaration convert(IMethod method, IType type) throws Jav

org.eclipse.jdt.internal.compiler.ast.TypeParameter[] typeParams = null;

// convert 1.5 specific constructs only if compliance is 1.5 or above
if (this.has1_5Compliance) {
/* convert type parameters */
ITypeParameter[] typeParameters = method.getTypeParameters();
if (typeParameters != null && typeParameters.length > 0) {
int parameterCount = typeParameters.length;
typeParams = new org.eclipse.jdt.internal.compiler.ast.TypeParameter[parameterCount];
for (int i = 0; i < parameterCount; i++) {
ITypeParameter typeParameter = typeParameters[i];
typeParams[i] =
createTypeParameter(
typeParameter.getElementName().toCharArray(),
stringArrayToCharArray(typeParameter.getBounds()),
0,
0);
}
// convert 1.5 specific constructs only
/* convert type parameters */
ITypeParameter[] typeParameters = method.getTypeParameters();
if (typeParameters != null && typeParameters.length > 0) {
int parameterCount = typeParameters.length;
typeParams = new org.eclipse.jdt.internal.compiler.ast.TypeParameter[parameterCount];
for (int i = 0; i < parameterCount; i++) {
ITypeParameter typeParameter = typeParameters[i];
typeParams[i] =
createTypeParameter(
typeParameter.getElementName().toCharArray(),
stringArrayToCharArray(typeParameter.getBounds()),
0,
0);
}
}

Expand Down Expand Up @@ -251,26 +249,24 @@ private TypeDeclaration convert(IType type, IType alreadyComputedMember,TypeDecl
System.arraycopy(typeDeclaration.fields, 0, typeDeclaration.superInterfaces = new TypeReference[interfaceCount], 0, interfaceCount);
}

// convert 1.5 specific constructs only if compliance is 1.5 or above
if (this.has1_5Compliance) {

/* convert type parameters */
ITypeParameter[] typeParameters = type.getTypeParameters();
if (typeParameters != null && typeParameters.length > 0) {
int parameterCount = typeParameters.length;
org.eclipse.jdt.internal.compiler.ast.TypeParameter[] typeParams = new org.eclipse.jdt.internal.compiler.ast.TypeParameter[parameterCount];
for (int i = 0; i < parameterCount; i++) {
ITypeParameter typeParameter = typeParameters[i];
typeParams[i] =
createTypeParameter(
typeParameter.getElementName().toCharArray(),
stringArrayToCharArray(typeParameter.getBounds()),
0,
0);
}

typeDeclaration.typeParameters = typeParams;
// convert 1.5 specific constructs

/* convert type parameters */
ITypeParameter[] typeParameters = type.getTypeParameters();
if (typeParameters != null && typeParameters.length > 0) {
int parameterCount = typeParameters.length;
org.eclipse.jdt.internal.compiler.ast.TypeParameter[] typeParams = new org.eclipse.jdt.internal.compiler.ast.TypeParameter[parameterCount];
for (int i = 0; i < parameterCount; i++) {
ITypeParameter typeParameter = typeParameters[i];
typeParams[i] =
createTypeParameter(
typeParameter.getElementName().toCharArray(),
stringArrayToCharArray(typeParameter.getBounds()),
0,
0);
}

typeDeclaration.typeParameters = typeParams;
}

/* convert member types */
Expand Down

0 comments on commit dba0ef7

Please sign in to comment.