Search in sources :

Example 1 with PsiForStatement

use of com.intellij.psi.PsiForStatement in project intellij-community by JetBrains.

the class ForLoopPredicate 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.FOR_KEYWORD.equals(tokenType)) {
        return false;
    }
    final PsiElement parent = element.getParent();
    return parent instanceof PsiForStatement && !ErrorUtil.containsError(parent);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiJavaToken(com.intellij.psi.PsiJavaToken) PsiForStatement(com.intellij.psi.PsiForStatement) PsiElement(com.intellij.psi.PsiElement)

Example 2 with PsiForStatement

use of com.intellij.psi.PsiForStatement 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

PsiForStatement (com.intellij.psi.PsiForStatement)2 PsiJavaToken (com.intellij.psi.PsiJavaToken)2 TextRange (com.intellij.openapi.util.TextRange)1 PsiElement (com.intellij.psi.PsiElement)1 PsiForeachStatement (com.intellij.psi.PsiForeachStatement)1 IElementType (com.intellij.psi.tree.IElementType)1