Nabil
11/14/2020, 1:36 AMHashMap
?
pluginContext.referenceClass(FqName("kotlin.collections.HashMap"))
• On JVM returns null
• On Macos (K/N) returns the symbol
Since HashMap
is a typealias to java.util.HashMap
I thought using pluginContext.referenceTypeAlias(FqName("kotlin.collections.HashMap"))
could work but it's behaving differently
• ON JVM it throws
AssertionError: Package or class expected: typealias HashMap; for K
t org.jetbrains.kotlin.ir.declarations.lazy.IrLazyDeclarationBase$createLazyParent$1.invoke(IrLazyDeclarationBase.kt:70)
• On K/N (macos) it returns null
How can one reference an available common class from the stdlib like kotlin.collections.HashMap
?
The only work around I can see is to test if pluginContext.referenceClass(FqName("java.util.HashMap"))
returns null, which indicates I'm running the compiler plugin within a K/N context and fallback to pluginContext.referenceClass(FqName("kotlin.collections.HashMap"))
...
Any thoughts appreciated 🙂svyatoslav.scherbina
11/16/2020, 12:58 PMThe only work around I can see is to test ifWhat’s wrong with this one, if it works? Generally, backends handle expect-actual not like frontend does, and I’m not sure one can reliably consider there is such thing as “common class” in this case (since there is no such class on JVM). Also, it should be possible to get information about platform directly, withreturns null, which indicates I’m running the compiler plugin within a K/N context and fallback topluginContext.referenceClass(FqName("java.util.HashMap"))
...pluginContext.referenceClass(FqName("kotlin.collections.HashMap"))
pluginContext.platform
.