merged three quickfixes for NON_VARARG_SPREAD, USELESS_(HIDDEN_)IMPORT, and UNUSED_VARIABLE into one file
This commit is contained in:
committed by
Andrey Breslav
parent
d928c09931
commit
36d613f1c4
@@ -24,6 +24,7 @@ remove.modifier.family=Remove Modifier
|
||||
remove.redundant.modifier=Remove redundant ''{0}'' modifier
|
||||
remove.parts.from.property=Remove {0} from property
|
||||
remove.parts.from.property.family=Remove Parts from Property
|
||||
remove.psi.element.family=Remove Element
|
||||
remove.right.part.of.binary.expression=Remove right part of a binary expression
|
||||
remove.cast=Remove cast
|
||||
remove.elvis.operator=Remove elvis operator
|
||||
|
||||
@@ -83,7 +83,7 @@ public class QuickFixes {
|
||||
factories.put(NON_ABSTRACT_FUNCTION_WITH_NO_BODY, addAbstractModifierFactory);
|
||||
factories.put(NON_ABSTRACT_FUNCTION_WITH_NO_BODY, addFunctionBodyFactory);
|
||||
|
||||
factories.put(NON_VARARG_SPREAD, RemoveSpreadFix.createFactory());
|
||||
factories.put(NON_VARARG_SPREAD, RemovePsiElementSimpleFix.createRemoveSpreadFactory());
|
||||
|
||||
factories.put(NON_MEMBER_FUNCTION_NO_BODY, addFunctionBodyFactory);
|
||||
|
||||
@@ -129,7 +129,7 @@ public class QuickFixes {
|
||||
JetIntentionActionFactory unresolvedReferenceFactory = ImportClassAndFunFix.createFactory();
|
||||
factories.put(UNRESOLVED_REFERENCE, unresolvedReferenceFactory);
|
||||
|
||||
JetIntentionActionFactory removeImportFixFactory = RemoveImportFix.createFactory();
|
||||
JetIntentionActionFactory removeImportFixFactory = RemovePsiElementSimpleFix.createRemoveImportFactory();
|
||||
factories.put(USELESS_SIMPLE_IMPORT, removeImportFixFactory);
|
||||
factories.put(USELESS_HIDDEN_IMPORT, removeImportFixFactory);
|
||||
|
||||
@@ -162,7 +162,7 @@ public class QuickFixes {
|
||||
actions.put(VAL_OR_VAR_ON_LOOP_PARAMETER, removeValVarFromParametersFix);
|
||||
actions.put(VAL_OR_VAR_ON_CATCH_PARAMETER, removeValVarFromParametersFix);
|
||||
|
||||
factories.put(UNUSED_VARIABLE, RemoveVariableFix.createRemoveVariableFactory());
|
||||
factories.put(UNUSED_VARIABLE, RemovePsiElementSimpleFix.createRemoveVariableFactory());
|
||||
|
||||
actions.put(UNNECESSARY_SAFE_CALL, ReplaceCallFix.toDotCallFromSafeCall());
|
||||
actions.put(UNSAFE_CALL, ReplaceCallFix.toSafeCall());
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* 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,116 @@
|
||||
/*
|
||||
* 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.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.impl.source.tree.LeafPsiElement;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetImportDirective;
|
||||
import org.jetbrains.jet.lang.psi.JetProperty;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
|
||||
public class RemovePsiElementSimpleFix extends JetIntentionAction<PsiElement> {
|
||||
|
||||
private final PsiElement element;
|
||||
private final String text;
|
||||
|
||||
|
||||
public RemovePsiElementSimpleFix(@NotNull PsiElement el, @NotNull String txt) {
|
||||
super(el);
|
||||
element = el;
|
||||
text = txt;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getFamilyName() {
|
||||
return JetBundle.message("remove.psi.element.family");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
element.delete();
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createRemoveImportFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
@Override
|
||||
public JetIntentionAction<PsiElement> createAction(Diagnostic diagnostic) {
|
||||
JetImportDirective directive = QuickFixUtil.getParentElementOfType(diagnostic, JetImportDirective.class);
|
||||
if (directive == null) return null;
|
||||
else {
|
||||
JetExpression exp = directive.getImportedReference();
|
||||
if (exp != null) {
|
||||
return new RemovePsiElementSimpleFix(directive,
|
||||
JetBundle.message("remove.useless.import", exp.getText()));
|
||||
}
|
||||
return new RemovePsiElementSimpleFix(directive,
|
||||
JetBundle.message("remove.useless.import",""));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createRemoveSpreadFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
@Override
|
||||
public JetIntentionAction<PsiElement> createAction(Diagnostic diagnostic) {
|
||||
PsiElement element = diagnostic.getPsiElement();
|
||||
if ((element instanceof LeafPsiElement) && ((LeafPsiElement) element).getElementType() == JetTokens.MUL) {
|
||||
return new RemovePsiElementSimpleFix(element, JetBundle.message("remove.spread.sign"));
|
||||
}
|
||||
else return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createRemoveVariableFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
@Override
|
||||
public JetIntentionAction<PsiElement> createAction(Diagnostic diagnostic) {
|
||||
final JetProperty expression = QuickFixUtil.getParentElementOfType(diagnostic, JetProperty.class);
|
||||
if (expression == null) return null;
|
||||
return new RemovePsiElementSimpleFix(expression,
|
||||
JetBundle.message("remove.variable.action", (expression.getName()))) {
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
JetExpression initializer = expression.getInitializer();
|
||||
if (initializer != null) {
|
||||
expression.replace(initializer);
|
||||
}
|
||||
else {
|
||||
expression.delete();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* 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.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.impl.source.tree.LeafPsiElement;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
|
||||
public class RemoveSpreadFix extends JetIntentionAction<LeafPsiElement>{
|
||||
private final LeafPsiElement spreadSign;
|
||||
|
||||
public RemoveSpreadFix(@NotNull LeafPsiElement element) {
|
||||
super(element);
|
||||
spreadSign = element;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
return JetBundle.message("remove.spread.sign");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getFamilyName() {
|
||||
return JetBundle.message("remove.spread.sign");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
spreadSign.delete();
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
@Override
|
||||
public JetIntentionAction<LeafPsiElement> createAction(Diagnostic diagnostic) {
|
||||
PsiElement element = diagnostic.getPsiElement();
|
||||
if ((element instanceof LeafPsiElement) && ((LeafPsiElement) element).getElementType() == JetTokens.MUL) {
|
||||
return new RemoveSpreadFix((LeafPsiElement) element);
|
||||
}
|
||||
else return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* 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.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetProperty;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
|
||||
public class RemoveVariableFix extends JetIntentionAction<JetProperty> {
|
||||
public RemoveVariableFix(@NotNull JetProperty element) {
|
||||
super(element);
|
||||
}
|
||||
|
||||
private String getVariableName() {
|
||||
return element.getName();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
return JetBundle.message("remove.variable.action", getVariableName());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getFamilyName() {
|
||||
return JetBundle.message("remove.variable.family.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
JetExpression initializer = element.getInitializer();
|
||||
if (initializer != null) {
|
||||
element.replace(initializer);
|
||||
}
|
||||
else {
|
||||
element.delete();
|
||||
}
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createRemoveVariableFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
@Override
|
||||
public JetIntentionAction createAction(Diagnostic diagnostic) {
|
||||
JetProperty expression = QuickFixUtil.getParentElementOfType(diagnostic, JetProperty.class);
|
||||
if (expression == null) return null;
|
||||
return new RemoveVariableFix(expression);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user