Search in sources :

Example 11 with PsiIfStatement

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

the class SimplifyIfElseIntention method getElementPredicate.

@NotNull
public PsiElementPredicate getElementPredicate() {
    return new PsiElementPredicate() {

        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;
            }
            return TrivialIfInspection.isTrivial((PsiIfStatement) parent);
        }
    };
}
Also used : PsiJavaToken(com.intellij.psi.PsiJavaToken) PsiIfStatement(com.intellij.psi.PsiIfStatement) PsiElementPredicate(com.siyeh.ipp.base.PsiElementPredicate) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with PsiIfStatement

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

the class IfToSwitchPredicate method satisfiedBy.

@Override
public boolean satisfiedBy(PsiElement element) {
    if (!(element instanceof PsiJavaToken)) {
        return false;
    }
    final PsiJavaToken token = (PsiJavaToken) element;
    if (token.getTokenType() != JavaTokenType.IF_KEYWORD) {
        return false;
    }
    final PsiElement parent = element.getParent();
    if (!(parent instanceof PsiIfStatement)) {
        return false;
    }
    final PsiIfStatement statement = (PsiIfStatement) parent;
    if (ErrorUtil.containsError(statement)) {
        return false;
    }
    return SwitchUtils.getSwitchExpression(statement, 0, false, true) != null;
}
Also used : PsiJavaToken(com.intellij.psi.PsiJavaToken) PsiIfStatement(com.intellij.psi.PsiIfStatement) PsiElement(com.intellij.psi.PsiElement)

Example 13 with PsiIfStatement

use of com.intellij.psi.PsiIfStatement in project Main by SpartanRefactoring.

the class UtilsTest method testGetDocumentFromPsiElement.

public void testGetDocumentFromPsiElement() throws Exception {
    PsiIfStatement i = createTestIfStatement("x > 2", "x++;");
    assertNull(getDocumentFromPsiElement(i));
}
Also used : PsiIfStatement(com.intellij.psi.PsiIfStatement)

Aggregations

PsiIfStatement (com.intellij.psi.PsiIfStatement)13 PsiElement (com.intellij.psi.PsiElement)7 PsiJavaToken (com.intellij.psi.PsiJavaToken)4 PsiStatement (com.intellij.psi.PsiStatement)4 Encapsulator (il.org.spartan.Leonidas.plugin.leonidas.BasicBlocks.Encapsulator)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 TextRange (com.intellij.openapi.util.TextRange)1 PsiConditionalExpression (com.intellij.psi.PsiConditionalExpression)1 PsiExpression (com.intellij.psi.PsiExpression)1 PsiFile (com.intellij.psi.PsiFile)1 PsiKeyword (com.intellij.psi.PsiKeyword)1 PsiElementPredicate (com.siyeh.ipp.base.PsiElementPredicate)1 Wrapper (il.org.spartan.Leonidas.auxilary_layer.Wrapper)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1