Search in sources :

Example 1 with PsiForeachStatement

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

TextRange (com.intellij.openapi.util.TextRange)1 PsiForStatement (com.intellij.psi.PsiForStatement)1 PsiForeachStatement (com.intellij.psi.PsiForeachStatement)1 PsiJavaToken (com.intellij.psi.PsiJavaToken)1