{"id":25905562,"url":"https://github.com/toxa2033/savedstatecompilerplugin","last_synced_at":"2025-10-05T22:47:25.008Z","repository":{"id":40561828,"uuid":"487284810","full_name":"Toxa2033/SavedStateCompilerPlugin","owner":"Toxa2033","description":"Kotlin compiler plugin generates support synthetic methods for use SaveStateHandle without constants and string variables.","archived":false,"fork":false,"pushed_at":"2022-10-07T09:53:45.000Z","size":125,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-03T05:15:22.884Z","etag":null,"topics":["compiler","generated-code","gradle-plugin","gradle-plugin-kotlin","idea-plugin","inspection","intellij-plugin","kotlin","kotlin-android","kotlin-compiler-plugin","kotlin-library","savedstatehandle"],"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/Toxa2033.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-04-30T13:29:31.000Z","updated_at":"2025-01-12T14:45:09.000Z","dependencies_parsed_at":"2022-08-09T23:10:56.957Z","dependency_job_id":null,"html_url":"https://github.com/Toxa2033/SavedStateCompilerPlugin","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Toxa2033%2FSavedStateCompilerPlugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Toxa2033%2FSavedStateCompilerPlugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Toxa2033%2FSavedStateCompilerPlugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Toxa2033%2FSavedStateCompilerPlugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Toxa2033","download_url":"https://codeload.github.com/Toxa2033/SavedStateCompilerPlugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241610986,"owners_count":19990508,"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":["compiler","generated-code","gradle-plugin","gradle-plugin-kotlin","idea-plugin","inspection","intellij-plugin","kotlin","kotlin-android","kotlin-compiler-plugin","kotlin-library","savedstatehandle"],"created_at":"2025-03-03T05:15:31.338Z","updated_at":"2025-10-05T22:47:19.945Z","avatar_url":"https://github.com/Toxa2033.png","language":"Kotlin","readme":"# Experimental not stable plugin\n\n# SavedState Compiler Plugin\n\nKotlin compiler plugin generates support methods for use SaveStateHandle without constants and string variables. \n\n# Example \n\nIf need to use SaveStateHandle, you must declare a variable, like that: \n```kotlin\n    companion object {\n        private const val TEXT_FIELD = \"text\"\n        private const val PASSWORD_FIELD = \"password\"\n    }\n\n    val text: MutableLiveData\u003cString\u003e = savedStateHandle.getLiveData(TEXT_FIELD, \"Hello World\")\n    \n    val password: String\n        get() = savedStateHandle[PASSWORD_FIELD]\n```\n\n\nThis plugin eliminates necessity declares a variable. Same example with plugin:\n\n```kotlin\n    @SaveState\n    val text: MutableLiveData\u003cString\u003e = getTextLiveData(\"Hello World\")\n    \n    @SaveState\n    val password: String\n        get() = gePasswordValue()\n   \n```\n\n# How it use\n\n1. Apply plugin to your module, sync it and you can use annotation `@SaveState`\n2. Mark by this annotation fields witch you want to use with SavedStateHandle, and support methods generated in realtime.\n\n**Importance:** \n* The SaveStateHandle variable mast be declarated in class. \n* As a key for SaveStateHandle plugin uses name of a annotated variable\n* Supported variable types are listed [here](https://developer.android.com/topic/libraries/architecture/viewmodel-savedstate#types). Also, all these types can be specified as a generic param in LiveData or MutableLiveData\n\n## 4 generated methods\n\nFor example takes this variable \n\n```kotlin\n    private val savedStateHandle: SavedStateHandle\n    \n    @SaveState\n    val text: LiveData\u003cString\u003e\n```\n\n\n### 1. getTextValue() \nIt method return value from SavedStateHandle. Inside it: \n```kotlin\n  private fun getTextValue(): String? {\n    return savedStateHandle.get\u003cString\u003e(key = \"text\")\n  }\n```\n\n### 2. getTextLiveData() \nIt method returns LiveData from SavedStateHandle. Inside it: \n```kotlin\n  private fun getTextLiveData(default: String? = null): MutableLiveData\u003cString\u003e {\n    return savedStateHandle.getLiveData\u003cString\u003e(key = \"text\", initialValue = default)\n  }\n```\n\n### 3. getIdentifierText() \nIt method returns the key witch uses for set and get value in SavedStateHandle. Inside it: \n```kotlin\n  private fun getIdentifierText(): String {\n    return \"text\"\n  }\n```\n\n### 4. setTextValue() \nIt method sets value in SavedStateHandle. Inside it: \n```kotlin\n  private fun setTextValue(text: String?) {\n    savedStateHandle.set\u003cString?\u003e(key = \"text\", value = text)\n  }\n```\n\n## One more things\nThe plugin also allows: \n\n1.Type checking. \nSupports all types from the [documentation](https://developer.android.com/topic/libraries/architecture/viewmodel-savedstate#types) and indicates an error if, for example, class did not implement parcelable\n\n\u003cimg width=\"618\" alt=\"Снимок экрана 2022-05-01 в 15 21 35\" src=\"https://user-images.githubusercontent.com/7330056/166145646-dfbf4767-f895-436d-9bf0-c512cda1b13f.png\"\u003e\n\n\n2. Validates presence of a variable SavedStateHandle in a class. If class contain an annotated variable and the variable SavedStateHandle is not found in the class, then the plugin will notify you\n\u003cimg width=\"600\" alt=\"Снимок экрана 2022-05-01 в 15 29 06\" src=\"https://user-images.githubusercontent.com/7330056/166145961-d1096126-9112-4c54-8d79-18e79edf455f.png\"\u003e\n\n\n## Installation\n\n- In project-level `build.gradle`:\n\n```gradle\nbuildscript {\n    repositories {\n        mavenCentral()\n        // Or\n        gradlePluginPortal()\n    }\n    dependencies {\n        classpath \"io.github.toxa2033.saved-state:gradle-plugin:1.0.5\"\n    }  \n}\n```\n\n- In module-level `build.gradle`:\n\n```gradle\n// For each module that needs to use the annotations\napply plugin: 'io.github.toxa2033.saved-state'\n//or \nplugins {\n    id 'io.github.toxa2033.saved-state'\n}\n```\n\n```gradle\ndependencies {\n    implementation \"androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version\"\n}\n```\n### IDE Support\n\n- Install the [IDEA plugin](https://plugins.jetbrains.com/plugin/19096-savedstatehandle-kotlin-compiler)\n1. Launch the IDE and open plugin settings (Preferences -\u003e Plugins -\u003e Marketplace)\n2. Search for \"SavedStateHandle Kotlin Compiler\" and click install\n\n## Versions\n\n| Kotlin Version | Plugin Version |\n| :------------: | :------------: |\n| 1.5.30 - 1.6.21 | 1.0.*\n\nLicense\n-------\n\n    Copyright (C) 2022 Toxa2033\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoxa2033%2Fsavedstatecompilerplugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftoxa2033%2Fsavedstatecompilerplugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoxa2033%2Fsavedstatecompilerplugin/lists"}