Search in sources :

Example 1 with KtPrefixExpression

use of org.jetbrains.kotlin.psi.KtPrefixExpression in project kotlin by JetBrains.

the class KotlinNotSurrounder method surroundExpression.

@Nullable
@Override
public TextRange surroundExpression(@NotNull Project project, @NotNull Editor editor, @NotNull KtExpression expression) {
    KtPrefixExpression prefixExpr = (KtPrefixExpression) KtPsiFactoryKt.KtPsiFactory(expression).createExpression("!(a)");
    KtParenthesizedExpression parenthesizedExpression = (KtParenthesizedExpression) prefixExpr.getBaseExpression();
    assert parenthesizedExpression != null : "JetParenthesizedExpression should exists for " + prefixExpr.getText() + " expression";
    KtExpression expressionWithoutParentheses = parenthesizedExpression.getExpression();
    assert expressionWithoutParentheses != null : "JetExpression should exists for " + parenthesizedExpression.getText() + " expression";
    expressionWithoutParentheses.replace(expression);
    expression = (KtExpression) expression.replace(prefixExpr);
    CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(expression);
    int offset = expression.getTextRange().getEndOffset();
    return new TextRange(offset, offset);
}
Also used : KtPrefixExpression(org.jetbrains.kotlin.psi.KtPrefixExpression) KtExpression(org.jetbrains.kotlin.psi.KtExpression) TextRange(com.intellij.openapi.util.TextRange) KtParenthesizedExpression(org.jetbrains.kotlin.psi.KtParenthesizedExpression) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

TextRange (com.intellij.openapi.util.TextRange)1 Nullable (org.jetbrains.annotations.Nullable)1 KtExpression (org.jetbrains.kotlin.psi.KtExpression)1 KtParenthesizedExpression (org.jetbrains.kotlin.psi.KtParenthesizedExpression)1 KtPrefixExpression (org.jetbrains.kotlin.psi.KtPrefixExpression)1