use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement in project intellij-community by JetBrains.
the class IfExprSurrounder method surroundExpression.
@Override
protected TextRange surroundExpression(@NotNull GrExpression expression, PsiElement context) {
GrIfStatement ifStatement = (GrIfStatement) GroovyPsiElementFactory.getInstance(expression.getProject()).createStatementFromText("if(a){4\n}", context);
replaceToOldExpression(ifStatement.getCondition(), expression);
ifStatement = expression.replaceWithStatement(ifStatement);
GrStatement thenBranch = ifStatement.getThenBranch();
assert thenBranch instanceof GrBlockStatement;
GrStatement[] statements = ((GrBlockStatement) thenBranch).getBlock().getStatements();
assert statements.length > 0;
GrStatement statement = statements[0];
int endOffset = statement.getTextRange().getStartOffset();
statement.getNode().getTreeParent().removeChild(statement.getNode());
return new TextRange(endOffset, endOffset);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement in project intellij-community by JetBrains.
the class GroovyElseSelectioner method select.
@Nullable
@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
if (!(e instanceof GrIfStatement))
return null;
GrIfStatement ifSt = (GrIfStatement) e;
GrStatement branch = ifSt.getElseBranch();
PsiElement elseKeyword = ifSt.getElseKeyword();
if (branch == null || elseKeyword == null)
return null;
return expandToWholeLine(editorText, new TextRange(elseKeyword.getTextRange().getStartOffset(), branch.getTextRange().getEndOffset()));
}
Aggregations