Skip to content

How to get the package name or the qualified name of a class? #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Danilo-Araujo-Silva opened this issue Mar 30, 2019 · 1 comment

Comments

@Danilo-Araujo-Silva
Copy link

Can we use this library with kotlin("multiplatform") plugin (build.gradle.kts)?

Can we get the qualifiedName or the package of a class with this library?

For example, I've seen that we can do something like:

@JsName("_")
external val `_`: dynamic

fun checkAndReturnPackage(package_: String, class_: KClass<*>): String {
	if (
		class_.js.name
		=== eval("get_js(Kotlin.getKClassFromExpression(_.$package_.${class_.simpleName})).name")
	) {
		return package_
	}

	throw IllegalArgumentException(
		"""
    	The package $package_ isn't the correct package for the class $class_.
    """
	)
}

fun checkExamplePackageAndReturnIt(): String {
	val expectedPackage = "com.my.package.js"
	if (
		Example::class.js.name
		=== `_`.com.my.package.js.Example::class.js.name
	) {
		return expectedPackage
	}

	throw IllegalArgumentException(
		"""
    	The "$expectedPackage" isn't the correct package for the class "${Example::class.simpleName}".
    """
	)
}

but I cannot really get the js package yet, so I was wondering if we can do something like this.

@robert-cronin
Copy link

Id love an answer to this one as well, seems a little sad that JetBrains haven't released a full reflection API as yet, one of our modules really needs access to class members

@Danilo-Araujo-Silva Danilo-Araujo-Silva changed the title How to the package name or the qualified name of a class? How to get the package name or the qualified name of a class? May 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants