private String getCardinalityString(TypeDefinition type) { if (type.cardinality().equals(Constants.RANGE_ONE_TO_ONE)) { return ""; } else if (type.cardinality().min() == 0 && type.cardinality().max() == 1) { return "?"; } else if (type.cardinality().min() == 0 && type.cardinality().max() == Integer.MAX_VALUE) { return "*"; } else { return new StringBuilder() .append('[') .append(type.cardinality().min()) .append(',') .append(type.cardinality().max()) .append(']') .toString(); } }
private void writeType(TypeDefinition type, boolean subType) throws IOException { StringBuilder builder = new StringBuilder(); if (subType) { builder.append('.'); } else { builder.append("type "); } builder.append(type.id()).append(getCardinalityString(type)).append(':'); if (type instanceof TypeDefinitionLink) { TypeDefinitionLink link = (TypeDefinitionLink) type; builder.append(link.linkedTypeName()); if (subType == false) { builder.append('\n'); } writeLine(builder.toString()); } else if (type.untypedSubTypes()) { builder.append("undefined"); writeLine(builder.toString()); writeLine(""); } else { builder.append(nativeTypeToString(type.nativeType())); if (type.hasSubTypes()) { builder.append(" {"); } writeLine(builder.toString()); if (type.hasSubTypes()) { indent(); for (Entry<String, TypeDefinition> entry : type.subTypes()) { writeType(entry.getValue(), true); } unindent(); writeLine("}"); } if (subType == false) { writeLine(""); } } }