From 50a3e041108ae58efdaf676f81370159d3911850 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=8A?= =?UTF-8?q?=D1=80=20=D0=9A=D1=83=D1=80=D1=82=D0=B0=D0=BA=D0=BE=D0=B2?= Date: Wed, 8 Jan 2025 18:27:24 +0200 Subject: [PATCH] DRAFT: Make AST map pre 1.8 versions to 1.8 As the compiler mandates 1.8 already it makes sense for the AST to do the same. --- .../eclipse/jdt/core/tests/dom/ASTTest.java | 15 +++--- .../dom/org/eclipse/jdt/core/dom/AST.java | 46 +++++++------------ 2 files changed, 23 insertions(+), 38 deletions(-) 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 5e77b288366..96a6dfc5e23 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 @@ -1245,22 +1245,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*/, @@ -1275,13 +1261,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); @@ -1302,13 +1288,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);