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++){}")));
}
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"));
}
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;
}
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);
}
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);
}
Aggregations