Fix "Make supertype open" quickfix in case of using secondary ctor
#KT-7002 Fixed
This commit is contained in:
+4
-4
@@ -29,10 +29,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic;
|
||||
import org.jetbrains.kotlin.idea.JetBundle;
|
||||
import org.jetbrains.kotlin.lexer.JetTokens;
|
||||
import org.jetbrains.kotlin.psi.JetClass;
|
||||
import org.jetbrains.kotlin.psi.JetFile;
|
||||
import org.jetbrains.kotlin.psi.JetSimpleNameExpression;
|
||||
import org.jetbrains.kotlin.psi.JetTypeReference;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
|
||||
public class AddOpenModifierToClassDeclarationFix extends JetIntentionAction<JetTypeReference> {
|
||||
private JetClass classDeclaration;
|
||||
@@ -55,6 +52,9 @@ public class AddOpenModifierToClassDeclarationFix extends JetIntentionAction<Jet
|
||||
PsiReference reference = referenceExpression.getReference();
|
||||
if (reference != null) {
|
||||
PsiElement target = reference.resolve();
|
||||
if (target instanceof JetSecondaryConstructor) {
|
||||
target = ((JetSecondaryConstructor) target).getClassOrObject();
|
||||
}
|
||||
if (target instanceof JetClass && QuickFixUtil.canModifyElement(target)) {
|
||||
classDeclaration = (JetClass) target;
|
||||
return !(classDeclaration.isEnum() || classDeclaration.isTrait());
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Make B open" "true"
|
||||
open class B {
|
||||
constructor() {
|
||||
}
|
||||
}
|
||||
|
||||
class A : <caret>B()
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Make B open" "true"
|
||||
open class B {
|
||||
constructor() {
|
||||
}
|
||||
}
|
||||
|
||||
class A : <caret>B {
|
||||
constructor() {}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Make B open" "true"
|
||||
class B {
|
||||
constructor() {
|
||||
}
|
||||
}
|
||||
|
||||
class A : <caret>B()
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Make B open" "true"
|
||||
class B {
|
||||
constructor() {
|
||||
}
|
||||
}
|
||||
|
||||
class A : <caret>B {
|
||||
constructor() {}
|
||||
}
|
||||
@@ -3222,6 +3222,18 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("beforeSecondaryCtrDelegationInHeader.kt")
|
||||
public void testSecondaryCtrDelegationInHeader() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/modifiers/addOpenToClassDeclaration/beforeSecondaryCtrDelegationInHeader.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("beforeSecondaryCtrDelegationInSecondary.kt")
|
||||
public void testSecondaryCtrDelegationInSecondary() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/modifiers/addOpenToClassDeclaration/beforeSecondaryCtrDelegationInSecondary.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/quickfix/modifiers/addOpenToClassDeclaration/finalJavaClass")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@InnerTestClasses({
|
||||
|
||||
Reference in New Issue
Block a user