private void writeStructType(StructType type) { writer.writeStartElement("struct"); writeCommon(type); type.attributes().forEach(this::writeAttribute); type.links().forEach(this::writeStructLink); writer.writeEndElement(); }
/** * 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; }
/** * Returns a stream that delivers all the links of this type, including the ones declared in base types. */ public Stream<Link> links() { Stream<Link> result = declaredLinks(); if (base != null && base instanceof StructType) { result = concat(((StructType) base).links(), result); } return result; }
/** * Adds the {@code GracePeriod} type to the model. */ private void addGracePeriodType(Model model) { // Create the type: StructType gracePeriodType = new StructType(); gracePeriodType.setName(NameParser.parseUsingCase("GracePeriod")); // Add the "expiry" attribute: Attribute expiryAttribute = new Attribute(); expiryAttribute.setName(NameParser.parseUsingCase("Expiry")); expiryAttribute.setType(model.getIntegerType()); expiryAttribute.setDeclaringType(gracePeriodType); gracePeriodType.addAttribute(expiryAttribute); // Add the type to the model: gracePeriodType.setModule(model.getModule(null)); model.addType(gracePeriodType); }
private void generateContainerSource(StructType type) { // Begin class: JavaClassName typeName = javaTypes.getInterfaceName(type); JavaClassName containerName = javaTypes.getContainerName(type); Type base = type.getBase(); JavaClassName baseName = base != null? javaTypes.getContainerName(base): javaTypes.getBaseContainerName(); javaBuffer.addImport(typeName); javaBuffer.addImport(baseName); javaBuffer.addLine("public class %1$s extends %2$s implements %3$s {", containerName.getSimpleName(), baseName.getSimpleName(), typeName.getSimpleName()); // Fields for attributes and links: type.declaredAttributes().sorted().forEach(this::generateContainerFields); type.declaredLinks().sorted().forEach(this::generateContainerFields); javaBuffer.addLine(); // Methods for attributes and links: type.declaredAttributes().sorted().forEach(this::generateContainerMethods); type.declaredLinks().sorted().forEach(this::generateContainerMethods); // End class: javaBuffer.addLine("}"); }
List<Attribute> attributes = type.getAttributes(); if (!attributes.isEmpty()) { docBuffer.addLine(".Attributes summary"); List<Link> links = type.getLinks(); if (!links.isEmpty()) { docBuffer.addLine(".Links summary");
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 writeStructMembers(StructType type) { // Write the attributes and links that are represented as XML elements: writer.writeStartElement(XS_URI, "sequence"); type.declaredAttributes() .filter(x -> !schemaNames.isRepresentedAsAttribute(x.getName())) .sorted() .forEach(this::writeStructMemberAsElement); type.declaredLinks() .filter(x -> !schemaNames.isRepresentedAsAttribute(x.getName())) .sorted() .forEach(this::writeStructMemberAsElement); writer.writeEndElement(); // Write the attributes and links that are represented as XML attributes, those need to go outside of the // "sequence" that contains the XML elements: type.declaredAttributes() .filter(x -> schemaNames.isRepresentedAsAttribute(x.getName())) .sorted() .forEach(this::writeStructMemberAsAttribute); type.declaredLinks() .filter(x -> schemaNames.isRepresentedAsAttribute(x.getName())) .sorted() .forEach(this::writeStructMemberAsAttribute); }
private void writeStructType(StructType type) { Name typeName = type.getName(); Name typePlural = names.getPlural(typeName); boolean isRoot = type.isExtension(identifiedType) || type == apiType; Type baseType = type.getBase(); if (baseType != null && baseType != identifiedType) { baseComplexTypeName = schemaNames.getSchemaTypeName(baseType); writer.writeLine(); if (!TYPES_WITHOUT_COLLECTION.contains(type.getName())) {
/** * Returns all the attributes of this type, including the ones declared in base types. The returned list is a copy * of the one used internally, so it is safe to modify it. If you aren't going to modify the list consider using the * {@link #attributes()} method instead. */ public List<Attribute> getAttributes() { List<Attribute> result = new ArrayList<>(attributes); if (base != null && base instanceof StructType) { result.addAll(((StructType) base).getAttributes()); } return result; }
/** * Returns all the links of this type, including the ones declared in base types. The returned list is a copy of the * one used internally, so it is safe to modify it. If you aren't going to modify the list consider using the * {@link #links()} method instead. */ public List<Link> getLinks() { List<Link> result = new ArrayList<>(links); if (base != null && base instanceof StructType) { result.addAll(((StructType) base).getLinks()); } return result; }
/** * Check if this type is an extension of the given type. */ public boolean isExtension(Type type) { if (type == this) { return true; } if (base != null && base instanceof StructType) { return ((StructType) base).isExtension(type); } return false; }
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 analyzeStruct(JavaClass javaClass) { StructType type = new StructType(); analyzeModule(javaClass, type); analyzeName(javaClass, type);
private void analyzeStructAttribute(JavaMethod javaMethod, StructType type) { // Create the model: Attribute attribute = new Attribute(); analyzeName(javaMethod, attribute); analyzeAnnotations(javaMethod, attribute); analyzeDocumentation(javaMethod, attribute); // Get the type: assignTypeReference(javaMethod.getReturns(), attribute::setType); // Add the member to the struct: attribute.setDeclaringType(type); type.addAttribute(attribute); }
containerName.getSimpleName() ); List<Link> links = type.links() .sorted() .filter(link -> link.getType() instanceof ListType)
private void analyzeStructLink(JavaMethod javaMethod, StructType type) { // Create the model: Link link = new Link(); analyzeName(javaMethod, link); analyzeAnnotations(javaMethod, link); analyzeDocumentation(javaMethod, link); // Get the type: assignTypeReference(javaMethod.getReturns(), link::setType); // Add the member to the struct: link.setDeclaringType(type); type.addLink(link); }
/** * Adds the {@code Fault} type to the model. */ private void addFaultType(Model model) { // Create the type: StructType faultType = new StructType(); faultType.setName(NameParser.parseUsingCase("Fault")); // Add the "reason" attribute: Attribute reasonAttribute = new Attribute(); reasonAttribute.setName(NameParser.parseUsingCase("Reason")); reasonAttribute.setType(model.getStringType()); reasonAttribute.setDeclaringType(faultType); faultType.addAttribute(reasonAttribute); // Add the "detail" attribute: Attribute detailAttribute = new Attribute(); detailAttribute.setName(NameParser.parseUsingCase("Detail")); detailAttribute.setType(model.getStringType()); detailAttribute.setDeclaringType(faultType); faultType.addAttribute(detailAttribute); // Add the type to the model: faultType.setModule(model.getModule(null)); model.addType(faultType); }
private void generateInterfaceSource(StructType type) { // Generate the documentation: generateDoc(type); // Begin class: JavaClassName interfaceName = javaTypes.getInterfaceName(type); Type base = type.getBase(); if (base != null) { JavaClassName baseName = javaTypes.getInterfaceName(base); javaBuffer.addImport(baseName); javaBuffer.addLine( "public interface %1$s extends %2$s {", interfaceName.getSimpleName(), baseName.getSimpleName() ); } else { javaBuffer.addLine("public interface %s {", interfaceName.getSimpleName()); } // Attributes and links: type.declaredAttributes().sorted().forEach(this::generateInterfaceMembers); type.declaredLinks().sorted().forEach(this::generateInterfaceMembers); // End class: javaBuffer.addLine("}"); }
members.addAll(type.getAttributes()); members.addAll(type.getLinks()); javaBuffer.addLine("public static %1$s readOne(JsonReader reader, boolean started) {", typeName.getSimpleName()); javaBuffer.addLine( "if (!started) {");