class TypeHelper {

    static String toTypeDescription(ParsedType parsedType) {
        boolean aliasedType = TYPE_DESCRIPTION_ALIASES.containsKey(parsedType.className);
        String type;
        if(aliasedType) {
            type = TYPE_DESCRIPTION_ALIASES.get(parsedType.className);
        } else {
            boolean primitive = parsedType.className.startsWith("java.lang");
            type =  parsedType.className.substring(parsedType.className.lastIndexOf('.') + 1);
            if (primitive) {
                type = type.toLowerCase();
            }
            if ("DateTime".equals(type) || "DateMidnight".equals(type)) {
                type = "Date";
            }
        }

        if(parsedType.parameters.isEmpty()) { // We're on a raw type
            return type;
        } else { // We're on a parameterized type
            String parametersTypeDescriptions = FluentIterable.from(parsedType.parameters)
                    .transform(new Function<ParsedType, String>() {
                        @Override
                        public String apply(ParsedType param) {
                            return toTypeDescription(param);
                        }
                    }).join(Joiner.on(", "));

            if(aliasedType) {
                return String.format("%s[%s]", type, parametersTypeDescriptions);
            } else {
                return String.format("%s<%s>", type, parametersTypeDescriptions);
            }
        }
    }

}