Bug 574428 - [DOM AST] Need getter for JLS_LATEST.

Change-Id: I362d775a8f00fb54718c2731468255fdabad8b71
Signed-off-by: Sravan Kumar Lakkimsetti <sravankumarl@in.ibm.com>
Reviewed-on: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/182404
Reviewed-by: Kalyan Prasad Tatavarthi <kalyan_prasad@in.ibm.com>
Tested-by: JDT Bot <jdt-bot@eclipse.org>
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java
index d81bf22..3401e5d 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java
@@ -65,7 +65,7 @@
 		super(name);
 	}
 
-	private static final int AST_JLS_LATEST = AST.JLS_Latest;
+	private static final int AST_JLS_LATEST = AST.getJLSLatest();
 
 	public ASTNode runConversion(
 			int astLevel,
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterJavadocTest_15.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterJavadocTest_15.java
index fb15b0d..958738b 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterJavadocTest_15.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterJavadocTest_15.java
@@ -111,7 +111,7 @@
 	protected boolean resolveBinding = true;

 	protected boolean packageBinding = true;

 	// AST Level

-	protected int astLevel = AST.JLS_Latest;

+	protected int astLevel = AST.getJLSLatest();

 	protected int savedLevel;

 	// Debug

 	protected String prefix = "";

diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java
index 44f41d0..4e28ce3 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java
@@ -176,7 +176,7 @@
 	 * Internal synonym for the latest AST level.
 	 *
 	 */
-	protected static final int AST_INTERNAL_LATEST = AST.JLS_Latest;
+	protected static final int AST_INTERNAL_LATEST = AST.getJLSLatest();
 
 	public static class BasicProblemRequestor implements IProblemRequestor {
 		public void acceptProblem(IProblem problem) {}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests9.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests9.java
index 626c2cc..7d4beaf 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests9.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests9.java
@@ -42,7 +42,7 @@
 	protected ICompilationUnit workingCopy;
 	protected ProblemRequestor problemRequestor;
 
-	/*package*/ static final int JLS_LATEST = AST.JLS_Latest;
+	/*package*/ static final int JLS_LATEST = AST.getJLSLatest();
 
 /**
  */
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 79b1be8..40e63f3 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
@@ -121,7 +121,7 @@
      * </p>
      *
 	 * @since 3.0
-	 * @deprecated Clients should use the  {@link #JLS_Latest} AST API instead.
+	 * @deprecated Clients should use the  {@link #getJLSLatest()} AST API instead.
 	 */
 	public static final int JLS2 = 2;
 
@@ -145,7 +145,7 @@
      * </p>
      *
 	 * @since 3.1
-	 * @deprecated Clients should use the {@link #JLS_Latest} AST API instead.
+	 * @deprecated Clients should use the {@link #getJLSLatest()} AST API instead.
 	 */
 	public static final int JLS3 = 3;
 
@@ -169,7 +169,7 @@
 	 * </p>
 	 *
 	 * @since 3.7.1
-	 * @deprecated Clients should use the {@link #JLS_Latest} AST API instead.
+	 * @deprecated Clients should use the {@link #getJLSLatest()} AST API instead.
 	 */
 	public static final int JLS4 = 4;
 
@@ -193,7 +193,7 @@
 	 * </p>
 	 *
 	 * @since 3.10
-	 * @deprecated Clients should use the {@link #JLS_Latest} AST API instead.
+	 * @deprecated Clients should use the {@link #getJLSLatest()} AST API instead.
 	 */
 	public static final int JLS8 = 8;
 
@@ -217,7 +217,7 @@
 	 * </p>
 	 *
 	 * @since 3.14
-	 * @deprecated Clients should use the {@link #JLS_Latest} AST API instead.
+	 * @deprecated Clients should use the {@link #getJLSLatest()} AST API instead.
 	 */
 	public static final int JLS9 = 9;
 
@@ -241,7 +241,7 @@
 	 * </p>
 	 *
 	 * @since 3.14
-	 * @deprecated Clients should use the {@link #JLS_Latest} AST API instead.
+	 * @deprecated Clients should use the {@link #getJLSLatest()} AST API instead.
 	 */
 	public static final int JLS10 = 10;
 
@@ -264,7 +264,7 @@
 	 * up to and including Java SE 11 (aka JDK 11).
 	 * </p>
 	 *
-	 * @deprecated Clients should use the {@link #JLS_Latest} AST API instead.
+	 * @deprecated Clients should use the {@link #getJLSLatest()} AST API instead.
 	 * @since 3.16
 	 */
 	public static final int JLS11 = 11;
@@ -287,7 +287,7 @@
 	 * programs written in all versions of the Java language
 	 * up to and including Java SE 12 (aka JDK 12).
 	 * </p>
-	 * @deprecated Clients should use the {@link #JLS_Latest} AST API instead.
+	 * @deprecated Clients should use the {@link #getJLSLatest()} AST API instead.
 	 * @since 3.18
 	 */
 	public static final int JLS12 = 12;
@@ -309,9 +309,9 @@
 	 * programs written in all versions of the Java language
 	 * up to and including Java SE 13 (aka JDK 13).
 	 * </p>
-	 * @deprecated Clients should use the {@link #JLS_Latest} AST API instead.
+	 * @deprecated Clients should use the {@link #getJLSLatest()} AST API instead.
 	 * @since 3.20
-	 * @deprecated Clients should use the {@link #JLS_Latest} AST API instead.
+	 * @deprecated Clients should use the {@link #getJLSLatest()} AST API instead.
 	 */
 	public static final int JLS13 = 13;
 
@@ -333,7 +333,7 @@
 	 * programs written in all versions of the Java language
 	 * up to and including Java SE 14(aka JDK 14).
 	 * </p>
-	 * @deprecated Clients should use the {@link #JLS_Latest} AST API instead.
+	 * @deprecated Clients should use the {@link #getJLSLatest()} AST API instead.
 	 * @since 3.22
 	 */
 	public static final int JLS14 = 14;
@@ -356,7 +356,7 @@
 	 * programs written in all versions of the Java language
 	 * up to and including Java SE 15(aka JDK 15).
 	 * </p>
-	 * @deprecated Clients should use the {@link #JLS_Latest} AST API instead.
+	 * @deprecated Clients should use the {@link #getJLSLatest()} AST API instead.
 	 * @since 3.24
 	 */
 	public static final int JLS15 = 15;
@@ -388,10 +388,17 @@
 	static final int JLS16_INTERNAL = JLS16;
 
 	/**
-	 * @since 3.26
+	 * Internal property for latest supported JLS level
 	 * This provides the latest JLS level.
 	 */
-	public static final int JLS_Latest = JLS16;
+	private static final int JLS_INTERNAL_Latest = JLS16;
+
+	/**
+	 * @since 3.26
+	 * This provides the latest JLS level.
+	 * @deprecated use {@link #getJLSLatest()}
+	 */
+	public static final int JLS_Latest = JLS_INTERNAL_Latest;
 
 	/*
 	 * Must not collide with a value for ICompilationUnit constants
@@ -3763,9 +3770,19 @@
 	 * @since 3.19
 	 */
 	public boolean isPreviewEnabled() {
-		if (this.apiLevel == AST.JLS_Latest && this.previewEnabled) {
+		if (this.apiLevel == AST.JLS_INTERNAL_Latest && this.previewEnabled) {
 				return true;
 		}
 		return false;
 	}
+
+	/**
+	 * Returns latest supportd JLS level
+	 *
+	 * @return the latest supported JLS level
+	 * @since 3.27
+	 */
+	public static int getJLSLatest() {
+		return JLS_INTERNAL_Latest;
+	}
 }
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java
index 1be071a..0cb731d 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java
@@ -1316,7 +1316,7 @@
 
 		CompilationUnit usedAstRoot= this.astRoot;
 		if (usedAstRoot == null) {
-			ASTParser parser= ASTParser.newParser(AST.JLS_Latest);
+			ASTParser parser= ASTParser.newParser(AST.getJLSLatest());
 			parser.setSource(this.compilationUnit);
 			parser.setFocalPosition(0); // reduced AST
 			parser.setResolveBindings(false);
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/util/DOMASTUtil.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/util/DOMASTUtil.java
index 2d2034a..d0c1783 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/util/DOMASTUtil.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/util/DOMASTUtil.java
@@ -148,8 +148,8 @@
 
 	@SuppressWarnings("deprecation")
 	public static void checkASTLevel(int level) {
-		// Clients can use AST.JLS_Latest
-		if(level >=AST.JLS8 && level <= AST.JLS_Latest )
+		// Clients can use AST.getJLSLatest()
+		if(level >=AST.JLS8 && level <= AST.getJLSLatest() )
 			return;
 		switch (level) {
 	        case AST.JLS2 :
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelOperation.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelOperation.java
index 16b3943..6911742 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelOperation.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelOperation.java
@@ -155,7 +155,7 @@
 	}
 
 	protected int getLatestASTLevel() {
-		return AST.JLS_Latest;
+		return AST.getJLSLatest();
 	}
 	/*
 	 * Registers the given action at the end of the list of actions to run.