use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrTryCatchStatement in project intellij-community by JetBrains.
the class GroovyTryUnwrapper method doUnwrap.
@Override
protected void doUnwrap(final PsiElement element, final Context context) throws IncorrectOperationException {
GrTryCatchStatement trySt = (GrTryCatchStatement) element;
context.extractFromCodeBlock(trySt.getTryBlock(), trySt);
GrFinallyClause finallyClause = trySt.getFinallyClause();
if (finallyClause != null) {
context.extractFromCodeBlock(finallyClause.getBody(), trySt);
}
context.delete(trySt);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrTryCatchStatement in project intellij-community by JetBrains.
the class TryCatchFinallySurrounder method doSurroundElements.
@Override
protected GroovyPsiElement doSurroundElements(PsiElement[] elements, PsiElement context) throws IncorrectOperationException {
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(elements[0].getProject());
GrTryCatchStatement tryStatement = (GrTryCatchStatement) factory.createStatementFromText("try {\n} catch(exception e){\n} finally{\n}", context);
addStatements(tryStatement.getTryBlock(), elements);
return tryStatement;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrTryCatchStatement in project intellij-community by JetBrains.
the class TrySurrounder method getSurroundSelectionRange.
@Override
protected TextRange getSurroundSelectionRange(GroovyPsiElement element) {
assert element instanceof GrTryCatchStatement;
int endOffset = element.getTextRange().getEndOffset();
GrTryCatchStatement tryCatchStatement = (GrTryCatchStatement) element;
GrCatchClause[] catchClauses = tryCatchStatement.getCatchClauses();
if (catchClauses != null && catchClauses.length > 0) {
GrParameter parameter = catchClauses[0].getParameter();
if (parameter == null) {
GrOpenBlock block = catchClauses[0].getBody();
assert block != null;
endOffset = block.getTextRange().getEndOffset();
} else {
endOffset = parameter.getTextRange().getStartOffset();
parameter.getParent().getNode().removeChild(parameter.getNode());
}
} else {
GrOpenBlock block = tryCatchStatement.getTryBlock();
if (block != null) {
GrStatement[] statements = block.getStatements();
if (statements.length > 0) {
endOffset = statements[0].getTextRange().getStartOffset();
}
}
}
return new TextRange(endOffset, endOffset);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrTryCatchStatement in project intellij-community by JetBrains.
the class TryFinallySurrounder method doSurroundElements.
@Override
protected GroovyPsiElement doSurroundElements(PsiElement[] elements, PsiElement context) throws IncorrectOperationException {
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(elements[0].getProject());
GrTryCatchStatement tryStatement = (GrTryCatchStatement) factory.createStatementFromText("try {\n} finally{\n}", context);
addStatements(tryStatement.getTryBlock(), elements);
return tryStatement;
}
Aggregations