1 package org.simantics.scl.compiler.markdown.html;
3 import java.util.ArrayList;
4 import java.util.Collections;
7 import org.simantics.scl.compiler.source.repository.ModuleSourceRepository;
9 import gnu.trove.map.hash.THashMap;
10 import gnu.trove.procedure.TObjectProcedure;
11 import gnu.trove.set.hash.THashSet;
13 public class HierarchicalDocumentationRef implements Comparable<HierarchicalDocumentationRef> {
15 final ArrayList<HierarchicalDocumentationRef> children = new ArrayList<HierarchicalDocumentationRef>();
16 String documentationName;
18 public HierarchicalDocumentationRef(String name) {
22 public String getName() {
26 public String getDocumentationName() {
27 return documentationName;
30 public List<HierarchicalDocumentationRef> getChildren() {
35 public int compareTo(HierarchicalDocumentationRef o) {
36 return name.compareTo(o.name);
39 public static HierarchicalDocumentationRef generateTree(ModuleSourceRepository sourceRepository) {
40 final THashMap<String,HierarchicalDocumentationRef> refMap = new THashMap<String,HierarchicalDocumentationRef>();
41 HierarchicalDocumentationRef root = new HierarchicalDocumentationRef("");
43 final THashSet<String> documentationPaths = new THashSet<String>();
44 TObjectProcedure<String> collector = new TObjectProcedure<String>() {
46 public boolean execute(String path) {
47 documentationPaths.add(path);
51 sourceRepository.forAllDocumentations(collector);
52 sourceRepository.forAllModules(collector);
53 documentationPaths.forEach(new TObjectProcedure<String>() {
54 HierarchicalDocumentationRef getRef(String path) {
55 HierarchicalDocumentationRef ref = refMap.get(path);
59 int p = path.lastIndexOf('/');
61 name = path.substring(p+1);
62 parentName = path.substring(0, p);
68 ref = new HierarchicalDocumentationRef(name);
69 refMap.put(path, ref);
70 getRef(parentName).children.add(ref);
76 public boolean execute(String documentationName) {
77 getRef(documentationName.contains("/")
78 ? documentationName : "StandardLibrary/" + documentationName)
79 .documentationName = documentationName;
90 Collections.sort(children);
91 for(HierarchicalDocumentationRef child : children)