Skip to content

Commit

Permalink
Remove compiler support for JLS source/target < 1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveeclipse committed Jun 18, 2024
1 parent 009e320 commit 8de8d42
Show file tree
Hide file tree
Showing 66 changed files with 277 additions and 640 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public CompilerInvocationTests(String name) {
super(name);
}
public static Test suite() {
return buildUniqueComplianceTestSuite(CompilerInvocationTests.class, ClassFileConstants.JDK1_6);
return buildUniqueComplianceTestSuite(CompilerInvocationTests.class, ClassFileConstants.JDK1_8);
}
public static Class<CompilerInvocationTests> testClass() {
return CompilerInvocationTests.class;
Expand All @@ -81,7 +81,7 @@ protected void checkClassFiles(String[] fileNames) {
fail("IO exception for file " + fileNames[i]);
}
assertNotNull("Could not read " + fileNames[i], reader);
assertEquals("Wrong Java version for " + fileNames[i], ClassFileConstants.JDK1_6, reader.getVersion());
assertEquals("Wrong Java version for " + fileNames[i], ClassFileConstants.JDK1_8, reader.getVersion());
}
}
void runTest(
Expand All @@ -96,7 +96,7 @@ void runTest(
String[] classFileNames) {
List<String> opt = options == null ? new ArrayList<>() : new ArrayList<>(options);
opt.add("-source");
opt.add("1.6");
opt.add("1.8");
super.runTest(
shouldCompileOK,
sourceFiles,
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.core.compiler.batch/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Main-Class: org.eclipse.jdt.internal.compiler.batch.Main
Bundle-ManifestVersion: 2
Bundle-Name: Eclipse Compiler for Java(TM)
Bundle-SymbolicName: org.eclipse.jdt.core.compiler.batch
Bundle-Version: 3.38.100.qualifier
Bundle-Version: 3.39.0.qualifier
Bundle-ClassPath: .
Bundle-Vendor: Eclipse.org
Automatic-Module-Name: org.eclipse.jdt.core.compiler.batch
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.core.compiler.batch/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<version>4.33.0-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.jdt.core.compiler.batch</artifactId>
<version>3.38.100-SNAPSHOT</version>
<version>3.39.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2183,6 +2183,8 @@ public interface IProblem {
int FeatureNotSupported = Compliance + 1107;
/** @since 3.26*/
int PreviewAPIUsed = Compliance + 1108;
/** @since 3.39*/
int JavaVersionNotSupported = Compliance + 1109;

/** @since 3.13 */
int UnlikelyCollectionMethodArgumentType = 1200;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -818,11 +818,31 @@ private void abortIfPreviewNotAllowed(ICompilationUnit[] sourceUnits, int maxUn
throw a;
}
}

private void abortIfVersionNotAllowed(ICompilationUnit[] sourceUnits, int maxUnits) {
try {
long firstSupportedJdkLevel = CompilerOptions.getFirstSupportedJdkLevel();
if (this.options.sourceLevel < firstSupportedJdkLevel
|| this.options.targetJDK < firstSupportedJdkLevel
|| this.options.complianceLevel < firstSupportedJdkLevel) {
long badVersion = Math.min(this.options.complianceLevel, Math.min(this.options.sourceLevel, this.options.targetJDK));
this.problemReporter.abortDueToNotSupportedJavaVersion(CompilerOptions.versionFromJdkLevel(badVersion),
CompilerOptions.getFirstSupportedJavaVersion());
}
} catch (AbortCompilation a) {
// best effort to find a way for reporting this problem: report on the first source
if (a.compilationResult == null) {
a.compilationResult = new CompilationResult(sourceUnits[0], 0, maxUnits, this.options.maxProblemsPerUnit);
}
throw a;
}
}
/**
* Add the initial set of compilation units into the loop
* -> build compilation unit declarations, their bindings and record their results.
*/
protected void internalBeginToCompile(ICompilationUnit[] sourceUnits, int maxUnits) {
abortIfVersionNotAllowed(sourceUnits,maxUnits);
abortIfPreviewNotAllowed(sourceUnits,maxUnits);
if (!this.useSingleThread && maxUnits >= ReadManager.THRESHOLD)
this.parser.readManager = new ReadManager(sourceUnits, maxUnits);
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ compile.severalClassFilesGenerated = [{0} .class files generated]
compile.failOnWarning = error: warnings found and -failOnWarning specified

### configure
configure.requiresJDK1.2orAbove = Need to use a JVM >= 1.2
configure.requiresJDK1.2orAbove = Need to use a JVM >= 1.8
configure.duplicateLog = duplicate log specification: {0}
configure.duplicateRepeat = duplicate repeat specification: {0}
configure.duplicateMaxProblems = duplicate max problems specification: {0}
Expand All @@ -71,7 +71,10 @@ configure.duplicateTarget = duplicate target compliance setting specification: {
configure.unsupportedReleaseOption = option --release is supported only when run with JDK 9 or above
configure.unsupportedWithRelease = option {0} is not supported when --release is used
configure.unsupportedReleaseVersion = release version {0} is not supported
configure.source = source level should be in ''1.1''...''1.8'',''9''...''22'' (or ''5.0''..''22.0''): {0}
configure.unsupportedComplianceVersion = compliance option {0} is no longer supported. Use {1} or later.
configure.unsupportedSourceVersion = source option {0} is no longer supported. Use {1} or later.
configure.unsupportedTargetVersion = target option {0} is no longer supported. Use {1} or later.
configure.source = source level should be in ''1.8'',''9''...''22'' (or ''5.0''..''22.0''): {0}
configure.invalidSystem = invalid location for system libraries: {0}
configure.unsupportedOption = option {0} not supported at compliance level 9 and above
configure.duplicateOutputPath = duplicate output path specification: {0}
Expand All @@ -92,9 +95,9 @@ configure.invalidDebugOption = invalid debug option: {0}
configure.invalidWarningConfiguration = invalid warning configuration: ''{0}''
configure.invalidWarning = invalid warning token: ''{0}''. Ignoring warning and compiling
configure.invalidWarningOption = invalid warning option: ''{0}''. Must specify a warning token
configure.targetJDK = target level should be in ''1.1''...''1.8'',''9''...''22'' (or ''5.0''..''22.0'') or cldc1.1: {0}
configure.targetJDK = target level should be in ''1.8'',''9''...''22'' (or ''8.0''..''22.0''): {0}
configure.incompatibleTargetForSource = Target level ''{0}'' is incompatible with source level ''{1}''. A target level ''{1}'' or better is required
configure.incompatibleTargetForGenericSource = Target level ''{0}'' is incompatible with source level ''{1}''. A source level ''1.5'' or better is required
configure.incompatibleTargetForGenericSource = Target level ''{0}'' is incompatible with source level ''{1}''. A source level ''1.8'' or better is required
configure.incompatibleComplianceForSource = Compliance level ''{0}'' is incompatible with source level ''{1}''. A compliance level ''{1}'' or better is required
configure.incompatibleComplianceForTarget = Compliance level ''{0}'' is incompatible with target level ''{1}''. A compliance level ''{1}'' or better is required
configure.repetition = repetition must be a positive integer: {0}
Expand Down Expand Up @@ -138,9 +141,7 @@ configure.invalidClassName = invalid class name: {0}
configure.invalidModuleName = invalid module name: {0}
configure.packageConflict = The package {0} is accessible from more than one module: {1}, {2}
configure.unavailableAPT = Unable to load annotation processing manager {0} from classpath.
configure.incorrectVMVersionforAPT = Annotation processing got disabled, since it requires a 1.6 compliant JVM
configure.incompatibleSourceForCldcTarget=Target level ''{0}'' is incompatible with source level ''{1}''. A source level ''1.3'' or lower is required
configure.incompatibleComplianceForCldcTarget=Target level ''{0}'' is incompatible with compliance level ''{1}''. A compliance level ''1.4''or lower is required
configure.incorrectVMVersionforAPT = Annotation processing got disabled, since it requires a 1.8 compliant JVM
configure.invalidClasspathSection = invalid Class-Path header in manifest of jar file: {0}
configure.multipleClasspathSections = multiple Class-Path headers in manifest of jar file: {0}
configure.missingwarningspropertiesfile=properties file {0} does not exist
Expand Down Expand Up @@ -248,11 +249,6 @@ misc.usage = {1} {2}\n\
\ --release <release> compile for a specific VM version\n\
\ \n\
\ Compliance options:\n\
\ -1.3 use 1.3 compliance (-source 1.3 -target 1.1)\n\
\ -1.4 + use 1.4 compliance (-source 1.3 -target 1.2)\n\
\ -1.5 -5 -5.0 use 1.5 compliance (-source 1.5 -target 1.5)\n\
\ -1.6 -6 -6.0 use 1.6 compliance (-source 1.6 -target 1.6)\n\
\ -1.7 -7 -7.0 use 1.7 compliance (-source 1.7 -target 1.7)\n\
\ -1.8 -8 -8.0 use 1.8 compliance (-source 1.8 -target 1.8)\n\
\ -1.9 -9 -9.0 use 1.9 compliance (-source 1.9 -target 1.9)\n\
\ -10 -10.0 use 10 compliance (-source 10 -target 10)\n\
Expand All @@ -268,12 +264,10 @@ misc.usage = {1} {2}\n\
\ -20 -20.0 use 20 compliance (-source 20 -target 20)\n\
\ -21 -21.0 use 21 compliance (-source 21 -target 21)\n\
\ -22 -22.0 use 22 compliance (-source 22 -target 22)\n\
\ -source <version> set source level: 1.3 to 1.9, 10 to 22\n\
\ (or 6, 6.0, etc)\n\
\ -target <version> set classfile target: 1.3 to 1.9, 10 to 22\n\
\ (or 6, 6.0, etc)\n\
\ cldc1.1 can also be used to generate the StackMap\n\
\ attribute\n\
\ -source <version> set source level: 1.8, 9 to 22\n\
\ (or 8.0, 9.0, etc)\n\
\ -target <version> set classfile target: 1.8, 9 to 22\n\
\ (or 8.0, 9.0, etc)\n\
\ --enable-preview enable support for preview features of the\n\
\ latest Java release\n\
\ \n\
Expand Down Expand Up @@ -316,7 +310,7 @@ misc.usage = {1} {2}\n\
\ -preserveAllLocals preserve unused local vars for debug purpose\n\
\ \n\
\ Annotation processing options:\n\
\ These options are meaningful only in a 1.6 environment.\n\
\ These options are meaningful only in a 1.8 environment.\n\
\ -Akey[=value] options that are passed to annotation processors\n\
\ -processorpath <directories and ZIP archives separated by {0}>\n\
\ specify locations where to find annotation processors.\n\
Expand Down Expand Up @@ -353,7 +347,7 @@ misc.usage = {1} {2}\n\
\ -noExit do not call System.exit(n) at end of compilation (n==0\n\
\ if no error)\n\
\ -repeat <n> repeat compilation process <n> times for perf analysis\n\
\ -inlineJSR inline JSR bytecode (implicit if target >= 1.5)\n\
\ -inlineJSR inline JSR bytecode (implicit if target >= 1.8)\n\
\ -enableJavadoc consider references in javadoc\n\
\ -parameters generate method parameters attribute (for target >= 1.8)\n\
\ -genericsignature generate generic signature for lambda expressions\n\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.compiler.Compiler;
Expand Down Expand Up @@ -258,6 +259,25 @@ public class CompilerOptions {
* Note: Whenever a new version is added, make sure getLatestVersion()
* is updated with it.
*/

/**
* Unsupported JLS versions
*/
/*
* Note: Whenever a new version is obsoleted, make sure getFirstVersion() is updated.
*/
public static Set<String> UNSUPPORTED_VERSIONS = Set.of(
VERSION_1_1,
VERSION_1_2,
VERSION_1_3,
VERSION_1_4,
VERSION_JSR14,
VERSION_CLDC1_1,
VERSION_1_5,
VERSION_1_6,
VERSION_1_7
);

public static final String ERROR = "error"; //$NON-NLS-1$
public static final String WARNING = "warning"; //$NON-NLS-1$
public static final String INFO = "info"; //$NON-NLS-1$
Expand Down Expand Up @@ -647,6 +667,18 @@ public CompilerOptions(Map<String, String> settings, boolean parseLiteralExpress
this.parseLiteralExpressionsAsConstants = parseLiteralExpressionsAsConstants;
}

/**
* Return the first (oldest) Java language version supported by the Eclipse compiler
*/
public static String getFirstSupportedJavaVersion() {
return VERSION_1_8;
}
/**
* Return the first (oldest) Java language level supported by the Eclipse compiler
*/
public static long getFirstSupportedJdkLevel() {
return ClassFileConstants.JDK1_8;
}
/**
* Return the latest Java language version supported by the Eclipse compiler
*/
Expand Down Expand Up @@ -1545,9 +1577,9 @@ protected void resetDefaults() {

// by default only lines and source attributes are generated.
this.produceDebugAttributes = ClassFileConstants.ATTR_SOURCE | ClassFileConstants.ATTR_LINES;
this.complianceLevel = this.originalComplianceLevel = ClassFileConstants.JDK1_4; // by default be compliant with 1.4
this.sourceLevel = this.originalSourceLevel = ClassFileConstants.JDK1_3; //1.3 source behavior by default
this.targetJDK = ClassFileConstants.JDK1_2; // default generates for JVM1.2
this.complianceLevel = this.originalComplianceLevel = ClassFileConstants.JDK1_8; // by default be compliant with 1.8
this.sourceLevel = this.originalSourceLevel = ClassFileConstants.JDK1_8; //1.8 source behavior by default
this.targetJDK = ClassFileConstants.JDK1_8; // default generates for JVM1.8

this.defaultEncoding = null; // will use the platform default encoding

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,16 @@ public void abortDueToPreviewEnablingNotAllowed(String sourceLevel, String expec
0,
0);
}
public void abortDueToNotSupportedJavaVersion(String notSupportedVersion, String firstSupportedVersion) {
String[] args = new String[] {notSupportedVersion, firstSupportedVersion};
this.handle(
IProblem.JavaVersionNotSupported,
args,
args,
ProblemSeverities.Error | ProblemSeverities.Abort | ProblemSeverities.Fatal,
0,
0);
}
public void abstractMethodCannotBeOverridden(SourceTypeBinding type, MethodBinding concreteMethod) {

this.handle(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@
264 = Invalid high surrogate: must be within 0xD800 and 0xDBFF
265 = Unnecessary $NON-NLS$ tag
266 = Invalid binary literal number (only '0' and '1' are expected)
267 = Binary literals can only be used with source level 1.7 or greater
267 = Binary literals can only be used with source level 1.8 or greater
268 = Underscores have to be located within digits
269 = Underscores can only be used with source level 1.7 or greater
269 = Underscores can only be used with source level 1.8 or greater
271 = This lambda expression refers to the missing type {0}
272 = Text block is not properly closed with the delimiter

Expand Down Expand Up @@ -441,8 +441,8 @@
433 = Too many methods for type {0}. Maximum is 65535
434 = The synthetic method created to access {0}({1}) of type {2} has too many parameters

440 = 'assert' should not be used as an identifier, since it is a reserved keyword from source level 1.4 on
441 = 'enum' should not be used as an identifier, since it is a reserved keyword from source level 1.5 on
440 = 'assert' should not be used as an identifier, since it is a reserved keyword from source level 1.8 on
441 = 'enum' should not be used as an identifier, since it is a reserved keyword from source level 1.8 on
442 = Enum constants cannot be surrounded by parenthesis
443 = '_' should not be used as an identifier, since it is a reserved keyword from source level 1.8 on
444 = The uninterned types {0} and {1} should not be compared using ==/!= operators.
Expand Down Expand Up @@ -594,14 +594,14 @@
585 = Type safety: Elements of type {0} need unchecked conversion to conform to {1}

### SOURCE LEVEL
590 = Syntax error, type parameters are only available if source level is 1.5 or greater
591 = Syntax error, static imports are only available if source level is 1.5 or greater
592 = Syntax error, 'for each' statements are only available if source level is 1.5 or greater
593 = Syntax error, parameterized types are only available if source level is 1.5 or greater
594 = Syntax error, enum declarations are only available if source level is 1.5 or greater
595 = Syntax error, varargs are only available if source level is 1.5 or greater
596 = Syntax error, annotations are only available if source level is 1.5 or greater
597 = Syntax error, annotation declarations are only available if source level is 1.5 or greater
590 = Syntax error, type parameters are only available if source level is 1.8 or greater
591 = Syntax error, static imports are only available if source level is 1.8 or greater
592 = Syntax error, 'for each' statements are only available if source level is 1.8 or greater
593 = Syntax error, parameterized types are only available if source level is 1.8 or greater
594 = Syntax error, enum declarations are only available if source level is 1.8 or greater
595 = Syntax error, varargs are only available if source level is 1.8 or greater
596 = Syntax error, annotations are only available if source level is 1.8 or greater
597 = Syntax error, annotation declarations are only available if source level is 1.8 or greater
598 = Syntax error, annotation declaration cannot have type parameters
599 = Syntax error, enum declaration cannot have type parameters

Expand Down Expand Up @@ -905,6 +905,7 @@
1106 = Preview features enabled at an invalid source release level {0}, preview can be enabled only at source level {1}
1107 = The Java feature ''{0}'' is only available with source level {1} and above
1108 = You are using an API that is part of a preview feature and may be removed in future
1109 = The Java version ''{0}'' is no longer supported. Use {1} or later.
# more programming problems:
1200 = Unlikely argument type {0} for {1} on a {2}
1201 = Unlikely argument type for equals(): {0} seems to be unrelated to {2}
Expand Down
6 changes: 3 additions & 3 deletions org.eclipse.jdt.core.tests.builder/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
</plugins>
</build>
<properties>
<tycho.surefire.argLine>--add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,17</tycho.surefire.argLine>
<tycho.surefire.argLine>--add-modules ALL-SYSTEM -Dcompliance=1.8,17</tycho.surefire.argLine>
</properties>
</profile>
<profile>
Expand All @@ -81,7 +81,7 @@
</plugins>
</build>
<properties>
<tycho.surefire.argLine>--add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,21</tycho.surefire.argLine>
<tycho.surefire.argLine>--add-modules ALL-SYSTEM -Dcompliance=1.8,21</tycho.surefire.argLine>
</properties>
</profile>
<profile>
Expand All @@ -102,7 +102,7 @@
</plugins>
</build>
<properties>
<tycho.surefire.argLine>--add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,21,22</tycho.surefire.argLine>
<tycho.surefire.argLine>--add-modules ALL-SYSTEM -Dcompliance=1.8,21,22</tycho.surefire.argLine>
</properties>
</profile>
</profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,13 +548,11 @@ private static Class[] getAllTestClasses() {
LeakTestsBefore9.class,
};
List<Class<?>> list = new ArrayList<>(Arrays.asList(classes));
if (matchesCompliance(F_1_5)) {
if (matchesCompliance(F_1_8)) {
list.add(Java50Tests.class);
list.add(PackageInfoTest.class);
list.add(ParticipantBuildTests.class);
list.add(AnnotationDependencyTests.class);
}
if (matchesCompliance(F_1_8)) {
list.add(Bug544921Test.class);
}
if (matchesCompliance(F_9)) {
Expand Down
Loading

0 comments on commit 8de8d42

Please sign in to comment.