Java 类com.intellij.psi.PsiBinaryExpression 实例源码

项目:intellij-ce-playground    文件:StringEqualityInspection.java   
@Override
public void visitBinaryExpression(@NotNull PsiBinaryExpression expression) {
  super.visitBinaryExpression(expression);
  if (!ComparisonUtils.isEqualityComparison(expression)) {
    return;
  }
  final PsiExpression lhs = expression.getLOperand();
  if (!ExpressionUtils.hasStringType(lhs)) {
    return;
  }
  final PsiExpression rhs = expression.getROperand();
  if (rhs == null || !ExpressionUtils.hasStringType(rhs)) {
    return;
  }
  if (ExpressionUtils.isNullLiteral(lhs) || ExpressionUtils.isNullLiteral(rhs)) {
    return;
  }
  final PsiJavaToken sign = expression.getOperationSign();
  registerError(sign);
}
项目:intellij-ce-playground    文件:ConstantOnRHSOfComparisonInspection.java   
@Override
public void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
  final PsiBinaryExpression expression = (PsiBinaryExpression)descriptor.getPsiElement();
  final PsiExpression rhs = expression.getROperand();
  if (rhs == null) {
    return;
  }
  final String flippedComparison = ComparisonUtils.getFlippedComparison(expression.getOperationTokenType());
  if (flippedComparison == null) {
    return;
  }
  final PsiExpression lhs = expression.getLOperand();
  final String rhsText = rhs.getText();
  final String lhsText = lhs.getText();
  PsiReplacementUtil.replaceExpression(expression, rhsText + ' ' + flippedComparison + ' ' + lhsText);
}
项目:intellij-ce-playground    文件:ConstantOnLHSOfComparisonInspection.java   
@Override
public void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
  final PsiBinaryExpression expression = (PsiBinaryExpression)descriptor.getPsiElement();
  final PsiExpression rhs = expression.getROperand();
  if (rhs == null) {
    return;
  }
  final String flippedComparison = ComparisonUtils.getFlippedComparison(expression.getOperationTokenType());
  if (flippedComparison == null) {
    return;
  }
  final PsiExpression lhs = expression.getLOperand();
  final String rhsText = rhs.getText();
  final String lhsText = lhs.getText();
  PsiReplacementUtil.replaceExpression(expression, rhsText + ' ' + flippedComparison + ' ' + lhsText);
}
项目:intellij-ce-playground    文件:CharacterComparisonInspection.java   
@Override
public void visitBinaryExpression(@NotNull PsiBinaryExpression expression) {
  super.visitBinaryExpression(expression);
  final PsiExpression rhs = expression.getROperand();
  if (!ComparisonUtils.isComparison(expression) || ComparisonUtils.isEqualityComparison(expression)) {
    return;
  }
  final PsiExpression lhs = expression.getLOperand();
  if (!isCharacter(lhs) || !isCharacter(rhs)) {
    return;
  }
  if (NonNlsUtils.isNonNlsAnnotated(lhs) || NonNlsUtils.isNonNlsAnnotated(rhs)) {
    return;
  }
  registerError(expression);
}
项目:intellij-ce-playground    文件:BadOddnessInspection.java   
@Override
public void visitBinaryExpression(
  @NotNull PsiBinaryExpression expression) {
  super.visitBinaryExpression(expression);
  if (expression.getROperand() == null) {
    return;
  }
  if (!ComparisonUtils.isEqualityComparison(expression)) {
    return;
  }
  final PsiExpression lhs = expression.getLOperand();
  final PsiExpression rhs = expression.getROperand();
  if (isModTwo(lhs) && hasValue(rhs, 1)) {
    registerError(expression, expression);
  }
  if (isModTwo(rhs) && hasValue(lhs, 1)) {
    registerError(expression, expression);
  }
}
项目:intellij-ce-playground    文件:BadOddnessInspection.java   
private static boolean isModTwo(PsiExpression exp) {
  if (!(exp instanceof PsiBinaryExpression)) {
    return false;
  }
  final PsiBinaryExpression binary = (PsiBinaryExpression)exp;
  final IElementType tokenType = binary.getOperationTokenType();
  if (!JavaTokenType.PERC.equals(tokenType)) {
    return false;
  }
  final PsiExpression rhs = binary.getROperand();
  final PsiExpression lhs = binary.getLOperand();
  if (rhs == null) {
    return false;
  }
  return hasValue(rhs, 2) || hasValue(lhs, 2);
}
项目:intellij-ce-playground    文件:ComparisonOfShortAndCharInspection.java   
@Override
public void visitBinaryExpression(@NotNull PsiBinaryExpression expression) {
  super.visitBinaryExpression(expression);
  if (!ComparisonUtils.isEqualityComparison(expression)) {
    return;
  }
  final PsiExpression lhs = expression.getLOperand();
  final PsiType lhsType = lhs.getType();
  final PsiExpression rhs = expression.getROperand();
  if (rhs == null) {
    return;
  }
  final PsiType rhsType = rhs.getType();
  if (PsiType.SHORT.equals(lhsType) && PsiType.CHAR.equals(rhsType)) {
    registerError(expression);
  }
  else if (PsiType.CHAR.equals(lhsType) && PsiType.SHORT.equals(rhsType)) {
    registerError(expression);
  }
}
项目:intellij-ce-playground    文件:FloatingPointEqualityInspection.java   
@Override
public void visitBinaryExpression(@NotNull PsiBinaryExpression expression) {
  super.visitBinaryExpression(expression);
  final PsiExpression rhs = expression.getROperand();
  if (rhs == null) {
    return;
  }
  if (!ComparisonUtils.isEqualityComparison(expression)) {
    return;
  }
  final PsiExpression lhs = expression.getLOperand();
  if (!TypeUtils.hasFloatingPointType(lhs) && !TypeUtils.hasFloatingPointType(rhs)) {
    return;
  }
  if (isInfinityOrZero(lhs) || isInfinityOrZero(rhs)) {
    return;
  }
  registerError(expression);
}
项目:intellij-ce-playground    文件:FlipComparisonIntention.java   
public String getTextForElement(PsiElement element) {
  String operatorText = "";
  String flippedOperatorText = "";
  final PsiBinaryExpression expression = (PsiBinaryExpression)element;
  if (expression != null) {
    final PsiJavaToken sign = expression.getOperationSign();
    operatorText = sign.getText();
    flippedOperatorText =
      ComparisonUtils.getFlippedComparison(sign.getTokenType());
  }
  if (operatorText.equals(flippedOperatorText)) {
    return IntentionPowerPackBundle.message("flip.smth.intention.name",
                                            operatorText);
  }
  else {
    return IntentionPowerPackBundle.message(
      "flip.comparison.intention.name",
      operatorText, flippedOperatorText);
  }
}
项目:intellij-ce-playground    文件:NegateComparisonIntention.java   
public String getTextForElement(PsiElement element) {
  String operatorText = "";
  String negatedOperatorText = "";
  final PsiBinaryExpression exp = (PsiBinaryExpression)element;
  if (exp != null) {
    final PsiJavaToken sign = exp.getOperationSign();
    operatorText = sign.getText();
    negatedOperatorText =
      ComparisonUtils.getNegatedComparison(sign.getTokenType());
  }
  if (operatorText.equals(negatedOperatorText)) {
    return IntentionPowerPackBundle.message(
      "negate.comparison.intention.name", operatorText);
  }
  else {
    return IntentionPowerPackBundle.message(
      "negate.comparison.intention.name1", operatorText,
      negatedOperatorText);
  }
}
项目:tools-idea    文件:StringEqualityInspection.java   
@Override
public void visitBinaryExpression(@NotNull PsiBinaryExpression expression) {
  super.visitBinaryExpression(expression);
  if (!ComparisonUtils.isEqualityComparison(expression)) {
    return;
  }
  final PsiExpression lhs = expression.getLOperand();
  if (!ExpressionUtils.hasStringType(lhs)) {
    return;
  }
  final PsiExpression rhs = expression.getROperand();
  if (rhs == null || !ExpressionUtils.hasStringType(rhs)) {
    return;
  }
  final String lhsText = lhs.getText();
  if (PsiKeyword.NULL.equals(lhsText)) {
    return;
  }
  final String rhsText = rhs.getText();
  if (PsiKeyword.NULL.equals(rhsText)) {
    return;
  }
  final PsiJavaToken sign = expression.getOperationSign();
  registerError(sign);
}
项目:tools-idea    文件:ConstantOnRHSOfComparisonInspection.java   
@Override
public void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
  final PsiBinaryExpression expression = (PsiBinaryExpression)descriptor.getPsiElement();
  final PsiExpression rhs = expression.getROperand();
  if (rhs == null) {
    return;
  }
  final String flippedComparison = ComparisonUtils.getFlippedComparison(expression.getOperationTokenType());
  if (flippedComparison == null) {
    return;
  }
  final PsiExpression lhs = expression.getLOperand();
  final String rhsText = rhs.getText();
  final String lhsText = lhs.getText();
  replaceExpression(expression, rhsText + ' ' + flippedComparison + ' ' + lhsText);
}
项目:tools-idea    文件:ConstantOnLHSOfComparisonInspection.java   
@Override
public void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
  final PsiBinaryExpression expression = (PsiBinaryExpression)descriptor.getPsiElement();
  final PsiExpression rhs = expression.getROperand();
  if (rhs == null) {
    return;
  }
  final String flippedComparison = ComparisonUtils.getFlippedComparison(expression.getOperationTokenType());
  if (flippedComparison == null) {
    return;
  }
  final PsiExpression lhs = expression.getLOperand();
  final String rhsText = rhs.getText();
  final String lhsText = lhs.getText();
  replaceExpression(expression, rhsText + ' ' + flippedComparison + ' ' + lhsText);
}
项目:tools-idea    文件:CharacterComparisonInspection.java   
@Override
public void visitBinaryExpression(@NotNull PsiBinaryExpression expression) {
  super.visitBinaryExpression(expression);
  final PsiExpression rhs = expression.getROperand();
  if (!ComparisonUtils.isComparison(expression) || ComparisonUtils.isEqualityComparison(expression)) {
    return;
  }
  final PsiExpression lhs = expression.getLOperand();
  if (!isCharacter(lhs) || !isCharacter(rhs)) {
    return;
  }
  if (NonNlsUtils.isNonNlsAnnotated(lhs) || NonNlsUtils.isNonNlsAnnotated(rhs)) {
    return;
  }
  registerError(expression);
}
项目:tools-idea    文件:BadOddnessInspection.java   
@Override
public void visitBinaryExpression(
  @NotNull PsiBinaryExpression expression) {
  super.visitBinaryExpression(expression);
  if (expression.getROperand() == null) {
    return;
  }
  if (!ComparisonUtils.isEqualityComparison(expression)) {
    return;
  }
  final PsiExpression lhs = expression.getLOperand();
  final PsiExpression rhs = expression.getROperand();
  if (isModTwo(lhs) && hasValue(rhs, 1)) {
    registerError(expression, expression);
  }
  if (isModTwo(rhs) && hasValue(lhs, 1)) {
    registerError(expression, expression);
  }
}
项目:tools-idea    文件:BadOddnessInspection.java   
private static boolean isModTwo(PsiExpression exp) {
  if (!(exp instanceof PsiBinaryExpression)) {
    return false;
  }
  final PsiBinaryExpression binary = (PsiBinaryExpression)exp;
  final IElementType tokenType = binary.getOperationTokenType();
  if (!JavaTokenType.PERC.equals(tokenType)) {
    return false;
  }
  final PsiExpression rhs = binary.getROperand();
  final PsiExpression lhs = binary.getLOperand();
  if (rhs == null) {
    return false;
  }
  return hasValue(rhs, 2) || hasValue(lhs, 2);
}
项目:tools-idea    文件:ComparisonOfShortAndCharInspection.java   
@Override
public void visitBinaryExpression(@NotNull PsiBinaryExpression expression) {
  super.visitBinaryExpression(expression);
  if (!ComparisonUtils.isEqualityComparison(expression)) {
    return;
  }
  final PsiExpression lhs = expression.getLOperand();
  final PsiType lhsType = lhs.getType();
  final PsiExpression rhs = expression.getROperand();
  if (rhs == null) {
    return;
  }
  final PsiType rhsType = rhs.getType();
  if (PsiType.SHORT.equals(lhsType) && PsiType.CHAR.equals(rhsType)) {
    registerError(expression);
  }
  else if (PsiType.CHAR.equals(lhsType) && PsiType.SHORT.equals(rhsType)) {
    registerError(expression);
  }
}
项目:tools-idea    文件:FloatingPointEqualityInspection.java   
@Override
public void visitBinaryExpression(@NotNull PsiBinaryExpression expression) {
  super.visitBinaryExpression(expression);
  final PsiExpression rhs = expression.getROperand();
  if (rhs == null) {
    return;
  }
  if (!ComparisonUtils.isEqualityComparison(expression)) {
    return;
  }
  final PsiExpression lhs = expression.getLOperand();
  if (!TypeUtils.hasFloatingPointType(lhs) && !TypeUtils.hasFloatingPointType(rhs)) {
    return;
  }
  if (ExpressionUtils.isZero(lhs) || ExpressionUtils.isZero(rhs)) {
    return;
  }
  registerError(expression);
}
项目:tools-idea    文件:FlipComparisonIntention.java   
public String getTextForElement(PsiElement element) {
  String operatorText = "";
  String flippedOperatorText = "";
  final PsiBinaryExpression expression = (PsiBinaryExpression)element;
  if (expression != null) {
    final PsiJavaToken sign = expression.getOperationSign();
    operatorText = sign.getText();
    flippedOperatorText =
      ComparisonUtils.getFlippedComparison(sign);
  }
  if (operatorText.equals(flippedOperatorText)) {
    return IntentionPowerPackBundle.message("flip.smth.intention.name",
                                            operatorText);
  }
  else {
    return IntentionPowerPackBundle.message(
      "flip.comparison.intention.name",
      operatorText, flippedOperatorText);
  }
}
项目:tools-idea    文件:NegateComparisonIntention.java   
public String getTextForElement(PsiElement element) {
  String operatorText = "";
  String negatedOperatorText = "";
  final PsiBinaryExpression exp = (PsiBinaryExpression)element;
  if (exp != null) {
    final PsiJavaToken sign = exp.getOperationSign();
    operatorText = sign.getText();
    negatedOperatorText =
      ComparisonUtils.getNegatedComparison(sign.getTokenType());
  }
  if (operatorText.equals(negatedOperatorText)) {
    return IntentionPowerPackBundle.message(
      "negate.comparison.intention.name", operatorText);
  }
  else {
    return IntentionPowerPackBundle.message(
      "negate.comparison.intention.name1", operatorText,
      negatedOperatorText);
  }
}
项目:consulo-java    文件:FlipComparisonIntention.java   
public String getTextForElement(PsiElement element)
{
    String operatorText = "";
    String flippedOperatorText = "";
    final PsiBinaryExpression expression = (PsiBinaryExpression) element;
    if(expression != null)
    {
        final PsiJavaToken sign = expression.getOperationSign();
        operatorText = sign.getText();
        flippedOperatorText = ComparisonUtils.getFlippedComparison(sign.getTokenType());
    }
    if(operatorText.equals(flippedOperatorText))
    {
        return IntentionPowerPackBundle.message("flip.smth.intention.name", operatorText);
    }
    else
    {
        return IntentionPowerPackBundle.message("flip.comparison.intention.name", operatorText, flippedOperatorText);
    }
}
项目:consulo-java    文件:NegateComparisonIntention.java   
public String getTextForElement(PsiElement element) {
  String operatorText = "";
  String negatedOperatorText = "";
  final PsiBinaryExpression exp = (PsiBinaryExpression)element;
  if (exp != null) {
    final PsiJavaToken sign = exp.getOperationSign();
    operatorText = sign.getText();
    negatedOperatorText =
      ComparisonUtils.getNegatedComparison(sign.getTokenType());
  }
  if (operatorText.equals(negatedOperatorText)) {
    return IntentionPowerPackBundle.message(
      "negate.comparison.intention.name", operatorText);
  }
  else {
    return IntentionPowerPackBundle.message(
      "negate.comparison.intention.name1", operatorText,
      negatedOperatorText);
  }
}
项目:consulo-java    文件:ConstantOnRHSOfComparisonInspection.java   
@Override
public void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
  final PsiBinaryExpression expression = (PsiBinaryExpression)descriptor.getPsiElement();
  final PsiExpression rhs = expression.getROperand();
  if (rhs == null) {
    return;
  }
  final String flippedComparison = ComparisonUtils.getFlippedComparison(expression.getOperationTokenType());
  if (flippedComparison == null) {
    return;
  }
  final PsiExpression lhs = expression.getLOperand();
  final String rhsText = rhs.getText();
  final String lhsText = lhs.getText();
  replaceExpression(expression, rhsText + ' ' + flippedComparison + ' ' + lhsText);
}
项目:consulo-java    文件:ConstantOnLHSOfComparisonInspection.java   
@Override
public void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
  final PsiBinaryExpression expression = (PsiBinaryExpression)descriptor.getPsiElement();
  final PsiExpression rhs = expression.getROperand();
  if (rhs == null) {
    return;
  }
  final String flippedComparison = ComparisonUtils.getFlippedComparison(expression.getOperationTokenType());
  if (flippedComparison == null) {
    return;
  }
  final PsiExpression lhs = expression.getLOperand();
  final String rhsText = rhs.getText();
  final String lhsText = lhs.getText();
  replaceExpression(expression, rhsText + ' ' + flippedComparison + ' ' + lhsText);
}
项目:consulo-java    文件:CharacterComparisonInspection.java   
@Override
public void visitBinaryExpression(@NotNull PsiBinaryExpression expression) {
  super.visitBinaryExpression(expression);
  final PsiExpression rhs = expression.getROperand();
  if (!ComparisonUtils.isComparison(expression) || ComparisonUtils.isEqualityComparison(expression)) {
    return;
  }
  final PsiExpression lhs = expression.getLOperand();
  if (!isCharacter(lhs) || !isCharacter(rhs)) {
    return;
  }
  if (NonNlsUtils.isNonNlsAnnotated(lhs) || NonNlsUtils.isNonNlsAnnotated(rhs)) {
    return;
  }
  registerError(expression);
}
项目:consulo-java    文件:ComparisonOfShortAndCharInspection.java   
@Override
public void visitBinaryExpression(@NotNull PsiBinaryExpression expression) {
  super.visitBinaryExpression(expression);
  if (!ComparisonUtils.isEqualityComparison(expression)) {
    return;
  }
  final PsiExpression lhs = expression.getLOperand();
  final PsiType lhsType = lhs.getType();
  final PsiExpression rhs = expression.getROperand();
  if (rhs == null) {
    return;
  }
  final PsiType rhsType = rhs.getType();
  if (PsiType.SHORT.equals(lhsType) && PsiType.CHAR.equals(rhsType)) {
    registerError(expression);
  }
  else if (PsiType.CHAR.equals(lhsType) && PsiType.SHORT.equals(rhsType)) {
    registerError(expression);
  }
}
项目:consulo-java    文件:FloatingPointEqualityInspection.java   
@Override
public void visitBinaryExpression(@NotNull PsiBinaryExpression expression) {
  super.visitBinaryExpression(expression);
  final PsiExpression rhs = expression.getROperand();
  if (rhs == null) {
    return;
  }
  if (!ComparisonUtils.isEqualityComparison(expression)) {
    return;
  }
  final PsiExpression lhs = expression.getLOperand();
  if (!TypeUtils.hasFloatingPointType(lhs) && !TypeUtils.hasFloatingPointType(rhs)) {
    return;
  }
  if (ExpressionUtils.isZero(lhs) || ExpressionUtils.isZero(rhs)) {
    return;
  }
  registerError(expression);
}
项目:intellij-ce-playground    文件:PsiBinaryExpressionPattern.java   
public PsiBinaryExpressionPattern left(@NotNull final ElementPattern pattern) {
  return with(new PatternCondition<PsiBinaryExpression>("left") {
    public boolean accepts(@NotNull final PsiBinaryExpression psiBinaryExpression, final ProcessingContext context) {
      return pattern.accepts(psiBinaryExpression.getLOperand(), context);
    }
  });
}
项目:intellij-ce-playground    文件:PsiBinaryExpressionPattern.java   
public PsiBinaryExpressionPattern right(@NotNull final ElementPattern pattern) {
  return with(new PatternCondition<PsiBinaryExpression>("right") {
    public boolean accepts(@NotNull final PsiBinaryExpression psiBinaryExpression, final ProcessingContext context) {
      return pattern.accepts(psiBinaryExpression.getROperand(), context);
    }
  });
}
项目:intellij-ce-playground    文件:PsiBinaryExpressionPattern.java   
public PsiBinaryExpressionPattern operation(final ElementPattern pattern) {
  return with(new PatternCondition<PsiBinaryExpression>("operation") {
    public boolean accepts(@NotNull final PsiBinaryExpression psiBinaryExpression, final ProcessingContext context) {
      return pattern.accepts(psiBinaryExpression.getOperationSign(), context);
    }
  });
}
项目:intellij-ce-playground    文件:JavaJspRecursiveElementVisitor.java   
@Override
public void visitElement(PsiElement element) {
  if (!myRefExprsInVisit.isEmpty() && myRefExprsInVisit.peek() == element) {
    myRefExprsInVisit.pop();
    myRefExprsInVisit.push(null);
  }
  else if (element instanceof PsiBinaryExpression) {
    //implement smart traversing to avoid stack overflow
    if (!myBinaryExpressions.isEmpty() && myBinaryExpressions.peek() == element) {
      return;
    }
    PsiElement child = element.getFirstChild();
    while (child != null) {
      if (child instanceof PsiBinaryExpression) {
        myBinaryExpressions.push((PsiBinaryExpression)child);
      }
      child.accept(this);
      child = child.getNextSibling();
      if (child == null) {
        child = myBinaryExpressions.isEmpty() ? null : myBinaryExpressions.pop();
        if (child != null) child = child.getFirstChild();
      }
    }
  }
  else {
    element.acceptChildren(this);
  }
}
项目:intellij-ce-playground    文件:ConstantOnRHSOfComparisonInspection.java   
@Override
public void visitBinaryExpression(@NotNull PsiBinaryExpression expression) {
  super.visitBinaryExpression(expression);
  if (!ComparisonUtils.isComparison(expression)) {
    return;
  }
  final PsiExpression lhs = expression.getLOperand();
  final PsiExpression rhs = expression.getROperand();
  if (!isConstantExpression(rhs) || isConstantExpression(lhs)) {
    return;
  }
  registerError(expression);
}
项目:intellij-ce-playground    文件:ConstantOnLHSOfComparisonInspection.java   
@Override
public void visitBinaryExpression(@NotNull PsiBinaryExpression expression) {
  super.visitBinaryExpression(expression);
  if (!ComparisonUtils.isComparison(expression)) {
    return;
  }
  final PsiExpression lhs = expression.getLOperand();
  final PsiExpression rhs = expression.getROperand();
  if (rhs == null || !isConstantExpression(lhs) || isConstantExpression(rhs)) {
    return;
  }
  registerError(expression);
}
项目:intellij-ce-playground    文件:BooleanExpressionMayBeConditionalInspection.java   
@Override
protected void doFix(Project project, ProblemDescriptor descriptor)  {
  final PsiElement element = descriptor.getPsiElement();
  if (!(element instanceof PsiBinaryExpression)) {
    return;
  }
  final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)element;
  final PsiExpression lhs = ParenthesesUtils.stripParentheses(binaryExpression.getLOperand());
  final PsiExpression rhs = ParenthesesUtils.stripParentheses(binaryExpression.getROperand());
  if (!(lhs instanceof PsiBinaryExpression) || !(rhs instanceof PsiBinaryExpression)) {
    return;
  }
  final PsiBinaryExpression lBinaryExpression = (PsiBinaryExpression)lhs;
  final PsiBinaryExpression rBinaryExpression = (PsiBinaryExpression)rhs;
  final PsiExpression llhs = ParenthesesUtils.stripParentheses(lBinaryExpression.getLOperand());
  final PsiExpression lrhs = ParenthesesUtils.stripParentheses(rBinaryExpression.getLOperand());
  if (llhs == null || lrhs == null) {
    return;
  }
  final PsiExpression thenExpression = ParenthesesUtils.stripParentheses(lBinaryExpression.getROperand());
  final PsiExpression elseExpression = ParenthesesUtils.stripParentheses(rBinaryExpression.getROperand());
  if (thenExpression == null || elseExpression == null) {
    return;
  }
  if (BoolUtils.isNegation(llhs) ) {
    PsiReplacementUtil.replaceExpression(binaryExpression,
                                         getText(lrhs) + '?' + getText(elseExpression) + ':' + getText(thenExpression));
  }
  else {
    PsiReplacementUtil.replaceExpression(binaryExpression,
                                         getText(llhs) + '?' + getText(thenExpression) + ':' + getText(elseExpression));
  }
}
项目:intellij-ce-playground    文件:BooleanExpressionMayBeConditionalInspection.java   
@Override
public void visitBinaryExpression(PsiBinaryExpression expression) {
  super.visitBinaryExpression(expression);
  final IElementType tokenType = expression.getOperationTokenType();
  if (!JavaTokenType.OROR.equals(tokenType)) {
    return;
  }
  final PsiExpression lhs = ParenthesesUtils.stripParentheses(expression.getLOperand());
  final PsiExpression rhs = ParenthesesUtils.stripParentheses(expression.getROperand());
  if (!(lhs instanceof PsiBinaryExpression) || !(rhs instanceof PsiBinaryExpression)) {
    return;
  }
  final PsiBinaryExpression lBinaryExpression = (PsiBinaryExpression)lhs;
  final PsiBinaryExpression rBinaryExpression = (PsiBinaryExpression)rhs;
  final IElementType lTokenType = lBinaryExpression.getOperationTokenType();
  final IElementType rTokenType = rBinaryExpression.getOperationTokenType();
  if (!JavaTokenType.ANDAND.equals(lTokenType) || !JavaTokenType.ANDAND.equals(rTokenType)) {
    return;
  }
  final PsiExpression expression1 = ParenthesesUtils.stripParentheses(lBinaryExpression.getLOperand());
  final PsiExpression expression2 = ParenthesesUtils.stripParentheses(rBinaryExpression.getLOperand());
  if (expression1 == null || expression2 == null ||
      ParenthesesUtils.stripParentheses(lBinaryExpression.getROperand()) == null ||
      ParenthesesUtils.stripParentheses(rBinaryExpression.getROperand()) == null) {
    return;
  }
  if (EquivalenceChecker.expressionsAreEquivalent(BoolUtils.getNegated(expression1), expression2) &&
      !SideEffectChecker.mayHaveSideEffects(expression2)) {
    registerError(expression);
  }
  else if (EquivalenceChecker.expressionsAreEquivalent(expression1, BoolUtils.getNegated(expression2)) &&
           !SideEffectChecker.mayHaveSideEffects(expression1)) {
    registerError(expression);
  }
}
项目:intellij-ce-playground    文件:ComparisonPredicate.java   
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);
}
项目:tools-idea    文件:PsiBinaryExpressionPattern.java   
public PsiBinaryExpressionPattern left(@NotNull final ElementPattern pattern) {
  return with(new PatternCondition<PsiBinaryExpression>("left") {
    public boolean accepts(@NotNull final PsiBinaryExpression psiBinaryExpression, final ProcessingContext context) {
      return pattern.getCondition().accepts(psiBinaryExpression.getLOperand(), context);
    }
  });
}
项目:tools-idea    文件:PsiBinaryExpressionPattern.java   
public PsiBinaryExpressionPattern right(@NotNull final ElementPattern pattern) {
  return with(new PatternCondition<PsiBinaryExpression>("right") {
    public boolean accepts(@NotNull final PsiBinaryExpression psiBinaryExpression, final ProcessingContext context) {
      return pattern.getCondition().accepts(psiBinaryExpression.getROperand(), context);
    }
  });
}
项目:tools-idea    文件:PsiBinaryExpressionPattern.java   
public PsiBinaryExpressionPattern operation(final ElementPattern pattern) {
  return with(new PatternCondition<PsiBinaryExpression>("operation") {
    public boolean accepts(@NotNull final PsiBinaryExpression psiBinaryExpression, final ProcessingContext context) {
      return pattern.getCondition().accepts(psiBinaryExpression.getOperationSign(), context);
    }
  });
}
项目:tools-idea    文件:JavaJspRecursiveElementVisitor.java   
@Override
public void visitElement(PsiElement element) {
  if (!myRefExprsInVisit.isEmpty() && myRefExprsInVisit.peek() == element) {
    myRefExprsInVisit.pop();
    myRefExprsInVisit.push(null);
  }
  else if (element instanceof PsiBinaryExpression) {
    //implement smart traversing to avoid stack overflow
    if (!myBinaryExpressions.isEmpty() && myBinaryExpressions.peek() == element) {
      return;
    }
    PsiElement child = element.getFirstChild();
    while (child != null) {
      if (child instanceof PsiBinaryExpression) {
        myBinaryExpressions.push((PsiBinaryExpression)child);
      }
      child.accept(this);
      child = child.getNextSibling();
      if (child == null) {
        child = myBinaryExpressions.isEmpty() ? null : myBinaryExpressions.pop();
        if (child != null) child = child.getFirstChild();
      }
    }
  }
  else {
    element.acceptChildren(this);
  }
}