All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.skillw.asahi.internal.namespacing.prefix.lang.linking.Java.kt Maven / Gradle / Ivy

There is a newer version: 1.6.7-beta-6
Show newest version
package com.skillw.asahi.internal.namespacing.prefix.lang.linking

import com.skillw.asahi.api.annotation.AsahiPrefix
import com.skillw.asahi.api.prefixParser
import com.skillw.asahi.api.quest
import com.skillw.asahi.api.quester
import com.skillw.pouvoir.util.findClass
import com.skillw.pouvoir.util.plugin.PluginUtils.getClasses
import taboolib.library.reflex.Reflex.Companion.invokeConstructor

/**
 * @className Java
 *
 * @author Glom
 * @date 2023/1/18 18:19 Copyright 2024 Glom.
 */
@AsahiPrefix(["java"], "lang")
private fun java() = prefixParser {
    val isPackage = expect("in")
    expect("of")
    val path = questString()
    result {
        if (isPackage) {
            getClasses(path.get()).forEach {
                context()[it.simpleName] = it
            }
        } else {
            path.get().findClass()
        }
    }
}

@AsahiPrefix(["new"], "lang")
private fun new() = prefixParser {
    val clazz = next().let { quester { context()[it] as Class<*> } }
    val paramsGetter = if (peek() == "[" || peek() == "(") quest() else quester { emptyList() }
    expect("[]", "()")
    result {
        val params = paramsGetter.get()
        clazz.get().invokeConstructor(*params.toTypedArray())
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy