Improved solution
This commit is contained in:
parent
96a184a28a
commit
d83136ef0f
|
@ -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<Class<? extends Property>> isModelProperties;
|
||||
protected static final List<String> 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<AccessType, Tree> 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<Class<? extends Property>> classes = new ArrayList<>();
|
||||
classes.add(Header.class);
|
||||
classes.add(Encrypted.class);
|
||||
classes.add(PropagationConstraint.class);
|
||||
for(Class<? extends Property> clz : classes) {
|
||||
for(Class<? extends Property> clz : isModelProperties) {
|
||||
Type t = TypeMapper.createTypeDefinition(clz);
|
||||
writeTypeToFile(t, is, 1);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue