Generate Secondary Constructor: Forbid inside of class with explicit primary constructor

This commit is contained in:
Alexey Sedunov
2015-10-23 14:28:16 +03:00
parent 22393d4cd2
commit 89132b3f66
4 changed files with 14 additions and 31 deletions
@@ -60,7 +60,11 @@ class KotlinGenerateSecondaryConstructorAction : KotlinGenerateMemberActionBase<
)
override fun isValidForClass(targetClass: KtClassOrObject): Boolean {
return targetClass is KtClass && targetClass !is KtEnumEntry && !targetClass.isInterface() && !targetClass.isAnnotation()
return targetClass is KtClass
&& targetClass !is KtEnumEntry
&& !targetClass.isInterface()
&& !targetClass.isAnnotation()
&& !targetClass.hasExplicitPrimaryConstructor()
}
private fun shouldPreselect(element: PsiElement) = element is KtProperty && !element.isVar
@@ -1,10 +1,7 @@
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateSecondaryConstructorAction
open class Base(n: Int) {
constructor(a: Int, b: Int): this(a + b)
}
class Foo(x: Int) : Base(x) {<caret>
val x = 1
// NOT_APPLICABLE
class Foo(x: Int) {<caret>
val x: Int
fun foo() {
@@ -1,18 +0,0 @@
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateSecondaryConstructorAction
open class Base(n: Int) {
constructor(a: Int, b: Int): this(a + b)
}
class Foo(x: Int) : Base(x) {
val x = 1
<caret>constructor(a: Int, b: Int) : super(a, b)
fun foo() {
}
fun bar() {
}
}
@@ -59,6 +59,12 @@ public class CodeInsightActionTestGenerated extends AbstractCodeInsightActionTes
doTest(fileName);
}
@TestMetadata("primaryExists.kt")
public void testPrimaryExists() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/generate/secondaryConstructors/primaryExists.kt");
doTest(fileName);
}
@TestMetadata("properties.kt")
public void testProperties() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/generate/secondaryConstructors/properties.kt");
@@ -83,12 +89,6 @@ public class CodeInsightActionTestGenerated extends AbstractCodeInsightActionTes
doTest(fileName);
}
@TestMetadata("supersPrimaryExists.kt")
public void testSupersPrimaryExists() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/generate/secondaryConstructors/supersPrimaryExists.kt");
doTest(fileName);
}
@TestMetadata("supersSomeExist.kt")
public void testSupersSomeExist() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/generate/secondaryConstructors/supersSomeExist.kt");