提交 8a73a1da 编写于 作者: K Kirill Rakhman 提交者: Mikhail Glukhikh

Implement Intention + Inspection to remove empty secondary constructor body #KT-14326 Fixed

上级 495dd364
<html>
<body>
This intention removes empty bodies of secondary constructors
</body>
</html>
\ No newline at end of file
......@@ -1420,6 +1420,11 @@
<category>Kotlin</category>
</intentionAction>
<intentionAction>
<className>org.jetbrains.kotlin.idea.intentions.RemoveEmptySecondaryConstructorBodyIntention</className>
<category>Kotlin</category>
</intentionAction>
<localInspection implementationClass="org.jetbrains.kotlin.idea.intentions.ObjectLiteralToLambdaInspection"
displayName="Object literal can be converted to lambda"
groupName="Kotlin"
......@@ -1902,6 +1907,14 @@
language="kotlin"
/>
<localInspection implementationClass="org.jetbrains.kotlin.idea.intentions.RemoveEmptySecondaryConstructorBodyInspection"
displayName="Remove empty constructor body"
groupName="Kotlin"
enabledByDefault="true"
level="WEAK WARNING"
language="kotlin"
/>
<referenceImporter implementation="org.jetbrains.kotlin.idea.quickfix.KotlinReferenceImporter"/>
<fileType.fileViewProviderFactory filetype="KJSM" implementationClass="com.intellij.psi.ClassFileViewProviderFactory"/>
......
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.idea.intentions
import com.intellij.codeInspection.CleanupLocalInspectionTool
import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
import org.jetbrains.kotlin.psi.KtBlockExpression
import org.jetbrains.kotlin.psi.KtSecondaryConstructor
class RemoveEmptySecondaryConstructorBodyInspection : IntentionBasedInspection<KtBlockExpression>(RemoveEmptySecondaryConstructorBodyIntention::class), CleanupLocalInspectionTool {
override val problemHighlightType: ProblemHighlightType
get() = ProblemHighlightType.LIKE_UNUSED_SYMBOL
}
class RemoveEmptySecondaryConstructorBodyIntention() : SelfTargetingOffsetIndependentIntention<KtBlockExpression>(KtBlockExpression::class.java, "Remove empty constructor body") {
override fun applyTo(element: KtBlockExpression, editor: Editor?) = element.delete()
override fun isApplicableTo(element: KtBlockExpression): Boolean {
if(element.parent !is KtSecondaryConstructor) return false
if(element.statements.isNotEmpty()) return false
return element.text.replace("{", "").replace("}", "").isBlank()
}
}
\ No newline at end of file
org.jetbrains.kotlin.idea.intentions.RemoveEmptySecondaryConstructorBodyIntention
\ No newline at end of file
// IS_APPLICABLE: false
class Foo() {
constructor(a: Int) : this() <caret>{
//comment
}
}
\ No newline at end of file
class Foo() {
constructor(a: Int) : this() <caret>{
}
}
\ No newline at end of file
class Foo() {
constructor(a: Int) : this()<caret>
}
\ No newline at end of file
......@@ -10843,6 +10843,27 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
}
}
@TestMetadata("idea/testData/intentions/removeEmptySecondaryConstructorBody")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class RemoveEmptySecondaryConstructorBody extends AbstractIntentionTest {
public void testAllFilesPresentInRemoveEmptySecondaryConstructorBody() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/removeEmptySecondaryConstructorBody"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), true);
}
@TestMetadata("comment.kt")
public void testComment() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeEmptySecondaryConstructorBody/comment.kt");
doTest(fileName);
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeEmptySecondaryConstructorBody/simple.kt");
doTest(fileName);
}
}
@TestMetadata("idea/testData/intentions/removeExplicitLambdaParameterTypes")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册