use of com.intellij.psi.PsiJavaToken in project intellij-community by JetBrains.
the class DoWhileLoopPredicate method satisfiedBy.
public boolean satisfiedBy(PsiElement element) {
if (!(element instanceof PsiJavaToken)) {
return false;
}
final PsiJavaToken token = (PsiJavaToken) element;
final IElementType tokenType = token.getTokenType();
if (!JavaTokenType.DO_KEYWORD.equals(tokenType)) {
return false;
}
final PsiElement parent = element.getParent();
if (!(parent instanceof PsiDoWhileStatement)) {
return false;
}
final PsiDoWhileStatement doWhileStatement = (PsiDoWhileStatement) parent;
return !(doWhileStatement.getCondition() == null || doWhileStatement.getBody() == null);
}
use of com.intellij.psi.PsiJavaToken in project intellij-community by JetBrains.
the class WhileLoopPredicate method satisfiedBy.
public boolean satisfiedBy(PsiElement element) {
if (!(element instanceof PsiJavaToken)) {
return false;
}
final PsiJavaToken token = (PsiJavaToken) element;
final IElementType tokenType = token.getTokenType();
if (!JavaTokenType.WHILE_KEYWORD.equals(tokenType)) {
return false;
}
final PsiElement parent = element.getParent();
if (!(parent instanceof PsiWhileStatement)) {
return false;
}
final PsiWhileStatement whileStatement = (PsiWhileStatement) parent;
return !(whileStatement.getCondition() == null || whileStatement.getBody() == null);
}
use of com.intellij.psi.PsiJavaToken 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.PsiJavaToken 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.PsiJavaToken in project intellij-community by JetBrains.
the class ForStatementHeaderSelectioner method select.
@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
PsiJavaToken lParen = e instanceof PsiForStatement ? ((PsiForStatement) e).getLParenth() : e instanceof PsiForeachStatement ? ((PsiForeachStatement) e).getLParenth() : null;
PsiJavaToken rParen = e instanceof PsiForStatement ? ((PsiForStatement) e).getRParenth() : e instanceof PsiForeachStatement ? ((PsiForeachStatement) e).getRParenth() : null;
if (lParen == null || rParen == null)
return null;
TextRange result = new TextRange(lParen.getTextRange().getEndOffset(), rParen.getTextRange().getStartOffset());
return result.containsOffset(cursorOffset) ? Collections.singletonList(result) : null;
}
Aggregations