Skip to content

Commit

Permalink
DRAFT: Make AST map pre 1.8 versions to 1.8
Browse files Browse the repository at this point in the history
As the compiler mandates 1.8 already it makes sense for the AST to do
the same.
  • Loading branch information
akurtakov committed Jan 10, 2025
1 parent 7ddead3 commit 50a3e04
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 */
Expand All @@ -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);
Expand Down
46 changes: 16 additions & 30 deletions org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/AST.java
Original file line number Diff line number Diff line change
Expand Up @@ -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*/,
Expand All @@ -1275,13 +1261,13 @@ public AST(Map options) {

private static Map<String, Long> getLevelMapTable() {
Map<String, Long> 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);
Expand All @@ -1302,13 +1288,13 @@ private static Map<String, Long> getLevelMapTable() {
}
private static Map<String, Integer> getApiLevelMapTable() {
Map<String, Integer> 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);
Expand Down

0 comments on commit 50a3e04

Please sign in to comment.