use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement in project intellij-community by JetBrains.
the class GroovyElseRemover method deleteSelectedElseIf.
private static void deleteSelectedElseIf(GrIfStatement selectedBranch, Context context) throws IncorrectOperationException {
GrIfStatement parentIf = (GrIfStatement) selectedBranch.getParent();
GrStatement childElse = selectedBranch.getElseBranch();
if (childElse == null) {
context.delete(selectedBranch);
return;
}
context.setElseBranch(parentIf, childElse);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement in project intellij-community by JetBrains.
the class GroovyElseUnwrapperBase method doUnwrap.
@Override
protected void doUnwrap(PsiElement element, Context context) throws IncorrectOperationException {
GrStatement elseBranch;
if (isElseKeyword(element)) {
elseBranch = ((GrIfStatement) element.getParent()).getElseBranch();
} else {
elseBranch = (GrStatement) element;
}
unwrapElseBranch(elseBranch, element.getParent(), context);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement in project intellij-community by JetBrains.
the class GrIntroduceVariableHandler method addVariable.
private static GrVariable addVariable(@NotNull GrIntroduceContext context, @NotNull GroovyIntroduceVariableSettings settings) {
GrStatement anchor = findAnchor(context, settings.replaceAllOccurrences());
PsiElement parent = anchor.getParent();
assert parent instanceof GrStatementOwner;
GrVariableDeclaration generated = generateDeclaration(context, settings);
GrStatement declaration = ((GrStatementOwner) parent).addStatementBefore(generated, anchor);
declaration = (GrStatement) JavaCodeStyleManager.getInstance(context.getProject()).shortenClassReferences(declaration);
return ((GrVariableDeclaration) declaration).getVariables()[0];
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement in project intellij-community by JetBrains.
the class GroovyIntroduceParameterUtil method findVar.
@Nullable
static GrVariable findVar(IntroduceParameterInfo info) {
GrVariable variable = info.getVar();
if (variable != null)
return variable;
final GrStatement[] statements = info.getStatements();
if (statements.length != 1)
return null;
return GrIntroduceHandlerBase.findVariable(statements[0]);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement 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);
}
Aggregations