summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-02-17 22:14:21 +0100
committerGitHub <noreply@github.com>2020-02-17 22:14:21 +0100
commit40be29e7cfc00e306f3a4ee30472f807d42ccb4a (patch)
tree29038cfae81b4b9d2cf924b6dd0997248ba933ac
parentdee144e9c3be81d5d23439a15673eabafa8f8bfc (diff)
parentff538e3fc238190ca5cb7b217f013dcd0b3d3438 (diff)
Merge pull request #12229 from vespa-engine/vekterli/add-imported-fields-to-generated-concrete-document-type
Add imported fields to generated concrete document type
-rw-r--r--vespa-documentgen-plugin/src/main/java/com/yahoo/vespa/DocumentGenMojo.java20
1 files changed, 16 insertions, 4 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 d95eddac57f..95b6528bd77 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
@@ -465,7 +465,8 @@ public class DocumentGenMojo extends AbstractMojo {
exportStructTypeGetter(docType.getName()+".body", docType.allBody().getFields(), out, 1, "getBodyStructType", "com.yahoo.document.StructDataType");
Collection<Field> allUniqueFields = getAllUniqueFields(multiExtends, docType.getAllFields());
- exportExtendedStructTypeGetter(className, docType.getName(), allUniqueFields, docType.getFieldSets(),out, 1, "getDocumentType", "com.yahoo.document.DocumentType");
+ exportExtendedStructTypeGetter(className, docType.getName(), 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);
@@ -627,10 +628,21 @@ public class DocumentGenMojo extends AbstractMojo {
}
out.write(ind(ind) + "ret.addFieldSets(fieldSets);\n");
}
+ private static void exportImportedFields(Set<String> importedFieldNames, Writer out, int ind) throws IOException {
+ out.write(ind(ind) + "java.util.Set<java.lang.String> importedFieldNames = new java.util.HashSet<>();\n");
+ for (String importedField : importedFieldNames) {
+ out.write(ind(ind) + "importedFieldNames.add(\"" + importedField + "\");\n");
+ }
+ }
private static void exportExtendedStructTypeGetter(String className, String name, Collection<Field> fields, Set<FieldSet> fieldSets,
- Writer out, int ind, String methodName, String retType) throws IOException {
+ Set<String> importedFieldNames, Writer out, int ind, String methodName, String retType) throws IOException {
out.write(ind(ind)+"private static "+retType+" "+methodName+"() {\n");
- out.write(ind(ind+1)+retType+" ret = new "+retType+"(\""+name+"\");\n");
+ if (importedFieldNames != null) {
+ exportImportedFields(importedFieldNames, out, ind + 1);
+ out.write(ind(ind+1)+retType+" ret = new "+retType+"(\"" + name + "\", importedFieldNames);\n");
+ } else {
+ out.write(ind(ind+1)+retType+" ret = new "+retType+"(\""+name+"\");\n");
+ }
for (Field f : fields) {
if (f.getDataType().equals(DataType.STRING)) {
addExtendedStringField(className, f, out, ind + 1);
@@ -783,7 +795,7 @@ 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, out, ind+1, "getStructType", "com.yahoo.document.StructDataType");
+ exportExtendedStructTypeGetter(structClassName, structType.getName(), 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);