/** * Returns a stream that delivers all the attributes of this type, including the ones declared in base types. */ public Stream<Attribute> attributes() { Stream<Attribute> result = declaredAttributes(); if (base != null && base instanceof StructType) { result = concat(result, ((StructType) base).attributes()); } return result; }
/** * 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 writeStructType(StructType type) { writer.writeStartElement("struct"); writeCommon(type); type.attributes().forEach(this::writeAttribute); type.links().forEach(this::writeStructLink); writer.writeEndElement(); }
/** * 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; }
private void generateRows(Concept concept) { csvBuffer.addRow( getKind(concept), getName(concept), String.valueOf(countItems(concept)), String.valueOf(countDocuments(concept)), getAnnotation(concept, AREA), getAnnotation(concept, AUTHOR), getAnnotation(concept, DATE), getAnnotation(concept, STATUS) ); if (concept instanceof StructType) { StructType type = (StructType) concept; type.attributes().sorted().forEach(this::generateRows); } else if (concept instanceof Service) { Service service = (Service) concept; service.methods().sorted().forEach(this::generateRows); } }
private void writeStructType(StructType type) { writer.writeStartObject(); writer.write("kind", "struct"); writeCommon(type); writer.writeStartArray("attributes"); type.attributes().forEach(this::writeStructAttribute); writer.writeEnd(); writer.writeStartArray("links"); type.links().forEach(this::writeStructLink); writer.writeEnd(); writer.writeEnd(); }
private void generateBuilderSource(StructType type) { // Begin class: JavaClassName builderName = javaTypes.getBuilderName(type); javaBuffer.addLine("public class %1$s {", builderName.getSimpleName()); // Generate the fields for attributes and links: Stream.concat(type.attributes(), type.links()).sorted().forEach(this::generateBuilderFields); javaBuffer.addLine(); // Generate the methods for attributes and links: Stream.concat(type.attributes(), type.links()) .sorted() .forEach(member -> generateBuilderMethods(type, member)); // Generate the "build" method: JavaClassName typeName = javaTypes.getInterfaceName(type); JavaClassName containerName = javaTypes.getContainerName(type); javaBuffer.addImport(typeName); javaBuffer.addImport(containerName); javaBuffer.addLine("public %1$s build() {", typeName.getSimpleName()); javaBuffer.addLine( "%1$s container = new %1$s();", containerName.getSimpleName()); Stream.concat(type.attributes(), type.links()).sorted().forEach(member -> { Name name = member.getName(); String field = javaNames.getJavaMemberStyleName(name); javaBuffer.addLine("container.%1$s(%1$s);", field); }); javaBuffer.addLine( "return container;"); javaBuffer.addLine("}"); // End class: javaBuffer.addLine("}"); }
private void generateStructWriteOne(StructType type) { // Calculate the name of the type and the XML tag: JavaClassName typeName = javaTypes.getInterfaceName(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.writeStartElement(tag);"); Stream.concat(type.attributes(), type.links()) .filter(x -> schemaNames.isRepresentedAsAttribute(x.getName())) .sorted() .forEach(this::generateStructWriteMemberAsAttribute); Stream.concat(type.attributes(), type.links()) .filter(x -> !schemaNames.isRepresentedAsAttribute(x.getName())) .sorted() .forEach(this::generateStructWriteMemberAsElement); javaBuffer.addLine("writer.writeEndElement();"); javaBuffer.addLine("}"); javaBuffer.addLine(); }
private void generateStructWriteOne(StructType type) { // Calculate the name of the type and the XML tag: JavaClassName typeName = javaTypes.getInterfaceName(type); // Add the required imports: javaBuffer.addImport(typeName); javaBuffer.addImport(JsonWriter.class); // Generate the method that uses the default name: javaBuffer.addLine("public static void writeOne(%1$s object, JsonWriter writer) {", typeName.getSimpleName()); javaBuffer.addLine(" writeOne(object, null, writer);"); javaBuffer.addLine("}"); javaBuffer.addLine(); // Generate the method that receives the name as parameter: javaBuffer.addLine("public static void writeOne(%1$s object, String name, JsonWriter writer) {", typeName.getSimpleName()); javaBuffer.addLine( "if (name != null) {"); javaBuffer.addLine( "writer.writeStartObject(name);"); javaBuffer.addLine( "}"); javaBuffer.addLine( "else {"); javaBuffer.addLine( "writer.writeStartObject();"); javaBuffer.addLine( "}"); Stream.concat(type.attributes(), type.links()).sorted().forEach(this::generateStructWriteMember); javaBuffer.addLine( "writer.writeEnd();"); javaBuffer.addLine("}"); javaBuffer.addLine(); }