MCPcopy Create free account
hub / github.com/apache/groovy / findMainMethod

Method findMainMethod

src/main/java/groovy/lang/GroovyShell.java:382–399  ·  view source on GitHub ↗

Finds the main method to invoke using JEP-512 priority order: static main(String[]) > static main(Object) > static main() > instance main(String[]) > instance main(Object) > instance main().

(Class<?> scriptClass)

Source from the content-addressed store, hash-verified

380 * &gt; instance main(String[]) &gt; instance main(Object) &gt; instance main().
381 */
382 private static Method findMainMethod(Class<?> scriptClass) {
383 Class<?>[][] signatures = { {String[].class}, {Object.class}, {} };
384 // static methods first
385 for (Class<?>[] paramTypes : signatures) {
386 try {
387 Method m = scriptClass.getMethod(MAIN_METHOD_NAME, paramTypes);
388 if (Modifier.isStatic(m.getModifiers())) return m;
389 } catch (NoSuchMethodException ignore) { }
390 }
391 // then instance methods
392 for (Class<?>[] paramTypes : signatures) {
393 try {
394 Method m = scriptClass.getMethod(MAIN_METHOD_NAME, paramTypes);
395 if (!Modifier.isStatic(m.getModifiers())) return m;
396 } catch (NoSuchMethodException ignore) { }
397 }
398 return null;
399 }
400
401 private static Object runRunnable(Class scriptClass, String[] args) {
402 Constructor constructor = null;

Callers 1

Calls 3

isStaticMethod · 0.65
getModifiersMethod · 0.65
getMethodMethod · 0.45

Tested by

no test coverage detected