use of com.intellij.psi.PsiIfStatement in project intellij-community by JetBrains.
the class JavaElseUnwrapperBase method collectElementsToIgnore.
@Override
public void collectElementsToIgnore(PsiElement element, Set<PsiElement> result) {
PsiElement parent = element.getParent();
while (parent instanceof PsiIfStatement) {
result.add(parent);
parent = parent.getParent();
}
}
use of com.intellij.psi.PsiIfStatement in project intellij-community by JetBrains.
the class IfStatementSelectioner method select.
@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
List<TextRange> result = new ArrayList<>();
result.addAll(expandToWholeLine(editorText, e.getTextRange(), false));
PsiIfStatement statement = (PsiIfStatement) e;
final PsiKeyword elseKeyword = statement.getElseElement();
if (elseKeyword != null) {
final PsiStatement then = statement.getThenBranch();
if (then != null) {
final TextRange thenRange = new TextRange(statement.getTextRange().getStartOffset(), then.getTextRange().getEndOffset());
if (thenRange.contains(cursorOffset)) {
result.addAll(expandToWholeLine(editorText, thenRange, false));
}
}
result.addAll(expandToWholeLine(editorText, new TextRange(elseKeyword.getTextRange().getStartOffset(), statement.getTextRange().getEndOffset()), false));
final PsiStatement branch = statement.getElseBranch();
if (branch instanceof PsiIfStatement) {
PsiIfStatement elseIf = (PsiIfStatement) branch;
final PsiKeyword element = elseIf.getElseElement();
if (element != null) {
final PsiStatement elseThen = elseIf.getThenBranch();
if (elseThen != null) {
result.addAll(expandToWholeLine(editorText, new TextRange(elseKeyword.getTextRange().getStartOffset(), elseThen.getTextRange().getEndOffset()), false));
}
}
}
}
return result;
}
use of com.intellij.psi.PsiIfStatement in project intellij-community by JetBrains.
the class MergeIfAndPredicate method satisfiedBy.
public boolean satisfiedBy(PsiElement element) {
if (!(element instanceof PsiJavaToken)) {
return false;
}
final PsiJavaToken token = (PsiJavaToken) element;
final PsiElement parent = token.getParent();
if (!(parent instanceof PsiIfStatement)) {
return false;
}
final PsiIfStatement ifStatement = (PsiIfStatement) parent;
if (ErrorUtil.containsError(ifStatement)) {
return false;
}
PsiStatement thenBranch = ifStatement.getThenBranch();
thenBranch = ControlFlowUtils.stripBraces(thenBranch);
PsiStatement elseBranch = ifStatement.getElseBranch();
elseBranch = ControlFlowUtils.stripBraces(elseBranch);
if (thenBranch == null) {
return false;
}
if (elseBranch != null) {
return false;
}
if (!(thenBranch instanceof PsiIfStatement)) {
return false;
}
final PsiIfStatement childIfStatement = (PsiIfStatement) thenBranch;
return childIfStatement.getElseBranch() == null;
}
use of com.intellij.psi.PsiIfStatement in project intellij-community by JetBrains.
the class SplitElseIfIntention method processIntention.
public void processIntention(PsiElement element) throws IncorrectOperationException {
final PsiJavaToken token = (PsiJavaToken) element;
final PsiIfStatement parentStatement = (PsiIfStatement) token.getParent();
if (parentStatement == null) {
return;
}
final PsiStatement elseBranch = parentStatement.getElseBranch();
if (elseBranch == null) {
return;
}
final String newStatement = '{' + elseBranch.getText() + '}';
PsiReplacementUtil.replaceStatement(elseBranch, newStatement);
}
use of com.intellij.psi.PsiIfStatement in project intellij-community by JetBrains.
the class ReplaceIfWithSwitchIntention method processIntention.
@Override
public void processIntention(@NotNull PsiElement element) {
final PsiElement parent = element.getParent();
if (!(parent instanceof PsiIfStatement)) {
return;
}
final PsiIfStatement ifStatement = (PsiIfStatement) parent;
IfCanBeSwitchInspection.replaceIfWithSwitch(ifStatement);
}
Aggregations