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 ENTITIES_FILENAME = "entities.rst";
|
||||||
public static final String RELATIONS_FILENAME = "relations.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;
|
protected Map<AccessType, Tree> types;
|
||||||
|
|
||||||
public TreeGenerator() {
|
public TreeGenerator() {
|
||||||
|
@ -56,11 +72,19 @@ public class TreeGenerator extends Generator {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void elaborateTree(final AccessType at, Tree tree, final File file) throws Exception {
|
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());
|
logger.debug("Going to elaborate the following type tree\n{}", tree.toString());
|
||||||
|
|
||||||
NodeElaborator ne = new NodeElaborator() {
|
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
|
@Override
|
||||||
public void elaborate(Node node, int level) throws Exception {
|
public void elaborate(Node node, int level) throws Exception {
|
||||||
Type type = node.getType();
|
Type type = node.getType();
|
||||||
|
@ -69,11 +93,15 @@ public class TreeGenerator extends Generator {
|
||||||
* Root node has been already documented in IS_MODEL_FILENAME
|
* Root node has been already documented in IS_MODEL_FILENAME
|
||||||
* Going to skip it
|
* Going to skip it
|
||||||
*/
|
*/
|
||||||
DocumentationGenerator dg = getDocumentationGenerator(type);
|
writeSectionOnly(type, level);
|
||||||
dg.setLevel(level);
|
}else if(isModelPropertyNames.contains(type.getName())){
|
||||||
StringBuffer sb = dg.generateSection();
|
// Can be Header, Encrypted or PropagationConstraint
|
||||||
Files.write(file.toPath(), sb.toString().getBytes(), StandardOpenOption.APPEND);
|
if(node.getChildrenNodes()!=null && node.getChildrenNodes().size()>0) {
|
||||||
}else {
|
// 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);
|
writeTypeToFile(type, file, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,11 +124,7 @@ public class TreeGenerator extends Generator {
|
||||||
switch (at) {
|
switch (at) {
|
||||||
case PROPERTY:
|
case PROPERTY:
|
||||||
file = getFile(PROPERTIES_FILENAME, true);
|
file = getFile(PROPERTIES_FILENAME, true);
|
||||||
List<Class<? extends Property>> classes = new ArrayList<>();
|
for(Class<? extends Property> clz : isModelProperties) {
|
||||||
classes.add(Header.class);
|
|
||||||
classes.add(Encrypted.class);
|
|
||||||
classes.add(PropagationConstraint.class);
|
|
||||||
for(Class<? extends Property> clz : classes) {
|
|
||||||
Type t = TypeMapper.createTypeDefinition(clz);
|
Type t = TypeMapper.createTypeDefinition(clz);
|
||||||
writeTypeToFile(t, is, 1);
|
writeTypeToFile(t, is, 1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue