[IDE] Update SuperClassNotInitialized to relaxed restrictions on sealed classes
This commit is contained in:
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
|||||||
import org.jetbrains.kotlin.renderer.render
|
import org.jetbrains.kotlin.renderer.render
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||||
|
import org.jetbrains.kotlin.resolve.descriptorUtil.classId
|
||||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.TypeConstructorSubstitution
|
import org.jetbrains.kotlin.types.TypeConstructorSubstitution
|
||||||
@@ -52,10 +53,10 @@ object SuperClassNotInitialized : KotlinIntentionActionsFactory() {
|
|||||||
|
|
||||||
val superClass = (type.constructor.declarationDescriptor as? ClassDescriptor) ?: return emptyList()
|
val superClass = (type.constructor.declarationDescriptor as? ClassDescriptor) ?: return emptyList()
|
||||||
val classDescriptor = classOrObjectDeclaration.resolveToDescriptorIfAny(BodyResolveMode.FULL) ?: return emptyList()
|
val classDescriptor = classOrObjectDeclaration.resolveToDescriptorIfAny(BodyResolveMode.FULL) ?: return emptyList()
|
||||||
val containingPackage = superClass.containingDeclaration as? PackageFragmentDescriptor
|
val containingPackage = superClass.classId?.packageFqName
|
||||||
val inSameFile = containingPackage == classDescriptor.containingDeclaration
|
val inSamePackage = containingPackage != null && containingPackage == classDescriptor.classId?.packageFqName
|
||||||
val constructors = superClass.constructors.filter {
|
val constructors = superClass.constructors.filter {
|
||||||
it.isVisible(classDescriptor) || (superClass.modality == Modality.SEALED && inSameFile)
|
it.isVisible(classDescriptor) && (superClass.modality != Modality.SEALED || inSamePackage && classDescriptor.visibility != DescriptorVisibilities.LOCAL)
|
||||||
}
|
}
|
||||||
if (constructors.isEmpty() && (!superClass.isExpect || superClass.kind != ClassKind.CLASS)) {
|
if (constructors.isEmpty() && (!superClass.isExpect || superClass.kind != ClassKind.CLASS)) {
|
||||||
return emptyList() // no accessible constructor
|
return emptyList() // no accessible constructor
|
||||||
|
|||||||
+1
-1
@@ -6,4 +6,4 @@ sealed class A
|
|||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
class B : A<caret>
|
class B : A<caret>
|
||||||
}
|
}
|
||||||
|
|||||||
-10
@@ -1,10 +0,0 @@
|
|||||||
// "Change to constructor invocation" "false"
|
|
||||||
// ACTION: Introduce import alias
|
|
||||||
// ERROR: This type has a constructor, and thus must be initialized here
|
|
||||||
// ERROR: This type is sealed, so it can be inherited by only its own nested classes or objects
|
|
||||||
|
|
||||||
class My {
|
|
||||||
sealed class A
|
|
||||||
|
|
||||||
class B : A<caret>
|
|
||||||
}
|
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
// "Change to constructor invocation" "true"
|
||||||
|
// ACTION: Introduce import alias
|
||||||
|
|
||||||
|
class My {
|
||||||
|
sealed class A
|
||||||
|
|
||||||
|
class B : A<caret>
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
// "Change to constructor invocation" "true"
|
||||||
|
// ACTION: Introduce import alias
|
||||||
|
|
||||||
|
class My {
|
||||||
|
sealed class A
|
||||||
|
|
||||||
|
class B : A<caret>()
|
||||||
|
}
|
||||||
@@ -12509,11 +12509,6 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
runTest("idea/testData/quickfix/supertypeInitialization/addParenthesisForInvalidSealedClass.kt");
|
runTest("idea/testData/quickfix/supertypeInitialization/addParenthesisForInvalidSealedClass.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("addParenthesisForInvalidSealedClass2.kt")
|
|
||||||
public void testAddParenthesisForInvalidSealedClass2() throws Exception {
|
|
||||||
runTest("idea/testData/quickfix/supertypeInitialization/addParenthesisForInvalidSealedClass2.kt");
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("addParenthesisForLocalClass.kt")
|
@TestMetadata("addParenthesisForLocalClass.kt")
|
||||||
public void testAddParenthesisForLocalClass() throws Exception {
|
public void testAddParenthesisForLocalClass() throws Exception {
|
||||||
runTest("idea/testData/quickfix/supertypeInitialization/addParenthesisForLocalClass.kt");
|
runTest("idea/testData/quickfix/supertypeInitialization/addParenthesisForLocalClass.kt");
|
||||||
@@ -12529,6 +12524,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
runTest("idea/testData/quickfix/supertypeInitialization/addParenthesisForSealedClass.kt");
|
runTest("idea/testData/quickfix/supertypeInitialization/addParenthesisForSealedClass.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("addParenthesisForSealedClass2.kt")
|
||||||
|
public void testAddParenthesisForSealedClass2() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/supertypeInitialization/addParenthesisForSealedClass2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
public void testAllFilesPresentInSupertypeInitialization() throws Exception {
|
public void testAllFilesPresentInSupertypeInitialization() throws Exception {
|
||||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/quickfix/supertypeInitialization"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), null, true);
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/quickfix/supertypeInitialization"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), null, true);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user