From d83136ef0f9beee31cd2ba57ca15e1f62d5914fa Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Tue, 24 Jan 2023 17:36:06 +0100 Subject: [PATCH] Improved solution --- .../generator/TreeGenerator.java | 44 ++++++++++++++----- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/gcube/informationsystem/utils/documentation/generator/TreeGenerator.java b/src/main/java/org/gcube/informationsystem/utils/documentation/generator/TreeGenerator.java index fcdd57e..c7e4ea8 100644 --- a/src/main/java/org/gcube/informationsystem/utils/documentation/generator/TreeGenerator.java +++ b/src/main/java/org/gcube/informationsystem/utils/documentation/generator/TreeGenerator.java @@ -34,6 +34,22 @@ public class TreeGenerator extends Generator { public static final String ENTITIES_FILENAME = "entities.rst"; public static final String RELATIONS_FILENAME = "relations.rst"; + protected static final List> isModelProperties; + protected static final List isModelPropertyNames; + + static { + isModelProperties = new ArrayList<>(); + isModelProperties.add(Header.class); + isModelProperties.add(Encrypted.class); + isModelProperties.add(PropagationConstraint.class); + + isModelPropertyNames= new ArrayList<>(); + isModelPropertyNames.add(Header.NAME); + isModelPropertyNames.add(Encrypted.NAME); + isModelPropertyNames.add(PropagationConstraint.NAME); + + } + protected Map types; public TreeGenerator() { @@ -56,11 +72,19 @@ public class TreeGenerator extends Generator { } + public void elaborateTree(final AccessType at, Tree tree, final File file) throws Exception { logger.debug("Going to elaborate the following type tree\n{}", tree.toString()); NodeElaborator ne = new NodeElaborator() { + protected void writeSectionOnly(Type type, int level) throws Exception { + DocumentationGenerator dg = getDocumentationGenerator(type); + dg.setLevel(level); + StringBuffer sb = dg.generateSection(); + Files.write(file.toPath(), sb.toString().getBytes(), StandardOpenOption.APPEND); + } + @Override public void elaborate(Node node, int level) throws Exception { Type type = node.getType(); @@ -69,11 +93,15 @@ public class TreeGenerator extends Generator { * Root node has been already documented in IS_MODEL_FILENAME * Going to skip it */ - DocumentationGenerator dg = getDocumentationGenerator(type); - dg.setLevel(level); - StringBuffer sb = dg.generateSection(); - Files.write(file.toPath(), sb.toString().getBytes(), StandardOpenOption.APPEND); - }else { + writeSectionOnly(type, level); + }else if(isModelPropertyNames.contains(type.getName())){ + // Can be Header, Encrypted or PropagationConstraint + if(node.getChildrenNodes()!=null && node.getChildrenNodes().size()>0) { + // If they have specialization I just add the section + // to maintain the level, otherwise I skip it + writeSectionOnly(type, level); + } + } else { writeTypeToFile(type, file, level); } @@ -96,11 +124,7 @@ public class TreeGenerator extends Generator { switch (at) { case PROPERTY: file = getFile(PROPERTIES_FILENAME, true); - List> classes = new ArrayList<>(); - classes.add(Header.class); - classes.add(Encrypted.class); - classes.add(PropagationConstraint.class); - for(Class clz : classes) { + for(Class clz : isModelProperties) { Type t = TypeMapper.createTypeDefinition(clz); writeTypeToFile(t, is, 1); }