private void exportDocumentClass(NewDocumentType docType, Writer out, String packageName) throws IOException {
        String className = className(docType.getName());
        Pair<String, Boolean> extendInfo = javaSuperType(docType);
        String superType = extendInfo.getFirst();
        boolean multiExtends = extendInfo.getSecond();
        out.write(
                "package "+packageName+";\n\n" +
                exportInnerImportsFromSuperTypes(docType, packageName) +
                "/**\n" +
                " *  Generated by vespa-documentgen-plugin, do not edit.\n" +
                " *  Input document type: "+docType.getName()+"\n" +
                " *  Date: "+new Date()+"\n" +
                " */\n" +
                "@com.yahoo.document.Generated\n" +
                "@SuppressWarnings(\"unchecked\")\n" +
                "public class "+className+" extends "+superType+" {\n\n"+
                ind(1)+"/** The doc type of this.*/\n" +
                ind(1)+"public static final com.yahoo.document.DocumentType type = getDocumentType();\n\n");

        // Constructor
        out.write(
                ind(1)+"public "+className+"(com.yahoo.document.DocumentId docId) {\n" +
                ind(2)+"super("+className+".type, docId);\n" +
                ind(1)+"}\n\n");
        out.write(
                ind(1)+"protected "+className+"(com.yahoo.document.DocumentType type, com.yahoo.document.DocumentId docId) {\n" +
                ind(2)+"super(type, docId);\n" +
                ind(1)+"}\n\n");
        // isGenerated()
        out.write(ind(1)+"@Override protected boolean isGenerated() { return true; }\n\n");

        Collection<Field> allUniqueFields = getAllUniqueFields(multiExtends, docType.getAllFields());
        exportExtendedStructTypeGetter(className, docType.getName(), docType.getInherited(), allUniqueFields, docType.getFieldSets(),
                docType.getImportedFieldNames(), out, 1, "getDocumentType", "com.yahoo.document.DocumentType");
        exportCopyConstructor(className, out, 1, true);

        exportFieldsAndAccessors(className, "com.yahoo.document.Document".equals(superType) ? allUniqueFields : docType.getFields(), out, 1, true);
        exportDocumentMethods(allUniqueFields, out, 1);
        exportHashCode(allUniqueFields, out, 1, "(getDataType() != null ? getDataType().hashCode() : 0) + getId().hashCode()");
        exportEquals(className, allUniqueFields, out, 1);
        Set<DataType> exportedStructs = exportStructTypes(docType.getTypes(), out, 1, null);
        if (hasAnyPositionField(allUniqueFields)) {
            exportedStructs = exportStructTypes(List.of(PositionDataType.INSTANCE), out, 1, exportedStructs);
        }
        docTypes.put(docType.getName(), packageName+"."+className);
        for (DataType exportedStruct : exportedStructs) {
            String fullName = packageName+"."+className+"."+className(exportedStruct.getName());
            structTypes.put(exportedStruct.getName(), fullName);
            if (exportedStruct instanceof OwnedStructDataType) {
                var owned = (OwnedStructDataType) exportedStruct;
                structTypes.put(owned.getUniqueName(), fullName);
            }
        }
        out.write("}\n");
    }
Generates the .java file for the Document subclass for the given document type
vespa-documentgen-plugin/src/main/java/com/yahoo/vespa/DocumentGenMojo.java