diff --git a/idea/src/org/jetbrains/jet/plugin/JetBundle.properties b/idea/src/org/jetbrains/jet/plugin/JetBundle.properties index ca3baf69497..05f1e2045e1 100644 --- a/idea/src/org/jetbrains/jet/plugin/JetBundle.properties +++ b/idea/src/org/jetbrains/jet/plugin/JetBundle.properties @@ -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 diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixes.java b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixes.java index ca38321cbf3..ebb7ce05b28 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixes.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixes.java @@ -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()); diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveImportFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveImportFix.java deleted file mode 100644 index 3142b50fbce..00000000000 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveImportFix.java +++ /dev/null @@ -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 { - 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 createAction(Diagnostic diagnostic) { - return new RemoveImportFix(QuickFixUtil.getParentElementOfType(diagnostic, JetImportDirective.class)); - } - }; - } -} diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/RemovePsiElementSimpleFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/RemovePsiElementSimpleFix.java new file mode 100644 index 00000000000..b3fd934f1f9 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/RemovePsiElementSimpleFix.java @@ -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 { + + 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 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 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 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(); + } + } + }; + } + }; + } +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveSpreadFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveSpreadFix.java deleted file mode 100644 index ba7797ccece..00000000000 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveSpreadFix.java +++ /dev/null @@ -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{ - 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 createAction(Diagnostic diagnostic) { - PsiElement element = diagnostic.getPsiElement(); - if ((element instanceof LeafPsiElement) && ((LeafPsiElement) element).getElementType() == JetTokens.MUL) { - return new RemoveSpreadFix((LeafPsiElement) element); - } - else return null; - } - }; - } -} diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveVariableFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveVariableFix.java deleted file mode 100644 index 10cc5238243..00000000000 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveVariableFix.java +++ /dev/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 { - 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); - } - }; - } -} -