Made "Remove val/var from parameter" quick fix local.
This commit is contained in:
@@ -171,7 +171,7 @@ options.kotlin.attribute.descriptor.smart.cast=Smart-cast value
|
|||||||
options.kotlin.attribute.descriptor.label=Label
|
options.kotlin.attribute.descriptor.label=Label
|
||||||
change.to.function.invocation=Change to function invocation
|
change.to.function.invocation=Change to function invocation
|
||||||
migrate.sure=Replace sure() calls by !! in project
|
migrate.sure=Replace sure() calls by !! in project
|
||||||
remove.val.var.from.parameter=Remove val/var from function, loop and catch parameters in project
|
remove.val.var.from.parameter=Remove ''{0}'' from parameter
|
||||||
add.override.to.equals.hashCode.toString=Add 'override' to equals, hashCode, toString in project
|
add.override.to.equals.hashCode.toString=Add 'override' to equals, hashCode, toString in project
|
||||||
add.when.else.branch.action.family.name=Add Else Branch
|
add.when.else.branch.action.family.name=Add Else Branch
|
||||||
add.when.else.branch.action=Add else branch
|
add.when.else.branch.action=Add else branch
|
||||||
|
|||||||
@@ -141,10 +141,10 @@ public class QuickFixRegistrar {
|
|||||||
QuickFixes.actions.put(VAL_REASSIGNMENT, changeVariableMutabilityFix);
|
QuickFixes.actions.put(VAL_REASSIGNMENT, changeVariableMutabilityFix);
|
||||||
QuickFixes.actions.put(VAR_OVERRIDDEN_BY_VAL, changeVariableMutabilityFix);
|
QuickFixes.actions.put(VAR_OVERRIDDEN_BY_VAL, changeVariableMutabilityFix);
|
||||||
|
|
||||||
RemoveValVarFromParametersFix removeValVarFromParametersFix = new RemoveValVarFromParametersFix();
|
JetSingleIntentionActionFactory removeValVarFromParameterFixFactory = RemoveValVarFromParametersFix.createFactory();
|
||||||
QuickFixes.actions.put(VAL_OR_VAR_ON_FUN_PARAMETER, removeValVarFromParametersFix);
|
QuickFixes.factories.put(VAL_OR_VAR_ON_FUN_PARAMETER, removeValVarFromParameterFixFactory);
|
||||||
QuickFixes.actions.put(VAL_OR_VAR_ON_LOOP_PARAMETER, removeValVarFromParametersFix);
|
QuickFixes.factories.put(VAL_OR_VAR_ON_LOOP_PARAMETER, removeValVarFromParameterFixFactory);
|
||||||
QuickFixes.actions.put(VAL_OR_VAR_ON_CATCH_PARAMETER, removeValVarFromParametersFix);
|
QuickFixes.factories.put(VAL_OR_VAR_ON_CATCH_PARAMETER, removeValVarFromParameterFixFactory);
|
||||||
|
|
||||||
QuickFixes.factories.put(VIRTUAL_MEMBER_HIDDEN, AddOverrideToEqualsHashCodeToStringFix.createFactory());
|
QuickFixes.factories.put(VIRTUAL_MEMBER_HIDDEN, AddOverrideToEqualsHashCodeToStringFix.createFactory());
|
||||||
|
|
||||||
|
|||||||
@@ -20,69 +20,52 @@ import com.intellij.codeInsight.intention.IntentionAction;
|
|||||||
import com.intellij.lang.ASTNode;
|
import com.intellij.lang.ASTNode;
|
||||||
import com.intellij.openapi.editor.Editor;
|
import com.intellij.openapi.editor.Editor;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.psi.PsiElement;
|
|
||||||
import com.intellij.psi.PsiFile;
|
|
||||||
import com.intellij.psi.TokenType;
|
import com.intellij.psi.TokenType;
|
||||||
|
import com.intellij.util.IncorrectOperationException;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetParameter;
|
||||||
import org.jetbrains.jet.plugin.JetBundle;
|
import org.jetbrains.jet.plugin.JetBundle;
|
||||||
import org.jetbrains.jet.plugin.project.PluginJetFilesProvider;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
public class RemoveValVarFromParametersFix extends JetIntentionAction<JetParameter> {
|
||||||
|
public RemoveValVarFromParametersFix(@NotNull JetParameter element) {
|
||||||
|
super(element);
|
||||||
|
}
|
||||||
|
|
||||||
public class RemoveValVarFromParametersFix implements IntentionAction {
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String getText() {
|
public String getText() {
|
||||||
return JetBundle.message("remove.val.var.from.parameter");
|
ASTNode valOrVarNode = element.getValOrVarNode();
|
||||||
|
return JetBundle.message("remove.val.var.from.parameter", valOrVarNode != null ? valOrVarNode.getText() : "null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String getFamilyName() {
|
public String getFamilyName() {
|
||||||
return JetBundle.message("remove.val.var.from.parameter");
|
return JetBundle.message("remove.val.var.from.parameter", "val/var");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
protected void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException {
|
||||||
return file.getManager().isInProject(file);
|
ASTNode valOrVarNode = element.getValOrVarNode();
|
||||||
|
if (valOrVarNode == null) return;
|
||||||
|
|
||||||
|
ASTNode whitespace = valOrVarNode.getTreeNext();
|
||||||
|
assert whitespace.getElementType() == TokenType.WHITE_SPACE;
|
||||||
|
|
||||||
|
element.getNode().removeRange(valOrVarNode, whitespace.getTreeNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) {
|
|
||||||
// TODO after M6, this quick fix should remove val/var only for current parameter
|
|
||||||
|
|
||||||
Collection<JetFile> files = PluginJetFilesProvider.allFilesInProject(project);
|
public static JetSingleIntentionActionFactory createFactory() {
|
||||||
for (JetFile jetFile : files) {
|
return new JetSingleIntentionActionFactory() {
|
||||||
jetFile.acceptChildren(new JetVisitorVoid() {
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public void visitParameter(@NotNull JetParameter parameter) {
|
public IntentionAction createAction(@NotNull Diagnostic diagnostic) {
|
||||||
visitJetElement(parameter); // run recursively for children
|
return new RemoveValVarFromParametersFix((JetParameter) diagnostic.getPsiElement().getParent());
|
||||||
|
}
|
||||||
PsiElement parent = parameter.getParent();
|
};
|
||||||
if (parent != null && parent.getParent() instanceof JetClass) {
|
|
||||||
return; // constructor parameter
|
|
||||||
}
|
|
||||||
|
|
||||||
ASTNode valOrVarNode = parameter.getValOrVarNode();
|
|
||||||
if (valOrVarNode != null) {
|
|
||||||
ASTNode whitespace = valOrVarNode.getTreeNext();
|
|
||||||
assert whitespace.getElementType() == TokenType.WHITE_SPACE;
|
|
||||||
|
|
||||||
parameter.getNode().removeRange(valOrVarNode, whitespace.getTreeNext());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visitJetElement(@NotNull JetElement element) {
|
|
||||||
element.acceptChildren(this);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean startInWriteAction() {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
// "Remove val/var from function, loop and catch parameters in project" "true"
|
|
||||||
|
|
||||||
class Class(a: Int, val b: Int, var c: Int, vararg val d: Int) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
fun f(a: Int, b: Int, c: Int, vararg d: Int) {
|
|
||||||
for (i in d) {
|
|
||||||
}
|
|
||||||
for (i in d) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
} catch (e: Exception) {
|
|
||||||
} catch (e: Exception) {
|
|
||||||
} catch (e: Exception) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
// "Remove val/var from function, loop and catch parameters in project" "true"
|
|
||||||
|
|
||||||
class Class(a: Int, val b: Int, var c: Int, vararg val d: Int) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
fun f(a: Int, <caret>val b: Int, var c: Int, vararg val d: Int) {
|
|
||||||
for (val i in d) {
|
|
||||||
}
|
|
||||||
for (var i in d) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
} catch (val e: Exception) {
|
|
||||||
} catch (var e: Exception) {
|
|
||||||
} catch (e: Exception) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// "Remove 'val' from parameter" "true"
|
||||||
|
fun f() {
|
||||||
|
try {
|
||||||
|
|
||||||
|
} catch (<caret>e: Exception) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
// "Remove 'val' from parameter" "true"
|
||||||
|
fun f(<caret>x: String) {
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// "Remove 'val' from parameter" "true"
|
||||||
|
fun f(list: List<String>) {
|
||||||
|
for (x in list) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// "Remove 'val' from parameter" "true"
|
||||||
|
fun f() {
|
||||||
|
try {
|
||||||
|
|
||||||
|
} catch (<caret>val e: Exception) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
// "Remove 'val' from parameter" "false"
|
||||||
|
class C(<caret>val x: String) {
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
// "Remove 'val' from parameter" "true"
|
||||||
|
fun f(<caret>val x: String) {
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// "Remove 'val' from parameter" "true"
|
||||||
|
fun f(list: List<String>) {
|
||||||
|
for (val<caret> x in list) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1799,12 +1799,6 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/migration"), Pattern.compile("^before(\\w+)\\.kt$"), true);
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/migration"), Pattern.compile("^before(\\w+)\\.kt$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("beforeValVarFromParameters.kt")
|
|
||||||
public void testValVarFromParameters() throws Exception {
|
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/beforeValVarFromParameters.kt");
|
|
||||||
doTest(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("idea/testData/quickfix/modifiers")
|
@TestMetadata("idea/testData/quickfix/modifiers")
|
||||||
@@ -3746,7 +3740,7 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
|
|
||||||
@TestMetadata("idea/testData/quickfix/variables")
|
@TestMetadata("idea/testData/quickfix/variables")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@InnerTestClasses({Variables.ChangeMutability.class, Variables.ChangeToBackingField.class, Variables.ChangeToFunctionInvocation.class, Variables.ChangeToPropertyName.class})
|
@InnerTestClasses({Variables.ChangeMutability.class, Variables.ChangeToBackingField.class, Variables.ChangeToFunctionInvocation.class, Variables.ChangeToPropertyName.class, Variables.RemoveValVarFromParameter.class})
|
||||||
@RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class)
|
@RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class)
|
||||||
public static class Variables extends AbstractQuickFixTest {
|
public static class Variables extends AbstractQuickFixTest {
|
||||||
public void testAllFilesPresentInVariables() throws Exception {
|
public void testAllFilesPresentInVariables() throws Exception {
|
||||||
@@ -3883,6 +3877,40 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("idea/testData/quickfix/variables/removeValVarFromParameter")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class)
|
||||||
|
public static class RemoveValVarFromParameter extends AbstractQuickFixTest {
|
||||||
|
public void testAllFilesPresentInRemoveValVarFromParameter() throws Exception {
|
||||||
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/variables/removeValVarFromParameter"), Pattern.compile("^before(\\w+)\\.kt$"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeCatchParameter.kt")
|
||||||
|
public void testCatchParameter() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/variables/removeValVarFromParameter/beforeCatchParameter.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeConstructorParameter.kt")
|
||||||
|
public void testConstructorParameter() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/variables/removeValVarFromParameter/beforeConstructorParameter.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeFunParameter.kt")
|
||||||
|
public void testFunParameter() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/variables/removeValVarFromParameter/beforeFunParameter.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeLoopParameter.kt")
|
||||||
|
public void testLoopParameter() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/variables/removeValVarFromParameter/beforeLoopParameter.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("idea/testData/quickfix/when")
|
@TestMetadata("idea/testData/quickfix/when")
|
||||||
|
|||||||
Reference in New Issue
Block a user