Skip to content

Commit

Permalink
fix Java 22 main method searching order (#548)
Browse files Browse the repository at this point in the history
  • Loading branch information
testforstephen committed Apr 10, 2024
1 parent 37d4e66 commit 83403a4
Showing 1 changed file with 7 additions and 15 deletions.
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

0 comments on commit 83403a4

Please sign in to comment.