public static void translate(PsiPolyadicExpression element, TranslationContext ctx) { for (PsiExpression expression : element.getOperands()) { PsiJavaToken token = element.getTokenBeforeOperand(expression); if (token != null) { ctx.append(' '); JavaTokenTranslator.translate(token, ctx); ctx.append(' '); } ExpressionTranslator.translate(expression, ctx); } }
@Nullable static PsiPolyadicExpression getSubexpression( PsiPolyadicExpression expression, PsiJavaToken token) { final PsiExpression[] operands = expression.getOperands(); if (operands.length == 2) { return expression; } 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; }