Search in sources :

Example 1 with KClass

use of kotlin.reflect.KClass in project sponge by softelnet.

the class NonScriptKotlinKnowledgeBaseInterpreter method createProcessorInstanceByProcessorClass.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public ProcessorInstanceHolder createProcessorInstanceByProcessorClass(KnowledgeBase knowledgeBase, Object processorClass, Class<?> javaClass) {
    if (processorClass instanceof KClass) {
        // Kotlin-based processor.
        KClass kclass = (KClass) processorClass;
        Class<?> destJavaClass = JvmClassMappingKt.getJavaClass(kclass);
        if (!javaClass.isAssignableFrom(destJavaClass)) {
            throw new SpongeException("Unsupported processor specification: " + destJavaClass.getName() + " can't be used as " + javaClass.getName());
        }
        try {
            return new GenericProcessorInstanceHolder((Processor) destJavaClass.newInstance(), KotlinUtils.createProcessorName(kclass), true);
        } catch (Throwable e) {
            throw SpongeUtils.wrapException(destJavaClass.getName(), e);
        }
    }
    return null;
}
Also used : KClass(kotlin.reflect.KClass) SpongeException(org.openksavi.sponge.SpongeException) GenericProcessorInstanceHolder(org.openksavi.sponge.core.engine.GenericProcessorInstanceHolder)

Aggregations

KClass (kotlin.reflect.KClass)1 SpongeException (org.openksavi.sponge.SpongeException)1 GenericProcessorInstanceHolder (org.openksavi.sponge.core.engine.GenericProcessorInstanceHolder)1