quick fixes refactoring (disuse of CodeEditUtil)
This commit is contained in:
@@ -80,21 +80,9 @@ public class ChangeVariableMutabilityFix implements IntentionAction {
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
JetProperty property = getCorrespondingProperty(editor, (JetFile)file);
|
||||
assert property != null && !property.isVar();
|
||||
JetProperty newElement = (JetProperty) property.copy();
|
||||
if (newElement.isVar()) {
|
||||
PsiElement varElement = newElement.getNode().findChildByType(JetTokens.VAR_KEYWORD).getPsi();
|
||||
|
||||
JetProperty valProperty = JetPsiFactory.createProperty(project, "x", "Any", false);
|
||||
PsiElement valElement = valProperty.getNode().findChildByType(JetTokens.VAL_KEYWORD).getPsi();
|
||||
CodeEditUtil.replaceChild(newElement.getNode(), varElement.getNode(), valElement.getNode());
|
||||
}
|
||||
else {
|
||||
PsiElement valElement = newElement.getNode().findChildByType(JetTokens.VAL_KEYWORD).getPsi();
|
||||
|
||||
JetProperty varProperty = JetPsiFactory.createProperty(project, "x", "Any", true);
|
||||
PsiElement varElement = varProperty.getNode().findChildByType(JetTokens.VAR_KEYWORD).getPsi();
|
||||
CodeEditUtil.replaceChild(newElement.getNode(), valElement.getNode(), varElement.getNode());
|
||||
}
|
||||
JetProperty newElement = JetPsiFactory.createProperty(project, property.getText().replaceFirst(
|
||||
property.isVar() ? "var" : "val", property.isVar() ? "val" : "var"));
|
||||
property.replace(newElement);
|
||||
}
|
||||
|
||||
|
||||
+11
-10
@@ -10,16 +10,17 @@ import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
|
||||
import org.jetbrains.jet.lang.psi.JetBinaryExpressionWithTypeRHS;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeReference;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public abstract class ReplaceOperationInBinaryExpressionFix<T extends JetExpression> extends JetIntentionAction<T> {
|
||||
private final String expressionWithNecessaryOperation;
|
||||
public ReplaceOperationInBinaryExpressionFix(@NotNull T element, String expressionWithNecessaryOperation) {
|
||||
private final String operation;
|
||||
public ReplaceOperationInBinaryExpressionFix(@NotNull T element, String operation) {
|
||||
super(element);
|
||||
this.expressionWithNecessaryOperation = expressionWithNecessaryOperation;
|
||||
this.operation = operation;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -31,12 +32,12 @@ public abstract class ReplaceOperationInBinaryExpressionFix<T extends JetExpress
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
if (element instanceof JetBinaryExpressionWithTypeRHS) {
|
||||
JetBinaryExpressionWithTypeRHS expression = (JetBinaryExpressionWithTypeRHS) JetPsiFactory.createExpression(project, expressionWithNecessaryOperation);
|
||||
|
||||
JetBinaryExpressionWithTypeRHS newElement = (JetBinaryExpressionWithTypeRHS) element.copy();
|
||||
CodeEditUtil.replaceChild(newElement.getNode(), newElement.getOperationSign().getNode(), expression.getOperationSign().getNode());
|
||||
|
||||
element.replace(newElement);
|
||||
JetExpression left = ((JetBinaryExpressionWithTypeRHS) element).getLeft();
|
||||
JetTypeReference right = ((JetBinaryExpressionWithTypeRHS) element).getRight();
|
||||
if (right != null) {
|
||||
JetExpression expression = JetPsiFactory.createExpression(project, left.getText() + operation + right.getText());
|
||||
element.replace(expression);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +46,7 @@ public abstract class ReplaceOperationInBinaryExpressionFix<T extends JetExpress
|
||||
@Override
|
||||
public JetIntentionAction<JetBinaryExpressionWithTypeRHS> createAction(DiagnosticWithPsiElement diagnostic) {
|
||||
assert diagnostic.getPsiElement() instanceof JetBinaryExpressionWithTypeRHS;
|
||||
return new ReplaceOperationInBinaryExpressionFix<JetBinaryExpressionWithTypeRHS>((JetBinaryExpressionWithTypeRHS) diagnostic.getPsiElement(), "2 : Int") {
|
||||
return new ReplaceOperationInBinaryExpressionFix<JetBinaryExpressionWithTypeRHS>((JetBinaryExpressionWithTypeRHS) diagnostic.getPsiElement(), " : ") {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// "Make variable mutable" "true"
|
||||
class A() {
|
||||
var a: Int = 0
|
||||
<caret>set(v: Int) {}
|
||||
set(v: Int) {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user