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