Search in sources :

Example 1 with PsiElementPredicate

use of com.siyeh.ipp.base.PsiElementPredicate in project intellij-community by JetBrains.

the class PostfixPrefixIntention method getElementPredicate.

@NotNull
@Override
protected PsiElementPredicate getElementPredicate() {
    return new PsiElementPredicate() {

        @Override
        public boolean satisfiedBy(PsiElement element) {
            final IElementType tokenType;
            if (element instanceof PsiPrefixExpression) {
                final PsiPrefixExpression prefixExpression = (PsiPrefixExpression) element;
                tokenType = prefixExpression.getOperationTokenType();
                if (prefixExpression.getOperand() == null) {
                    return false;
                }
            } else if (element instanceof PsiPostfixExpression) {
                final PsiPostfixExpression postfixExpression = (PsiPostfixExpression) element;
                tokenType = postfixExpression.getOperationTokenType();
            } else {
                return false;
            }
            return JavaTokenType.PLUSPLUS.equals(tokenType) || JavaTokenType.MINUSMINUS.equals(tokenType);
        }
    };
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiElementPredicate(com.siyeh.ipp.base.PsiElementPredicate) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with PsiElementPredicate

use of com.siyeh.ipp.base.PsiElementPredicate in project intellij-community by JetBrains.

the class ConvertToNestedIfIntention method getElementPredicate.

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

        public boolean satisfiedBy(PsiElement element) {
            if (!(element instanceof PsiReturnStatement)) {
                return false;
            }
            final PsiReturnStatement returnStatement = (PsiReturnStatement) element;
            final PsiExpression returnValue = ParenthesesUtils.stripParentheses(returnStatement.getReturnValue());
            if (!(returnValue instanceof PsiPolyadicExpression)) {
                return false;
            }
            final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression) returnValue;
            final IElementType tokenType = polyadicExpression.getOperationTokenType();
            return tokenType == JavaTokenType.ANDAND || tokenType == JavaTokenType.OROR;
        }
    };
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiElementPredicate(com.siyeh.ipp.base.PsiElementPredicate) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with PsiElementPredicate

use of com.siyeh.ipp.base.PsiElementPredicate 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)

Aggregations

PsiElementPredicate (com.siyeh.ipp.base.PsiElementPredicate)3 NotNull (org.jetbrains.annotations.NotNull)3 IElementType (com.intellij.psi.tree.IElementType)2 PsiElement (com.intellij.psi.PsiElement)1 PsiIfStatement (com.intellij.psi.PsiIfStatement)1 PsiJavaToken (com.intellij.psi.PsiJavaToken)1