PsiPolyadicExpression (PsiPolyadicExpression expression, PsiJavaToken token) { final PsiExpression[] operands = expression.getOperands(); if (operands.length == 2) { return expression; } IElementType type = token.getTokenType(); if (!type.equals(JavaTokenType.PLUS) && !type.equals(JavaTokenType.ASTERISK) && !type.equals(JavaTokenType.OR) && !type.equals(JavaTokenType.AND) && !type.equals(JavaTokenType.XOR)) { return null; } for (int i = 1; i < operands.length; i++) { final PsiExpression operand = operands[i]; final PsiJavaToken currentToken = expression.getTokenBeforeOperand(operand); if (currentToken == token) { final String binaryExpressionText = operands[i - 1].getText() + ' ' + token.getText() + ' ' + operand.getText(); final PsiElementFactory factory = JavaPsiFacade.getElementFactory(expression.getProject()); return (PsiPolyadicExpression)factory.createExpressionFromText(binaryExpressionText, expression); } } return null; }