diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTTest.java index ad348282fb0..2fbedeebd8d 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTTest.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTTest.java @@ -1323,12 +1323,11 @@ private static int getApiLevel(String s) { if (s == null) return AST.JLS12; switch (s) { - case JavaCore.VERSION_1_2 : return AST.JLS2; - case JavaCore.VERSION_1_3: return AST.JLS3; - case JavaCore.VERSION_1_4: return AST.JLS4; - case JavaCore.VERSION_1_5: return AST.JLS4; - case JavaCore.VERSION_1_6: return AST.JLS4; - case JavaCore.VERSION_1_7: return AST.JLS4; + case JavaCore.VERSION_1_2 : return AST.JLS8; + case JavaCore.VERSION_1_3: return AST.JLS8; + case JavaCore.VERSION_1_4: return AST.JLS8; + case JavaCore.VERSION_1_5: return AST.JLS8; + case JavaCore.VERSION_1_6: return AST.JLS8; case JavaCore.VERSION_1_8: return AST.JLS8; case JavaCore.VERSION_9: return AST.JLS9; case JavaCore.VERSION_10: return AST.JLS10; @@ -1342,7 +1341,7 @@ private static int getApiLevel(String s) { case JavaCore.VERSION_18: return AST.JLS18; case JavaCore.VERSION_19: return AST.JLS19; case JavaCore.VERSION_20: return AST.JLS20; - default: return AST.JLS2; + default: return AST.JLS8; } } /** @deprecated using deprecated code */ @@ -1355,7 +1354,7 @@ public void testAST() { int apiLevelCal = ASTTest.getApiLevel(JavaCore.getDefaultOptions().get(JavaCore.COMPILER_SOURCE)); assertTrue(a0.apiLevel() == apiLevelCal); AST a1 = new AST(new HashMap()); // deprecated, but still 2.0 - assertTrue(a1.apiLevel() == AST.JLS2); + assertEquals(AST.JLS8,a1.apiLevel()); AST a2 = AST.newAST(AST.JLS2, false); assertTrue(a2.apiLevel() == AST.JLS2); AST a3 = AST.newAST(JLS3_INTERNAL, false); diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/AST.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/AST.java index fddc84e74f8..4aa80c87317 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/AST.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/AST.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2024 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -1229,22 +1229,8 @@ public AST(Map options) { this(apiLevelMap.get(options.get(JavaCore.COMPILER_SOURCE)), JavaCore.ENABLED.equals(options.get(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES))); - long sourceLevel; - long complianceLevel; - switch(this.apiLevel) { - case JLS2_INTERNAL : - case JLS3_INTERNAL : - sourceLevel = ClassFileConstants.JDK1_3; - complianceLevel = ClassFileConstants.JDK1_5; - break; - case JLS4_INTERNAL : - sourceLevel = ClassFileConstants.JDK1_7; - complianceLevel = ClassFileConstants.JDK1_7; - break; - default : - sourceLevel = AST.jdkLevelMap.get(options.get(JavaCore.COMPILER_SOURCE)); - complianceLevel = sourceLevel; - } + long sourceLevel = AST.jdkLevelMap.get(options.get(JavaCore.COMPILER_SOURCE)); + long complianceLevel = sourceLevel; this.scanner = new Scanner( true /*comment*/, true /*whitespace*/, @@ -1259,13 +1245,13 @@ public AST(Map options) { private static Map getLevelMapTable() { Map t = new HashMap<>(); - t.put(null, ClassFileConstants.JDK1_2); - t.put(JavaCore.VERSION_1_2, ClassFileConstants.JDK1_2); - t.put(JavaCore.VERSION_1_3, ClassFileConstants.JDK1_3); - t.put(JavaCore.VERSION_1_4, ClassFileConstants.JDK1_4); - t.put(JavaCore.VERSION_1_5, ClassFileConstants.JDK1_5); - t.put(JavaCore.VERSION_1_6, ClassFileConstants.JDK1_6); - t.put(JavaCore.VERSION_1_7, ClassFileConstants.JDK1_7); + t.put(null, ClassFileConstants.JDK1_8); + t.put(JavaCore.VERSION_1_2, ClassFileConstants.JDK1_8); + t.put(JavaCore.VERSION_1_3, ClassFileConstants.JDK1_8); + t.put(JavaCore.VERSION_1_4, ClassFileConstants.JDK1_8); + t.put(JavaCore.VERSION_1_5, ClassFileConstants.JDK1_8); + t.put(JavaCore.VERSION_1_6, ClassFileConstants.JDK1_8); + t.put(JavaCore.VERSION_1_7, ClassFileConstants.JDK1_8); t.put(JavaCore.VERSION_1_8, ClassFileConstants.JDK1_8); t.put(JavaCore.VERSION_9, ClassFileConstants.JDK9); t.put(JavaCore.VERSION_10, ClassFileConstants.JDK10); @@ -1286,13 +1272,13 @@ private static Map getLevelMapTable() { } private static Map getApiLevelMapTable() { Map t = new HashMap<>(); - t.put(null, JLS2_INTERNAL); - t.put(JavaCore.VERSION_1_2, JLS2_INTERNAL); - t.put(JavaCore.VERSION_1_3, JLS3_INTERNAL); - t.put(JavaCore.VERSION_1_4, JLS4_INTERNAL); - t.put(JavaCore.VERSION_1_5, JLS4_INTERNAL); - t.put(JavaCore.VERSION_1_6, JLS4_INTERNAL); - t.put(JavaCore.VERSION_1_7, JLS4_INTERNAL); + t.put(null, JLS8_INTERNAL); + t.put(JavaCore.VERSION_1_2, JLS8_INTERNAL); + t.put(JavaCore.VERSION_1_3, JLS8_INTERNAL); + t.put(JavaCore.VERSION_1_4, JLS8_INTERNAL); + t.put(JavaCore.VERSION_1_5, JLS8_INTERNAL); + t.put(JavaCore.VERSION_1_6, JLS8_INTERNAL); + t.put(JavaCore.VERSION_1_7, JLS8_INTERNAL); t.put(JavaCore.VERSION_1_8, JLS8_INTERNAL); t.put(JavaCore.VERSION_9, JLS9_INTERNAL); t.put(JavaCore.VERSION_10, JLS10_INTERNAL);