src/main/java/nonapi/io/github/classgraph/classpath/ClassLoaderAndModuleFinder.java
private static List<ModuleRef> findModuleRefsFromCallstack(final Class<?>[] callStack, final ScanSpec scanSpec,
            final LogNode log) {
        final LinkedHashSet<Object> layers = new LinkedHashSet<>();
        if (callStack != null) {
            for (final Class<?> stackFrameClass : callStack) {
                final Object /* Module */ module = ReflectionUtils.invokeMethod(stackFrameClass, "getModule",
                        /* throwException = */ false);
                if (module != null) {
                    final Object /* ModuleLayer */ layer = ReflectionUtils.invokeMethod(module, "getLayer",
                            /* throwException = */ true);
                    // getLayer() returns null for unnamed modules -- have to get their classes from java.class.path 
                    if (layer != null) {
                        layers.add(layer);
                    }
                }
            }
        }
        // Add system modules from boot layer, if they weren't already found in stacktrace
        Class<?> moduleLayerClass = null;
        try {
            moduleLayerClass = Class.forName("java.lang.ModuleLayer");
        } catch (ClassNotFoundException | LinkageError e) {
            // Ignored
        }
        if (moduleLayerClass != null) {
            final Object /* ModuleLayer */ bootLayer = ReflectionUtils.invokeStaticMethod(moduleLayerClass, "boot",
                    /* throwException = */ false);
            if (bootLayer != null) {
                layers.add(bootLayer);
            }
        }
        return findModuleRefs(layers, scanSpec, log);
    }
/**
     * Get all visible ModuleReferences in all layers, given an array of stack frame {@code Class<?>} references.
     *
     * @param callStack
     *            the call stack
     * @param scanSpec
     *            the scan spec
     * @param log
     *            the log
     * @return the list
     */
Get all visible ModuleReferences in all layers, given an array of stack frame  Class references.
@param callStack
the call stack
@param scanSpec
the scan spec
@param log
the log
@return the list
Get all visible ModuleReferences in all layers given an array of stack frame Class references . @param callStack the call stack @param scanSpec the scan spec @param log the log @return the list
private static List<ModuleRef> findModuleRefsFromCallstack(final Class<?>[] callStack, final ScanSpec scanSpec,
            final LogNode log) {
        final LinkedHashSet<Object> layers = new LinkedHashSet<>();
        if (callStack != null) {
            for (final Class<?> stackFrameClass : callStack) {
                final Object /* Module */ module = ReflectionUtils.invokeMethod(stackFrameClass, "getModule",
                        /* throwException = */ false);
                if (module != null) {
                    final Object /* ModuleLayer */ layer = ReflectionUtils.invokeMethod(module, "getLayer",
                            /* throwException = */ true);
                    if (layer != null) {
                        layers.add(layer);
                    }
                }
            }
        }
        Class<?> moduleLayerClass = null;
        try {
            moduleLayerClass = Class.forName("java.lang.ModuleLayer");
        } catch (ClassNotFoundException | LinkageError e) {
        }
        if (moduleLayerClass != null) {
            final Object /* ModuleLayer */ bootLayer = ReflectionUtils.invokeStaticMethod(moduleLayerClass, "boot",
                    /* throwException = */ false);
            if (bootLayer != null) {
                layers.add(bootLayer);
            }
        }
        return findModuleRefs(layers, scanSpec, log);
    }
private static List < ModuleRef > findModuleRefsFromCallstack ( final Class < ? > [ ] callStack , final ScanSpec scanSpec , final LogNode log ) { final LinkedHashSet < Object > layers = new LinkedHashSet < > ( ) ; if ( callStack != null ) { for ( final Class < ? > stackFrameClass : callStack ) { final Object /* Module */ module = ReflectionUtils . invokeMethod ( stackFrameClass , "getModule" , /* throwException = */ false ) ; if ( module != null ) { final Object /* ModuleLayer */ layer = ReflectionUtils . invokeMethod ( module , "getLayer" , /* throwException = */ true ) ; if ( layer != null ) { layers . add ( layer ) ; } } } } Class < ? > moduleLayerClass = null ; try { moduleLayerClass = Class . forName ( "java.lang.ModuleLayer" ) ; } catch ( ClassNotFoundException | LinkageError e ) { } if ( moduleLayerClass != null ) { final Object /* ModuleLayer */ bootLayer = ReflectionUtils . invokeStaticMethod ( moduleLayerClass , "boot" , /* throwException = */ false ) ; if ( bootLayer != null ) { layers . add ( bootLayer ) ; } } return findModuleRefs ( layers , scanSpec , log ) ; }
Get all visible ModuleReferences in all layers, given an array of stack frame {@code Class<?>} references.
Get all visible ModuleReferences in all layers given an array of stack frame { @code Class<? > } references .
// getLayer() returns null for unnamed modules -- have to get their classes from java.class.path  // Add system modules from boot layer, if they weren't already found in stacktrace // Ignored