Search in sources :

Example 1 with PsiBinaryExpression

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

the class azTest method testAzJavaToken.

public void testAzJavaToken() throws Exception {
    PsiElement t1 = ((PsiBinaryExpression) createTestExpression("x == y")).getOperationSign();
    assert az.javaToken(t1) != null;
    PsiElement t2 = ((PsiBinaryExpression) createTestExpression("x != y")).getOperationSign();
    assert az.javaToken(t2) != null;
    assertNull(az.javaToken(createTestForStatementFromString("for(int i = 0 ; i < 5 ; i++){}")));
}
Also used : PsiElement(com.intellij.psi.PsiElement) PsiBinaryExpression(com.intellij.psi.PsiBinaryExpression)

Example 2 with PsiBinaryExpression

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

the class hazTest method testHazEqualsOperator.

public void testHazEqualsOperator() throws Exception {
    PsiBinaryExpression e1 = (PsiBinaryExpression) createTestExpression("x == y");
    assert haz.equalsOperator(e1);
    PsiBinaryExpression e2 = (PsiBinaryExpression) createTestExpression("x != y");
    assert !haz.equalsOperator(e2);
    assert !haz.equalsOperator((PsiBinaryExpression) createTestExpression("x > y"));
}
Also used : PsiBinaryExpression(com.intellij.psi.PsiBinaryExpression)

Example 3 with PsiBinaryExpression

use of com.intellij.psi.PsiBinaryExpression in project timber by JakeWharton.

the class WrongTimberUsageDetector method findLiteralValue.

private static String findLiteralValue(PsiExpression argument) {
    if (argument instanceof PsiLiteralExpression) {
        PsiLiteralExpression literalExpression = (PsiLiteralExpression) argument;
        Object value = literalExpression.getValue();
        if (value instanceof String) {
            return (String) value;
        }
    } else if (argument instanceof PsiBinaryExpression) {
        PsiBinaryExpression binaryExpression = (PsiBinaryExpression) argument;
        if (binaryExpression.getOperationTokenType() == JavaTokenType.PLUS) {
            String left = findLiteralValue(binaryExpression.getLOperand());
            String right = findLiteralValue(binaryExpression.getROperand());
            if (left != null && right != null) {
                return left + right;
            }
        }
    } else if (argument instanceof PsiReferenceExpression) {
        PsiReferenceExpression referenceExpression = (PsiReferenceExpression) argument;
        PsiElement resolved = referenceExpression.resolve();
        if (resolved instanceof PsiField) {
            PsiField field = (PsiField) resolved;
            Object value = field.computeConstantValue();
            if (value instanceof String) {
                return (String) value;
            }
        }
    }
    return null;
}
Also used : PsiLiteralExpression(com.intellij.psi.PsiLiteralExpression) PsiReferenceExpression(com.intellij.psi.PsiReferenceExpression) PsiField(com.intellij.psi.PsiField) PsiElement(com.intellij.psi.PsiElement) PsiBinaryExpression(com.intellij.psi.PsiBinaryExpression)

Example 4 with PsiBinaryExpression

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

the class NegateComparisonIntention method processIntention.

public void processIntention(PsiElement element) throws IncorrectOperationException {
    final PsiBinaryExpression expression = (PsiBinaryExpression) element;
    final PsiExpression lhs = expression.getLOperand();
    final PsiExpression rhs = expression.getROperand();
    final String negatedOperator = ComparisonUtils.getNegatedComparison(expression.getOperationTokenType());
    final String lhsText = lhs.getText();
    assert rhs != null;
    final String rhsText = rhs.getText();
    replaceExpressionWithNegatedExpressionString(lhsText + negatedOperator + rhsText, expression);
}
Also used : PsiExpression(com.intellij.psi.PsiExpression) PsiBinaryExpression(com.intellij.psi.PsiBinaryExpression)

Example 5 with PsiBinaryExpression

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

the class ComparisonPredicate method satisfiedBy.

public boolean satisfiedBy(PsiElement element) {
    if (!(element instanceof PsiBinaryExpression)) {
        return false;
    }
    final PsiBinaryExpression expression = (PsiBinaryExpression) element;
    final PsiExpression rhs = expression.getROperand();
    if (rhs == null) {
        return false;
    }
    if (!ComparisonUtils.isComparison((PsiExpression) element)) {
        return false;
    }
    return !ErrorUtil.containsError(element);
}
Also used : PsiExpression(com.intellij.psi.PsiExpression) PsiBinaryExpression(com.intellij.psi.PsiBinaryExpression)

Aggregations

PsiBinaryExpression (com.intellij.psi.PsiBinaryExpression)11 PsiExpression (com.intellij.psi.PsiExpression)5 PsiElement (com.intellij.psi.PsiElement)4 IElementType (com.intellij.psi.tree.IElementType)3 PsiField (com.intellij.psi.PsiField)2 PsiJavaToken (com.intellij.psi.PsiJavaToken)2 PsiReferenceExpression (com.intellij.psi.PsiReferenceExpression)2 Nullable (com.android.annotations.Nullable)1 PsiArrayInitializerExpression (com.intellij.psi.PsiArrayInitializerExpression)1 PsiArrayType (com.intellij.psi.PsiArrayType)1 PsiAssignmentExpression (com.intellij.psi.PsiAssignmentExpression)1 PsiClass (com.intellij.psi.PsiClass)1 PsiClassType (com.intellij.psi.PsiClassType)1 PsiConditionalExpression (com.intellij.psi.PsiConditionalExpression)1 PsiDeclarationStatement (com.intellij.psi.PsiDeclarationStatement)1 PsiExpressionStatement (com.intellij.psi.PsiExpressionStatement)1 PsiLiteral (com.intellij.psi.PsiLiteral)1 PsiLiteralExpression (com.intellij.psi.PsiLiteralExpression)1 PsiLocalVariable (com.intellij.psi.PsiLocalVariable)1 PsiNewExpression (com.intellij.psi.PsiNewExpression)1