@Override public void processIntention(@NotNull PsiElement element) throws IncorrectOperationException { final JSBinaryExpression exp = (JSBinaryExpression) element; final JSExpression lhs = exp.getLOperand(); final JSExpression rhs = exp.getROperand(); final IElementType sign = exp.getOperationSign(); final String negatedOperator = ComparisonUtils.getNegatedOperatorText(sign); final String lhsText = lhs.getText(); assert (rhs != null); JSElementFactory.replaceExpressionWithNegatedExpressionString( exp, lhsText + negatedOperator + rhs.getText()); }
@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()); }
String calculateReplacementExpression(JSExpression expression) { final JSBinaryExpression exp = (JSBinaryExpression) expression; final JSExpression lhs = exp.getLOperand(); final JSExpression rhs = exp.getROperand(); final IElementType tokenType = exp.getOperationSign(); assert rhs != null; if (tokenType.equals(JSTokenTypes.AND)) { if (isZero(lhs) || isAllOnes(rhs)) { return lhs.getText(); } else { return rhs.getText(); } } else if (tokenType.equals(JSTokenTypes.OR)) { if (isZero(lhs) || isAllOnes(rhs)) { return rhs.getText(); } else { return lhs.getText(); } } else if (tokenType.equals(JSTokenTypes.XOR)) { if (isAllOnes(lhs)) { return '~' + rhs.getText(); } else if (isAllOnes(rhs)) { return '~' + lhs.getText(); } else if (isZero(rhs)) { return lhs.getText(); } else { return rhs.getText(); } } else if (tokenType.equals(JSTokenTypes.LTLT) || tokenType.equals(JSTokenTypes.GTGT) || tokenType.equals(JSTokenTypes.GTGTGT)) { return lhs.getText(); } else { return ""; } }