{"id":21168528,"url":"https://github.com/jetbrains-research/reflekt","last_synced_at":"2025-04-05T19:14:22.452Z","repository":{"id":37068855,"uuid":"293503377","full_name":"JetBrains-Research/reflekt","owner":"JetBrains-Research","description":"A plugin for Kotlin compiler for compile-time reflection","archived":false,"fork":false,"pushed_at":"2024-02-14T05:46:08.000Z","size":1489,"stargazers_count":372,"open_issues_count":17,"forks_count":13,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-03-29T18:07:50.040Z","etag":null,"topics":["compile-time","compile-time-reflection","kotlin","reflection"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JetBrains-Research.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"docs/contributing.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-07T11:03:43.000Z","updated_at":"2025-03-27T14:32:22.000Z","dependencies_parsed_at":"2023-01-19T11:01:37.924Z","dependency_job_id":"3fafdd1f-46e5-4889-9861-0359b3f7535f","html_url":"https://github.com/JetBrains-Research/reflekt","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JetBrains-Research%2Freflekt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JetBrains-Research%2Freflekt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JetBrains-Research%2Freflekt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JetBrains-Research%2Freflekt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JetBrains-Research","download_url":"https://codeload.github.com/JetBrains-Research/reflekt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247386266,"owners_count":20930619,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compile-time","compile-time-reflection","kotlin","reflection"],"created_at":"2024-11-20T15:14:51.677Z","updated_at":"2025-04-05T19:14:22.419Z","avatar_url":"https://github.com/JetBrains-Research.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![JetBrains Research](https://jb.gg/badges/research.svg)](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub)\n![Gradle Build](https://github.com/nbirillo/reflekt/workflows/Gradle%20Build/badge.svg?branch=master)\n[![Run deteKT](https://github.com/JetBrains-Research/reflekt/actions/workflows/detekt.yml/badge.svg)](https://github.com/JetBrains-Research/reflekt/actions/workflows/detekt.yml)\n[![Run diKTat](https://github.com/JetBrains-Research/reflekt/actions/workflows/diktat.yml/badge.svg)](https://github.com/JetBrains-Research/reflekt/actions/workflows/diktat.yml)\n\n# Reflekt\n\nReflekt is a compile-time reflection library that leverages the flows of the \nstandard reflection approach and can find classes, objects (singleton classes) or functions \nby some conditions in compile-time.\n\nInstead of relying on JVM reflection, Reflekt performs compile-time resolution of reflection queries\nusing Kotlin compiler analysis, providing a convenient reflection API without actually using\nreflection.\n\nReflekt is a joint project of [JetBrains Research](https://research.jetbrains.org/) and\nthe [Kotless](https://github.com/JetBrains/kotless) team. The main reason for its creation was the\nnecessity of GraalVM support in modern Java applications, especially on Serverless workloads. With\nthe help of the Reflekt project, Kotless will be able to provide access to GraalVM to users of\nhistorically reflection-based frameworks such as Spring or their own Kotless DSL.\n\nWe have implemented two approaches - searching classes\\objects or functions via a limited DSL \nand by custom user condition via an extended DSL. \nThe first one will be called `Reflekt`, and the second `SmartReflekt`.\n\n**Restrictions**. Reflekt analyses only `.kt` files (in the project and in the libraries); uses\nKotlin `1.7.0`. Reflekt does not currently support incremental compilation.\n\n**Note**, we use [Intermediate Representation](https://kotlinlang.org/docs/whatsnew14.html#unified-backends-and-extensibility) of code in this plugin.\nIt means, that Reflekt can be used for all available platforms: JVM, Native and JavaScript.\n___\n\n## Table of contents\n\n- [Getting started](#getting-started)\n- [Local start](#local-start)\n- [Supported features](#supported-features)\n- [Examples](#examples)\n- [Want to know more?](#want-to-know-more?)\n\n## Getting started\n\n**Note**, currently we support the following Reflekt and Kotlin versions:\n`1.7.0` (only for local usage), `1.5.30`, `1.5.21`, `1.5.20`, `1.5.10`, `1.5.0`\n\nReflekt uses Gradle. If you have a Gradle project, you only need to do three things.\n\nFirstly, set up the Reflekt plugin. You need to apply the plugin. In the `build.gradle.kts` file,\nadd the following lines in the `plugins` section:\n\n```kotlin\nplugins {\n    // Version of Kotlin should be 1.5.0+ that supports IR backend\n    kotlin(\"jvm\") version \"1.7.0\"\n\n    // Please, use the same version with the Kotlin version in your project\n    id(\"org.jetbrains.reflekt\") version \"1.7.0\"\n\n    // Necessary only for this example, for Kotless library\n    id(\"io.kotless\") version \"0.1.6\"\n}\n```\n\nAt the same time, add to the `settings.gradle.kts` file the following snippet:\n\n```kotlin\npluginManagement {\n    repositories {\n        //add the dependency to Reflekt Maven repository\n        maven(url = uri(\"https://packages.jetbrains.team/maven/p/reflekt/reflekt\"))\n\n        // Necessary only for this example, for Kotless library\n        maven(url = uri(\"https://plugins.gradle.org/m2/\"))\n    }\n}\n```\n\nSecondly, add the Reflekt DSL as a library to your application. In the `build.gradle.kts` file, add\nthe following lines in the `dependencies` section:\n\n```kotlin\ndependencies {\n    // The version here and the version in the plugins sections should be equal\n    implementation(\"org.jetbrains.reflekt\", \"reflekt-dsl\", \"1.7.0\")\n\n    // Necessary for this example\n    compileOnly(\"io.kotless\", \"kotless-lang\", \"0.1.6\")\n}\n```\n\nAt the same time, add the following lines in the `repositories` section:\n```kotlin\nrepositories {\n    //... Any other repositories\n    // add Reflekt repository for libraries resolving\n    maven(url = uri(\"https://packages.jetbrains.team/maven/p/reflekt/reflekt\"))\n}\n```\n\nThirdly, customize the Reflekt plugin. In the `build.gradle.kts` file, add the `reflekt` object:\n\n```kotlin\nreflekt {\n    // Enable or disable Reflekt plugin\n    enabled = true\n}\n```\n\n**Please note** that the Reflekt can also analyze the files from the external libraries. \nReflekt can handle only libraries from the `dependencies` section and \nDependencyHandlers of them should be `canBeResolve = True`, e.g.:\n```kotlin\nval reflektConfiguration by configurations.creating {\n    isCanBeResolved = true\n}\n\nconfigurations[\"implementation\"].extendsFrom(reflektConfiguration)\n```\nAlso, this library should contain a special file `ReflektMeta`. The last point means the library\nshould use Reflekt with the following configuration:\n```kotlin\nreflekt {\n    // Enable or disable Reflekt plugin\n    enabled = true\n    // Create ReflektMeta file\n    toSaveMetadata = true\n}\n```\n\n\nTo avoid some bugs and enable IR, please add the following compilation settings \nfor Java and Kotlin in the `build.gradle.kts` file:\n\n```kotlin\nimport org.jetbrains.kotlin.gradle.tasks.KotlinCompile\n\nkotlin.jvmToolchain(11)\n\ntasks.withType\u003cKotlinCompile\u003e {\n    kotlinOptions {\n        // Current Reflekt version does not support incremental compilation process\n        incremental = false\n    }\n}\n```\n\n**Note**: Please note that the current version of Reflekt and SmartReflekt does not support incremental\ncompilation process\n\nThis gives you access to [the limited  Reflekt DSL](./reflekt-dsl/src/main/kotlin/org/jetbrains/reflekt/Reflekt.kt)\ninterfaces.\n\nThis gives you access\nto [the extended SmartReflekt DSL](./reflekt-dsl/src/main/kotlin/org/jetbrains/reflekt/SmartReflekt.kt), which allow\nfiltering classes/objects\\functions by user condition.\n\nNow you can use the Reflekt plugin to find objects, classes, and functions in your project:\n\n```kotlin\nval objects = Reflekt.objects().withSupertype\u003cAInterface\u003e()\n    .withAnnotations\u003cAInterface\u003e(FirstAnnotation::class, SecondAnnotation::class).toList()\n\nval classes = Reflekt.classes().withSupertype\u003cBInterface\u003e().toSet()\n\nval functions = Reflekt.functions().withAnnotations\u003c() -\u003e Unit\u003e().toList()\n```\n\nAnd the SmartReflekt plugin:\n\n```kotlin\nval objects = SmartReflekt.objects\u003cAInterface\u003e().filter { TODO(\"some user's condition\") }.resolve()\n\nval classes = SmartReflekt.classes\u003cBInterface\u003e().filter { TODO(\"some user's condition\") }.resolve()\n\nval functions =\n    SmartReflekt.functions\u003c() -\u003e Unit\u003e().filter { TODO(\"some user's condition\") }.toList()\n```\n\n## Local start\n\nYou can use `any` unpublished Reflekt version. You should do the following steps:\n\n- Clone the Reflekt project (the official repo, any fork, branch, etc.).\n- Build the project `./gradlew build`\n- Publish the project to maven local `./gradlew publishToMavenLocal`\n- Add `mavenLocal()` in the repositories section in the `build.gradle.kts` file in your project:\n\n```kotlin\nrepositories {\n    mavenLocal()\n}\n```\n\nPlease note that if you build a Reflekt version with a customized\n[version](https://github.com/JetBrains-Research/reflekt/blob/master/build.gradle.kts#L4) number,\nwrite this version in the plugins and dependencies sections.\n\n## Supported features\n\n- [x] Compile-time reflection by [Reflekt DSL](./reflekt-dsl/src/main/kotlin/org/jetbrains/reflekt/Reflekt.kt)\n  for `multi-module` projects:\n    - [x] project's files\n    - [x] external libraries\n- [x] Compile-time reflection by custom users' filters for `multi-module` projects\n  by [SmartReflekt DSL](./reflekt-dsl/src/main/kotlin/org/jetbrains/reflekt/SmartReflekt.kt)\n    - [x] project's files\n    - [ ] external libraries\n- [x] Bytecode generation -\u003e IR generation\n- [ ] Incremental compilation process\n- [ ] Search in all modules of the project\n- [ ] Code generation.\n\n_Note: We analyze modules independently of each other. If an object\\class\\function is in module A,\nand you run Reflekt in module B, then the object\\class\\function will not be found. You can find this\nexample in the [examples folder](./examples)._\n\n## Examples\n\nAny explanation becomes much better with a proper example.\n\nIn the repository's [examples folder](./examples), you can find an example project that uses the\nReflekt plugin by [Reflekt DSL](./reflekt-dsl/src/main/kotlin/org/jetbrains/reflekt/Reflekt.kt)\nand by [SmartReflekt DSL](./reflekt-dsl/src/main/kotlin/org/jetbrains/reflekt/SmartReflekt.kt).\n\nYou can also find many examples of searching algorithm work in the [test](./reflekt-plugin/src/test)\nfolder.\n\nBy default, the examples project uses Reflekt from the local maven repository. \nIf you would like to use a released version, please, \nuncomment the corresponding lines in the `setting.gradle.kts` and `build.gradle.kts` files in the examples project.\n\n## Want to know more?\n\nThe Reflekt code itself is widely documented, and you can take a look into its interfaces to get to\nknow Reflekt better.\n\nYou may ask questions and participate in discussions on\nrepository [issues](https://github.com/JetBrains-Research/reflekt/issues).\n\n## Contribution\n\nPlease be sure to review project's [contributing guidelines](./docs/contributing.md) to learn how to help the project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjetbrains-research%2Freflekt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjetbrains-research%2Freflekt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjetbrains-research%2Freflekt/lists"}