Search in sources :

Example 6 with PsiJavaToken

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);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiJavaToken(com.intellij.psi.PsiJavaToken) PsiDoWhileStatement(com.intellij.psi.PsiDoWhileStatement) PsiElement(com.intellij.psi.PsiElement)

Example 7 with PsiJavaToken

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);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiJavaToken(com.intellij.psi.PsiJavaToken) PsiWhileStatement(com.intellij.psi.PsiWhileStatement) PsiElement(com.intellij.psi.PsiElement)

Example 8 with PsiJavaToken

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;
}
Also used : PsiStatement(com.intellij.psi.PsiStatement) PsiJavaToken(com.intellij.psi.PsiJavaToken) PsiIfStatement(com.intellij.psi.PsiIfStatement) PsiElement(com.intellij.psi.PsiElement)

Example 9 with PsiJavaToken

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);
}
Also used : PsiStatement(com.intellij.psi.PsiStatement) PsiJavaToken(com.intellij.psi.PsiJavaToken) PsiIfStatement(com.intellij.psi.PsiIfStatement)

Example 10 with PsiJavaToken

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;
}
Also used : PsiJavaToken(com.intellij.psi.PsiJavaToken) PsiForeachStatement(com.intellij.psi.PsiForeachStatement) PsiForStatement(com.intellij.psi.PsiForStatement) TextRange(com.intellij.openapi.util.TextRange)

Aggregations

PsiJavaToken (com.intellij.psi.PsiJavaToken)19 PsiElement (com.intellij.psi.PsiElement)12 PsiPolyadicExpression (com.intellij.psi.PsiPolyadicExpression)5 PsiExpression (com.intellij.psi.PsiExpression)4 PsiIfStatement (com.intellij.psi.PsiIfStatement)4 IElementType (com.intellij.psi.tree.IElementType)4 Document (com.intellij.openapi.editor.Document)2 TextRange (com.intellij.openapi.util.TextRange)2 PsiBinaryExpression (com.intellij.psi.PsiBinaryExpression)2 PsiForStatement (com.intellij.psi.PsiForStatement)2 PsiStatement (com.intellij.psi.PsiStatement)2 PsiWhileStatement (com.intellij.psi.PsiWhileStatement)2 PsiAssignmentExpression (com.intellij.psi.PsiAssignmentExpression)1 PsiBlockStatement (com.intellij.psi.PsiBlockStatement)1 PsiCodeBlock (com.intellij.psi.PsiCodeBlock)1 PsiDoWhileStatement (com.intellij.psi.PsiDoWhileStatement)1 PsiForeachStatement (com.intellij.psi.PsiForeachStatement)1 PsiSwitchStatement (com.intellij.psi.PsiSwitchStatement)1 PsiTypeCastExpression (com.intellij.psi.PsiTypeCastExpression)1 PsiElementPredicate (com.siyeh.ipp.base.PsiElementPredicate)1