Added quickfix for NULLABLE_SUPERTYPE
This commit is contained in:
committed by
Andrey Breslav
parent
3293e08d97
commit
42b7b7e221
@@ -24,6 +24,7 @@ remove.right.part.of.binary.expression=Remove right part of a binary expression
|
|||||||
remove.cast=Remove cast
|
remove.cast=Remove cast
|
||||||
remove.elvis.operator=Remove elvis operator
|
remove.elvis.operator=Remove elvis operator
|
||||||
remove.redundant.nullable=Remove redundant '?'
|
remove.redundant.nullable=Remove redundant '?'
|
||||||
|
remove.supertype.nullable=Remove '?'
|
||||||
remove.nullable.family=Remove '?'
|
remove.nullable.family=Remove '?'
|
||||||
remove.useless.import=Remove useless import for ''{0}''
|
remove.useless.import=Remove useless import for ''{0}''
|
||||||
remove.useless.import.family=Remove useless import
|
remove.useless.import.family=Remove useless import
|
||||||
|
|||||||
@@ -134,7 +134,8 @@ public class QuickFixes {
|
|||||||
|
|
||||||
factories.put(UNRESOLVED_REFERENCE, MigrateSureInProjectFix.createFactory());
|
factories.put(UNRESOLVED_REFERENCE, MigrateSureInProjectFix.createFactory());
|
||||||
|
|
||||||
factories.put(REDUNDANT_NULLABLE, RemoveRedundantNullableFix.createFactory());
|
factories.put(REDUNDANT_NULLABLE, RemoveNullableFix.createFactory(false));
|
||||||
|
factories.put(NULLABLE_SUPERTYPE, RemoveNullableFix.createFactory(true));
|
||||||
|
|
||||||
ImplementMethodsHandler implementMethodsHandler = new ImplementMethodsHandler();
|
ImplementMethodsHandler implementMethodsHandler = new ImplementMethodsHandler();
|
||||||
actions.put(ABSTRACT_MEMBER_NOT_IMPLEMENTED, implementMethodsHandler);
|
actions.put(ABSTRACT_MEMBER_NOT_IMPLEMENTED, implementMethodsHandler);
|
||||||
|
|||||||
+13
-5
@@ -26,15 +26,23 @@ import org.jetbrains.jet.lang.psi.JetNullableType;
|
|||||||
import org.jetbrains.jet.lang.psi.JetTypeElement;
|
import org.jetbrains.jet.lang.psi.JetTypeElement;
|
||||||
import org.jetbrains.jet.plugin.JetBundle;
|
import org.jetbrains.jet.plugin.JetBundle;
|
||||||
|
|
||||||
public class RemoveRedundantNullableFix extends JetIntentionAction<JetNullableType> {
|
public class RemoveNullableFix extends JetIntentionAction<JetNullableType> {
|
||||||
public RemoveRedundantNullableFix(@NotNull JetNullableType element) {
|
boolean isInSuperType;
|
||||||
|
|
||||||
|
public RemoveNullableFix(@NotNull JetNullableType element, boolean isInSuperTypeArg) {
|
||||||
super(element);
|
super(element);
|
||||||
|
isInSuperType = isInSuperTypeArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String getText() {
|
public String getText() {
|
||||||
return JetBundle.message("remove.redundant.nullable");
|
if (isInSuperType) {
|
||||||
|
return JetBundle.message("remove.supertype.nullable");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return JetBundle.message("remove.redundant.nullable");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -49,13 +57,13 @@ public class RemoveRedundantNullableFix extends JetIntentionAction<JetNullableTy
|
|||||||
super.element.replace(type);
|
super.element.replace(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JetIntentionActionFactory createFactory() {
|
public static JetIntentionActionFactory createFactory(final boolean isInSupertypeArg) {
|
||||||
return new JetIntentionActionFactory() {
|
return new JetIntentionActionFactory() {
|
||||||
@Override
|
@Override
|
||||||
public JetIntentionAction<JetNullableType> createAction(Diagnostic diagnostic) {
|
public JetIntentionAction<JetNullableType> createAction(Diagnostic diagnostic) {
|
||||||
JetNullableType type = QuickFixUtil.getParentElementOfType(diagnostic, JetNullableType.class);
|
JetNullableType type = QuickFixUtil.getParentElementOfType(diagnostic, JetNullableType.class);
|
||||||
if (type == null) return null;
|
if (type == null) return null;
|
||||||
return new RemoveRedundantNullableFix(type);
|
return new RemoveNullableFix(type, isInSupertypeArg);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
// "Remove '?'" "true"
|
||||||
|
open class Foo() {}
|
||||||
|
class Bar() : Foo<caret>() {}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
// "Remove '?'" "true"
|
||||||
|
trait Foo {}
|
||||||
|
class Bar : Foo<caret> {}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
// "Remove '?'" "true"
|
||||||
|
open class Foo() {}
|
||||||
|
class Bar() : Foo?<caret>() {}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
// "Remove '?'" "true"
|
||||||
|
trait Foo {}
|
||||||
|
class Bar : Foo?<caret> {}
|
||||||
@@ -541,6 +541,16 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
doTest("idea/testData/quickfix/nullables/beforeRemoveRedundantNullable.kt");
|
doTest("idea/testData/quickfix/nullables/beforeRemoveRedundantNullable.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeRemoveSupertypeNullable1.kt")
|
||||||
|
public void testRemoveSupertypeNullable1() throws Exception {
|
||||||
|
doTest("idea/testData/quickfix/nullables/beforeRemoveSupertypeNullable1.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeRemoveSupertypeNullable2.kt")
|
||||||
|
public void testRemoveSupertypeNullable2() throws Exception {
|
||||||
|
doTest("idea/testData/quickfix/nullables/beforeRemoveSupertypeNullable2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("idea/testData/quickfix/override")
|
@TestMetadata("idea/testData/quickfix/override")
|
||||||
|
|||||||
Reference in New Issue
Block a user