Generate Secondary Constructor: Forbid inside of class with explicit primary constructor
This commit is contained in:
+5
-1
@@ -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
|
||||
|
||||
+3
-6
@@ -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() {
|
||||
|
||||
-18
@@ -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() {
|
||||
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user