package io.domisum.lib.auxiliumlib.util;

import com.google.common.reflect.ClassPath;
import io.domisum.lib.auxiliumlib.annotations.API;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Objects;
import java.util.Optional;

@API
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class ClassUtil
{
	
	@API
	public static Class<?> getClass(String className, String errorMessage)
	{
		try
		{
			return Class.forName(className);
		}
		catch(ClassNotFoundException e)
		{
			throw new IllegalArgumentException(errorMessage, e);
		}
	}
	
	@API
	public static Optional<Class<?>> getClassOptional(String className)
	{
		try
		{
			return Optional.ofNullable(Class.forName(className));
		}
		catch(ClassNotFoundException ignored)
		{
			return Optional.empty();
		}
	}
	
	@API
	public static Collection<Class<?>> getClassesWithSimpleName(String simpleName, String... searchPackages)
	{
		var classes = new HashSet<Class<?>>();
		for(String searchPackage : searchPackages)
			for(var clazz : getClasses(searchPackage))
				if(Objects.equals(simpleName, clazz.getSimpleName()))
					classes.add(clazz);
		
		return classes;
	}
	
	
	@API
	@SuppressWarnings("UnstableApiUsage")
	public static Collection<Class<?>> getClasses(String _package)
	{
		try
		{
			var classPath = ClassPath.from(ClassUtil.class.getClassLoader());
			var classInfos = classPath.getTopLevelClassesRecursive(_package);
			
			var classes = new ArrayList<Class<?>>();
			for(var classInfo : classInfos)
				getClassOptional(classInfo.getName()).ifPresent(classes::add);
			
			return classes;
		}
		catch(IOException e)
		{
			throw new UncheckedIOException(e);
		}
	}
	
}

@@ -79,16 +79,55 @@
 ssPath;%0A
+import io.domisum.lib.auxiliumlib.PHR;%0A
 import i
@@ -557,33 +557,191 @@
 getClass(String 
-c
+fullClassName)%0A%09%7B%0A%09%09return getClass(fullClassName, PHR.r(%22Class '%7B%7D' does not exist%22, fullClassName));%0A%09%7D%0A%09%0A%09@API%0A%09public static Class%3C?%3E getClass(String fullC
 lassName, String
@@ -784,33 +784,37 @@
 n Class.forName(
-c
+fullC
 lassName);%0A%09%09%7D%0A%09
@@ -1137,32 +1137,34 @@
 pty();%0A%09%09%7D%0A%09%7D%0A%09%0A
+%09%0A
 %09@API%0A%09public st

Add ClassUtil.getClass with default error message