Java 类com.intellij.lang.javascript.psi.JSBinaryExpression 实例源码

项目:consulo-javascript    文件:SubBlockVisitor.java   
@Nullable
private static Alignment alignmentProjection(final Alignment defaultAlignment, final ASTNode parent, final ASTNode child)
{
    if(parent.getElementType() == JSElementTypes.FOR_STATEMENT && (JSElementTypes.EXPRESSIONS.contains(child.getElementType()) || child.getElementType
            () == JSElementTypes.VAR_STATEMENT))
    {
        return defaultAlignment;
    }
    else if(parent.getElementType() == JSElementTypes.PARAMETER_LIST && child.getElementType() == JSElementTypes.FORMAL_PARAMETER)
    {
        return defaultAlignment;
    }
    else if(parent.getPsi() instanceof JSBinaryExpression && JSElementTypes.EXPRESSIONS.contains(child.getElementType()))
    {
        return defaultAlignment;
    }
    else if(parent.getElementType() == JSElementTypes.CONDITIONAL_EXPRESSION && JSElementTypes.EXPRESSIONS.contains(child.getElementType()))
    {
        return defaultAlignment;
    }

    return null;
}
项目:consulo-javascript    文件:OverlyComplexBooleanExpressionJSInspection.java   
private int countTerms(JSExpression expression) {
    if (expression == null) {
        return 0;
    }
    if (!isBoolean(expression)) {
        return 1;
    }
    if (expression instanceof JSBinaryExpression) {
        final JSBinaryExpression binaryExpression = (JSBinaryExpression) expression;
        final JSExpression lhs = binaryExpression.getLOperand();
        final JSExpression rhs = binaryExpression.getROperand();
        return countTerms(lhs) + countTerms(rhs);
    } else if (expression instanceof JSPrefixExpression) {
        final JSPrefixExpression prefixExpression = (JSPrefixExpression) expression;
        final JSExpression operand = prefixExpression.getExpression();
        return countTerms(operand);
    } else if (expression instanceof JSParenthesizedExpression) {
        final JSParenthesizedExpression parenthesizedExpression = (JSParenthesizedExpression) expression;
        final JSExpression contents = parenthesizedExpression.getInnerExpression();
        return countTerms(contents);
    }
    return 1;
}
项目:consulo-javascript    文件:EqualityComparisonWithCoercionJSInspection.java   
@Override public void visitJSBinaryExpression(
            @NotNull JSBinaryExpression expression) {
        super.visitJSBinaryExpression(expression);
        final JSExpression lhs = expression.getLOperand();
        if (lhs == null) {
            return;
        }
        final JSExpression rhs = expression.getROperand();
        if (rhs == null) {
            return;
        }
        final IElementType tokenType = expression.getOperationSign();
        if (!JSTokenTypes.EQEQ.equals(tokenType) &&
                !JSTokenTypes.NE.equals(tokenType)) {
            return;
        }
        if(!mayCauseCoercion(rhs) &&!mayCauseCoercion(lhs)) {
return;
        }
        registerError(expression);
    }
项目:consulo-javascript    文件:DivideByZeroJSInspection.java   
@Override public void visitJSBinaryExpression(
        @NotNull JSBinaryExpression expression) {
    super.visitJSBinaryExpression(expression);
    final JSExpression rhs = expression.getROperand();
    if (rhs == null) {
        return;
    }
    final IElementType tokenType = expression.getOperationSign();
    if (!JSTokenTypes.DIV.equals(tokenType) &&
            !JSTokenTypes.PERC.equals(tokenType)) {
        return;
    }
    if(!isZero(rhs))
    {
        return;
    }
    registerError(expression);
}
项目:consulo-javascript    文件:ConstantOnRHSOfComparisonJSInspection.java   
@Override public void visitJSBinaryExpression(@NotNull JSBinaryExpression expression) {
    super.visitJSBinaryExpression(expression);
    if (!(expression.getROperand() != null)) {
        return;
    }
    if (!ComparisonUtils.isComparison(expression)) {
        return;
    }
    final JSExpression lhs = expression.getLOperand();
    final JSExpression rhs = expression.getROperand();
    if (lhs instanceof JSLiteralExpression ||
            !(rhs instanceof JSLiteralExpression)) {
        return;
    }
    registerError(expression);
}
项目:consulo-javascript    文件:ConstantOnLHSOfComparisonJSInspection.java   
@Override public void visitJSBinaryExpression(@NotNull JSBinaryExpression expression) {
    super.visitJSBinaryExpression(expression);
    if (!(expression.getROperand() != null)) {
        return;
    }
    if (!ComparisonUtils.isComparison(expression)) {
        return;
    }
    final JSExpression lhs = expression.getLOperand();
    final JSExpression rhs = expression.getROperand();
    if (!(lhs instanceof JSLiteralExpression) ||
            rhs instanceof JSLiteralExpression) {
        return;
    }
    registerError(expression);
}
项目:consulo-javascript    文件:ChainedEqualityJSInspection.java   
@Override public void visitJSBinaryExpression(
        @NotNull JSBinaryExpression expression) {
    super.visitJSBinaryExpression(expression);
    if (!(expression.getROperand() != null)) {
        return;
    }
    if (!isEqualityComparison(expression)) {
        return;
    }
    final JSExpression lhs = expression.getLOperand();
    if (!(lhs instanceof JSBinaryExpression)) {
        return;
    }
    if (!isEqualityComparison((JSBinaryExpression) lhs)) {
        return;
    }
    registerError(expression);
}
项目:consulo-javascript    文件:IncompatibleMaskJSInspection.java   
private static boolean isConstantMask(JSExpression expression) {
    if (expression == null) {
        return false;
    }
    if (!(expression instanceof JSBinaryExpression)) {
        return false;
    }
    final JSBinaryExpression binaryExpression =
            (JSBinaryExpression) expression;
    final IElementType tokenType = binaryExpression.getOperationSign();
    if (!JSTokenTypes.OR.equals(tokenType) &&
            !JSTokenTypes.AND.equals(tokenType)) {
        return false;
    }
    final JSExpression rhs = binaryExpression.getROperand();
    if (ExpressionUtil.isConstantExpression(rhs)) {
        return true;
    }
    final JSExpression lhs = binaryExpression.getLOperand();
    return ExpressionUtil.isConstantExpression(lhs);
}
项目:consulo-javascript    文件:RecursionUtil.java   
private static boolean binaryExpressionDefinitelyRecurses(
        JSBinaryExpression expression, JSFunction method) {
    final JSExpression lhs = expression.getLOperand();

    if (RecursionUtil.expressionDefinitelyRecurses(lhs, method)) {
        return true;
    }

    final IElementType tokenType = expression.getOperationSign();

    if (tokenType.equals(JSTokenTypes.ANDAND) ||
        tokenType.equals(JSTokenTypes.OROR)) {
        return false;
    }

    return RecursionUtil.expressionDefinitelyRecurses(expression.getROperand(), method);
}
项目:consulo-javascript    文件:BoolUtils.java   
public static JSExpression getNegated(JSExpression condition) {
    if (condition instanceof JSPrefixExpression) {
        final JSPrefixExpression prefixExp = (JSPrefixExpression) condition;
        final JSExpression       operand   = prefixExp.getExpression();

        return ParenthesesUtils.stripParentheses(operand);
    } else if (condition instanceof JSBinaryExpression) {
        final JSBinaryExpression binaryExpression = (JSBinaryExpression) condition;
        final IElementType sign        = binaryExpression.getOperationSign();
        final JSExpression lhs         = binaryExpression.getLOperand();
        final JSExpression rhs         = binaryExpression.getROperand();
        final String       negatedSign = ComparisonUtils.getNegatedOperatorText(sign);
        final String       negatedText = lhs.getText() + negatedSign + rhs.getText();

        return (JSExpression) JSChangeUtil.createExpressionFromText(
          condition.getProject(),
          negatedText);
    } else if (condition instanceof JSParenthesizedExpression) {
        return getNegated(((JSParenthesizedExpression) condition).getInnerExpression());
    }
    return condition;
}
项目:consulo-javascript    文件:JSConstantSubexpressionIntention.java   
@Override
protected String getTextForElement(PsiElement element) {
       final PsiElement         parent           = element.getParent();
       final JSBinaryExpression binaryExpression = (JSBinaryExpression) (parent instanceof JSBinaryExpression ? parent : element);
       final JSExpression       lhs              = binaryExpression.getLOperand();
       final JSExpression       leftSide;

       if (lhs instanceof JSBinaryExpression) {
           leftSide = ((JSBinaryExpression) lhs).getROperand();
       } else {
           leftSide = lhs;
       }
       final IElementType operationSign = binaryExpression.getOperationSign();
       final JSExpression rhs           = binaryExpression.getROperand();

       assert (rhs != null);
       assert (leftSide != null);

       return this.getText(leftSide.getText(), BinaryOperatorUtils.getOperatorText(operationSign), rhs.getText());
   }
项目:consulo-javascript    文件:JSFlipComparisonIntention.java   
@Override
public String getTextForElement(PsiElement element) {
       final JSBinaryExpression exp                 = (JSBinaryExpression) element;
       String                   operatorText        = null;
       String                   flippedOperatorText = null;

       if (exp != null) {
           operatorText        = ComparisonUtils.getOperatorText       (exp.getOperationSign());
           flippedOperatorText = ComparisonUtils.getFlippedOperatorText(exp.getOperationSign());
       }

       if (exp == null) {
           return this.getSuffixedDisplayName("unknown");
       } else if (operatorText.equals(flippedOperatorText)) {
           return this.getSuffixedDisplayName("equals", operatorText);
       } else {
           return this.getSuffixedDisplayName("not-equals", operatorText, flippedOperatorText);
       }
   }
项目:consulo-javascript    文件:JSRemoveBooleanEqualityIntention.java   
@Override
public boolean satisfiedBy(@NotNull PsiElement element) {
          if (!(element instanceof JSBinaryExpression)) {
              return false;
          }
          if (ErrorUtil.containsError(element)) {
              return false;
          }

          final JSBinaryExpression expression = (JSBinaryExpression) element;
          final IElementType       sign       = expression.getOperationSign();

          if (!(sign.equals(JSTokenTypes.EQEQ) || sign.equals(JSTokenTypes.NE))) {
              return false;
          }

          final JSExpression lhs = expression.getLOperand();
          final JSExpression rhs = expression.getROperand();

          return (lhs != null && rhs != null &&
                  (BoolUtils.isBooleanLiteral(lhs) || BoolUtils.isBooleanLiteral(rhs)));
      }
项目:consulo-javascript    文件:JSNegateComparisonIntention.java   
@Override
public String getTextForElement(PsiElement element) {
       final JSBinaryExpression expression          = (JSBinaryExpression) element;
       String                   operatorText        = "";
       String                   negatedOperatorText = "";

       if (expression != null) {
           final IElementType sign = expression.getOperationSign();

           operatorText        = ComparisonUtils.getOperatorText(sign);
           negatedOperatorText = ComparisonUtils.getNegatedOperatorText(sign);
       }

       if (operatorText.equals(negatedOperatorText)) {
           return this.getSuffixedDisplayName("equals", operatorText);
       } else {
           return this.getSuffixedDisplayName("not-equals", operatorText, negatedOperatorText);
       }
   }
项目:consulo-javascript    文件:ComparisonPredicate.java   
@Override
public boolean satisfiedBy(@NotNull PsiElement element) {
       if (!(element instanceof JSBinaryExpression)) {
           return false;
       }
       if (ErrorUtil.containsError(element)) {
           return false;
       }

       final JSBinaryExpression expression = (JSBinaryExpression) element;
       final JSExpression       rhs        = expression.getROperand();

       return (rhs != null &&
               ComparisonUtils.isComparisonOperator((JSExpression) element));

   }
项目:consulo-javascript    文件:JSJoinConcatenatedStringLiteralsIntention.java   
@Override
public void processIntention(@NotNull PsiElement element)
           throws IncorrectOperationException {
       final JSBinaryExpression expression = (JSBinaryExpression) element;
       final JSExpression       lhs        = expression.getLOperand();
       final JSExpression       rhs        = expression.getROperand();

       assert (lhs instanceof JSLiteralExpression && rhs instanceof JSLiteralExpression);

       final JSLiteralExpression  leftLiteral  = (JSLiteralExpression) lhs;
       final JSLiteralExpression  rightLiteral = (JSLiteralExpression) rhs;
       String                     lhsText      = lhs.getText();
       String                     rhsText      = rhs.getText();
       final String               newExpression;

       if (StringUtil.isSimpleQuoteStringLiteral(leftLiteral) &&
           StringUtil.isDoubleQuoteStringLiteral(rightLiteral)) {
           rhsText = JSDoubleToSingleQuotedStringIntention.changeQuotes(rhsText);
       } else if (StringUtil.isDoubleQuoteStringLiteral(leftLiteral) &&
                  StringUtil.isSimpleQuoteStringLiteral(rightLiteral)) {
           rhsText = JSSingleToDoubleQuotedStringIntention.changeQuotes(rhsText);
       }

       newExpression = lhsText.substring(0, lhsText.length() - 1) + rhsText.substring(1);
       JSElementFactory.replaceExpression(expression, newExpression);
   }
项目:consulo-javascript    文件:JSJoinConcatenatedStringLiteralsIntention.java   
@Override
public boolean satisfiedBy(@NotNull PsiElement element) {
          if (!(element instanceof JSBinaryExpression)) {
              return false;
          }

          final JSBinaryExpression expression = (JSBinaryExpression) element;
          final IElementType       sign       = expression.getOperationSign();

          if (!sign.equals(JSTokenTypes.PLUS)) {
              return false;
          }
          final JSExpression lhs = expression.getLOperand();
          final JSExpression rhs = expression.getROperand();

          if (!isApplicableLiteral(lhs)) {
              return false;
          }
          if (!isApplicableLiteral(rhs)) {
              return false;
          }

          return true;
      }
项目:consulo-javascript    文件:JSReplaceMultiplyWithShiftIntention.java   
private void replaceMultiplyOrDivideWithShift(JSBinaryExpression exp)
        throws IncorrectOperationException {
    JSExpression       lhs            = exp.getLOperand();
    JSExpression       rhs            = exp.getROperand();
    final IElementType tokenType      = exp.getOperationSign();
    final String       operatorString = (tokenType.equals(JSTokenTypes.MULT) ? "<<" : ">>");

    if (ShiftUtils.isPowerOfTwo(lhs) && tokenType.equals(JSTokenTypes.MULT)) {
        JSExpression  swap = lhs;

        lhs = rhs;
        rhs = swap;
    }

    final String     lhsText   = ParenthesesUtils.getParenthesized(lhs, ParenthesesUtils.SHIFT_PRECENDENCE);
    String           expString = lhsText + operatorString + ShiftUtils.getLogBase2(rhs);
    final  JSElement parent    = (JSElement) exp.getParent();

    if (parent != null && parent instanceof JSExpression) {
        if (!(parent instanceof JSParenthesizedExpression)  &&
            ParenthesesUtils.getPrecendence((JSExpression) parent) < ParenthesesUtils.SHIFT_PRECENDENCE) {
            expString = '(' + expString + ')';
        }
    }
    JSElementFactory.replaceExpression(exp, expString);
}
项目:consulo-javascript    文件:JSReplaceShiftWithMultiplyIntention.java   
private void replaceShiftWithMultiplyOrDivide(JSBinaryExpression exp)
        throws IncorrectOperationException {
    final JSExpression  lhs            = exp.getLOperand();
    final JSExpression  rhs            = exp.getROperand();
    final IElementType  tokenType      = exp.getOperationSign();
    final String        operatorString = ((tokenType.equals(JSTokenTypes.LTLT)) ? "*" : "/");
    final String        lhsText        = ParenthesesUtils.getParenthesized(lhs, ParenthesesUtils.MULTIPLICATIVE_PRECENDENCE);
    String              expString      = lhsText + operatorString + ShiftUtils.getExpBase2(rhs);
    final JSElement     parent         = (JSElement) exp.getParent();

    if (parent != null && parent instanceof JSExpression) {
        if (!(parent instanceof JSParenthesizedExpression)  &&
            ParenthesesUtils.getPrecendence((JSExpression) parent) < ParenthesesUtils.MULTIPLICATIVE_PRECENDENCE) {
            expString = '(' + expString + ')';
        }
    }
    JSElementFactory.replaceExpression(exp, expString);
}
项目:consulo-javascript    文件:JSReplaceWithOperatorAssignmentIntention.java   
@Override
public void processIntention(@NotNull PsiElement element) throws IncorrectOperationException {
       final JSAssignmentExpression exp = (JSAssignmentExpression) element;
       final JSBinaryExpression     rhs = (JSBinaryExpression) exp.getROperand();
       final JSExpression           lhs = exp.getLOperand();

       assert (rhs != null);

       final IElementType  sign    = rhs.getOperationSign();
       final String        operand = BinaryOperatorUtils.getOperatorText(sign);
       final JSExpression  rhsrhs  = rhs.getROperand();

       assert (rhsrhs != null);

       JSElementFactory.replaceExpression(exp, lhs.getText() + operand + '=' + rhsrhs.getText());
   }
项目:consulo-javascript    文件:JSSplitIfOrIntention.java   
@Override
public boolean satisfiedBy(@NotNull PsiElement element) {
          PsiElement parent = element.getParent();

          if (!(parent instanceof JSIfStatement)) {
              if (element instanceof JSIfStatement) {
                  parent = element;
              } else {
                  return false;
              }
          }

          final JSIfStatement ifStatement = (JSIfStatement) parent;
          final JSExpression  condition   = ifStatement.getCondition();

          if (condition == null || ErrorUtil.containsError(condition)) {
              return false;
          }

          return (condition instanceof JSBinaryExpression &&
                  ((JSBinaryExpression) condition).getOperationSign().equals(JSTokenTypes.OROR));
      }
项目:consulo-javascript    文件:JSSplitIfAndIntention.java   
@Override
public boolean satisfiedBy(@NotNull PsiElement element) {
          PsiElement parent = element.getParent();

          if (!(parent instanceof JSIfStatement)) {
              if (element instanceof JSIfStatement) {
                  parent = element;
              } else {
                  return false;
              }
          }

          final JSIfStatement ifStatement = (JSIfStatement) parent;
          final JSExpression  condition   = ifStatement.getCondition();

          if (condition == null || ErrorUtil.containsError(condition)) {
              return false;
          }

          return (condition instanceof JSBinaryExpression &&
                  ((JSBinaryExpression) condition).getOperationSign().equals(JSTokenTypes.ANDAND));
      }
项目:eslint-plugin    文件:NoNegatedInLhsActionFix.java   
@Override
    public void invoke(@NotNull Project project, @NotNull PsiFile psiFile, @Nullable("is null when called from inspection") Editor editor, @NotNull PsiElement element, @NotNull PsiElement end) throws IncorrectOperationException {
//        PsiElement element = descriptor.getPsiElement();
        JSBinaryExpression binary = PsiTreeUtil.getParentOfType(element, JSBinaryExpression.class);
        JSBinaryExpression binaryClone = (JSBinaryExpression) binary.copy();
        binaryClone.getLOperand().replace(binary.getLOperand().getLastChild());
        ASTNode negate = JSChangeUtil.createStatementFromText(project, "!(true)");
        JSParenthesizedExpression paren = PsiTreeUtil.getChildOfType(negate.getPsi().getFirstChild(), JSParenthesizedExpression.class);
        paren.getInnerExpression().replace(binaryClone);
        binary.replace(negate.getPsi());
    }
项目:eslint-plugin    文件:JSBinaryExpressionUtil.java   
public static ASTNode getOperator(PsiElement element) {
    PsiElement binary = PsiTreeUtil.findFirstParent(element, new Condition<PsiElement>() {
        @Override
        public boolean value(PsiElement psiElement) {
            return psiElement instanceof JSBinaryExpression;
        }
    });
    return binary == null ? null : binary.getNode().getChildren(BINARY_OPERATIONS)[0];
}
项目:consulo-javascript    文件:JSUtils.java   
public static boolean isNeedParenthesis(JSExpression oldExpr, JSExpression newExpr)
{
    int priority = getExpressionPrecedence(newExpr);
    final PsiElement parent = oldExpr.getParent();
    if(!(parent instanceof JSExpression))
    {
        return false;
    }
    int parentPriority = getExpressionPrecedence((JSExpression) parent);
    if(priority < parentPriority)
    {
        return true;
    }
    if(priority == parentPriority && parent instanceof JSBinaryExpression)
    {
        final IElementType operationSign = ((JSBinaryExpression) parent).getOperationSign();
        if(oldExpr != ((JSBinaryExpression) parent).getROperand())
        {
            return false;
        }
        if(!ASSOC_OPERATIONS.contains(operationSign))
        {
            return true;
        }

        return (((JSBinaryExpression) newExpr).getOperationSign() != operationSign);
    }

    return false;
}
项目:consulo-javascript    文件:JSDefinitionExpressionImpl.java   
@Override
public void delete() throws IncorrectOperationException
{
    final PsiElement parent = getParent();

    if(parent instanceof JSAssignmentExpression)
    {
        final PsiElement grandParent = parent.getParent();

        if(grandParent instanceof JSStatement)
        {
            grandParent.delete();
            return;
        }
        else if(grandParent instanceof JSBinaryExpression)
        {
            ((JSBinaryExpression) grandParent).getROperand().replace(((JSAssignmentExpression) parent).getROperand());
            return;
        }
        else if(grandParent instanceof JSVariable)
        {
            final JSExpression initializerExpression = ((JSVariable) grandParent).getInitializer();
            initializerExpression.replace(((JSAssignmentExpression) parent).getROperand());
            return;
        }
    }
    super.delete();
}
项目:consulo-javascript    文件:ReplaceAssignmentWithOperatorAssignmentJSInspection.java   
@Override public void visitJSAssignmentExpression(@NotNull JSAssignmentExpression assignment) {
    super.visitJSAssignmentExpression(assignment);

    final IElementType sign = assignment.getOperationSign();
    if (!JSTokenTypes.EQ.equals(sign)) {
        return;
    }
    JSExpression lhs = assignment.getLOperand();
    final JSExpression rhs = assignment.getROperand();
    if (rhs == null || lhs == null) {
        return;
    }
    if (!(rhs instanceof JSBinaryExpression)) {
        return;
    }
    final JSBinaryExpression binaryRhs = (JSBinaryExpression) rhs;
    if (!(binaryRhs.getROperand() != null)) {
        return;
    }
    IElementType operationSign = binaryRhs.getOperationSign();
    if (operationSign == JSTokenTypes.ANDAND ||
        operationSign == JSTokenTypes.OROR) {
        return;
    }
    final JSExpression lOperand = binaryRhs.getLOperand();
    if (SideEffectChecker.mayHaveSideEffects(lhs)) {
        return;
    }
    if(lhs instanceof JSDefinitionExpression)
    {
        lhs = ((JSDefinitionExpression)lhs).getExpression();
    }
    if (!EquivalenceChecker.expressionsAreEquivalent(lhs, lOperand)) {
        return;
    }
    registerError(assignment);
}
项目:consulo-javascript    文件:PointlessBooleanExpressionJSInspection.java   
@Override
public String buildErrorString(Object... args) {
       if ( args[0]instanceof JSBinaryExpression) {
           return InspectionJSBundle.message("pointless.boolean.error.string", calculateSimplifiedBinaryExpression((JSBinaryExpression) args[0]));
       } else {
           return InspectionJSBundle.message("pointless.boolean.error.string", calculateSimplifiedPrefixExpression((JSPrefixExpression) args[0]));
       }
   }
项目:consulo-javascript    文件:PointlessBooleanExpressionJSInspection.java   
@Override public void visitJSBinaryExpression(@NotNull JSBinaryExpression expression) {
    super.visitJSBinaryExpression(expression);
    if (!(expression.getROperand() != null)) {
        return;
    }
    final IElementType sign = expression.getOperationSign();
    if (!booleanTokens.contains(sign)) {
        return;
    }
    final JSExpression rhs = expression.getROperand();
    final JSExpression lhs = expression.getLOperand();
    final boolean isPointless;
    if (JSTokenTypes.EQEQ.equals(sign) /*||
            JSTokenTypes.EQEQEQ.equals(sign) ||
            JSTokenTypes.NE.equals(sign) ||
            JSTokenTypes.NEQEQ.equals(sign)*/) {
        isPointless = equalityExpressionIsPointless(lhs, rhs);
    } else if (JSTokenTypes.ANDAND.equals(sign) ||
            JSTokenTypes.AND.equals(sign)) {
        isPointless = andExpressionIsPointless(lhs, rhs);
    } else if (JSTokenTypes.OROR.equals(sign) ||
            JSTokenTypes.OR.equals(sign)) {
        isPointless = orExpressionIsPointless(lhs, rhs);
    } else if (JSTokenTypes.XOR.equals(sign)) {
        isPointless = xorExpressionIsPointless(lhs, rhs);
    } else {
        isPointless = false;
    }
    if (!isPointless) {
        return;
    }
    registerError(expression);
}
项目:consulo-javascript    文件:PointlessArithmeticExpressionJSInspection.java   
@Override public void visitJSBinaryExpression(
        @NotNull JSBinaryExpression expression) {
    super.visitJSBinaryExpression(expression);
    if (!(expression.getROperand() != null)) {
        return;
    }
    final IElementType sign = expression.getOperationSign();
    if (!arithmeticTokens.contains(sign)) {
        return;
    }
    final JSExpression rhs = expression.getROperand();
    final JSExpression lhs = expression.getLOperand();

    if (rhs == null) {
        return;
    }

    final boolean isPointless;
    if (sign.equals(JSTokenTypes.PLUS)) {
        isPointless = additionExpressionIsPointless(lhs, rhs);
    } else if (sign.equals(JSTokenTypes.MINUS)) {
        isPointless = subtractionExpressionIsPointless(rhs);
    } else if (sign.equals(JSTokenTypes.MULT)) {
        isPointless = multiplyExpressionIsPointless(lhs, rhs);
    } else if (sign.equals(JSTokenTypes.DIV)) {
        isPointless = divideExpressionIsPointless(rhs);
    } else {
        isPointless = false;
    }
    if (!isPointless) {
        return;
    }

    registerError(expression);
}
项目:consulo-javascript    文件:NegatedConditionalExpressionJSInspection.java   
private boolean isNotEquals(JSExpression expression) {
    if (!(expression instanceof JSBinaryExpression)) {
        return false;
    }
    final JSBinaryExpression binaryExpression =
            (JSBinaryExpression) expression;
    final IElementType sign = binaryExpression.getOperationSign();
    return JSTokenTypes.NE.equals(sign) ||JSTokenTypes.NEQEQ.equals(sign);
}
项目:consulo-javascript    文件:NegatedIfStatementJSInspection.java   
private boolean isNotEquals(JSExpression expression) {
    if (!(expression instanceof JSBinaryExpression)) {
        return false;
    }
    final JSBinaryExpression binaryExpression =
            (JSBinaryExpression) expression;
    final IElementType sign = binaryExpression.getOperationSign();
    return JSTokenTypes.NE.equals(sign) || JSTokenTypes.NEQEQ.equals(sign);
}
项目:consulo-javascript    文件:ComparisonUtils.java   
public static boolean isComparison(@Nullable JSExpression exp) {
    if (!(exp instanceof JSBinaryExpression)) {
        return false;
    }
    final JSBinaryExpression binaryExpression = (JSBinaryExpression) exp;
    final IElementType sign = binaryExpression.getOperationSign();
    return s_comparisonStrings.contains(sign);
}
项目:consulo-javascript    文件:EqualityComparisonWithCoercionJSInspection.java   
@Override
protected InspectionJSFix buildFix(PsiElement location) {
    final JSBinaryExpression expression = (JSBinaryExpression) location;
    final IElementType sign = expression.getOperationSign();
    if (JSTokenTypes.EQEQ == sign) {
        return new EqualityComparisonWithCoercionFix("===");
    } else if (JSTokenTypes.NE == sign) {
        return new EqualityComparisonWithCoercionFix("!==");
    }
    return null;
}
项目:consulo-javascript    文件:EqualityComparisonWithCoercionJSInspection.java   
@Override
protected void doFix(Project project, ProblemDescriptor descriptor)
        throws IncorrectOperationException {
    final JSBinaryExpression expression = (JSBinaryExpression) descriptor.getPsiElement();
    final JSExpression lhs = expression.getLOperand();
    final JSExpression rhs = expression.getROperand();
    replaceExpression(expression, lhs.getText() + sign + rhs.getText());
}
项目:consulo-javascript    文件:NonShortCircuitBooleanExpressionJSInspection.java   
@Override public void visitJSBinaryExpression(
        @NotNull JSBinaryExpression expression) {
    super.visitJSBinaryExpression(expression);
    if (!(expression.getROperand() != null)) {
        return;
    }
    final IElementType sign = expression.getOperationSign();
    if (!JSTokenTypes.AND.equals(sign) &&
            !JSTokenTypes.OR.equals(sign)) {
        return;
    }
    registerError(expression);
}
项目:consulo-javascript    文件:ShiftOutOfRangeJSInspection.java   
@Override public void visitJSBinaryExpression(
        @NotNull JSBinaryExpression expression) {
    super.visitJSBinaryExpression(expression);
    final IElementType tokenType = expression.getOperationSign();
    if (tokenType == null ||
          ( !tokenType.equals(JSTokenTypes.LTLT) &&
            !tokenType.equals(JSTokenTypes.GTGT) &&
            !tokenType.equals(JSTokenTypes.GTGTGT) )) {
        return;
    }
    final JSExpression rhs = expression.getROperand();
    if (rhs == null) {
        return;
    }
    if (!ExpressionUtil.isConstantExpression(rhs)) {
        return;
    }
    final Object valueObject =
             ExpressionUtil.computeConstantExpression(rhs);
    if (!(valueObject instanceof Integer)) {
        return;
    }
    final int value = (Integer) valueObject;
    if (value < 0 || value > 31) {
        registerError(expression, value);
    }
}
项目:consulo-javascript    文件:PointlessBitwiseExpressionJSInspection.java   
@Override public void visitJSBinaryExpression(
        @NotNull JSBinaryExpression expression) {
    super.visitJSBinaryExpression(expression);
    final IElementType sign = expression.getOperationSign();
    if (!bitwiseTokens.contains(sign)) {
        return;
    }

    final JSExpression rhs = expression.getROperand();
    if (rhs == null) {
        return;
    }

    final JSExpression lhs = expression.getLOperand();

    final boolean isPointless;
    if (JSTokenTypes.AND.equals(sign)) {
        isPointless = andExpressionIsPointless(lhs, rhs);
    } else if (JSTokenTypes.OR.equals(sign)) {
        isPointless = orExpressionIsPointless(lhs, rhs);
    } else if (JSTokenTypes.XOR.equals(sign)) {
        isPointless = xorExpressionIsPointless(lhs, rhs );
    } else if (JSTokenTypes.LTLT.equals(sign) ||
            JSTokenTypes.GTGT.equals(sign) ||
            JSTokenTypes.GTGTGT.equals(sign)) {
        isPointless = shiftExpressionIsPointless(rhs);
    } else {
        isPointless = false;
    }
    if (isPointless) {
        registerError(expression, expression);
    }
}
项目:consulo-javascript    文件:IncompatibleMaskJSInspection.java   
@Override
@NotNull
   public String buildErrorString(Object... args) {
       final JSBinaryExpression binaryExpression =
               (JSBinaryExpression) args[0];
       final IElementType tokenType =
               binaryExpression.getOperationSign();
       if (JSTokenTypes.EQEQ.equals(tokenType)) {
           return InspectionJSBundle.message(
                   "incompatible.mask.operation.problem.descriptor.always.false");
       } else {
           return InspectionJSBundle.message(
                   "incompatible.mask.operation.problem.descriptor.always.true");
       }
   }
项目:consulo-javascript    文件:IncompatibleMaskJSInspection.java   
@Override public void visitJSBinaryExpression(
        @NotNull JSBinaryExpression expression) {
    super.visitJSBinaryExpression(expression);
    final JSExpression rhs = expression.getROperand();
    if (!ComparisonUtils.isEqualityComparison(expression)) {
        return;
    }
    final JSExpression strippedRhs =
            ParenthesesUtils.stripParentheses(rhs);
    if (strippedRhs == null) {
        return;
    }
    final JSExpression lhs = expression.getLOperand();
    final JSExpression strippedLhs =
            ParenthesesUtils.stripParentheses(lhs);
    if (strippedLhs == null) {
        return;
    }
    if (isConstantMask(strippedLhs) &&
            ExpressionUtil.isConstantExpression(strippedRhs)) {
        if (isIncompatibleMask((JSBinaryExpression) strippedLhs,
                strippedRhs)) {
            registerError(expression, expression);
        }
    } else if (isConstantMask(strippedRhs) &&
            ExpressionUtil.isConstantExpression(strippedLhs)) {
        if (isIncompatibleMask((JSBinaryExpression) strippedRhs,
                strippedLhs)) {
            registerError(expression, expression);
        }
    }
}