├── .editorconfig ├── .gitignore ├── LICENCE ├── README-1.md ├── README.md ├── build.gradle.kts ├── eden-ide ├── build.gradle.kts ├── gradle.properties └── src │ └── main │ ├── java │ └── com │ │ └── zsu │ │ └── eden │ │ ├── EdenController.kt │ │ ├── EdenModuleCache.kt │ │ ├── EdenModuleListener.kt │ │ ├── EdenSearch.kt │ │ ├── EdenService.kt │ │ ├── ModuleAnnotatedHolder.kt │ │ ├── ModuleContent.kt │ │ ├── SimpleAnnotatedChange.kt │ │ ├── extensions │ │ ├── EdenClassFinder.kt │ │ ├── EdenClassNamesCache.kt │ │ └── ShortClassNamesCache.kt │ │ └── util.kt │ └── resources │ └── META-INF │ └── Eden-plugin.xml ├── eden-poet ├── build.gradle.kts ├── gradle.properties └── src │ └── main │ └── java │ └── com │ └── zsu │ └── eden │ └── EdenPoetApt.kt ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── img └── gif.gif ├── sample ├── build.gradle.kts └── src │ └── main │ ├── java │ └── com │ │ └── zsu │ │ └── eden │ │ └── sample │ │ └── FakeApt.kt │ └── resources │ └── META-INF │ └── plugin.xml └── settings.gradle /.editorconfig: -------------------------------------------------------------------------------- 1 | # This .editorconfig section approximates ktfmt's formatting rules. You can include it in an 2 | # existing .editorconfig file or use it standalone by copying it to /.editorconfig 3 | # and making sure your editor is set to read settings from .editorconfig files. 4 | # 5 | # It includes editor-specific config options for IntelliJ IDEA. 6 | # 7 | # If any option is wrong, PR are welcome 8 | 9 | [{*.kt,*.kts}] 10 | indent_style = space 11 | insert_final_newline = true 12 | max_line_length = 100 13 | indent_size = 4 14 | ij_continuation_indent_size = 4 15 | ij_java_names_count_to_use_import_on_demand = 9999 16 | ij_kotlin_align_in_columns_case_branch = false 17 | ij_kotlin_align_multiline_binary_operation = false 18 | ij_kotlin_align_multiline_extends_list = false 19 | ij_kotlin_align_multiline_method_parentheses = false 20 | ij_kotlin_align_multiline_parameters = true 21 | ij_kotlin_align_multiline_parameters_in_calls = false 22 | ij_kotlin_allow_trailing_comma = true 23 | ij_kotlin_allow_trailing_comma_on_call_site = true 24 | ij_kotlin_assignment_wrap = normal 25 | ij_kotlin_blank_lines_after_class_header = 0 26 | ij_kotlin_blank_lines_around_block_when_branches = 0 27 | ij_kotlin_blank_lines_before_declaration_with_comment_or_annotation_on_separate_line = 1 28 | ij_kotlin_block_comment_at_first_column = true 29 | ij_kotlin_call_parameters_new_line_after_left_paren = true 30 | ij_kotlin_call_parameters_right_paren_on_new_line = false 31 | ij_kotlin_call_parameters_wrap = on_every_item 32 | ij_kotlin_catch_on_new_line = false 33 | ij_kotlin_class_annotation_wrap = split_into_lines 34 | ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL 35 | ij_kotlin_continuation_indent_for_chained_calls = true 36 | ij_kotlin_continuation_indent_for_expression_bodies = true 37 | ij_kotlin_continuation_indent_in_argument_lists = true 38 | ij_kotlin_continuation_indent_in_elvis = false 39 | ij_kotlin_continuation_indent_in_if_conditions = false 40 | ij_kotlin_continuation_indent_in_parameter_lists = false 41 | ij_kotlin_continuation_indent_in_supertype_lists = false 42 | ij_kotlin_else_on_new_line = false 43 | ij_kotlin_enum_constants_wrap = off 44 | ij_kotlin_extends_list_wrap = normal 45 | ij_kotlin_field_annotation_wrap = split_into_lines 46 | ij_kotlin_finally_on_new_line = false 47 | ij_kotlin_if_rparen_on_new_line = false 48 | ij_kotlin_import_nested_classes = false 49 | ij_kotlin_insert_whitespaces_in_simple_one_line_method = true 50 | ij_kotlin_keep_blank_lines_before_right_brace = 2 51 | ij_kotlin_keep_blank_lines_in_code = 2 52 | ij_kotlin_keep_blank_lines_in_declarations = 2 53 | ij_kotlin_keep_first_column_comment = true 54 | ij_kotlin_keep_indents_on_empty_lines = false 55 | ij_kotlin_keep_line_breaks = true 56 | ij_kotlin_lbrace_on_next_line = false 57 | ij_kotlin_line_comment_add_space = false 58 | ij_kotlin_line_comment_at_first_column = true 59 | ij_kotlin_method_annotation_wrap = split_into_lines 60 | ij_kotlin_method_call_chain_wrap = normal 61 | ij_kotlin_method_parameters_new_line_after_left_paren = true 62 | ij_kotlin_method_parameters_right_paren_on_new_line = true 63 | ij_kotlin_method_parameters_wrap = on_every_item 64 | ij_kotlin_name_count_to_use_star_import = 9999 65 | ij_kotlin_name_count_to_use_star_import_for_members = 9999 66 | ij_kotlin_parameter_annotation_wrap = off 67 | ij_kotlin_space_after_comma = true 68 | ij_kotlin_space_after_extend_colon = true 69 | ij_kotlin_space_after_type_colon = true 70 | ij_kotlin_space_before_catch_parentheses = true 71 | ij_kotlin_space_before_comma = false 72 | ij_kotlin_space_before_extend_colon = true 73 | ij_kotlin_space_before_for_parentheses = true 74 | ij_kotlin_space_before_if_parentheses = true 75 | ij_kotlin_space_before_lambda_arrow = true 76 | ij_kotlin_space_before_type_colon = false 77 | ij_kotlin_space_before_when_parentheses = true 78 | ij_kotlin_space_before_while_parentheses = true 79 | ij_kotlin_spaces_around_additive_operators = true 80 | ij_kotlin_spaces_around_assignment_operators = true 81 | ij_kotlin_spaces_around_equality_operators = true 82 | ij_kotlin_spaces_around_function_type_arrow = true 83 | ij_kotlin_spaces_around_logical_operators = true 84 | ij_kotlin_spaces_around_multiplicative_operators = true 85 | ij_kotlin_spaces_around_range = false 86 | ij_kotlin_spaces_around_relational_operators = true 87 | ij_kotlin_spaces_around_unary_operator = false 88 | ij_kotlin_spaces_around_when_arrow = true 89 | ij_kotlin_variable_annotation_wrap = off 90 | ij_kotlin_while_on_new_line = false 91 | ij_kotlin_wrap_elvis_expressions = 1 92 | ij_kotlin_wrap_expression_body_functions = 1 93 | ij_kotlin_wrap_first_method_in_call_chain = false 94 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /eden-ide/build/ 2 | /sample/build/ 3 | /build/ 4 | 5 | .gradle 6 | .idea 7 | local.properties 8 | /eden-poet/build/ 9 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README-1.md: -------------------------------------------------------------------------------- 1 | # Eden 2 | 3 | No more wasted time waiting for kapt/ksp to generate classes for compilation! 4 | Scan annotated elements and generating the classes we want to generate automatically, while 5 | giving the IDE real-time hints! 6 | 7 | 再也不需要等待 kapt/ksp 生成类的编译浪费时间!使用 IDE 插件实时扫描带注解的类、方法、属性,并生成我们想生成的类,同时给予实时提示! 8 | 9 | ## Preview 10 | 11 | ![](https://cdn.jsdelivr.net/gh/zsqw123/cdn@master/picCDN/202206111257981.gif) 12 | This is implemented by writing a very simple DSL: 13 | 14 | ```kotlin 15 | Eden.fakeClass("Fake${ktDeclaration.capitalizeAsciiOnly()}", ktDeclaration.packageName) { 16 | field("fakeFieldStatic", "int", isStatic = true) 17 | clazz("FakeInnerClassStatic") { isStatic = true } 18 | method("fakeMethod") 19 | } 20 | ``` 21 | 22 | ## Usage 23 | 24 | ### 1. Add Dependencies 25 | 26 | maven-central 27 | release 28 | version: [![Maven Central](https://img.shields.io/maven-central/v/io.github.zsqw123/eden-idea)](https://search.maven.org/artifact/io.github.zsqw123/eden-idea) 29 | 30 | ```groovy 31 | repositories { 32 | mavenCentral() 33 | } 34 | dependencies { 35 | implementation("io.github.zsqw123:eden-idea:$version") 36 | } 37 | ``` 38 | 39 | ### 2. Implement Annotation Processor 40 | 41 | 1. Define the annotations to be processed 42 | 2. Handling the `KtDeclaration` which annotated by the specified annotation. 43 | 3. Generate virtual classes for IDE hints 44 | 45 | ```kotlin 46 | val fakeFqn = "com.fake.FakeClass" // the annotation full qualified name which need to process 47 | 48 | @Service // Regist a IDEA light service 49 | class FakeClassCache(project: Project) : EdenCache(project, fakeFqn) { 50 | // The `KtDeclaration` annotated by the specified annotation needs to be processed here, 51 | // and the corresponding virtual class generated is returned. 52 | override fun processAnnotation(annotations: Sequence): Sequence = 53 | annotations.mapNotNull { ktDeclaration -> 54 | val name = ktDeclaration.name ?: return@mapNotNull null 55 | val className = "Fake${name.capitalizeAsciiOnly()}" 56 | Eden.fakeClass(className, ktDeclaration.packageName) { 57 | method("fakeMethod") // Generate virtual methods inside this class 58 | field("fakeField", "String") // Generate virtual variables inside this class 59 | clazz("FakeInnerClass") // virtual internal classes 60 | } 61 | } 62 | 63 | companion object { 64 | fun getInstance(project: Project) = project.getService(FakeClassCache::class.java) 65 | } 66 | } 67 | ``` 68 | 69 | ### 3. Implement Caching and Real-Time Hints 70 | 71 | 1. Real-time hints as characters are entered 72 | 2. Avoid virtual class report error when parsing in the IDE 73 | 3. Drop the previously generated virtual class cache when the annotated element changes 74 | 75 | ```kotlin 76 | // Live alert box when entering characters 77 | class FakeShortNameCache(project: Project) : 78 | EdenClassNamesCache(FakeClassCache.getInstance(project), FakeTracker.getInstance(project)) 79 | 80 | // Avoid virtual class report error when parsing in the IDE 81 | class FakeClassFinder(project: Project) : 82 | EdenClassFinder(FakeClassCache.getInstance(project), FakeTracker.getInstance(project)) 83 | 84 | @Service // refreshing the cache by ModificationTracker 85 | class FakeTracker : EdenModificationTracker() { 86 | companion object { 87 | fun getInstance(project: Project) = project.getService(FakeTracker::class.java) 88 | } 89 | } 90 | ``` 91 | 92 | register it in `plugin.xml`, don't forget include `Eden-plugin.xml`! 93 | 94 | ```xml 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | ``` 104 | 105 | ## Fake DSL 106 | 107 | In Eden, the process of generating a virtual class only requires `Eden.fakeClass` to generate a virtual class. 108 | It supports the construction of virtual class structures using simple DSLs. 109 | 110 | 在 Eden 框架中,生成虚拟类的过程是简单的,只需要通过 `Eden.fakeClass` 即可生成一个虚拟类。它支持使用简单的 DSL 构建虚拟的类结构。 111 | 112 | ```kotlin 113 | val fakeClass = Eden.fakeClass("Test", "com.fake.test") { 114 | imports("java.util.ArrayList", "java.util.HashMap") // import list 115 | isPublic = false // public / private 116 | typeParam("A") // 泛型参数 117 | typeParam("B", "String") // 再加一个泛型参数,但是继承了某个类型 118 | typeParam("C", "Integer") 119 | extends("HashMap") // 继承某个类 120 | implements("ArrayList") // 实现某个接口 (当然,这个 ArrayList 肯定不是接口 = =) 121 | field("f", "ArrayList", isPublic = false, isStatic = false) // 增加一个变量 122 | field("fs", "int", isPublic = true, isStatic = true) // 增加一个静态变量 123 | method("m") { // 增加一个方法 124 | isStatic = true // 静态方法 125 | param("p0" to "int", "p1" to "String") // 方法参数 126 | } 127 | method("m") { 128 | returnType = "ArrayList" // 返回值类型 129 | isPublic = false 130 | typeParam("D", "String") 131 | navigateTo = psiElement // used for idea navigation 132 | } 133 | clazz("I") { // 内部类 134 | method("iA") 135 | isPublic = false 136 | } 137 | clazz("J") { 138 | isStatic = true // 静态内部类 139 | } 140 | navigateTo = psiElement // used for idea navigation 141 | } 142 | ``` 143 | > These methods actually generate the corresponding java psi behind the scenes, and for the time being do not support 144 | > declaring the type nullable. The structure of the method and the initialization body of the variable are omitted, as 145 | > generating an overly heavy structure would add to the parsing burden of the IDE 146 | > 147 | > 这些方法其实背后生成了对应的 java psi,暂时不支持声明类型是否可空,方法的结构体和变量的初始化体均被省略,因为生成过重的结构会加重 IDE 解析的负担 148 | 149 | ## More 150 | 151 | - For an example, see the `sample` module: [sample](/sample) 152 | - About `Fake DSL` example: [FakeClassGenTest](/eden-ide/src/test/java/FakeClassGenTest.kt) 153 | 154 | ### Environment 155 | 156 | | java | idea | 157 | |------|--------------| 158 | | 11+ | 201.6858.69+ | 159 | 160 | ## License & References 161 | 162 | [Apache License 2.0](./LICENCE) 163 | 164 | This project uses the following open source projects: 165 | 166 | - JetBrains IDEA 167 | - JetBrains Kotlin 168 | - Android IDEA Plugin 169 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Eden 2 | 3 | No more wasted time waiting for kapt/ksp to generate classes for compilation! 4 | Scan annotated elements and generating the classes we want to generate automatically, while 5 | giving the IDE real-time hints! 6 | 7 | 再也不需要等待 kapt/ksp 生成类的编译浪费时间!使用 IDE 插件实时扫描带注解的类、方法、属性,并生成我们想生成的类,同时给予实时提示! 8 | 9 | > Version 2.0 compared with version 1.0 is completely incapable, version 1.0: [README-1](README-1.md) 10 | > 11 | > Notice: 2.0 版本与 1.0 版本为完全不兼容改动,1.0 版本的 README: [README-1](README-1.md) 12 | 13 | ## Preview 14 | 15 | It will generate files produced by the annotation processor in real-time when modifying elements containing specified 16 | annotations. 17 | 18 | 它会在改动包含指定注解的元素的时候,实时生成注解处理器产生的文件 19 | 20 | ![](img/gif.gif) 21 | 22 | ## Usage 23 | 24 | ### 1. Add Dependencies 25 | 26 | maven-central release 27 | version: [![Maven Central](https://img.shields.io/maven-central/v/io.github.zsqw123/eden-idea)](https://central.sonatype.com/search?q=eden-idea) 28 | 29 | ```groovy 30 | repositories { 31 | mavenCentral() 32 | } 33 | dependencies { 34 | implementation("io.github.zsqw123:eden-idea:$version") 35 | // implementation following if kotlin-poet is needed 36 | implementation("io.github.zsqw123:eden-poet:$version") 37 | } 38 | ``` 39 | 40 | ### 2. Implement Annotation Processor 41 | 42 | 1. Define the annotations to be processed 43 | 2. Handling the `KtDeclaration` which annotated by the specified annotation. 44 | 3. Generate files in real-time 45 | 46 | ```kotlin 47 | private const val FAKE_FQN = "com.fake.FakeClass" // the annotation full qualified name 48 | 49 | class FakeApt : EdenPoetApt() { 50 | override val annotationFqn: String = FAKE_FQN 51 | override fun processWithPoet(all: List): List { 52 | return all.mapNotNull { it.name }.map { name -> 53 | val className = "Fake${name.capitalizeAsciiOnly()}" 54 | // generate codes by kotlinpoet 55 | val type = TypeSpec.classBuilder(className).build() 56 | FileSpec.builder("com.zsu", className).addType(type).build() 57 | } 58 | } 59 | } 60 | ``` 61 | 62 | and register it in `plugin.xml`, don't forget include `Eden-plugin.xml`! 63 | 64 | ```xml 65 | 66 | 67 | 68 | 69 | 70 | 71 | ``` 72 | 73 | ## More 74 | 75 | - For an example, see the `sample` module: [sample](/sample) 76 | 77 | ### Environment 78 | 79 | | java | idea | 80 | |------|--------------| 81 | | 11+ | 201.6858.69+ | 82 | 83 | ## License & References 84 | 85 | [Apache License 2.0](./LICENCE) 86 | 87 | This project uses the following open source projects: 88 | 89 | - JetBrains IDEA 90 | - JetBrains Kotlin 91 | - Android IDEA Plugin 92 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | import java.util.* 2 | 3 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 4 | buildscript { 5 | repositories { 6 | mavenCentral() 7 | gradlePluginPortal() 8 | } 9 | dependencies { 10 | classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.20") 11 | classpath("org.jetbrains.intellij.plugins:gradle-intellij-plugin:1.5.2") 12 | classpath("com.vanniktech:gradle-maven-publish-plugin:0.20.0") 13 | } 14 | } 15 | 16 | allprojects { 17 | repositories { 18 | google() 19 | maven { setUrl("https://www.jetbrains.com/intellij-repository/releases/") } 20 | maven { setUrl("https://www.jetbrains.com/intellij-repository/snapshots") } 21 | mavenCentral() 22 | } 23 | extra["idePath"] = getIdePath() 24 | } 25 | 26 | task("clean", Delete::class) { 27 | delete(rootProject.buildDir) 28 | } 29 | 30 | fun getIdePath(): String { 31 | val localPropertiesFile = File("local.properties") 32 | var path = "" 33 | if (localPropertiesFile.exists()) { 34 | val prop = Properties() 35 | prop.load(localPropertiesFile.inputStream()) 36 | path = prop.getProperty("ide_path", "") 37 | } 38 | return path 39 | } 40 | -------------------------------------------------------------------------------- /eden-ide/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.jetbrains.kotlin.gradle.tasks.KotlinCompile 2 | 3 | plugins { 4 | id("org.jetbrains.intellij") 5 | id("com.vanniktech.maven.publish") 6 | kotlin("jvm") 7 | } 8 | 9 | repositories { 10 | mavenCentral() 11 | } 12 | 13 | group = "io.github.zsqw123" 14 | version = ext.get("edenPublishVersion")!! 15 | 16 | // See https://github.com/JetBrains/gradle-intellij-plugin/ 17 | intellij { 18 | version.set("2022.1") // target version 19 | type.set("IC") 20 | updateSinceUntilBuild.set(false) 21 | plugins.set(listOf("com.intellij.java", "org.jetbrains.kotlin")) 22 | } 23 | 24 | tasks { 25 | withType { 26 | sourceCompatibility = JavaVersion.VERSION_11.toString() 27 | targetCompatibility = JavaVersion.VERSION_11.toString() 28 | } 29 | withType { 30 | kotlinOptions.jvmTarget = JavaVersion.VERSION_11.toString() 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /eden-ide/gradle.properties: -------------------------------------------------------------------------------- 1 | POM_ARTIFACT_ID=eden-idea -------------------------------------------------------------------------------- /eden-ide/src/main/java/com/zsu/eden/EdenController.kt: -------------------------------------------------------------------------------- 1 | package com.zsu.eden 2 | 3 | import com.intellij.openapi.components.Service 4 | import com.intellij.openapi.components.service 5 | import com.intellij.openapi.fileEditor.FileEditorManager 6 | import com.intellij.openapi.module.ModuleManager 7 | import com.intellij.openapi.module.ModuleUtilCore 8 | import com.intellij.openapi.project.Project 9 | 10 | @Service 11 | class EdenController(private val project: Project) { 12 | private val moduleCache = EdenModuleCache.getInstance(project) 13 | 14 | /** 15 | * @param scope refresh scope 16 | * @param fqns annotation fqns which need refresh 17 | * @param needClean remove generated before processing 18 | * @return true if refresh success 19 | * @see Scope 20 | */ 21 | fun refresh( 22 | scope: Scope, 23 | fqns: List? = null, 24 | needClean: Boolean = false, 25 | ): Boolean { 26 | when (scope) { 27 | Scope.CURRENT_MODULE -> { 28 | val selectedFile = FileEditorManager.getInstance(project).selectedFiles 29 | .firstOrNull() ?: return false 30 | val currentModule = ModuleUtilCore.findModuleForFile(selectedFile, project) 31 | ?: return false 32 | moduleCache.refresh(currentModule, fqns, needClean) 33 | return true 34 | } 35 | 36 | Scope.PROJECT -> { 37 | moduleCache.refresh(fqns, needClean) 38 | return true 39 | } 40 | } 41 | } 42 | 43 | /** 44 | * It is **strongly not recommended** to generate the entire project, as it can be quite time-consuming 45 | */ 46 | fun manualGenerate( 47 | scope: Scope, 48 | fqns: List? = null, 49 | ): Boolean { 50 | when (scope) { 51 | Scope.CURRENT_MODULE -> { 52 | val selectedFile = FileEditorManager.getInstance(project).selectedFiles 53 | .firstOrNull() ?: return false 54 | val currentModule = ModuleUtilCore.findModuleForFile(selectedFile, project) 55 | ?: return false 56 | ModuleContent(currentModule).refresh(fqns, false) 57 | return true 58 | } 59 | 60 | Scope.PROJECT -> { 61 | ModuleManager.getInstance(project).modules.forEach { 62 | ModuleContent(it).refresh(fqns, false) 63 | } 64 | return true 65 | } 66 | } 67 | } 68 | 69 | enum class Scope { 70 | CURRENT_MODULE, // refresh selected file's project 71 | PROJECT, // refresh whole project 72 | } 73 | 74 | companion object { 75 | fun getInstance(project: Project) = project.service() 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /eden-ide/src/main/java/com/zsu/eden/EdenModuleCache.kt: -------------------------------------------------------------------------------- 1 | package com.zsu.eden 2 | 3 | import com.intellij.openapi.components.Service 4 | import com.intellij.openapi.components.service 5 | import com.intellij.openapi.module.Module 6 | import com.intellij.openapi.project.DumbService 7 | import com.intellij.openapi.project.Project 8 | import com.intellij.openapi.util.Disposer 9 | import com.intellij.psi.search.GlobalSearchScope 10 | 11 | @Service 12 | class EdenModuleCache(private val project: Project) { 13 | private val moduleMap: HashMap = hashMapOf() 14 | private val enabled = EdenService.getInstance(project).allApt.values.any { 15 | it.checkEnable(project) 16 | } 17 | 18 | internal fun addModule(module: Module) { 19 | if (!enabled) return 20 | moduleMap[module] = ModuleContent(module) 21 | } 22 | 23 | internal fun removeModule(module: Module) { 24 | val content = moduleMap.remove(module) 25 | if (content != null) { 26 | Disposer.dispose(content) 27 | } 28 | } 29 | 30 | internal fun clear() { 31 | moduleMap.values.forEach { 32 | Disposer.dispose(it) 33 | } 34 | } 35 | 36 | internal fun refresh(module: Module, fqns: List?, needClean: Boolean) { 37 | moduleMap[module]?.refresh(fqns, needClean) 38 | } 39 | 40 | internal fun refresh(fqns: List?, needClean: Boolean) { 41 | moduleMap.forEach { it.value.refresh(fqns, needClean) } 42 | } 43 | 44 | @Volatile 45 | private var loading = false 46 | fun tryLoadCache(scope: GlobalSearchScope) { 47 | if (loading) return 48 | if (DumbService.isDumb(project)) return 49 | try { 50 | loading = true 51 | for ((k, v) in moduleMap) { 52 | if (!scope.isSearchInModuleContent(k)) continue 53 | v.cached.value 54 | } 55 | } finally { 56 | loading = false 57 | } 58 | } 59 | 60 | companion object { 61 | fun getInstance(project: Project) = project.service() 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /eden-ide/src/main/java/com/zsu/eden/EdenModuleListener.kt: -------------------------------------------------------------------------------- 1 | package com.zsu.eden 2 | 3 | import com.intellij.openapi.module.Module 4 | import com.intellij.openapi.project.ModuleListener 5 | import com.intellij.openapi.project.Project 6 | import com.intellij.openapi.project.ProjectManagerListener 7 | 8 | class EdenModuleListener : ModuleListener, ProjectManagerListener { 9 | override fun moduleAdded(project: Project, module: Module) { 10 | EdenModuleCache.getInstance(project).addModule(module) 11 | } 12 | 13 | override fun moduleRemoved(project: Project, module: Module) { 14 | EdenModuleCache.getInstance(project).removeModule(module) 15 | } 16 | 17 | override fun projectClosing(project: Project) { 18 | EdenModuleCache.getInstance(project).clear() 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /eden-ide/src/main/java/com/zsu/eden/EdenSearch.kt: -------------------------------------------------------------------------------- 1 | package com.zsu.eden 2 | 3 | import com.intellij.openapi.module.Module 4 | import com.intellij.psi.JavaPsiFacade 5 | import org.jetbrains.kotlin.idea.search.ideaExtensions.KotlinAnnotatedElementsSearcher 6 | import org.jetbrains.kotlin.psi.KtNamedDeclaration 7 | 8 | object EdenSearch { 9 | fun getAnnotatedElements( 10 | module: Module, annotationFqn: String, 11 | ): List = buildList { 12 | val annotationClass = JavaPsiFacade.getInstance(module.project).findClass( 13 | annotationFqn, 14 | module.getModuleWithDependenciesAndLibrariesScope(true), 15 | ) ?: return@buildList 16 | 17 | // in IDEA 2023 (223), it has been changed with: 18 | // org.jetbrains.kotlin.idea.base.searching.KotlinAnnotatedElementsSearcher. 19 | KotlinAnnotatedElementsSearcher.processAnnotatedMembers( 20 | annotationClass, 21 | module.moduleScope, 22 | ) { declaration -> 23 | if (declaration is KtNamedDeclaration) add(declaration) 24 | true 25 | } 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /eden-ide/src/main/java/com/zsu/eden/EdenService.kt: -------------------------------------------------------------------------------- 1 | package com.zsu.eden 2 | 3 | import com.intellij.openapi.components.Service 4 | import com.intellij.openapi.components.service 5 | import com.intellij.openapi.extensions.ExtensionPointName 6 | import com.intellij.openapi.module.Module 7 | import com.intellij.openapi.project.Project 8 | import com.intellij.openapi.vfs.VirtualFile 9 | import org.jetbrains.kotlin.psi.KtNamedDeclaration 10 | import java.io.File 11 | 12 | @Service 13 | class EdenService(private val project: Project) { 14 | internal val allApt = HashMap() 15 | fun addApt(edenApt: EdenApt) { 16 | allApt[edenApt.annotationFqn] = edenApt 17 | } 18 | 19 | init { 20 | EdenApt.getAll().forEach { 21 | addApt(it) 22 | } 23 | } 24 | 25 | companion object { 26 | fun getInstance(project: Project) = project.service() 27 | } 28 | } 29 | 30 | abstract class EdenApt { 31 | abstract val annotationFqn: String 32 | abstract fun processSingleModule(all: List): List 33 | 34 | open fun getGeneratePath(module: Module): VirtualFile? = null 35 | 36 | open fun checkEnable(project: Project): Boolean = true 37 | open fun checkEnable(module: Module): Boolean = true 38 | open val kspVariant: String = "main" 39 | 40 | companion object { 41 | @Suppress("MemberVisibilityCanBePrivate") 42 | val EP_NAME: ExtensionPointName = 43 | ExtensionPointName.create("com.zsu.eden.edenApt") 44 | 45 | fun getAll(): Array = EP_NAME.extensions 46 | } 47 | } 48 | 49 | interface EdenFile { 50 | val packageName: String 51 | val name: String // without `.kt` 52 | 53 | /** @param ioFile sourceRoot of this file */ 54 | fun writeTo(ioFile: File) 55 | 56 | abstract class Impl( 57 | override val packageName: String, 58 | override val name: String, 59 | ) : EdenFile { 60 | abstract fun content(): String 61 | override fun writeTo(ioFile: File) { 62 | val packageName = packageName 63 | var outputDirectory = ioFile.toPath() 64 | if (packageName.isNotEmpty()) { 65 | for (packageComponent in packageName.split('.') 66 | .dropLastWhile { it.isEmpty() }) { 67 | outputDirectory = outputDirectory.resolve(packageComponent) 68 | } 69 | } 70 | val outputFolder = outputDirectory.toFile() 71 | if (!outputFolder.exists()) outputFolder.mkdirs() 72 | File(outputFolder, "$name.kt").writeText(content()) 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /eden-ide/src/main/java/com/zsu/eden/ModuleAnnotatedHolder.kt: -------------------------------------------------------------------------------- 1 | package com.zsu.eden 2 | 3 | import com.intellij.openapi.diagnostic.Logger 4 | import com.intellij.openapi.module.Module 5 | import com.intellij.openapi.project.rootManager 6 | import com.intellij.openapi.vfs.LocalFileSystem 7 | import com.intellij.openapi.vfs.VfsUtilCore 8 | import com.intellij.openapi.vfs.VirtualFile 9 | import org.jetbrains.jps.model.java.JavaSourceRootType 10 | import org.jetbrains.jps.model.module.JpsModuleSourceRootType 11 | import org.jetbrains.kotlin.config.SourceKotlinRootType 12 | import org.jetbrains.kotlin.idea.configuration.externalProjectPath 13 | import org.jetbrains.kotlin.idea.util.application.runReadAction 14 | import java.io.File 15 | import java.util.concurrent.Executors 16 | 17 | internal class ModuleAnnotatedHolder( 18 | private val module: Module, 19 | private val annotationFqn: String, 20 | ) { 21 | private val edenService = EdenService.getInstance(module.project) 22 | private var generated: List = emptyList() 23 | fun create(): Boolean { 24 | val singleApt = edenService.allApt[annotationFqn] 25 | if (singleApt == null) { 26 | logger.warn("[$annotationFqn] apt didn't exists when scan module [${module.name}]") 27 | return false 28 | } 29 | val allFiles = runReadAction { 30 | val all = EdenSearch.getAnnotatedElements(module, annotationFqn) 31 | try { 32 | singleApt.processSingleModule(all) 33 | } catch (e: Exception) { 34 | logger.logErrorIfNeeded( 35 | "meet exception when process module [${module.name}] with [$annotationFqn]!", 36 | e, 37 | ) 38 | emptyList() 39 | } 40 | } 41 | if (allFiles.isNotEmpty()) executor.execute { 42 | cleanAllGenerated() 43 | createFiles(module, allFiles, singleApt) { 44 | generated = it 45 | } 46 | } 47 | return true 48 | } 49 | 50 | fun cleanAllGenerated() { 51 | generated.forEach { if (it.exists()) it.delete() } 52 | } 53 | 54 | companion object { 55 | private val logger = Logger.getInstance(ModuleAnnotatedHolder::class.java) 56 | private val kotlinSourceRoots: MutableSet> = 57 | hashSetOf(JavaSourceRootType.SOURCE, SourceKotlinRootType) 58 | 59 | private val executor = Executors.newSingleThreadExecutor() 60 | private inline fun createFiles( 61 | module: Module, allFiles: List, apt: EdenApt, 62 | addedCallback: (added: List) -> Unit, 63 | ) { 64 | if (allFiles.isEmpty()) return 65 | val sourceRoot = guessRootPath(apt, module) 66 | if (sourceRoot == null) { 67 | logger.warn("no kotlin/java source root found in [${module.name}]!") 68 | return 69 | } 70 | val ioFile = VfsUtilCore.virtualToIoFile(sourceRoot) 71 | val added = arrayListOf() 72 | for (file in allFiles) { 73 | file.writeTo(ioFile) 74 | var outputDirectory = ioFile.toPath() 75 | if (file.packageName.isNotEmpty()) { 76 | for (packageComponent in file.packageName.split('.') 77 | .dropLastWhile { it.isEmpty() }) { 78 | outputDirectory = outputDirectory.resolve(packageComponent) 79 | } 80 | } 81 | val outputPath = outputDirectory.resolve("${file.name}.kt") 82 | added += outputPath.toFile() 83 | } 84 | addedCallback(added) 85 | sourceRoot.refresh(true, true) 86 | } 87 | 88 | private fun guessRootPath(apt: EdenApt, module: Module): VirtualFile? { 89 | val sourceRoot = apt.getGeneratePath(module) 90 | if (sourceRoot != null) return sourceRoot 91 | 92 | val extProjectPath = module.externalProjectPath 93 | if (extProjectPath != null) { 94 | val file = File(extProjectPath, "build/generated/ksp/${apt.kspVariant}/kotlin") 95 | if (!file.exists()) file.mkdirs() 96 | return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file) 97 | } 98 | return module.rootManager.getSourceRoots(kotlinSourceRoots).firstOrNull() 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /eden-ide/src/main/java/com/zsu/eden/ModuleContent.kt: -------------------------------------------------------------------------------- 1 | package com.zsu.eden 2 | 3 | import com.intellij.openapi.Disposable 4 | import com.intellij.openapi.module.Module 5 | import com.intellij.openapi.project.DumbService 6 | import com.intellij.openapi.util.SimpleModificationTracker 7 | import com.intellij.psi.PsiManager 8 | import com.intellij.psi.PsiTreeChangeListener 9 | import com.intellij.psi.search.PsiSearchScopeUtil 10 | import com.intellij.psi.util.CachedValue 11 | import org.jetbrains.kotlin.idea.util.cachedValue 12 | import org.jetbrains.kotlin.psi.KtDeclaration 13 | import kotlin.concurrent.thread 14 | 15 | internal class ModuleContent( 16 | private val module: Module, 17 | private val enabledFqns: List? = null, 18 | ) : Disposable { 19 | private val project = module.project 20 | private val scope = module.moduleScope 21 | private val annotatedCache = HashMap() 22 | private val edenService = EdenService.getInstance(project) 23 | private val availableApt: Map = if (enabledFqns == null) { 24 | edenService.allApt.filter { it.value.checkEnable(module) } 25 | } else { 26 | edenService.allApt.filter { it.key in enabledFqns } 27 | } 28 | 29 | private val allAptFqn: Collection 30 | private val allAptSimple: Collection 31 | 32 | init { 33 | if (availableApt.isNotEmpty()) { 34 | allAptFqn = availableApt.keys 35 | allAptSimple = allAptFqn.map { it.substringAfterLast('.') } 36 | .filter { it.isNotBlank() } 37 | allAptFqn.forEach { 38 | annotatedCache[it] = ModuleAnnotatedHolder(module, it) 39 | } 40 | } else { 41 | allAptFqn = emptyList() 42 | allAptSimple = emptyList() 43 | } 44 | } 45 | 46 | private val tracker = SimpleModificationTracker() 47 | private val psiManager = PsiManager.getInstance(project) 48 | 49 | private val changeListener: PsiTreeChangeListener? 50 | 51 | init { 52 | if (availableApt.isNotEmpty()) { 53 | changeListener = ChangeListener() 54 | psiManager.addPsiTreeChangeListener(changeListener, this) 55 | } else { 56 | changeListener = null 57 | } 58 | } 59 | 60 | val cached: CachedValue<*> = cachedValue( 61 | project, tracker, 62 | DumbService.getInstance(project).modificationTracker, 63 | ) { 64 | annotatedCache.values.forEach { it.create() } 65 | } 66 | 67 | override fun dispose() { 68 | if (changeListener != null) { 69 | psiManager.removePsiTreeChangeListener(changeListener) 70 | } 71 | } 72 | 73 | fun refresh(fqns: List?, needClean: Boolean) { 74 | if (fqns == null) { 75 | tracker.incModificationCount() 76 | return 77 | } 78 | for ((annotation, holder) in annotatedCache) { 79 | if (annotation in fqns) { 80 | if (needClean) { 81 | holder.cleanAllGenerated() 82 | } 83 | holder.create() 84 | break 85 | } 86 | } 87 | } 88 | 89 | private inner class ChangeListener : SimpleAnnotatedChange(allAptSimple) { 90 | private var lastChanged = 0L 91 | override fun onAnnotatedElementChange(declaration: KtDeclaration) { 92 | if (!PsiSearchScopeUtil.isInScope(scope, declaration)) return 93 | val current = System.currentTimeMillis() 94 | val timeAfterLastChanged = (current - lastChanged).coerceAtLeast(0) 95 | if (timeAfterLastChanged < 1500) { 96 | shouldCheck = false 97 | thread { 98 | Thread.sleep(1500 - timeAfterLastChanged) 99 | lastChanged = System.currentTimeMillis() 100 | shouldCheck = true 101 | tracker.incModificationCount() 102 | } 103 | } else { 104 | lastChanged = System.currentTimeMillis() 105 | tracker.incModificationCount() 106 | } 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /eden-ide/src/main/java/com/zsu/eden/SimpleAnnotatedChange.kt: -------------------------------------------------------------------------------- 1 | package com.zsu.eden 2 | 3 | import com.intellij.psi.PsiElement 4 | import com.intellij.psi.PsiTreeChangeAdapter 5 | import com.intellij.psi.PsiTreeChangeEvent 6 | import com.intellij.psi.util.parentsOfType 7 | import org.jetbrains.kotlin.psi.KtDeclaration 8 | 9 | abstract class SimpleAnnotatedChange(private val shortNames: Collection) : 10 | PsiTreeChangeAdapter() { 11 | final override fun childAdded(event: PsiTreeChangeEvent) { 12 | onChange(event.child) 13 | } 14 | 15 | final override fun childRemoved(event: PsiTreeChangeEvent) { 16 | onChange(event.child) 17 | } 18 | 19 | final override fun childReplaced(event: PsiTreeChangeEvent) { 20 | onChange(event.newChild) 21 | } 22 | 23 | final override fun childMoved(event: PsiTreeChangeEvent) { 24 | onChange(event.child) 25 | } 26 | 27 | final override fun childrenChanged(event: PsiTreeChangeEvent) { 28 | onChange(event.parent) 29 | } 30 | 31 | final override fun propertyChanged(event: PsiTreeChangeEvent) { 32 | onChange(event.element) 33 | } 34 | 35 | @Volatile 36 | protected var shouldCheck = true 37 | private fun onChange(element: PsiElement?) { 38 | element ?: return 39 | if (!shouldCheck) return 40 | // Checking its 3 parent nodes, not checking too much here, because of performance loss concerns 41 | for (ktDeclaration in element.parentsOfType().take(3)) { 42 | val annotations = ktDeclaration.annotationEntries 43 | if (annotations.isEmpty()) continue 44 | val hasChange = annotations.any { currentAnnotation -> 45 | shortNames.any { shortNames -> 46 | currentAnnotation.shortName?.asString() == shortNames 47 | } 48 | } 49 | if (hasChange) { 50 | onAnnotatedElementChange(ktDeclaration) 51 | break 52 | } 53 | } 54 | } 55 | 56 | protected abstract fun onAnnotatedElementChange(declaration: KtDeclaration) 57 | } 58 | -------------------------------------------------------------------------------- /eden-ide/src/main/java/com/zsu/eden/extensions/EdenClassFinder.kt: -------------------------------------------------------------------------------- 1 | package com.zsu.eden.extensions 2 | 3 | import com.intellij.openapi.components.Service 4 | import com.intellij.openapi.project.Project 5 | import com.intellij.psi.PsiClass 6 | import com.intellij.psi.PsiElementFinder 7 | import com.intellij.psi.PsiPackage 8 | import com.intellij.psi.search.GlobalSearchScope 9 | import com.zsu.eden.EdenModuleCache 10 | 11 | @Service 12 | class EdenClassFinder(project: Project) : PsiElementFinder() { 13 | private val edenModuleCache = EdenModuleCache.getInstance(project) 14 | private fun tryRefresh(scope: GlobalSearchScope) { 15 | edenModuleCache.tryLoadCache(scope) 16 | } 17 | 18 | override fun findClass(qualifiedName: String, scope: GlobalSearchScope): PsiClass? { 19 | tryRefresh(scope) 20 | return null 21 | } 22 | 23 | override fun findClasses(qualifiedName: String, scope: GlobalSearchScope): Array { 24 | findClass(qualifiedName, scope) 25 | return PsiClass.EMPTY_ARRAY 26 | } 27 | 28 | // for `*` import 29 | override fun getClasses(psiPackage: PsiPackage, scope: GlobalSearchScope): Array { 30 | tryRefresh(scope) 31 | return PsiClass.EMPTY_ARRAY 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /eden-ide/src/main/java/com/zsu/eden/extensions/EdenClassNamesCache.kt: -------------------------------------------------------------------------------- 1 | package com.zsu.eden.extensions 2 | 3 | import com.intellij.openapi.components.Service 4 | import com.intellij.openapi.project.Project 5 | import com.intellij.psi.PsiClass 6 | import com.intellij.psi.search.GlobalSearchScope 7 | import com.zsu.eden.EdenModuleCache 8 | 9 | private val stubArray = arrayOf("__FAKE_STUB") 10 | 11 | @Service 12 | class EdenClassNamesCache(project: Project) : ShortClassNamesCache() { 13 | private val edenModuleCache = EdenModuleCache.getInstance(project) 14 | override fun getAllClassNames(): Array = stubArray 15 | override fun getClassesByName(name: String, scope: GlobalSearchScope): Array { 16 | edenModuleCache.tryLoadCache(scope) 17 | return PsiClass.EMPTY_ARRAY 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /eden-ide/src/main/java/com/zsu/eden/extensions/ShortClassNamesCache.kt: -------------------------------------------------------------------------------- 1 | package com.zsu.eden.extensions 2 | 3 | import com.intellij.psi.PsiField 4 | import com.intellij.psi.PsiMethod 5 | import com.intellij.psi.search.GlobalSearchScope 6 | import com.intellij.psi.search.PsiShortNamesCache 7 | import com.intellij.util.Processor 8 | 9 | abstract class ShortClassNamesCache : PsiShortNamesCache() { 10 | private val emptyArray = emptyArray() 11 | override fun getAllMethodNames(): Array = emptyArray 12 | override fun getAllFieldNames(): Array = emptyArray 13 | override fun getMethodsByName(name: String, scope: GlobalSearchScope): Array = PsiMethod.EMPTY_ARRAY 14 | override fun getMethodsByNameIfNotMoreThan(name: String, scope: GlobalSearchScope, maxCount: Int): Array = 15 | PsiMethod.EMPTY_ARRAY 16 | 17 | override fun processMethodsWithName(name: String, scope: GlobalSearchScope, processor: Processor): Boolean = true 18 | override fun getFieldsByNameIfNotMoreThan(name: String, scope: GlobalSearchScope, maxCount: Int): Array = PsiField.EMPTY_ARRAY 19 | override fun getFieldsByName(name: String, scope: GlobalSearchScope): Array = PsiField.EMPTY_ARRAY 20 | } 21 | -------------------------------------------------------------------------------- /eden-ide/src/main/java/com/zsu/eden/util.kt: -------------------------------------------------------------------------------- 1 | package com.zsu.eden 2 | 3 | import com.intellij.openapi.diagnostic.Logger 4 | import com.intellij.openapi.progress.ProcessCanceledException 5 | 6 | fun Logger.logErrorIfNeeded(message: String, e: Throwable) { 7 | if (e is ProcessCanceledException) { 8 | return // process cancellation is not allowed to be logged and will throw 9 | } 10 | error(message, e) 11 | } 12 | -------------------------------------------------------------------------------- /eden-ide/src/main/resources/META-INF/Eden-plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | com.intellij.modules.platform 3 | com.intellij.modules.lang 4 | com.intellij.java 5 | org.jetbrains.kotlin 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /eden-poet/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("org.jetbrains.intellij") 3 | id("com.vanniktech.maven.publish") 4 | kotlin("jvm") 5 | } 6 | group = "io.github.zsqw123" 7 | version = ext.get("edenPublishVersion")!! 8 | 9 | repositories { 10 | mavenCentral() 11 | } 12 | 13 | dependencies { 14 | compileOnly(project(":eden-ide")) 15 | compileOnly("com.squareup:kotlinpoet:1.12.0") 16 | } 17 | 18 | // See https://github.com/JetBrains/gradle-intellij-plugin/ 19 | intellij { 20 | version.set("2022.1") // target version 21 | type.set("IC") 22 | updateSinceUntilBuild.set(false) 23 | plugins.set(listOf("com.intellij.java", "org.jetbrains.kotlin")) 24 | } 25 | 26 | tasks { 27 | withType { 28 | sourceCompatibility = JavaVersion.VERSION_11.toString() 29 | targetCompatibility = JavaVersion.VERSION_11.toString() 30 | } 31 | withType { 32 | kotlinOptions.jvmTarget = JavaVersion.VERSION_11.toString() 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /eden-poet/gradle.properties: -------------------------------------------------------------------------------- 1 | POM_ARTIFACT_ID=eden-poet -------------------------------------------------------------------------------- /eden-poet/src/main/java/com/zsu/eden/EdenPoetApt.kt: -------------------------------------------------------------------------------- 1 | package com.zsu.eden 2 | 3 | import com.squareup.kotlinpoet.FileSpec 4 | import org.jetbrains.kotlin.psi.KtNamedDeclaration 5 | import java.io.File 6 | 7 | abstract class EdenPoetApt : EdenApt() { 8 | abstract fun processWithPoet(all: List): List 9 | override fun processSingleModule(all: List): List { 10 | return processWithPoet(all).map { PoetEdenFile(it) } 11 | } 12 | } 13 | 14 | private class PoetEdenFile(private val poetFile: FileSpec) : EdenFile { 15 | override val name: String = poetFile.name 16 | override val packageName: String = poetFile.packageName 17 | override fun writeTo(ioFile: File) = poetFile.writeTo(ioFile) 18 | } 19 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app"s APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | # Kotlin code style for this project: "official" or "obsolete": 21 | kotlin.code.style=official 22 | 23 | GROUP=io.github.zsqw123 24 | POM_NAME=Eden 25 | POM_DESCRIPTION=Real-time annotation processor for Kotlin. 26 | POM_INCEPTION_YEAR=2022 27 | POM_URL=https://github.com/zsqw123/Eden 28 | POM_LICENCE_NAME=The Apache Software License, Version 2.0 29 | POM_LICENCE_URL=https://www.apache.org/licenses/LICENSE-2.0.txt 30 | POM_LICENCE_DIST=repo 31 | POM_SCM_URL=https://github.com/zsqw123/Eden 32 | POM_SCM_CONNECTION=scm:git:git://github.com/zsqw123/Eden.git 33 | POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/zsqw123/Eden.git 34 | POM_DEVELOPER_ID=zsqw123 35 | POM_DEVELOPER_NAME=zsqw123 36 | POM_DEVELOPER_URL=https://github.com/zsqw123/ 37 | SONATYPE_HOST=S01 38 | 39 | edenPublishVersion=2.0.7 40 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zsqw123/Eden/df7644b2bec1f4ff60281aac364ecbcd4f5d0a67/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /img/gif.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zsqw123/Eden/df7644b2bec1f4ff60281aac364ecbcd4f5d0a67/img/gif.gif -------------------------------------------------------------------------------- /sample/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("org.jetbrains.intellij") 3 | kotlin("jvm") 4 | } 5 | 6 | repositories { 7 | mavenCentral() 8 | mavenLocal() 9 | } 10 | 11 | // See https://github.com/JetBrains/gradle-intellij-plugin/ 12 | intellij { 13 | version.set("2022.1") // target version 14 | type.set("IC") 15 | updateSinceUntilBuild.set(false) 16 | plugins.set(listOf("com.intellij.java", "org.jetbrains.kotlin")) 17 | } 18 | 19 | dependencies { 20 | implementation(project(":eden-ide")) 21 | implementation(project(":eden-poet")) 22 | 23 | // implementation("io.github.zsqw123:eden-idea:1.0.0") 24 | implementation("com.squareup:kotlinpoet:1.12.0") 25 | } 26 | 27 | tasks { 28 | getByName("test") { 29 | useJUnitPlatform() 30 | } 31 | withType { 32 | sourceCompatibility = JavaVersion.VERSION_11.toString() 33 | targetCompatibility = JavaVersion.VERSION_11.toString() 34 | } 35 | withType { 36 | kotlinOptions.jvmTarget = JavaVersion.VERSION_11.toString() 37 | } 38 | runIde { 39 | val idePath: String by project.extra 40 | if (idePath.isNotEmpty()) { 41 | println("config ide_path: $idePath") 42 | ideDir.set(file(idePath)) 43 | } 44 | jvmArgs("-Xmx2048m") 45 | } 46 | withType { 47 | changeNotes.set( 48 | """Add change notes here.
49 | most HTML tags may be used""" 50 | ) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /sample/src/main/java/com/zsu/eden/sample/FakeApt.kt: -------------------------------------------------------------------------------- 1 | package com.zsu.eden.sample 2 | 3 | import com.squareup.kotlinpoet.FileSpec 4 | import com.squareup.kotlinpoet.TypeSpec 5 | import com.zsu.eden.EdenPoetApt 6 | import org.jetbrains.kotlin.psi.KtNamedDeclaration 7 | import org.jetbrains.kotlin.util.capitalizeDecapitalize.capitalizeAsciiOnly 8 | 9 | internal const val fakeFqn = "com.fake.FakeClass" 10 | 11 | class FakeApt : EdenPoetApt() { 12 | override val annotationFqn: String = fakeFqn 13 | override fun processWithPoet(all: List): List { 14 | val allNames = all.mapNotNull { it.name } 15 | val allFiles = allNames.map { name -> 16 | val className = "Fake${name.capitalizeAsciiOnly()}" 17 | val type = TypeSpec.classBuilder(className).build() 18 | FileSpec.builder("com.zsu", className) 19 | .addType(type) 20 | .build() 21 | } 22 | return allFiles 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /sample/src/main/resources/META-INF/plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | com.zsu.eden.idea.sample 3 | Eden-IDEA 4 | 5 | 1.5.2.1 6 | zsu 7 | 8 | 10 | Eden Lint IDEA Plugin.
11 | ]]>
12 | 13 | 14 | 16 | com.intellij.modules.platform 17 | com.intellij.modules.lang 18 | com.intellij.java 19 | org.jetbrains.kotlin 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 |
-------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = "Eden" 2 | 3 | include(':eden-ide') 4 | include 'sample' 5 | include 'eden-poet' 6 | 7 | --------------------------------------------------------------------------------