Added quickfix for REDUNDANT_NULLABLE.

This commit is contained in:
Jack Zhou
2013-02-04 12:20:12 -05:00
committed by Andrey Breslav
parent 93e3bd930e
commit 5ee9b2fdd1
5 changed files with 74 additions and 0 deletions
@@ -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
@@ -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);
@@ -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<JetNullableType> {
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<JetNullableType> createAction(Diagnostic diagnostic) {
JetNullableType type = QuickFixUtil.getParentElementOfType(diagnostic, JetNullableType.class);
if (type == null) return null;
return new RemoveRedundantNullableFix(type);
}
};
}
}
@@ -0,0 +1,4 @@
// "Remove redundant '?'" "true"
fun main(args : Array<String>) {
val x : Int? = 15
}
@@ -0,0 +1,4 @@
// "Remove redundant '?'" "true"
fun main(args : Array<String>) {
val x : Int??<caret> = 15
}