From 9a74339e5053c5570f1a70e23d9f7a6f3f518e97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Nenz=C3=A9n?= Date: Fri, 25 Mar 2022 12:16:08 +0100 Subject: [PATCH 1/3] Updates to work with 221.* and convert gradle scripts to kts --- .circleci/config.yml | 8 +- .idea/compiler.xml | 2 +- .idea/gradle.xml | 3 +- .idea/misc.xml | 7 +- CHANGELOG.md | 3 + README.md | 3 + build.gradle | 84 ------------------ build.gradle.kts | 108 +++++++++++++++++++++++ gradle.properties | 15 ++++ gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle => settings.gradle.kts | 4 +- 11 files changed, 144 insertions(+), 95 deletions(-) create mode 100644 CHANGELOG.md delete mode 100644 build.gradle create mode 100644 build.gradle.kts create mode 100644 gradle.properties rename settings.gradle => settings.gradle.kts (74%) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8961bc4..5cf0a73 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -10,13 +10,13 @@ jobs: - checkout - restore_cache: keys: - - v1-dependencies-{{ checksum "build.gradle" }} + - v1-dependencies-{{ checksum "build.gradle.kts" }} - v1-dependencies- - run: ./gradlew dependencies - save_cache: paths: - ~/.gradle - key: v1-dependencies-{{ checksum "build.gradle" }} + key: v1-dependencies-{{ checksum "build.gradle.kts" }} lint: docker: - image: circleci/openjdk:11-jdk @@ -25,7 +25,7 @@ jobs: - checkout - restore_cache: keys: - - v1-dependencies-{{ checksum "build.gradle" }} + - v1-dependencies-{{ checksum "build.gradle.kts" }} - v1-dependencies- - run: ./gradlew ktlint test: @@ -36,7 +36,7 @@ jobs: - checkout - restore_cache: keys: - - v1-dependencies-{{ checksum "build.gradle" }} + - v1-dependencies-{{ checksum "build.gradle.kts" }} - v1-dependencies- - run: ./gradlew test diff --git a/.idea/compiler.xml b/.idea/compiler.xml index dcb1ffc..368c8f1 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,7 +1,7 @@ - + diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 1166b6d..3e9cef1 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -9,13 +9,12 @@ - diff --git a/.idea/misc.xml b/.idea/misc.xml index a134cd6..d9dbfcd 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -4,7 +4,12 @@ - + + + + \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..faa22d1 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +## [1.0.11] +### Added +- Add support for 213* / 2021.3 version of IDEA #56 \ No newline at end of file diff --git a/README.md b/README.md index e4bf1e3..549d8f3 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,16 @@ [![jetBrains](https://img.shields.io/jetbrains/plugin/d/10942-kotlin-fill-class.svg)](https://plugins.jetbrains.com/plugin/10942-kotlin-fill-class) # kotlin-fill-class plugin + Intellij plugin that provide intention action for empty constructor or function to fill property with default value. Inspired by Go [fillstruct](https://github.com/davidrjenni/reftools/tree/master/cmd/fillstruct) + ## Usage This plugin add intention action for invalid constructor or function expression. ![kotlin fill class demo](https://user-images.githubusercontent.com/8841470/59397528-e61a4380-8dc7-11e9-9684-d82d225316fe.gif) + ### Configure settings You can configure the plugin settings by `Edit inspection profile setting` ![Edit inspection profile setting](https://user-images.githubusercontent.com/1121855/107631811-f4a9b400-6ca8-11eb-9ea8-1b0b56f0fda9.png) diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 5f819e9..0000000 --- a/build.gradle +++ /dev/null @@ -1,84 +0,0 @@ -buildscript { - ext.kotlinVersion = '1.4.10' - repositories { - mavenCentral() - } - dependencies { - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" - } -} - -plugins { - id 'java' - id 'org.jetbrains.intellij' version '0.6.5' - id 'org.jetbrains.kotlin.jvm' version '1.4.21' -} - -apply plugin: 'org.jetbrains.intellij' -apply plugin: 'kotlin' - -sourceCompatibility = JavaVersion.VERSION_11 -targetCompatibility = JavaVersion.VERSION_11 - -intellij { - version '2021.3' - plugins = ['Kotlin', 'java'] - pluginName 'kotlin-fill-class' - publishPlugin { - token System.getenv('TOKEN') - } - patchPluginXml { - sinceBuild '191.8026.42' - } -} - -repositories { - mavenCentral() - jcenter() -} - -group 'com.github.suusan2go.kotlin-fill-class' -version '1.0.11' - -sourceCompatibility = 11 - -repositories { - mavenCentral() -} - -configurations { - ktlint -} - -dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" - testImplementation group: 'junit', name: 'junit', version: '4.13.1' - - ktlint "com.github.shyiko:ktlint:0.31.0" -} - -compileKotlin { - kotlinOptions.jvmTarget = "11" -} -compileTestKotlin { - kotlinOptions.jvmTarget = "11" -} - -task ktlint(type: JavaExec, group: "verification") { - description = "Check Kotlin code style." - main = "com.github.shyiko.ktlint.Main" - classpath = configurations.ktlint - args "src/**/*.kt" - // to generate report in checkstyle format prepend following args: - // "--reporter=plain", "--reporter=checkstyle,output=${buildDir}/ktlint.xml" - // see https://github.com/shyiko/ktlint#usage for more -} -check.dependsOn ktlint - -task ktlintFormat(type: JavaExec, group: "formatting") { - description = "Fix Kotlin code style deviations." - main = "com.github.shyiko.ktlint.Main" - classpath = configurations.ktlint - args "-F", "src/**/*.kt" -} - diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..7bcbe56 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,108 @@ +import org.jetbrains.changelog.markdownToHTML +import org.jetbrains.kotlin.config.KotlinCompilerVersion +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import org.jlleitschuh.gradle.ktlint.KtlintExtension + +fun properties(key: String) = project.findProperty(key).toString() + +plugins { + id("java") + id("org.jetbrains.kotlin.jvm") version "1.6.10" + id("org.jetbrains.intellij") version "1.4.0" + id("org.jetbrains.changelog") version "1.3.1" + id("org.jlleitschuh.gradle.ktlint") version "10.2.1" +} + +group = properties("pluginGroup") +version = properties("pluginVersion") + +repositories { + mavenCentral() +} + +intellij { + pluginName.set(properties("pluginName")) + version.set(properties("platformVersion")) + type.set(properties("platformType")) + plugins.set(properties("platformPlugins").split(',').map(String::trim).filter(String::isNotEmpty)) +} + +changelog { + version.set(properties("pluginVersion")) + groups.set(emptyList()) +} + +configure { + filter { + include("src/**/*.kt") + } +} + +dependencies { + testImplementation(group = "junit", name = "junit", version = "4.13.1") +} + +tasks { + // Set the JVM compatibility versions + properties("javaVersion").let { + withType { + sourceCompatibility = it + targetCompatibility = it + } + withType { + kotlinOptions.jvmTarget = it + } + } + + wrapper { + gradleVersion = properties("gradleVersion") + } + + patchPluginXml { + version.set(properties("pluginVersion")) + sinceBuild.set(properties("pluginSinceBuild")) + untilBuild.set(properties("pluginUntilBuild")) + + // Extract the section from README.md and provide for the plugin's manifest + pluginDescription.set( + projectDir.resolve("README.md").readText().lines().run { + val start = "" + val end = "" + + if (!containsAll(listOf(start, end))) { + throw GradleException("Plugin description section not found in README.md:\n$start ... $end") + } + subList(indexOf(start) + 1, indexOf(end)) + }.joinToString("\n") + .run { markdownToHTML(this) } + .plus("" + + "\"fill-class\"" + + "

" + ) + ) + + // Get the latest available change notes from the changelog file + changeNotes.set(provider { + changelog.run { + getOrNull(properties("pluginVersion")) ?: getLatest() + }.toHTML() + }) + } + + // Configure UI tests plugin + // Read more: https://github.com/JetBrains/intellij-ui-test-robot + runIdeForUiTests { + systemProperty("robot-server.port", "8082") + systemProperty("ide.mac.message.dialogs.as.sheets", "false") + systemProperty("jb.privacy.policy.text", "") + systemProperty("jb.consents.confirmation.enabled", "false") + } + + publishPlugin { + dependsOn("patchChangelog") + token.set(System.getenv("TOKEN")) + channels.set(listOf(properties("pluginVersion").split('-').getOrElse(1) { "default" }.split('.').first())) + } +} + + diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..35401f5 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,15 @@ +pluginGroup = com.github.suusan2go.kotlin-fill-class +pluginName = kotlin-fill-class +pluginVersion = 1.0.12 +pluginSinceBuild = 191.8026.42 +pluginUntilBuild = 221.* +platformType = IC +platformVersion = 2021.1.3 +platformPlugins = com.intellij.java, org.jetbrains.kotlin +javaVersion = 11 +gradleVersion = 7.4 + +# Opt-out flag for bundling Kotlin standard library. +# See https://plugins.jetbrains.com/docs/intellij/kotlin.html#kotlin-standard-library for details. +# suppress inspection "UnusedProperty" +kotlin.stdlib.default.dependency = false \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 6623300..d7e66b5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle b/settings.gradle.kts similarity index 74% rename from settings.gradle rename to settings.gradle.kts index 8afdb2f..a34b08c 100644 --- a/settings.gradle +++ b/settings.gradle.kts @@ -1,5 +1,5 @@ /* - * This file was generated by the Gradle 'init' task. + * This file was generated by the Gradle "init" task. * * The settings file is used to specify which projects to include in your build. * @@ -7,5 +7,5 @@ * in the user guide at https://docs.gradle.org/4.8.1/userguide/multi_project_builds.html */ -rootProject.name = 'kotlin-fill-class' +rootProject.name = "kotlin-fill-class" From 50a4b934494513c36b4c05c8fe6cc79c6871c742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Nenz=C3=A9n?= Date: Mon, 4 Apr 2022 21:00:46 +0200 Subject: [PATCH 2/3] Fixes ktlint check for CI --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5cf0a73..ec40792 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -27,7 +27,7 @@ jobs: keys: - v1-dependencies-{{ checksum "build.gradle.kts" }} - v1-dependencies- - - run: ./gradlew ktlint + - run: ./gradlew ktlintCheck test: docker: - image: circleci/openjdk:11-jdk From 8000ff72c145f3529590e49c50908459a4b0aae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Nenz=C3=A9n?= Date: Mon, 4 Apr 2022 21:10:09 +0200 Subject: [PATCH 3/3] ktlintFormat --- build.gradle.kts | 18 +-- settings.gradle.kts | 1 - .../inspections/FillClassInspectionTest.kt | 112 ++++++++++++------ 3 files changed, 86 insertions(+), 45 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 7bcbe56..a019b2e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,4 @@ import org.jetbrains.changelog.markdownToHTML -import org.jetbrains.kotlin.config.KotlinCompilerVersion import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jlleitschuh.gradle.ktlint.KtlintExtension @@ -75,18 +74,21 @@ tasks { subList(indexOf(start) + 1, indexOf(end)) }.joinToString("\n") .run { markdownToHTML(this) } - .plus("" + + .plus( + "" + "\"fill-class\"" + "

" ) ) // Get the latest available change notes from the changelog file - changeNotes.set(provider { - changelog.run { - getOrNull(properties("pluginVersion")) ?: getLatest() - }.toHTML() - }) + changeNotes.set( + provider { + changelog.run { + getOrNull(properties("pluginVersion")) ?: getLatest() + }.toHTML() + } + ) } // Configure UI tests plugin @@ -104,5 +106,3 @@ tasks { channels.set(listOf(properties("pluginVersion").split('-').getOrElse(1) { "default" }.split('.').first())) } } - - diff --git a/settings.gradle.kts b/settings.gradle.kts index a34b08c..409d6e4 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -8,4 +8,3 @@ */ rootProject.name = "kotlin-fill-class" - diff --git a/src/test/kotlin/com/github/suusan2go/kotlinfillclass/inspections/FillClassInspectionTest.kt b/src/test/kotlin/com/github/suusan2go/kotlinfillclass/inspections/FillClassInspectionTest.kt index 32cca27..b9cdbc8 100644 --- a/src/test/kotlin/com/github/suusan2go/kotlinfillclass/inspections/FillClassInspectionTest.kt +++ b/src/test/kotlin/com/github/suusan2go/kotlinfillclass/inspections/FillClassInspectionTest.kt @@ -8,55 +8,67 @@ import org.jetbrains.kotlin.idea.KotlinFileType class FillClassInspectionTest : BasePlatformTestCase() { fun `test fill class constructor`() { - doAvailableTest(""" + doAvailableTest( + """ class User(val name: String, val age: Int) fun test() { User() } - """, """ + """, + """ class User(val name: String, val age: Int) fun test() { User(name = "", age = 0) } - """) + """ + ) } fun `test can't fill class constructor`() { - doUnavailableTest(""" + doUnavailableTest( + """ class User(val name: String, val age: Int) fun test() { User("", 0) } - """) + """ + ) } fun `test fill function`() { - doAvailableTest(""" + doAvailableTest( + """ class User(val name: String, val age: Int) fun foo(s: String, t: Int, u: User) {} fun test() { foo() } - """, """ + """, + """ class User(val name: String, val age: Int) fun foo(s: String, t: Int, u: User) {} fun test() { foo(s = "", t = 0, u = User(name = "", age = 0)) } - """, "Fill function") + """, + "Fill function" + ) } fun `test can't fill function`() { - doUnavailableTest(""" + doUnavailableTest( + """ fun foo(s: String, t: Int) {} fun test() { foo("", 0) } - """) + """ + ) } fun `test fill for non primitive types`() { - doAvailableTest(""" + doAvailableTest( + """ class A(a1: String, a2: Int) class B(b1: Int, b2: String, a: A) class C @@ -64,7 +76,8 @@ class FillClassInspectionTest : BasePlatformTestCase() { fun test() { D() } - """, """ + """, + """ class A(a1: String, a2: Int) class B(b1: Int, b2: String, a: A) class C @@ -72,11 +85,13 @@ class FillClassInspectionTest : BasePlatformTestCase() { fun test() { D(a = A(a1 = "", a2 = 0), b = B(b1 = 0, b2 = "", a = A(a1 = "", a2 = 0)), c = C(), r =) } - """) + """ + ) } fun `test don't add default value for enum,abstract,sealed`() { - doAvailableTest(""" + doAvailableTest( + """ enum class A(val a: String) { Foo("foo"), Bar("bar"), Baz("baz"); } @@ -86,7 +101,8 @@ class FillClassInspectionTest : BasePlatformTestCase() { fun test() { Test() } - """, """ + """, + """ enum class A(val a: String) { Foo("foo"), Bar("bar"), Baz("baz"); } @@ -96,7 +112,8 @@ class FillClassInspectionTest : BasePlatformTestCase() { fun test() { Test(a =, b =, c =) } - """) + """ + ) } fun `test add import directives`() { @@ -106,16 +123,20 @@ class FillClassInspectionTest : BasePlatformTestCase() { class A class B(a: A) """ - doAvailableTest(""" + doAvailableTest( + """ import com.example.B val b = B() - """, """ + """, + """ import com.example.A import com.example.B val b = B(a = A()) - """, dependencies = listOf(dependency)) + """, + dependencies = listOf(dependency) + ) } fun `test call java constructor`() { @@ -125,11 +146,14 @@ class FillClassInspectionTest : BasePlatformTestCase() { } } """ - doUnavailableTest(""" + doUnavailableTest( + """ fun test() { Java() } - """, javaDependencies = listOf(javaDependency)) + """, + javaDependencies = listOf(javaDependency) + ) } fun `test call java method`() { @@ -142,49 +166,63 @@ class FillClassInspectionTest : BasePlatformTestCase() { } } """ - doUnavailableTest(""" + doUnavailableTest( + """ fun test() { Java("").foo() } - """, javaDependencies = listOf(javaDependency)) + """, + javaDependencies = listOf(javaDependency) + ) } fun `test fill super type call entry`() { - doAvailableTest(""" + doAvailableTest( + """ open class C(p1: Int, p2: Int) class D : C() - """, """ + """, + """ open class C(p1: Int, p2: Int) class D : C(p1 = 0, p2 = 0) - """) + """ + ) } fun `test fill class constructor without default values`() { - doAvailableTest(""" + doAvailableTest( + """ class User(val name: String, val age: Int) fun test() { User() } - """, """ + """, + """ class User(val name: String, val age: Int) fun test() { User(name =, age =) } - """, withoutDefaultValues = true) + """, + withoutDefaultValues = true + ) } fun `test do not fill default arguments`() { - doAvailableTest(""" + doAvailableTest( + """ class User(val name: String, val age: Int = 0) fun test() { User() } - """, """ + """, + """ class User(val name: String, val age: Int = 0) fun test() { User(name = "") } - """, withoutDefaultArguments = true) + """, + withoutDefaultArguments = true + ) } fun `test fill lambda arguments`() { @@ -196,20 +234,24 @@ class FillClassInspectionTest : BasePlatformTestCase() { class B(f1: () -> Unit, f2: (Int) -> String, f3: (Int, String?, A) -> String) """.trimIndent() - doAvailableTest(""" + doAvailableTest( + """ import foo.B fun test() { B() } - """, """ + """, + """ import foo.A import foo.B fun test() { B(f1 = {}, f2 = {}, f3 = { i: Int, s: String?, a: A -> }) } - """, withoutDefaultArguments = true, dependencies = listOf(dependency)) + """, + withoutDefaultArguments = true, dependencies = listOf(dependency) + ) } private fun doAvailableTest(