diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterJavadocTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterJavadocTest.java
index 957791d9504..c2423efb5d3 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterJavadocTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterJavadocTest.java
@@ -1635,7 +1635,6 @@ public void testBug55221c() throws JavaModelException {
methodLength = compilUnit.getExtendedLength(method);
assumeEquals("Method declaration "+method+" does not end at the right position",method.getLength(), methodLength);
}
- /** @deprecated using deprecated code */
public void testBug55221d() throws JavaModelException {
this.sourceUnit = getCompilationUnit("Converter" , "src", "javadoc.testBug55221.d", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
ASTNode result = runConversion(this.sourceUnit, false);
@@ -1653,7 +1652,7 @@ public void testBug55221d() throws JavaModelException {
int methodLength = compilUnit.getExtendedLength(method);
assumeEquals("Method "+method+" does not have the right length", methodLength, method.getLength());
// get return type
- node = method.getReturnType();
+ node = method.getReturnType2();
assumeNotNull("We should get a non-null ast node", node);
assumeTrue("Not return type", node.getNodeType() == ASTNode.PRIMITIVE_TYPE); //$NON-NLS-1$
PrimitiveType returnType = (PrimitiveType) node;
@@ -1702,7 +1701,6 @@ public void testBug55223a() throws JavaModelException {
idx++;
}
}
- /** @deprecated using deprecated code */
public void testBug55223b() throws JavaModelException {
this.sourceUnit = getCompilationUnit("Converter" , "src", "javadoc.testBug55223", "TestB.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
ASTNode result = runConversion(this.sourceUnit, false);
@@ -1718,7 +1716,7 @@ public void testBug55223b() throws JavaModelException {
assumeEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType()); //$NON-NLS-1$
MethodDeclaration method = (MethodDeclaration) node;
// get return type
- node = method.getReturnType();
+ node = method.getReturnType2();
assumeNotNull("We should get a non-null ast node", node);
assumeTrue("Not return type", node.getNodeType() == ASTNode.SIMPLE_TYPE); //$NON-NLS-1$
SimpleType returnType = (SimpleType) node;
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTStructuralPropertyTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTStructuralPropertyTest.java
index 05454e4dafa..dc15970fe4d 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTStructuralPropertyTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTStructuralPropertyTest.java
@@ -41,9 +41,6 @@ public static Test suite() {
Method[] methods = c.getMethods();
for (int i = 0, max = methods.length; i < max; i++) {
if (methods[i].getName().startsWith("test")) { //$NON-NLS-1$
- suite.addTest(new ASTStructuralPropertyTest(methods[i].getName(), AST.JLS2));
- suite.addTest(new ASTStructuralPropertyTest(methods[i].getName(), AST.JLS3));
- suite.addTest(new ASTStructuralPropertyTest(methods[i].getName(), AST.JLS4));
suite.addTest(new ASTStructuralPropertyTest(methods[i].getName(), AST.JLS8));
}
}
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 584819d0775..b7abf10c293 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
@@ -763,9 +763,6 @@ public static Test suite() {
Method[] methods = c.getMethods();
for (int i = 0, max = methods.length; i < max; i++) {
if (methods[i].getName().startsWith("test")) { //$NON-NLS-1$
- suite.addTest(new ASTTest(methods[i].getName(), AST.JLS2));
- suite.addTest(new ASTTest(methods[i].getName(), JLS3_INTERNAL));
- suite.addTest(new ASTTest(methods[i].getName(), AST.JLS4));
suite.addTest(new ASTTest(methods[i].getName(), getJLS8()));
suite.addTest(new ASTTest(methods[i].getName(), AST_INTERNAL_JLS23));
}
@@ -1312,46 +1309,31 @@ void genericPropertyListTest(ASTNode node, List children, Property prop) {
@SuppressWarnings("deprecation")
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_8: return AST.JLS8;
- case JavaCore.VERSION_9: return AST.JLS9;
- case JavaCore.VERSION_10: return AST.JLS10;
- case JavaCore.VERSION_11: return AST.JLS11;
- case JavaCore.VERSION_12: return AST.JLS12;
- case JavaCore.VERSION_13: return AST.JLS13;
- case JavaCore.VERSION_14: return AST.JLS14;
- case JavaCore.VERSION_15: return AST.JLS15;
- case JavaCore.VERSION_16: return AST.JLS16;
- case JavaCore.VERSION_17: return AST.JLS17;
- 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;
- }
+ try {
+ int apiLevel = Integer.valueOf(s);
+ if (AST.isSupportedVersion(apiLevel)) {
+ return apiLevel;
+ }
+ } catch (NumberFormatException e) {
+ if (s.equals(JavaCore.VERSION_1_8)) {
+ return AST.JLS8;
+ }
+ }
+ return AST.getJLSLatest();
+
}
/** @deprecated using deprecated code */
public void testAST() {
- assertSame(AST.JLS2, 2);
- assertSame(JLS3_INTERNAL, 3);
-
AST a0 = new AST(); // deprecated, now 3 from JavaCore.defaultOptions
- int apiLevelCal = ASTTest.getApiLevel(JavaCore.getDefaultOptions().get(JavaCore.COMPILER_SOURCE));
+ int apiLevelCal = 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);
+ assertEquals(AST.JLS8, a2.apiLevel());
AST a3 = AST.newAST(JLS3_INTERNAL, false);
- assertTrue(a3.apiLevel() == JLS3_INTERNAL);
+ assertEquals(AST.JLS8, a3.apiLevel());
// modification count is always non-negative
assertTrue(this.ast.modificationCount() >= 0);
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SortCompilationUnitElementsTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SortCompilationUnitElementsTests.java
index e20057f1fb7..6522ee3ff52 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SortCompilationUnitElementsTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SortCompilationUnitElementsTests.java
@@ -1878,8 +1878,8 @@ public int compare(Object o1, Object o2) {
Javadoc javadoc2 = bodyDeclaration2.getJavadoc();
if (javadoc1 != null && javadoc2 != null) {
var comment1 = ((AbstractTextElement)((TagElement)javadoc1.tags().get(0)).fragments().get(0)).getText();
- var comment2 = ((AbstractTextElement)((TagElement)javadoc2.tags().get(0)).fragments().get(0)).getText();
- return comment1.compareTo(comment2);
+ var comment2 = ((AbstractTextElement)((TagElement)javadoc2.tags().get(0)).fragments().get(0)).getText();
+ return comment1.compareTo(comment2);
}
final int sourceStart1 = ((Integer) bodyDeclaration1.getProperty(CompilationUnitSorter.RELATIVE_ORDER)).intValue();
final int sourceStart2 = ((Integer) bodyDeclaration2.getProperty(CompilationUnitSorter.RELATIVE_ORDER)).intValue();
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTest.java
index 728508b8534..80158b573f4 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTest.java
@@ -188,7 +188,10 @@ protected static TestSuite createSuite(Class testClass, int classSince) {
String suffix = name.substring(index + ONLY_AST_STRING.length() + 1);
String[] levels = suffix.split(STRING_);
for (int l= 0; l < levels.length; l++) {
- suite.addTest((Test) cons.newInstance(new Object[]{name, Integer.valueOf(levels[l])}));
+ int level = Integer.valueOf(levels[l]);
+ if (AST.isSupportedVersion(level)) {
+ suite.addTest((Test) cons.newInstance(name, level));
+ }
}
} else {
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingInsertTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingInsertTest.java
index 42113081a94..baefe947798 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingInsertTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingInsertTest.java
@@ -448,7 +448,6 @@ public void test0007() throws Exception {
// assertEqualString(preview, buf.toString());
// }
- /** @deprecated using deprecated code */
public void test0010() throws Exception {
String source = "\n";
CompilationUnit astRoot= createCU(source.toCharArray());
@@ -495,7 +494,6 @@ public void test0011() throws Exception {
assertEqualString(preview, buf.toString());
}
- /** @deprecated using deprecated code */
public void test0012() throws Exception {
String source = "\n";
CompilationUnit astRoot= createCU(source.toCharArray());
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 4a8f023d5cf..7b423b90f2f 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
@@ -1131,36 +1131,10 @@ public AST() {
*/
private AST(int level, boolean previewEnabled) {
this.previewEnabled = previewEnabled;
+ if (ALL_VERSIONS.contains(level) && !SUPPORTED_VERSIONS.contains(level)) {
+ level = SUPPORTED_VERSIONS.get(0);
+ }
switch(level) {
- case JLS2_INTERNAL :
- case JLS3_INTERNAL :
- this.apiLevel = level;
- // initialize a scanner
- this.scanner = new Scanner(
- true /*comment*/,
- true /*whitespace*/,
- false /*nls*/,
- ClassFileConstants.JDK1_3 /*sourceLevel*/,
- ClassFileConstants.JDK1_5 /*complianceLevel*/,
- null/*taskTag*/,
- null/*taskPriorities*/,
- true/*taskCaseSensitive*/,
- false/*isPreviewEnabled*/);
- break;
- case JLS4_INTERNAL :
- this.apiLevel = level;
- // initialize a scanner
- this.scanner = new Scanner(
- true /*comment*/,
- true /*whitespace*/,
- false /*nls*/,
- ClassFileConstants.JDK1_7 /*sourceLevel*/,
- ClassFileConstants.JDK1_7 /*complianceLevel*/,
- null/*taskTag*/,
- null/*taskPriorities*/,
- true/*taskCaseSensitive*/,
- false/*isPreviewEnabled*/);
- break;
case JLS8_INTERNAL :
this.apiLevel = level;
// initialize a scanner
@@ -1234,8 +1208,6 @@ private AST(int level, boolean previewEnabled) {
* indicates the api level and source compatibility mode (as per JavaCore
) - defaults to 1.3
*
"1.3"
means the source code is as per JDK 1.3 and api level {@link #JLS3}."1.4", "1.5", "1.6", "1.7"
implies the respective source JDK levels 1.4, 1.5, 1.6, 1.7 and api level {@link #JLS4}."1.8"
implies the respective source JDK level 1.8 and api level {@link #JLS8}."9", "10", "11" up to "23"
implies the respective JDK levels 9, 10, 11 up to 23
* and api levels {@link #JLS9}, {@link #JLS10}, {@link #JLS11} up to {@link #JLS23}.