Added quickfix for USELESS_SIMPLE_IMPORT.

This commit is contained in:
Jack Zhou
2013-01-31 17:05:46 -05:00
committed by Andrey Breslav
parent 3930d2ca33
commit 93e3bd930e
5 changed files with 84 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.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
replace.cast.with.static.assert=Replace a cast with a static assert
replace.with.dot.call=Replace with dot call
@@ -120,6 +120,8 @@ public class QuickFixes {
JetIntentionActionFactory unresolvedReferenceFactory = ImportClassAndFunFix.createFactory();
factories.put(UNRESOLVED_REFERENCE, unresolvedReferenceFactory);
factories.put(USELESS_SIMPLE_IMPORT, RemoveImportFix.createFactory());
factories.put(SUPERTYPE_NOT_INITIALIZED_DEFAULT, ChangeToConstructorInvocationFix.createFactory());
factories.put(FUNCTION_CALL_EXPECTED, ChangeToFunctionInvocationFix.createFactory());
@@ -0,0 +1,63 @@
/*
* 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.annotations.Nullable;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.psi.JetImportDirective;
import org.jetbrains.jet.plugin.JetBundle;
public class RemoveImportFix extends JetIntentionAction<JetImportDirective> {
private final JetImportDirective directive;
public RemoveImportFix(JetImportDirective directive) {
super(directive);
this.directive = directive;
}
@NotNull
@Override
public String getText() {
return JetBundle.message("remove.useless.import", directive.getImportedReference().getText());
}
@NotNull
@Override
public String getFamilyName() {
return JetBundle.message("remove.useless.import.family");
}
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
directive.delete();
}
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
@Nullable
@Override
public JetIntentionAction<JetImportDirective> createAction(Diagnostic diagnostic) {
return new RemoveImportFix(QuickFixUtil.getParentElementOfType(diagnostic, JetImportDirective.class));
}
};
}
}
@@ -0,0 +1,8 @@
// "Remove useless import for 'test'" "true"
package test
import org.jetbrains
fun main(args : Array<String>) {
}
@@ -0,0 +1,9 @@
// "Remove useless import for 'test'" "true"
package test
import org.jetbrains
import test<caret>
fun main(args : Array<String>) {
}