use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement in project intellij-community by JetBrains.
the class GroovyInlineMethodUtil method checkTailOpenBlock.
private static boolean checkTailOpenBlock(GrOpenBlock block, Collection<GrStatement> returnStatements) {
if (block == null)
return false;
GrStatement[] statements = block.getStatements();
if (statements.length == 0)
return false;
GrStatement last = statements[statements.length - 1];
if (returnStatements.contains(last)) {
returnStatements.remove(last);
return true;
}
if (last instanceof GrIfStatement) {
return checkTailIfStatement(((GrIfStatement) last), returnStatements);
}
return false;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement in project intellij-community by JetBrains.
the class GrIfConditionFixer method apply.
@Override
public void apply(@NotNull Editor editor, @NotNull GroovySmartEnterProcessor processor, @NotNull PsiElement psiElement) {
if (psiElement instanceof GrIfStatement) {
final Document doc = editor.getDocument();
final GrIfStatement ifStatement = (GrIfStatement) psiElement;
final PsiElement rParen = ifStatement.getRParenth();
final PsiElement lParen = ifStatement.getLParenth();
final GrExpression condition = ifStatement.getCondition();
if (condition == null) {
if (lParen == null || rParen == null) {
int stopOffset = doc.getLineEndOffset(doc.getLineNumber(ifStatement.getTextRange().getStartOffset()));
final GrStatement then = ifStatement.getThenBranch();
if (then != null) {
stopOffset = Math.min(stopOffset, then.getTextRange().getStartOffset());
}
stopOffset = Math.min(stopOffset, ifStatement.getTextRange().getEndOffset());
doc.replaceString(ifStatement.getTextRange().getStartOffset(), stopOffset, "if ()");
processor.registerUnresolvedError(ifStatement.getTextRange().getStartOffset() + "if (".length());
} else {
processor.registerUnresolvedError(lParen.getTextRange().getEndOffset());
}
} else if (rParen == null) {
doc.insertString(condition.getTextRange().getEndOffset(), ")");
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement in project intellij-community by JetBrains.
the class GroovyIfStatementWithTooManyBranchesInspectionBase method buildErrorString.
@Override
protected String buildErrorString(Object... args) {
final GrIfStatement statement = (GrIfStatement) args[0];
final int branches = calculateNumBranches(statement);
return "'#ref' statement with too many branches (" + branches + ") #loc";
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement in project intellij-community by JetBrains.
the class FlipIfIntention method processIntention.
@Override
protected void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
final GrIfStatement ifStatement = DefaultGroovyMethods.asType(element.getParent(), GrIfStatement.class);
final GrIfStatement elseIf = getElseIf(ifStatement);
final GrIfStatement elseIfCopy = DefaultGroovyMethods.asType(elseIf.copy(), GrIfStatement.class);
elseIf.getCondition().replaceWithExpression(ifStatement.getCondition(), true);
elseIf.getThenBranch().replaceWithStatement(ifStatement.getThenBranch());
ifStatement.getCondition().replaceWithExpression(elseIfCopy.getCondition(), true);
ifStatement.getThenBranch().replaceWithStatement(elseIfCopy.getThenBranch());
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement in project intellij-community by JetBrains.
the class FlipIfIntention method getElementPredicate.
@NotNull
@Override
protected PsiElementPredicate getElementPredicate() {
return new PsiElementPredicate() {
@Override
public boolean satisfiedBy(PsiElement element) {
if (!element.getNode().getElementType().equals(GroovyTokenTypes.kIF))
return false;
if (!(element.getParent() instanceof GrIfStatement))
return false;
final GrIfStatement ifStatement = DefaultGroovyMethods.asType(element.getParent(), GrIfStatement.class);
final GrIfStatement elseIf = getElseIf(ifStatement);
return elseIf != null && checkIf(ifStatement) && checkIf(elseIf);
}
};
}
Aggregations