use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory in project intellij-community by JetBrains.
the class ForSurrounder method doSurroundElements.
@Override
protected GroovyPsiElement doSurroundElements(PsiElement[] elements, PsiElement context) throws IncorrectOperationException {
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(elements[0].getProject());
GrForStatement whileStatement = (GrForStatement) factory.createStatementFromText("for(a in b){\n}", context);
addStatements(((GrBlockStatement) whileStatement.getBody()).getBlock(), elements);
return whileStatement;
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory in project intellij-community by JetBrains.
the class GrBracesSurrounder method doSurroundElements.
@Override
protected GroovyPsiElement doSurroundElements(PsiElement[] elements, PsiElement context) throws IncorrectOperationException {
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(elements[0].getProject());
final PsiElement e0 = elements[0];
final PsiElement parent = e0.getParent();
final GrCodeBlock block;
if (parent instanceof GrControlStatement) {
block = factory.createMethodBodyFromText("\n");
final PsiElement prev = e0.getPrevSibling();
if (prev != null && prev.getNode().getElementType().equals(GroovyTokenTypes.mNLS)) {
final ASTNode parentNode = e0.getParent().getNode();
parentNode.addLeaf(TokenType.WHITE_SPACE, " ", prev.getNode());
parentNode.removeChild(prev.getNode());
}
} else {
block = factory.createClosureFromText("{}");
}
GroovyManyStatementsSurrounder.addStatements(block, elements);
return block;
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory in project intellij-community by JetBrains.
the class GroovySimpleManyStatementsSurrounder method doSurroundElements.
@Override
protected final GroovyPsiElement doSurroundElements(PsiElement[] elements, PsiElement context) throws IncorrectOperationException {
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(elements[0].getProject());
GrMethodCallExpression withCall = (GrMethodCallExpression) factory.createExpressionFromText(getReplacementTokens(), context);
addStatements(withCall.getClosureArguments()[0], elements);
return withCall;
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory in project intellij-community by JetBrains.
the class IfElseSurrounder method doSurroundElements.
@Override
protected GroovyPsiElement doSurroundElements(PsiElement[] elements, PsiElement context) throws IncorrectOperationException {
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(elements[0].getProject());
GrIfStatement ifStatement = (GrIfStatement) factory.createStatementFromText("if (a) {\n} else {\n}", context);
addStatements(((GrBlockStatement) ifStatement.getThenBranch()).getBlock(), elements);
return ifStatement;
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory in project intellij-community by JetBrains.
the class IfSurrounder method doSurroundElements.
@Override
protected GroovyPsiElement doSurroundElements(PsiElement[] elements, PsiElement context) throws IncorrectOperationException {
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(elements[0].getProject());
GrIfStatement ifStatement = (GrIfStatement) factory.createStatementFromText("if (a) {\n}", context);
addStatements(((GrBlockStatement) ifStatement.getThenBranch()).getBlock(), elements);
return ifStatement;
}
Aggregations