Skip to content

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

Roberto edited this page Jan 17, 2020 · 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.hunter.ClassHunter;
import org.burningwave.core.classes.hunter.ClassHunter.SearchResult;
import org.burningwave.core.classes.hunter.SearchConfig;
import org.burningwave.core.io.PathHelper;

public class Finder {

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

		SearchResult searchResult = classHunter.findBy(
			SearchConfig.forPaths(
					pathHelper.getMainClassPaths()
			).by(
				ClassCriteria.create().allThat((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