"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.cast.with.static.assert=Replace a cast with a static assert
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
implement.members=Implement members
new.kotlin.file.action=Kotlin File
@@ -31,23 +31,26 @@ import org.jetbrains.jet.plugin.JetBundle;
* @author svtk
*/
public class ReplaceCallFix implements IntentionAction {
private final boolean toSafe;
private final boolean safe;
private final boolean fromDot;
public ReplaceCallFix(boolean toSafe) {
this.toSafe = toSafe;
public ReplaceCallFix(boolean safe, boolean fromDot) {
this.safe = safe;
this.fromDot = fromDot;
}
@NotNull
@Override
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
@Override
public String getFamilyName() {
return toSafe ? JetBundle.message("replace.with.safe.call") : JetBundle.message("replace.with.dot.call");
return getText();
}
@Override
@@ -60,7 +63,7 @@ public class ReplaceCallFix implements IntentionAction {
private JetQualifiedExpression getCallExpression(@NotNull Editor editor, @NotNull JetFile file) {
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
@@ -71,7 +74,8 @@ public class ReplaceCallFix implements IntentionAction {
JetExpression selector = callExpression.getSelectorExpression();
if (selector != null) {
JetQualifiedExpression newElement = (JetQualifiedExpression) JetPsiFactory.createExpression(
project, callExpression.getReceiverExpression().getText() + (toSafe ? "?." : ".") + selector.getText());
project,
callExpression.getReceiverExpression().getText() + (fromDot ? (safe ? "?." : "!!.") : ".") + selector.getText());
callExpression.replace(newElement);
}