aboutsummaryrefslogtreecommitdiffstats
path: root/vespa-documentgen-plugin/src
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@yahooinc.com>2023-02-22 16:30:32 +0100
committerTor Brede Vekterli <vekterli@yahooinc.com>2023-02-22 16:38:27 +0100
commit19da4dc4a9d36646d985a9a4dbd74910932a5099 (patch)
treefc5199531ffb5637cb06cc1db2bb964559a1afc2 /vespa-documentgen-plugin/src
parentfc02e9f48338cb2d0288e8297381de319f71610e (diff)
Emit type inheritance statements for concrete document types
This relates to issue #26126 where inheritance specified in the schema was not propagated to the generated meta type, causing `is-a` type checks to not give the expected results.
Diffstat (limited to 'vespa-documentgen-plugin/src')
-rw-r--r--vespa-documentgen-plugin/src/main/java/com/yahoo/vespa/DocumentGenMojo.java24
1 files changed, 17 insertions, 7 deletions
diff --git a/vespa-documentgen-plugin/src/main/java/com/yahoo/vespa/DocumentGenMojo.java b/vespa-documentgen-plugin/src/main/java/com/yahoo/vespa/DocumentGenMojo.java
index 0f3531720ae..d753f3d9e73 100644
--- a/vespa-documentgen-plugin/src/main/java/com/yahoo/vespa/DocumentGenMojo.java
+++ b/vespa-documentgen-plugin/src/main/java/com/yahoo/vespa/DocumentGenMojo.java
@@ -448,7 +448,7 @@ public class DocumentGenMojo extends AbstractMojo {
out.write(ind(1)+"@Override protected boolean isGenerated() { return true; }\n\n");
Collection<Field> allUniqueFields = getAllUniqueFields(multiExtends, docType.getAllFields());
- exportExtendedStructTypeGetter(className, docType.getName(), allUniqueFields, docType.getFieldSets(),
+ exportExtendedStructTypeGetter(className, docType.getName(), docType.getInherited(), allUniqueFields, docType.getFieldSets(),
docType.getImportedFieldNames(), out, 1, "getDocumentType", "com.yahoo.document.DocumentType");
exportCopyConstructor(className, out, 1, true);
@@ -612,14 +612,17 @@ public class DocumentGenMojo extends AbstractMojo {
out.write(ind(ind) + "importedFieldNames.add(\"" + importedField + "\");\n");
}
}
- private static void exportExtendedStructTypeGetter(String className, String name, Collection<Field> fields, Set<FieldSet> fieldSets,
- Set<String> importedFieldNames, Writer out, int ind, String methodName, String retType) throws IOException {
+ private static void exportExtendedStructTypeGetter(String className, String name, Collection<NewDocumentType> parentTypes,
+ Collection<Field> fields, Set<FieldSet> fieldSets,
+ Set<String> importedFieldNames, Writer out, int ind,
+ String methodName, String retType) throws IOException {
out.write(ind(ind)+"private static "+retType+" "+methodName+"() {\n");
+ String bodyIndent = ind(ind + 1);
if (importedFieldNames != null) {
exportImportedFields(importedFieldNames, out, ind + 1);
- out.write(ind(ind+1)+retType+" ret = new "+retType+"(\"" + name + "\", importedFieldNames);\n");
+ out.write(bodyIndent+retType+" ret = new "+retType+"(\"" + name + "\", importedFieldNames);\n");
} else {
- out.write(ind(ind+1)+retType+" ret = new "+retType+"(\""+name+"\");\n");
+ out.write(bodyIndent+retType+" ret = new "+retType+"(\""+name+"\");\n");
}
for (Field f : fields) {
if (f.getDataType().equals(DataType.STRING)) {
@@ -631,8 +634,13 @@ public class DocumentGenMojo extends AbstractMojo {
if (fieldSets != null) {
exportFieldSetDefinition(fieldSets, out, ind+1);
}
+ for (NewDocumentType parentType : parentTypes) {
+ if (!parentType.getName().equals("document")) {
+ out.write("%sret.inherit(%s.type);\n".formatted(bodyIndent, className(parentType.getName())));
+ }
+ }
- out.write(ind(ind+1)+"return ret;\n");
+ out.write(bodyIndent+"return ret;\n");
out.write(ind(ind)+"}\n\n");
}
@@ -762,7 +770,9 @@ public class DocumentGenMojo extends AbstractMojo {
ind(ind+2)+"super("+structClassName+".type);\n" +
ind(ind+1)+"}\n\n");
exportCopyConstructor(structClassName, out, ind+1, false);
- exportExtendedStructTypeGetter(structClassName, structType.getName(), structType.getFields(), null, null, out, ind+1, "getStructType", "com.yahoo.document.StructDataType");
+ exportExtendedStructTypeGetter(structClassName, structType.getName(), List.of(),
+ structType.getFields(), null, null, out, ind+1, "getStructType",
+ "com.yahoo.document.StructDataType");
exportAssign(structType, structClassName, out, ind+1);
exportFieldsAndAccessors(structClassName, structType.getFields(), out, ind+1, true);