private String getValueValues(EnumType enumType) { StringBuilder builder = new StringBuilder(); for (EnumValue enumValue : enumType.getValues()) { builder.append("'") .append(getValueText(enumValue)) .append("', "); } builder.deleteCharAt(builder.length()-1); builder.deleteCharAt(builder.length()-1); return builder.toString(); }
private void writeEnumType(EnumType type) { writer.writeStartElement("enum"); writeCommon(type); type.values().forEach(this::writeEnumValue); writer.writeEndElement(); }
private JavaClassName getEnumName(EnumType type) { JavaClassName enumName = new JavaClassName(); enumName.setPackageName(javaPackages.getXjcPackageName()); enumName.setSimpleName(javaNames.getJavaClassStyleName(type.getName())); return enumName; }
private void analyzeEnum(JavaClass javaClass) { // Create the type: EnumType type = new EnumType(); analyzeSource(javaClass, type); analyzeModule(javaClass, type); analyzeName(javaClass, type); analyzeAnnotations(javaClass, type); analyzeDocumentation(javaClass, type); // Get the values: javaClass.getEnumConstants().forEach(x -> analyzeEnumValue(x, type)); // Add the type to the model: model.addType(type); }
private void analyzeEnumValue(JavaField javaField, EnumType type) { // Create the value: EnumValue value = new EnumValue(); analyzeSource(javaField, value); analyzeName(javaField, value); analyzeAnnotations(javaField, type); analyzeDocumentation(javaField, value); // Add the value to the type: value.setDeclaringType(type); type.addValue(value); }
private JavaTypeReference getEnumReference(EnumType type) { JavaTypeReference reference = new JavaTypeReference(); String text = javaNames.getJavaClassStyleName(type.getName()); reference.setText(text); reference.addImport(javaPackages.getTypesPackageName(), text); return reference; }
/** * Counts the total items that can be potentially documented in a concept. For example, in a struct type with two * attributes there are three items: the type itself and the two attributes. */ private int countItems(Concept concept) { int count = 1; if (concept instanceof StructType) { StructType type = (StructType) concept; count += type.attributes().mapToInt(this::countItems).sum(); count += type.links().mapToInt(this::countItems).sum(); } else if (concept instanceof EnumType) { EnumType type = (EnumType) concept; count += type.values().mapToInt(this::countItems).sum(); } else if (concept instanceof Service) { Service service = (Service) concept; count += service.methods().mapToInt(this::countItems).sum(); count += service.locators().mapToInt(this::countItems).sum(); } else if (concept instanceof Method) { Method method = (Method) concept; count += method.parameters().mapToInt(this::countItems).sum(); } return count; }
private void generateEnumWriteOne(EnumType type) { // Calculate the name of the type and the XML tag: JavaClassName typeName = javaTypes.getEnumName(type); String tag = schemaNames.getSchemaTagName(type.getName()); // Add the required imports: javaBuffer.addImport(typeName); javaBuffer.addImport(XmlWriter.class); // Generate the method that uses the default tag name: javaBuffer.addLine("public static void writeOne(%1$s object, XmlWriter writer) {", typeName.getSimpleName()); javaBuffer.addLine( "writeOne(object, \"%1$s\", writer);", tag); javaBuffer.addLine("}"); javaBuffer.addLine(); // Generate the method that receives the tag name as parameter: javaBuffer.addLine( "public static void writeOne(%1$s object, String tag, XmlWriter writer) {", typeName.getSimpleName()); javaBuffer.addLine("writer.writeElement(tag, object.value());"); javaBuffer.addLine("}"); javaBuffer.addLine(); }
private void writeEnumValues(EnumType type) { Iterator<EnumValue> iterator = type.getValues().iterator(); while (iterator.hasNext()) { EnumValue value = iterator.next(); javaBuffer.addLine(getEnumValueLine(value, !iterator.hasNext())); } javaBuffer.addLine(); }
/** * Counts the number of items in a concept tha are documented. */ private int countDocuments(Concept concept) { int count = 0; if (concept.getDoc() != null) { count++; } if (concept instanceof StructType) { StructType type = (StructType) concept; count += type.attributes().mapToInt(this::countDocuments).sum(); count += type.links().mapToInt(this::countDocuments).sum(); } else if (concept instanceof EnumType) { EnumType type = (EnumType) concept; count += type.values().mapToInt(this::countDocuments).sum(); } else if (concept instanceof Service) { Service service = (Service) concept; count += service.methods().mapToInt(this::countDocuments).sum(); count += service.locators().mapToInt(this::countDocuments).sum(); } else if (concept instanceof Method) { Method method = (Method) concept; count += method.parameters().mapToInt(this::countDocuments).sum(); } return count; }
writer.writeStartElement(XS_URI, "sequence"); for (EnumType type : types) { Name name = type.getName(); Name plural = names.getPlural(name); writer.writeStartElement(XS_URI, "element"); Name name = type.getName(); writer.writeStartElement(XS_URI, "complexType"); writer.writeAttribute("name", getSchemaEnumTypeValuesName(name));
private void documentEnum(EnumType type) { // General description: docBuffer.addId(getId(type)); docBuffer.addLine("=== %s [small]#enum#", getName(type)); docBuffer.addLine(); addDoc(type); // Table of values: List<EnumValue> values = type.getValues(); if (!values.isEmpty()) { docBuffer.addLine(".Values summary"); docBuffer.addLine("[cols=\"20,80\"]"); docBuffer.addLine("|==="); docBuffer.addLine("|Name |Summary"); docBuffer.addLine(); values.stream().sorted().forEach(value -> { docBuffer.addLine("|`%s`", getName(value)); docBuffer.addLine("|%s", getSummary(value)); docBuffer.addLine(); }); docBuffer.addLine("|==="); docBuffer.addLine(); } // Detail of values: values.stream().sorted().forEach(value -> documentValue(type, value)); }
private void writeEnumType(EnumType type) { writer.writeStartObject(); writer.write("kind", "enum"); writeCommon(type); writer.writeStartArray("values"); type.values().forEach(this::writeEnumValue); writer.writeEnd(); writer.writeEnd(); }
private void writeEnumType(EnumType type) { // Get the enum values and sort them by name: List<EnumValue> values = new ArrayList<>(type.getValues()); values.sort(comparing(Concept::getName)); // Generate the XML schema enumerated type that will for attributes whose value is of this enum type: writer.writeStartElement(XS_URI, "simpleType"); writer.writeAttribute("name", schemaNames.getSchemaTypeName(type)); writer.writeStartElement(XS_URI, "restriction"); writer.writeAttribute("base", "xs:string"); for (EnumValue value : values) { writer.writeStartElement(XS_URI, "enumeration"); writer.writeAttribute("value", getSchemaEnumValueName(value)); writeJaxbProperty(getJavaEnumValueName(value)); writer.writeEndElement(); } writer.writeEndElement(); writer.writeEndElement(); writer.writeLine(); }