Skip to content

Finding all classes for module name (Java 9 and later)

Roberto Gentili edited this page Oct 13, 2021 · 11 revisions

Here the solution:

import java.util.Collection;

import org.burningwave.core.assembler.ComponentContainer;
import org.burningwave.core.assembler.ComponentSupplier;
import org.burningwave.core.classes.ClassCriteria;
import org.burningwave.core.classes.ClassHunter;
import org.burningwave.core.classes.ClassHunter.SearchResult;
import org.burningwave.core.classes.SearchConfig;
import org.burningwave.core.io.PathHelper;

public class Finder {

    public Collection<Class<?>> find() {
        ComponentSupplier componentSupplier = ComponentContainer.getInstance();
        PathHelper pathHelper = componentSupplier.getPathHelper();
        ClassHunter classHunter = componentSupplier.getClassHunter();

        try (ClassHunter.SearchResult searchResult = classHunter.findBy(
                SearchConfig.forPaths(
                	pathHelper.getAllMainClassPaths()
                ).by(
                    ClassCriteria.create().allThoseThatMatch((currentScannedClass) ->
                        currentScannedClass.getModule().getName() != null && 
                        currentScannedClass.getModule().getName().equals("jdk.xml.dom")
                    )
                )
            )
        ) {
            return searchResult.getClasses();
        }
    }
}

Examples of use of some components:

BackgroundExecutor
ClassFactory
ClassHunter
ClassPathHunter
CodeExecutor
Constructors
Fields
FileSystemItem
FunctionalInterfaceFactory
IterableObjectHelper
JavaMemoryCompiler
Methods
PathHelper
PropertyAccessor
UnitSourceGenerator

HitCount

Clone this wiki locally