use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrCondition in project intellij-community by JetBrains.
the class GrTraditionalForClauseImpl method getConditionInner.
private GrCondition getConditionInner(final int i) {
int passed = 0;
boolean waitForSemicolon = false;
for (ASTNode child = getNode().getFirstChildNode(); child != null; child = child.getTreeNext()) {
if (child.getElementType() == GroovyTokenTypes.mSEMI) {
if (waitForSemicolon) {
waitForSemicolon = false;
} else {
if (passed == i) {
return null;
}
passed++;
}
} else if (child.getPsi() instanceof GrCondition) {
if (passed == i) {
return (GrCondition) child.getPsi();
}
passed++;
waitForSemicolon = true;
}
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrCondition in project intellij-community by JetBrains.
the class ControlFlowBuilder method visitSwitchStatement.
@Override
public void visitSwitchStatement(@NotNull GrSwitchStatement switchStatement) {
final GrCondition condition = switchStatement.getCondition();
if (condition != null) {
condition.accept(this);
}
final InstructionImpl instruction = startNode(switchStatement);
final GrCaseSection[] sections = switchStatement.getCaseSections();
if (!containsAllCases(switchStatement)) {
addPendingEdge(switchStatement, instruction);
}
for (GrCaseSection section : sections) {
myHead = instruction;
section.accept(this);
}
finishNode(instruction);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrCondition in project intellij-community by JetBrains.
the class ControlFlowBuilder method visitIfStatement.
@Override
public void visitIfStatement(@NotNull GrIfStatement ifStatement) {
InstructionImpl ifInstruction = startNode(ifStatement);
FList<ConditionInstruction> conditionsBefore = myConditions;
final GrCondition condition = ifStatement.getCondition();
final GrStatement thenBranch = ifStatement.getThenBranch();
final GrStatement elseBranch = ifStatement.getElseBranch();
InstructionImpl conditionEnd = null;
InstructionImpl thenEnd = null;
InstructionImpl elseEnd = null;
if (condition != null) {
condition.accept(this);
conditionEnd = myHead;
}
List<GotoInstruction> negations = collectAndRemoveAllPendingNegations(ifStatement);
if (thenBranch != null) {
thenBranch.accept(this);
handlePossibleReturn(thenBranch);
thenEnd = myHead;
interruptFlow();
readdPendingEdge(ifStatement);
}
myHead = reduceAllNegationsIntoInstruction(ifStatement, negations);
if (myHead == null && conditionEnd != null) {
myHead = conditionEnd;
}
if (elseBranch != null) {
elseBranch.accept(this);
handlePossibleReturn(elseBranch);
elseEnd = myHead;
interruptFlow();
}
if (thenBranch != null || elseBranch != null) {
if (thenEnd != null || elseEnd != null || elseBranch == null) {
final InstructionImpl end = new IfEndInstruction(ifStatement);
addNode(end);
if (thenEnd != null) {
addEdge(thenEnd, end);
}
if (elseEnd != null) {
addEdge(elseEnd, end);
} else if (elseBranch == null) {
// addEdge(conditionEnd != null ? conditionEnd : ifInstruction, end);
}
}
}
myConditions = conditionsBefore;
finishNode(ifInstruction);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrCondition in project intellij-community by JetBrains.
the class GrWhileConditionFixer method apply.
@Override
public void apply(@NotNull Editor editor, @NotNull GroovySmartEnterProcessor processor, @NotNull PsiElement psiElement) {
if (psiElement instanceof GrWhileStatement) {
final Document doc = editor.getDocument();
final GrWhileStatement whileStatement = (GrWhileStatement) psiElement;
final PsiElement rParenth = whileStatement.getRParenth();
final PsiElement lParenth = whileStatement.getLParenth();
final GrCondition condition = whileStatement.getCondition();
if (condition == null) {
if (lParenth == null || rParenth == null) {
int stopOffset = doc.getLineEndOffset(doc.getLineNumber(whileStatement.getTextRange().getStartOffset()));
final GrStatement block = whileStatement.getBody();
if (block != null) {
stopOffset = Math.min(stopOffset, block.getTextRange().getStartOffset());
}
stopOffset = Math.min(stopOffset, whileStatement.getTextRange().getEndOffset());
doc.replaceString(whileStatement.getTextRange().getStartOffset(), stopOffset, "while ()");
processor.registerUnresolvedError(whileStatement.getTextRange().getStartOffset() + "while (".length());
} else {
processor.registerUnresolvedError(lParenth.getTextRange().getEndOffset());
}
} else if (rParenth == null) {
doc.insertString(condition.getTextRange().getEndOffset(), ")");
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrCondition in project intellij-community by JetBrains.
the class WhileSurrounder method getSurroundSelectionRange.
@Override
protected TextRange getSurroundSelectionRange(GroovyPsiElement element) {
assert element instanceof GrWhileStatement;
GrCondition condition = ((GrWhileStatement) element).getCondition();
int endOffset = element.getTextRange().getEndOffset();
if (condition != null) {
endOffset = condition.getTextRange().getStartOffset();
condition.getParent().getNode().removeChild(condition.getNode());
}
return new TextRange(endOffset, endOffset);
}
Aggregations