boolean (Exprent exprent, VarType leftType, TextBuffer buffer, int indent, boolean castNull, boolean castAlways, boolean castNarrowing, boolean unbox, BytecodeMappingTracer tracer) { if (unbox) { // "unbox" invocation parameters, e.g. 'byteSet.add((byte)123)' or 'new ShortContainer((short)813)' if (exprent.type == Exprent.EXPRENT_INVOCATION && ((InvocationExprent)exprent).isBoxingCall()) { InvocationExprent invocationExprent = (InvocationExprent)exprent; exprent = invocationExprent.getParameters().get(0); int paramType = invocationExprent.getDescriptor().params[0].getType(); if (exprent.type == Exprent.EXPRENT_CONST && ((ConstExprent)exprent).getConstType().getType() != paramType) { leftType = new VarType(paramType); } } } VarType rightType = exprent.getExprType(); boolean cast = castAlways || (!leftType.isSuperset(rightType) && (rightType.equals(VarType.VARTYPE_OBJECT) || leftType.getType() != CodeConstants.TYPE_OBJECT)) || (castNull && rightType.getType() == CodeConstants.TYPE_NULL && !UNDEFINED_TYPE_STRING.equals(getTypeName(leftType, Collections.emptyList()))) || (castNarrowing && isIntConstant(exprent) && isNarrowedIntType(leftType)); boolean quote = cast && exprent.getPrecedence() >= FunctionExprent.getPrecedence(FunctionExprent.FUNCTION_CAST); // cast instead to 'byte' / 'short' when int constant is used as a value for 'Byte' / 'Short' if (castNarrowing && exprent.type == Exprent.EXPRENT_CONST && !((ConstExprent) exprent).isNull()) { if (leftType.equals(VarType.VARTYPE_BYTE_OBJ)) { leftType = VarType.VARTYPE_BYTE; } else if (leftType.equals(VarType.VARTYPE_SHORT_OBJ)) { leftType = VarType.VARTYPE_SHORT; } } if (cast) buffer.append('(').append(ExprProcessor.getCastTypeName(leftType, Collections.emptyList())).append(')'); if (quote) buffer.append('('); if (exprent.type == Exprent.EXPRENT_CONST) { ((ConstExprent) exprent).adjustConstType(leftType); } buffer.append(exprent.toJava(indent, tracer)); if (quote) buffer.append(')'); return cast; }