diff --git a/idea/src/org/jetbrains/jet/plugin/JetBundle.properties b/idea/src/org/jetbrains/jet/plugin/JetBundle.properties index f622e917cce..47f9209039d 100644 --- a/idea/src/org/jetbrains/jet/plugin/JetBundle.properties +++ b/idea/src/org/jetbrains/jet/plugin/JetBundle.properties @@ -23,6 +23,8 @@ remove.parts.from.property.family=Remove parts from property remove.right.part.of.binary.expression=Remove right part of a binary expression remove.cast=Remove cast remove.elvis.operator=Remove elvis operator +remove.redundant.nullable=Remove redundant '?' +remove.nullable.family=Remove '?' remove.useless.import=Remove useless import for ''{0}'' remove.useless.import.family=Remove useless import replace.operation.in.binary.expression=Replace operation in a binary expression diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixes.java b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixes.java index d485c8d8c59..24b307387f2 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixes.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixes.java @@ -132,6 +132,8 @@ public class QuickFixes { factories.put(UNRESOLVED_REFERENCE, MigrateSureInProjectFix.createFactory()); + factories.put(REDUNDANT_NULLABLE, RemoveRedundantNullableFix.createFactory()); + ImplementMethodsHandler implementMethodsHandler = new ImplementMethodsHandler(); actions.put(ABSTRACT_MEMBER_NOT_IMPLEMENTED, implementMethodsHandler); actions.put(MANY_IMPL_MEMBER_NOT_IMPLEMENTED, implementMethodsHandler); diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveRedundantNullableFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveRedundantNullableFix.java new file mode 100644 index 00000000000..5e95266b657 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveRedundantNullableFix.java @@ -0,0 +1,62 @@ +/* + * Copyright 2010-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.quickfix; + +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiFile; +import com.intellij.util.IncorrectOperationException; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.diagnostics.Diagnostic; +import org.jetbrains.jet.lang.psi.JetNullableType; +import org.jetbrains.jet.lang.psi.JetTypeElement; +import org.jetbrains.jet.plugin.JetBundle; + +public class RemoveRedundantNullableFix extends JetIntentionAction { + public RemoveRedundantNullableFix(@NotNull JetNullableType element) { + super(element); + } + + @NotNull + @Override + public String getText() { + return JetBundle.message("remove.redundant.nullable"); + } + + @NotNull + @Override + public String getFamilyName() { + return JetBundle.message("remove.nullable.family"); + } + + @Override + public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { + JetTypeElement type = super.element.getInnerType(); + super.element.replace(type); + } + + public static JetIntentionActionFactory createFactory() { + return new JetIntentionActionFactory() { + @Override + public JetIntentionAction createAction(Diagnostic diagnostic) { + JetNullableType type = QuickFixUtil.getParentElementOfType(diagnostic, JetNullableType.class); + if (type == null) return null; + return new RemoveRedundantNullableFix(type); + } + }; + } +} diff --git a/idea/testData/quickfix/nullables/afterRemoveRedundantNullable.kt b/idea/testData/quickfix/nullables/afterRemoveRedundantNullable.kt new file mode 100644 index 00000000000..4ddf231cd74 --- /dev/null +++ b/idea/testData/quickfix/nullables/afterRemoveRedundantNullable.kt @@ -0,0 +1,4 @@ +// "Remove redundant '?'" "true" +fun main(args : Array) { + val x : Int? = 15 +} diff --git a/idea/testData/quickfix/nullables/beforeRemoveRedundantNullable.kt b/idea/testData/quickfix/nullables/beforeRemoveRedundantNullable.kt new file mode 100644 index 00000000000..e06372018de --- /dev/null +++ b/idea/testData/quickfix/nullables/beforeRemoveRedundantNullable.kt @@ -0,0 +1,4 @@ +// "Remove redundant '?'" "true" +fun main(args : Array) { + val x : Int?? = 15 +}