X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Fmarkdown%2Fhtml%2FHierarchicalDocumentationRef.java;h=f48db6283b817f42714077dd882ece5a417400ae;hb=56f843ece1f6c8cbe55a5dc3495d828a1163c2fe;hp=93c8c8d2f17ee8a816e7811f58b13d5eb8a0a6db;hpb=9a175feb652b2b7bba7afa540831b9076be3c10e;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/markdown/html/HierarchicalDocumentationRef.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/markdown/html/HierarchicalDocumentationRef.java index 93c8c8d2f..f48db6283 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/markdown/html/HierarchicalDocumentationRef.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/markdown/html/HierarchicalDocumentationRef.java @@ -1,94 +1,94 @@ -package org.simantics.scl.compiler.markdown.html; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.simantics.scl.compiler.source.repository.ModuleSourceRepository; - -import gnu.trove.map.hash.THashMap; -import gnu.trove.procedure.TObjectProcedure; -import gnu.trove.set.hash.THashSet; - -public class HierarchicalDocumentationRef implements Comparable { - final String name; - final ArrayList children = new ArrayList(); - String documentationName; - - public HierarchicalDocumentationRef(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - public String getDocumentationName() { - return documentationName; - } - - public List getChildren() { - return children; - } - - @Override - public int compareTo(HierarchicalDocumentationRef o) { - return name.compareTo(o.name); - } - - public static HierarchicalDocumentationRef generateTree(ModuleSourceRepository sourceRepository) { - final THashMap refMap = new THashMap(); - HierarchicalDocumentationRef root = new HierarchicalDocumentationRef(""); - refMap.put("", root); - final THashSet documentationPaths = new THashSet(); - TObjectProcedure collector = new TObjectProcedure() { - @Override - public boolean execute(String path) { - documentationPaths.add(path); - return true; - } - }; - sourceRepository.forAllDocumentations(collector); - sourceRepository.forAllModules(collector); - documentationPaths.forEach(new TObjectProcedure() { - HierarchicalDocumentationRef getRef(String path) { - HierarchicalDocumentationRef ref = refMap.get(path); - if(ref == null) { - String name; - String parentName; - int p = path.lastIndexOf('/'); - if(p >= 0) { - name = path.substring(p+1); - parentName = path.substring(0, p); - } - else { - name = path; - parentName = ""; - } - ref = new HierarchicalDocumentationRef(name); - refMap.put(path, ref); - getRef(parentName).children.add(ref); - } - return ref; - } - - @Override - public boolean execute(String documentationName) { - getRef(documentationName.contains("/") - ? documentationName : "StandardLibrary/" + documentationName) - .documentationName = documentationName; - return true; - } - }); - - root.sort(); - - return root; - } - - private void sort() { - Collections.sort(children); - for(HierarchicalDocumentationRef child : children) - child.sort(); - } +package org.simantics.scl.compiler.markdown.html; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.simantics.scl.compiler.source.repository.ModuleSourceRepository; + +import gnu.trove.map.hash.THashMap; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.set.hash.THashSet; + +public class HierarchicalDocumentationRef implements Comparable { + final String name; + final ArrayList children = new ArrayList(); + String documentationName; + + public HierarchicalDocumentationRef(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public String getDocumentationName() { + return documentationName; + } + + public List getChildren() { + return children; + } + + @Override + public int compareTo(HierarchicalDocumentationRef o) { + return name.compareTo(o.name); + } + + public static HierarchicalDocumentationRef generateTree(ModuleSourceRepository sourceRepository) { + final THashMap refMap = new THashMap(); + HierarchicalDocumentationRef root = new HierarchicalDocumentationRef(""); + refMap.put("", root); + final THashSet documentationPaths = new THashSet(); + TObjectProcedure collector = new TObjectProcedure() { + @Override + public boolean execute(String path) { + documentationPaths.add(path); + return true; + } + }; + sourceRepository.forAllDocumentations(collector); + sourceRepository.forAllModules(collector); + documentationPaths.forEach(new TObjectProcedure() { + HierarchicalDocumentationRef getRef(String path) { + HierarchicalDocumentationRef ref = refMap.get(path); + if(ref == null) { + String name; + String parentName; + int p = path.lastIndexOf('/'); + if(p >= 0) { + name = path.substring(p+1); + parentName = path.substring(0, p); + } + else { + name = path; + parentName = ""; + } + ref = new HierarchicalDocumentationRef(name); + refMap.put(path, ref); + getRef(parentName).children.add(ref); + } + return ref; + } + + @Override + public boolean execute(String documentationName) { + getRef(documentationName.contains("/") + ? documentationName : "StandardLibrary/" + documentationName) + .documentationName = documentationName; + return true; + } + }); + + root.sort(); + + return root; + } + + private void sort() { + Collections.sort(children); + for(HierarchicalDocumentationRef child : children) + child.sort(); + } } \ No newline at end of file