"Replace with !!." has been added

This commit is contained in:
Sergey Lukjanov
2012-06-18 18:44:35 +04:00
parent 7b4fda4345
commit 5ae88184af
2 changed files with 14 additions and 9 deletions
@@ -23,7 +23,8 @@ remove.elvis.operator=Remove elvis operator
replace.operation.in.binary.expression=Replace operation in a binary expression replace.operation.in.binary.expression=Replace operation in a binary expression
replace.cast.with.static.assert=Replace a cast with a static assert replace.cast.with.static.assert=Replace a cast with a static assert
replace.with.dot.call=Replace with dot call replace.with.dot.call=Replace with dot call
replace.with.safe.call=Replace with safe call replace.with.safe.call=Replace with safe (?.) call
replace.with.nna.call=Replace with non-null asserted (!!.) call
change.to.backing.field=Change reference to backing field change.to.backing.field=Change reference to backing field
implement.members=Implement members implement.members=Implement members
new.kotlin.file.action=Kotlin File new.kotlin.file.action=Kotlin File
@@ -31,23 +31,26 @@ import org.jetbrains.jet.plugin.JetBundle;
* @author svtk * @author svtk
*/ */
public class ReplaceCallFix implements IntentionAction { public class ReplaceCallFix implements IntentionAction {
private final boolean toSafe; private final boolean safe;
private final boolean fromDot;
public ReplaceCallFix(boolean toSafe) { public ReplaceCallFix(boolean safe, boolean fromDot) {
this.toSafe = toSafe; this.safe = safe;
this.fromDot = fromDot;
} }
@NotNull @NotNull
@Override @Override
public String getText() { public String getText() {
return toSafe ? JetBundle.message("replace.with.safe.call") : JetBundle.message("replace.with.dot.call"); return fromDot
? (safe ? JetBundle.message("replace.with.safe.call") : JetBundle.message("replace.with.nna.call"))
: JetBundle.message("replace.with.dot.call");
} }
@NotNull @NotNull
@Override @Override
public String getFamilyName() { public String getFamilyName() {
return toSafe ? JetBundle.message("replace.with.safe.call") : JetBundle.message("replace.with.dot.call"); return getText();
} }
@Override @Override
@@ -60,7 +63,7 @@ public class ReplaceCallFix implements IntentionAction {
private JetQualifiedExpression getCallExpression(@NotNull Editor editor, @NotNull JetFile file) { private JetQualifiedExpression getCallExpression(@NotNull Editor editor, @NotNull JetFile file) {
final PsiElement elementAtCaret = file.findElementAt(editor.getCaretModel().getOffset()); final PsiElement elementAtCaret = file.findElementAt(editor.getCaretModel().getOffset());
return PsiTreeUtil.getParentOfType(elementAtCaret, toSafe ? JetDotQualifiedExpression.class : JetSafeQualifiedExpression.class); return PsiTreeUtil.getParentOfType(elementAtCaret, fromDot ? JetDotQualifiedExpression.class : JetSafeQualifiedExpression.class);
} }
@Override @Override
@@ -71,7 +74,8 @@ public class ReplaceCallFix implements IntentionAction {
JetExpression selector = callExpression.getSelectorExpression(); JetExpression selector = callExpression.getSelectorExpression();
if (selector != null) { if (selector != null) {
JetQualifiedExpression newElement = (JetQualifiedExpression) JetPsiFactory.createExpression( JetQualifiedExpression newElement = (JetQualifiedExpression) JetPsiFactory.createExpression(
project, callExpression.getReceiverExpression().getText() + (toSafe ? "?." : ".") + selector.getText()); project,
callExpression.getReceiverExpression().getText() + (fromDot ? (safe ? "?." : "!!.") : ".") + selector.getText());
callExpression.replace(newElement); callExpression.replace(newElement);
} }