Object (final Object operand, PsiType castType) { if (operand == null || castType == null) return null; Object value; if (operand instanceof String && castType.equalsToText(JAVA_LANG_STRING) || operand instanceof Boolean && PsiTypes.booleanType().equals(castType)) { value = operand; } else { final PsiType primitiveType = wrapperToPrimitive(operand); if (primitiveType == null) return null; // identity cast, including (boolean)boolValue if (castType.equals(primitiveType)) return operand; final int rankTo = getTypeRank(castType); value = cast(operand, rankTo); } return value; }