mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 22:51:17 +07:00
IJ-CR-167991 [java] IDEA-375376 Support JVM Runners for new instance main methods
-small refactoring (cherry picked from commit 90f8ebc2feae64cb504e0ada6a5625bd25d0b6c9) (cherry picked from commit 3077e1b9185fb214707c9ce20644ec0faa8b0de4) IJ-MR-169535 GitOrigin-RevId: 46ff90b6d78ace4f4246c6c3c2e5482686d0926e
This commit is contained in:
committed by
intellij-monorepo-bot
parent
601316af28
commit
14ed29db53
@@ -29,18 +29,22 @@ public final class JvmMainMethodUtil {
|
|||||||
public static boolean isMainMethod(@NotNull JvmMethod method) {
|
public static boolean isMainMethod(@NotNull JvmMethod method) {
|
||||||
if (!MAIN.equals(method.getName())) return false;
|
if (!MAIN.equals(method.getName())) return false;
|
||||||
final JvmClass containingClass = method.getContainingClass();
|
final JvmClass containingClass = method.getContainingClass();
|
||||||
return containingClass != null && canBeMainClass(containingClass) && (hasMainMethodSignature(method) ||
|
return containingClass != null && canBeMainClass(containingClass) && hasMainMethodSignature(method);
|
||||||
//just to partially support instance methods for Java, these methods are abandoned
|
|
||||||
//please use original methods
|
|
||||||
(method instanceof PsiMethod && PsiMethodUtil.isMainMethod((PsiMethod)method)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasMainMethodInHierarchy(@NotNull JvmClass clazz) {
|
public static boolean hasMainMethodInHierarchy(@NotNull JvmClass clazz) {
|
||||||
if (!canBeMainClass(clazz)) return false;
|
if (!canBeMainClass(clazz)) return false;
|
||||||
return findMainMethodInHierarchy(clazz) != null ||
|
//just to partially support instance methods for Java, these methods are abandoned,
|
||||||
//just to partially support instance methods for Java, these methods are abandoned,
|
//please use original methods
|
||||||
//please use original methods
|
if (clazz instanceof PsiClass && PsiMethodUtil.hasMainMethod((PsiClass)clazz)) return true;
|
||||||
(clazz instanceof PsiClass && PsiMethodUtil.hasMainMethod((PsiClass)clazz));
|
|
||||||
|
JvmMethod methodInHierarchy = JvmHierarchyUtil.traverseSupers(clazz, superClazz -> {
|
||||||
|
if (superClazz.getClassKind() == JvmClassKind.INTERFACE) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return findMainMethodInClass(superClazz);
|
||||||
|
});
|
||||||
|
return methodInHierarchy != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean canBeMainClass(@NotNull JvmClass clazz) {
|
private static boolean canBeMainClass(@NotNull JvmClass clazz) {
|
||||||
@@ -50,24 +54,22 @@ public final class JvmMainMethodUtil {
|
|||||||
return clazz.getContainingClass() == null || clazz.hasModifier(JvmModifier.STATIC);
|
return clazz.getContainingClass() == null || clazz.hasModifier(JvmModifier.STATIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static @Nullable JvmMethod findMainMethodInHierarchy(@NotNull JvmClass clazz) {
|
|
||||||
return JvmHierarchyUtil.traverseSupers(clazz, superClazz -> {
|
|
||||||
if (superClazz.getClassKind() == JvmClassKind.INTERFACE) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return findMainMethodInClass(superClazz);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private static @Nullable JvmMethod findMainMethodInClass(@NotNull JvmClass clazz) {
|
private static @Nullable JvmMethod findMainMethodInClass(@NotNull JvmClass clazz) {
|
||||||
JvmMethod[] candidates = clazz.findMethodsByName(MAIN);
|
JvmMethod[] candidates = clazz.findMethodsByName(MAIN);
|
||||||
return find(candidates, JvmMainMethodUtil::hasMainMethodSignature);
|
return find(candidates, JvmMainMethodUtil::hasMainMethodSignature);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {@code true} if the method matches {@code public static void xxx(String[] args) {}}, otherwise {@code false}
|
* @return {@code true} if the method matches {@code public static void xxx(String[] args) {}}, otherwise {@code false}.
|
||||||
|
* It also supports java instance methods.
|
||||||
|
* @see JvmMainMethodUtil
|
||||||
*/
|
*/
|
||||||
private static boolean hasMainMethodSignature(@NotNull JvmMethod method) {
|
private static boolean hasMainMethodSignature(@NotNull JvmMethod method) {
|
||||||
|
//just to partially support instance methods for Java, these methods are abandoned
|
||||||
|
//please use original methods
|
||||||
|
if (method instanceof PsiMethod &&
|
||||||
|
PsiMethodUtil.isMainMethod((PsiMethod)method)) return true;
|
||||||
|
|
||||||
if (method.isConstructor()) return false;
|
if (method.isConstructor()) return false;
|
||||||
if (!method.hasModifier(JvmModifier.PUBLIC)) return false;
|
if (!method.hasModifier(JvmModifier.PUBLIC)) return false;
|
||||||
if (!method.hasModifier(JvmModifier.STATIC)) return false;
|
if (!method.hasModifier(JvmModifier.STATIC)) return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user