diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt index 66c2a65fabe..4f2ef7a3b63 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt @@ -542,7 +542,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { psiFactory.createEnumEntry("$safeName${if (hasParameters) "()" else " "}") } else -> { - val openMod = if (open) "open " else "" + val openMod = if (open && kind != ClassKind.INTERFACE) "open " else "" val innerMod = if (inner || isInsideInnerOrLocalClass()) "inner " else "" val typeParamList = when (kind) { ClassKind.PLAIN_CLASS, ClassKind.INTERFACE -> "<>" diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/CreateClassFromTypeReferenceActionFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/CreateClassFromTypeReferenceActionFactory.kt index 4d185b5ab73..1edbf7fb644 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/CreateClassFromTypeReferenceActionFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/CreateClassFromTypeReferenceActionFactory.kt @@ -9,8 +9,10 @@ import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.idea.caches.resolve.analyzeAndGetResult import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.TypeInfo +import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypeAndBranch +import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.types.KotlinType @@ -28,16 +30,17 @@ object CreateClassFromTypeReferenceActionFactory : CreateClassFromUsageFactory { extendsBound } != null || typeReference?.getParentOfTypeAndBranch { boundTypeReference } != null - return when { - interfaceExpected -> Collections.singletonList(ClassKind.INTERFACE) + return when (typeRefParent) { + is KtSuperTypeEntry -> listOfNotNull( + ClassKind.INTERFACE, + if (typeRefParent.classExpected()) ClassKind.PLAIN_CLASS else null + ) else -> ClassKind.values().filter { val noTypeArguments = element.typeArgumentsAsTypes.isEmpty() when (it) { @@ -51,6 +54,13 @@ object CreateClassFromTypeReferenceActionFactory : CreateClassFromUsageFactory() ?: return false + return !containingClass.hasModifier(KtTokens.ANNOTATION_KEYWORD) + && !containingClass.hasModifier(KtTokens.ENUM_KEYWORD) + && !containingClass.hasModifier(KtTokens.INLINE_KEYWORD) + } + private fun getExpectedUpperBound(element: KtUserType, context: BindingContext): KotlinType? { val projection = (element.parent as? KtTypeReference)?.parent as? KtTypeProjection ?: return null val argumentList = projection.parent as? KtTypeArgumentList ?: return null @@ -64,7 +74,8 @@ object CreateClassFromTypeReferenceActionFactory : CreateClassFromUsageFactoryA { - -} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperClassFromSuperTypeEntry.kt b/idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperClassFromSuperTypeEntry.kt new file mode 100644 index 00000000000..8f80cfaaa18 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperClassFromSuperTypeEntry.kt @@ -0,0 +1,4 @@ +// "Create class 'Unknown'" "true" +class A : Unknown { + constructor() +} diff --git a/idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperClassFromSuperTypeEntry.kt.after b/idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperClassFromSuperTypeEntry.kt.after new file mode 100644 index 00000000000..3dd501cbdcc --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperClassFromSuperTypeEntry.kt.after @@ -0,0 +1,8 @@ +// "Create class 'Unknown'" "true" +class A : Unknown { + constructor() +} + +open class Unknown { + +} diff --git a/idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperClassFromSuperTypeEntry2.kt b/idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperClassFromSuperTypeEntry2.kt new file mode 100644 index 00000000000..9d86e7e6ab5 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperClassFromSuperTypeEntry2.kt @@ -0,0 +1,6 @@ +// "Create class 'Unknown'" "true" +// ACTION: Create interface 'Unknown' +// ACTION: Create type parameter 'Unknown' in class 'A' +// DISABLE-ERRORS +class A : Unknown { +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperClassFromSuperTypeEntry2.kt.after b/idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperClassFromSuperTypeEntry2.kt.after new file mode 100644 index 00000000000..22ad44a5bc1 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperClassFromSuperTypeEntry2.kt.after @@ -0,0 +1,10 @@ +// "Create class 'Unknown'" "true" +// ACTION: Create interface 'Unknown' +// ACTION: Create type parameter 'Unknown' in class 'A' +// DISABLE-ERRORS +class A : Unknown { +} + +open class Unknown { + +} diff --git a/idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperClassFromSuperTypeEntry3.kt b/idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperClassFromSuperTypeEntry3.kt new file mode 100644 index 00000000000..f33659ec84e --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperClassFromSuperTypeEntry3.kt @@ -0,0 +1,7 @@ +// "Create class 'Unknown'" "true" +// ACTION: Create interface 'Unknown' +// ACTION: Create type parameter 'Unknown' in class 'A' +// DISABLE-ERRORS +class A() : Unknown { + constructor(i: Int) +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperClassFromSuperTypeEntry3.kt.after b/idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperClassFromSuperTypeEntry3.kt.after new file mode 100644 index 00000000000..3d34b4c2d98 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperClassFromSuperTypeEntry3.kt.after @@ -0,0 +1,11 @@ +// "Create class 'Unknown'" "true" +// ACTION: Create interface 'Unknown' +// ACTION: Create type parameter 'Unknown' in class 'A' +// DISABLE-ERRORS +class A() : Unknown { + constructor(i: Int) +} + +open class Unknown { + +} diff --git a/idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperClassFromSuperTypeEntryForAnnotation.kt b/idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperClassFromSuperTypeEntryForAnnotation.kt new file mode 100644 index 00000000000..08e44ae17b5 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperClassFromSuperTypeEntryForAnnotation.kt @@ -0,0 +1,5 @@ +// "Create class 'Unknown'" "false" +// ACTION: Create interface 'Unknown' +// ACTION: Create type parameter 'Unknown' in class 'A' +// DISABLE-ERRORS +annotation class A : Unknown \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperClassFromSuperTypeEntryForEnum.kt b/idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperClassFromSuperTypeEntryForEnum.kt new file mode 100644 index 00000000000..1e29e4e4063 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperClassFromSuperTypeEntryForEnum.kt @@ -0,0 +1,5 @@ +// "Create class 'Unknown'" "false" +// ACTION: Create interface 'Unknown' +// ACTION: Create type parameter 'Unknown' in class 'A' +// DISABLE-ERRORS +enum class A : Unknown \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperClassFromSuperTypeEntryForInline.kt b/idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperClassFromSuperTypeEntryForInline.kt new file mode 100644 index 00000000000..9476e72c6cd --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperClassFromSuperTypeEntryForInline.kt @@ -0,0 +1,5 @@ +// "Create class 'Unknown'" "false" +// ACTION: Create interface 'Unknown' +// ACTION: Create type parameter 'Unknown' in class 'A' +// DISABLE-ERRORS +inline class A(val a: String) : Unknown \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java index 5be93f1062f..65f1907fa2b 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -3277,9 +3277,34 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), null, true); } - @TestMetadata("classDelegatorToSuperclass.kt") - public void testClassDelegatorToSuperclass() throws Exception { - runTest("idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/classDelegatorToSuperclass.kt"); + @TestMetadata("createSuperClassFromSuperTypeEntry.kt") + public void testCreateSuperClassFromSuperTypeEntry() throws Exception { + runTest("idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperClassFromSuperTypeEntry.kt"); + } + + @TestMetadata("createSuperClassFromSuperTypeEntry2.kt") + public void testCreateSuperClassFromSuperTypeEntry2() throws Exception { + runTest("idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperClassFromSuperTypeEntry2.kt"); + } + + @TestMetadata("createSuperClassFromSuperTypeEntry3.kt") + public void testCreateSuperClassFromSuperTypeEntry3() throws Exception { + runTest("idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperClassFromSuperTypeEntry3.kt"); + } + + @TestMetadata("createSuperClassFromSuperTypeEntryForAnnotation.kt") + public void testCreateSuperClassFromSuperTypeEntryForAnnotation() throws Exception { + runTest("idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperClassFromSuperTypeEntryForAnnotation.kt"); + } + + @TestMetadata("createSuperClassFromSuperTypeEntryForEnum.kt") + public void testCreateSuperClassFromSuperTypeEntryForEnum() throws Exception { + runTest("idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperClassFromSuperTypeEntryForEnum.kt"); + } + + @TestMetadata("createSuperClassFromSuperTypeEntryForInline.kt") + public void testCreateSuperClassFromSuperTypeEntryForInline() throws Exception { + runTest("idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperClassFromSuperTypeEntryForInline.kt"); } @TestMetadata("createSuperclassInsideSubclass.kt")