Skip to content

Commit

Permalink
use AST.getJLSLatest() instead of DecompilerOutputUtil.getMaxJSLLevel()
Browse files Browse the repository at this point in the history
  • Loading branch information
nbauma109 committed May 26, 2024
1 parent c0ccce9 commit 81f9cf4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Map;

import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
Expand All @@ -12,7 +13,7 @@ private ASTParserUtil() {
}

public static CompilationUnit parse(String sourceCode) {
ASTParser parser = ASTParser.newParser(DecompilerOutputUtil.getMaxJSLLevel());
ASTParser parser = ASTParser.newParser(AST.getJLSLatest());
CompilerOptions option = new CompilerOptions();
Map<String, String> options = option.getMap();
options.put(CompilerOptions.OPTION_Compliance, DecompilerOutputUtil.getMaxDecompileLevel()); // $NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.util.regex.Pattern;

import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
import org.eclipse.jdt.core.dom.CompilationUnit;
Expand Down Expand Up @@ -778,27 +777,4 @@ public static String getMaxDecompileLevel() {
level = "1.8"; //$NON-NLS-1$
return level;
}

private static int jslLevel = -1;

public static int getMaxJSLLevel() {
if (jslLevel == -1) {
if (ReflectionUtils.getDeclaredField(AST.class, "JLS8") != null) //$NON-NLS-1$
{
jslLevel = (Integer) ReflectionUtils.getFieldValue(AST.class, "JLS8"); //$NON-NLS-1$
} else if (ReflectionUtils.getDeclaredField(AST.class, "JLS4") != null) //$NON-NLS-1$
{
jslLevel = (Integer) ReflectionUtils.getFieldValue(AST.class, "JLS4"); //$NON-NLS-1$
} else if (ReflectionUtils.getDeclaredField(AST.class, "JLS3") != null) //$NON-NLS-1$
{
jslLevel = (Integer) ReflectionUtils.getFieldValue(AST.class, "JLS3"); //$NON-NLS-1$
} else if (ReflectionUtils.getDeclaredField(AST.class, "JLS2") != null) //$NON-NLS-1$
{
jslLevel = (Integer) ReflectionUtils.getFieldValue(AST.class, "JLS2"); //$NON-NLS-1$
} else {
jslLevel = 3;
}
}
return jslLevel;
}
}

0 comments on commit 81f9cf4

Please sign in to comment.