use of com.intellij.psi.PsiStatement in project intellij-community by JetBrains.
the class JavaIfUnwrapper method doUnwrap.
@Override
protected void doUnwrap(PsiElement element, Context context) throws IncorrectOperationException {
PsiStatement then = ((PsiIfStatement) element).getThenBranch();
context.extractFromBlockOrSingleStatement(then, element);
context.delete(element);
}
use of com.intellij.psi.PsiStatement in project intellij-community by JetBrains.
the class JavaElseUnwrapperBase method doUnwrap.
@Override
protected void doUnwrap(PsiElement element, Context context) throws IncorrectOperationException {
PsiStatement elseBranch;
if (isElseKeyword(element)) {
elseBranch = ((PsiIfStatement) element.getParent()).getElseBranch();
} else {
elseBranch = (PsiStatement) element;
}
unwrapElseBranch(elseBranch, element.getParent(), context);
}
use of com.intellij.psi.PsiStatement in project intellij-community by JetBrains.
the class BlockBraceFixer method apply.
@Override
public void apply(Editor editor, JavaSmartEnterProcessor processor, PsiElement psiElement) throws IncorrectOperationException {
if (psiElement instanceof PsiCodeBlock && afterUnmatchedBrace(editor, psiElement.getContainingFile().getFileType())) {
PsiCodeBlock block = (PsiCodeBlock) psiElement;
int stopOffset = block.getTextRange().getEndOffset();
final PsiStatement[] statements = block.getStatements();
if (statements.length > 0) {
stopOffset = statements[0].getTextRange().getEndOffset();
}
editor.getDocument().insertString(stopOffset, "}");
}
}
use of com.intellij.psi.PsiStatement 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.PsiStatement 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;
}
Aggregations