protected Object tryAssignOverload()

in src/main/java/org/apache/commons/jexl3/internal/Operators.java [190:277]


    protected Object tryAssignOverload(final JexlNode node,
                                       final JexlOperator operator,
                                       final Consumer<Object> assignFun,
                                       final Object...args) {
        final JexlArithmetic arithmetic = interpreter.arithmetic;
        if (args.length < operator.getArity()) {
            return JexlEngine.TRY_FAILED;
        }
        Object result;
        try {
        // if some overloads exist...
        if (operators != null) {
            // try to call overload with side effect; the object is modified
            result = tryOverload(node, operator, arguments(operator, args));
            if (result != JexlEngine.TRY_FAILED) {
                return result; // 1
            }
            // try to call base overload (ie + for +=)
            final JexlOperator base = operator.getBaseOperator();
            if (base != null && operators.overloads(base)) {
                result = tryOverload(node, base, arguments(base, args));
                if (result != JexlEngine.TRY_FAILED) {
                    assignFun.accept(result);
                    return isPostfix(operator) ? args[0] : result; // 2
                }
            }
        }
        // base eval
        switch (operator) {
            case SELF_ADD:
                result = arithmetic.add(args[0], args[1]);
                break;
            case SELF_SUBTRACT:
                result = arithmetic.subtract(args[0], args[1]);
                break;
            case SELF_MULTIPLY:
                result = arithmetic.multiply(args[0], args[1]);
                break;
            case SELF_DIVIDE:
                result = arithmetic.divide(args[0], args[1]);
                break;
            case SELF_MOD:
                result = arithmetic.mod(args[0], args[1]);
                break;
            case SELF_AND:
                result = arithmetic.and(args[0], args[1]);
                break;
            case SELF_OR:
                result = arithmetic.or(args[0], args[1]);
                break;
            case SELF_XOR:
                result = arithmetic.xor(args[0], args[1]);
                break;
            case SELF_SHIFTLEFT:
                result = arithmetic.shiftLeft(args[0], args[1]);
                break;
            case SELF_SHIFTRIGHT:
                result = arithmetic.shiftRight(args[0], args[1]);
                break;
            case SELF_SHIFTRIGHTU:
                result = arithmetic.shiftRightUnsigned(args[0], args[1]);
                break;
            case INCREMENT_AND_GET:
                result = arithmetic.increment(args[0]);
                break;
            case DECREMENT_AND_GET:
                result = arithmetic.decrement(args[0]);
                break;
            case GET_AND_INCREMENT:
                result = args[0];
                assignFun.accept(arithmetic.increment(result));
                return result; // 3
            case GET_AND_DECREMENT: {
                result = args[0];
                assignFun.accept(arithmetic.decrement(result));
                return result; // 4
            }
            default:
                // unexpected, new operator added?
                throw new UnsupportedOperationException(operator.getOperatorSymbol());
            }
            assignFun.accept(result);
            return result; // 5
        } catch (final Exception xany) {
            interpreter.operatorError(node, operator, xany);
        }
        return JexlEngine.TRY_FAILED;
    }