void (PyExpression argument, @Nullable PyExpression afterThis) { if (afterThis == null) { addArgumentFirst(argument); return; } boolean good = false; for (PyExpression expression : getArguments()) { if (expression == afterThis) { good = true; break; } } if (!good) { throw new IllegalArgumentException("Expression " + afterThis + " is not an argument (" + Arrays.toString(getArguments()) + ")"); } // CASES: ASTNode node = afterThis.getNode().getTreeNext(); while (node != null) { IElementType type = node.getElementType(); if (type == PyTokenTypes.RPAR) { // 1: Nothing, just add addArgumentNode(argument, node, true); break; } else if (PythonDialectsTokenSetProvider.getInstance().getExpressionTokens().contains(type)) { // 2: After some argument followed by comma: after comma, add element, add comma // 3: After some argument not followed by comma: add comma, add element addArgumentNode(argument, node, true); break; } else if (type == PyTokenTypes.COMMA) { ASTNode next = PyPsiUtils.getNextNonWhitespaceSibling(node); if (next == null) { addArgumentLastWithoutComma(argument); } else if (next.getElementType() == PyTokenTypes.RPAR) { addArgumentNode(argument, next, false); } else { addArgumentNode(argument, next, false); } break; } node = node.getTreeNext(); } }