https://github.com/fluidsonic/fluid-meta
Converts Kotlin metadata into an easily usable data model
https://github.com/fluidsonic/fluid-meta
Last synced: 9 months ago
JSON representation
Converts Kotlin metadata into an easily usable data model
- Host: GitHub
- URL: https://github.com/fluidsonic/fluid-meta
- Owner: fluidsonic
- License: apache-2.0
- Created: 2019-02-01T18:00:26.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-06-24T02:25:53.000Z (over 2 years ago)
- Last Synced: 2025-03-27T19:41:43.841Z (10 months ago)
- Language: Kotlin
- Homepage:
- Size: 813 KB
- Stars: 14
- Watchers: 0
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
fluid-meta
==========
[](https://search.maven.org/artifact/io.fluidsonic.meta/fluid-meta)
[](https://github.com/JetBrains/kotlin/releases/v1.8.22)
[](https://kotlinlang.slack.com/messages/C7UDFSVT2/)
Converts Kotlin metadata into a usable data model. Includes pretty printing for easy inspection, see the output
for [Kotlin's Standard Library](https://github.com/fluidsonic/fluid-meta/blob/master/kotlin-stdlib.kt) for example :)
Installation
------------
`build.gradle.kts`:
```kotlin
dependencies {
implementation("io.fluidsonic.meta:fluid-meta:0.14.0")
}
```
Example
-------
Let's say you want to inspect the type `Hello` at runtime or during annotation processing and get additional type information which is specific to Kotlin, e.g.
nullability, internal visibility, data class, inline and default parameters.
```kotlin
package hello.world
internal data class Hello(
private val world: String = "cool!",
val foo: Int?
) {
constructor() : this(foo = 3)
inline fun hey() = println("hey")
}
```
All you need to do is to use `Meta.of(…)` to inspect the respective `KClass` (or `Element` when processing annotations):
```kotlin
package hello.world
import io.fluidsonic.meta.*
fun main() {
println(Meta.of(Hello::class))
}
```
And you'll get well-structured metadata objects like `MClass` which print output like the following when using `.toString()`:
```kotlin
internal data class hello.world.Hello {
// *** PROPERTIES ***
// JVM field = foo:Ljava/lang/Integer;
val foo: Int?
// JVM field = world:Ljava/lang/String;
private val world: String
// *** CONSTRUCTORS ***
// JVM method = ()V
/* secondary */ constructor()
// JVM method = (Ljava/lang/String;Ljava/lang/Integer;)V
constructor(world: String /* = default */, foo: Int?)
// *** FUNCTIONS ***
// JVM method = component1()Ljava/lang/String;
private /* synthesized */ operator fun component1(): String
// JVM method = component2()Ljava/lang/Integer;
/* synthesized */ operator fun component2(): Int?
// JVM method = copy(Ljava/lang/String;Ljava/lang/Integer;)Lhello/world/Hello;
/* synthesized */ fun copy(world: String /* = default */, foo: Int? /* = default */): hello.world.Hello
// JVM method = equals(Ljava/lang/Object;)Z
/* synthesized */ open operator fun equals(other: Any?): Boolean
// JVM method = hashCode()I
/* synthesized */ open fun hashCode(): Int
// JVM method = hey()V
inline fun hey()
// JVM method = toString()Ljava/lang/String;
/* synthesized */ open fun toString(): String
}
```
License
-------
Apache 2.0