Better code for change variable mutability fix
This commit is contained in:
@@ -37,7 +37,7 @@ import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
|
|||||||
|
|
||||||
public class ChangeVariableMutabilityFix implements IntentionAction {
|
public class ChangeVariableMutabilityFix implements IntentionAction {
|
||||||
private boolean isVar;
|
private boolean isVar;
|
||||||
|
|
||||||
public ChangeVariableMutabilityFix(boolean isVar) {
|
public ChangeVariableMutabilityFix(boolean isVar) {
|
||||||
this.isVar = isVar;
|
this.isVar = isVar;
|
||||||
}
|
}
|
||||||
@@ -45,7 +45,7 @@ public class ChangeVariableMutabilityFix implements IntentionAction {
|
|||||||
public ChangeVariableMutabilityFix() {
|
public ChangeVariableMutabilityFix() {
|
||||||
this(false);
|
this(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String getText() {
|
public String getText() {
|
||||||
@@ -86,11 +86,8 @@ public class ChangeVariableMutabilityFix implements IntentionAction {
|
|||||||
@Override
|
@Override
|
||||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||||
JetProperty property = getCorrespondingProperty(editor, (JetFile)file);
|
JetProperty property = getCorrespondingProperty(editor, (JetFile)file);
|
||||||
assert property != null && !property.isVar();
|
assert property != null;
|
||||||
|
property.getValOrVarNode().getPsi().replace(JetPsiFactory.createValOrVarNode(project, isVar ? "val" : "var").getPsi());
|
||||||
JetProperty newElement = JetPsiFactory.createProperty(project, property.getText().replaceFirst(
|
|
||||||
property.isVar() ? "var" : "val", property.isVar() ? "val" : "var"));
|
|
||||||
property.replace(newElement);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// "Make variable mutable" "true"
|
// "Make variable mutable" "true"
|
||||||
class A() {
|
class A() {
|
||||||
var a: Int = 0
|
var a: Int = 0
|
||||||
set(v: Int) {
|
set(v: Int) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user