Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Java 22 main method searching order #548

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,23 +142,15 @@ private static boolean isInstanceMainMethodSupported(IType type) {
return CompilerOptions.versionToJdkLevel(options.get(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM)) >= ClassFileConstants.JDK21;
}

/**
* See Java 22 JEP 463 https://openjdk.org/jeps/463.
* It searches the main method in the launched class by following a specific order:
* - If the launched class contains a main method with a String[] parameter then choose that method.
* - Otherwise, if the class contains a main method with no parameters then choose that method.
*/
private static int getMainMethodPriority(IMethod method) {
int flags = 0;
try {
flags = method.getFlags();
} catch (JavaModelException e) {
// do nothing
}
String[] params = method.getParameterTypes();
if (Flags.isStatic(flags) && params.length == 1) {
return 1;
} else if (Flags.isStatic(flags)) {
return 2;
} else if (params.length == 1) {
return 3;
}

return 4;
return params.length == 1 ? 1 : 2;
}

private static List<IType> getPotentialMainClassTypes(ICompilationUnit compilationUnit) throws JavaModelException {
Expand Down
Loading