remove useless nullable qfix and test done

This commit is contained in:
Kevin F. Chen
2013-02-14 12:50:03 -05:00
committed by Evgeny Gerashchenko
parent 5d33f779be
commit 5db0f2132c
6 changed files with 36 additions and 14 deletions
@@ -28,6 +28,7 @@ remove.cast=Remove cast
remove.elvis.operator=Remove elvis operator
remove.redundant.nullable=Remove redundant '?'
remove.supertype.nullable=Remove '?'
remove.useless.nullable=Remove useless '?'
remove.nullable.family=Remove '?'
remove.spread.sign=Remove '*'
remove.useless.import=Remove useless import for ''{0}''
@@ -21,6 +21,7 @@ import com.google.common.collect.Multimap;
import com.intellij.codeInsight.intention.IntentionAction;
import org.jetbrains.jet.lang.diagnostics.AbstractDiagnosticFactory;
import org.jetbrains.jet.lang.psi.JetClass;
import org.jetbrains.jet.plugin.JetBundle;
import org.jetbrains.jet.plugin.codeInsight.ImplementMethodsHandler;
import java.util.Collection;
@@ -143,8 +144,10 @@ public class QuickFixes {
factories.put(UNRESOLVED_REFERENCE, MigrateSureInProjectFix.createFactory());
factories.put(REDUNDANT_NULLABLE, RemoveNullableFix.createFactory(false));
factories.put(NULLABLE_SUPERTYPE, RemoveNullableFix.createFactory(true));
factories.put(REDUNDANT_NULLABLE, RemoveNullableFix.createFactory(RemoveNullableFix.NullableKind.REDUNDANT));
factories.put(NULLABLE_SUPERTYPE, RemoveNullableFix.createFactory(RemoveNullableFix.NullableKind.SUPERTYPE));
factories.put(USELESS_NULLABLE_CHECK, RemoveNullableFix.createFactory(RemoveNullableFix.NullableKind.USELESS));
ImplementMethodsHandler implementMethodsHandler = new ImplementMethodsHandler();
actions.put(ABSTRACT_MEMBER_NOT_IMPLEMENTED, implementMethodsHandler);
@@ -27,21 +27,26 @@ import org.jetbrains.jet.lang.psi.JetTypeElement;
import org.jetbrains.jet.plugin.JetBundle;
public class RemoveNullableFix extends JetIntentionAction<JetNullableType> {
boolean isInSuperType;
public enum NullableKind {
REDUNDANT, SUPERTYPE, USELESS
}
private final NullableKind typeOfError;
public RemoveNullableFix(@NotNull JetNullableType element, boolean isInSuperTypeArg) {
public RemoveNullableFix(@NotNull JetNullableType element, @NotNull NullableKind type) {
super(element);
isInSuperType = isInSuperTypeArg;
typeOfError = type;
}
@NotNull
@Override
public String getText() {
if (isInSuperType) {
return JetBundle.message("remove.supertype.nullable");
}
else {
return JetBundle.message("remove.redundant.nullable");
switch (typeOfError) {
case REDUNDANT:
return JetBundle.message("remove.redundant.nullable");
case SUPERTYPE:
return JetBundle.message("remove.supertype.nullable");
default:
return JetBundle.message("remove.useless.nullable");
}
}
@@ -57,13 +62,13 @@ public class RemoveNullableFix extends JetIntentionAction<JetNullableType> {
super.element.replace(type);
}
public static JetIntentionActionFactory createFactory(final boolean isInSupertypeArg) {
public static JetIntentionActionFactory createFactory(final NullableKind typeOfError) {
return new JetIntentionActionFactory() {
@Override
public JetIntentionAction<JetNullableType> createAction(Diagnostic diagnostic) {
JetNullableType type = QuickFixUtil.getParentElementOfType(diagnostic, JetNullableType.class);
if (type == null) return null;
return new RemoveNullableFix(type, isInSupertypeArg);
JetNullableType nullType = QuickFixUtil.getParentElementOfType(diagnostic, JetNullableType.class);
if (nullType == null) return null;
return new RemoveNullableFix(nullType, typeOfError);
}
};
}
@@ -0,0 +1,4 @@
// "Remove useless '?'" "true"
fun f(a: Int) : Boolean {
return a is Int<caret>
}
@@ -0,0 +1,4 @@
// "Remove useless '?'" "true"
fun f(a: Int) : Boolean {
return a is Int?<caret>
}
@@ -668,6 +668,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
doTest("idea/testData/quickfix/nullables/beforeRemoveSupertypeNullable2.kt");
}
@TestMetadata("beforeRemoveUselessNullable.kt")
public void testRemoveUselessNullable() throws Exception {
doTest("idea/testData/quickfix/nullables/beforeRemoveUselessNullable.kt");
}
@TestMetadata("idea/testData/quickfix/nullables/unsafeInfixCall")
public static class UnsafeInfixCall extends AbstractQuickFixTest {
public void testAllFilesPresentInUnsafeInfixCall() throws Exception {