]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/markdown/html/SCLDocumentationExtensionNodeHandler.java
Replace System.err and System.out with SLF4J Logging
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / markdown / html / SCLDocumentationExtensionNodeHandler.java
index 6a505fabb272fe39786186ba25a655c8c9fe7708..d9e65e28c39208b575234aae41e3a94000702912 100644 (file)
@@ -1,9 +1,5 @@
 package org.simantics.scl.compiler.markdown.html;
 
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.procedure.TObjectProcedure;
-import gnu.trove.set.hash.THashSet;
-
 import java.util.ArrayList;
 import java.util.Collections;
 
@@ -11,6 +7,7 @@ import org.simantics.scl.compiler.common.datatypes.Constructor;
 import org.simantics.scl.compiler.elaboration.modules.SCLValue;
 import org.simantics.scl.compiler.elaboration.modules.TypeClass;
 import org.simantics.scl.compiler.elaboration.modules.TypeConstructor;
+import org.simantics.scl.compiler.elaboration.modules.TypeDescriptor;
 import org.simantics.scl.compiler.environment.filter.AcceptAllNamespaceFilter;
 import org.simantics.scl.compiler.errors.Failable;
 import org.simantics.scl.compiler.markdown.internal.ExtensionNodeHandler;
@@ -26,9 +23,16 @@ import org.simantics.scl.compiler.types.TPred;
 import org.simantics.scl.compiler.types.TVar;
 import org.simantics.scl.compiler.types.Types;
 import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.procedure.TObjectProcedure;
+import gnu.trove.set.hash.THashSet;
 
 public class SCLDocumentationExtensionNodeHandler implements ExtensionNodeHandler {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(SCLDocumentationExtensionNodeHandler.class);
     final ModuleRepository moduleRepository;
     final String documentationName;
     
@@ -55,7 +59,7 @@ public class SCLDocumentationExtensionNodeHandler implements ExtensionNodeHandle
                 if(name.isEmpty())
                     continue;
                 if(!documentedValues.add(name))
-                    System.err.println("Value '" + name + "' has already been documented in " + documentationName + ".");
+                    LOGGER.warn("Value '" + name + "' has already been documented in " + documentationName + ".");
                 generateValueDocumentation(container, name);
             }
             return container;
@@ -68,7 +72,7 @@ public class SCLDocumentationExtensionNodeHandler implements ExtensionNodeHandle
                 if(name.isEmpty())
                     continue;
                 if(!documentedClasses.add(name))
-                    System.err.println("Class '" + name + "' has already been documented in " + documentationName + ".");
+                    LOGGER.warn("Class '" + name + "' has already been documented in " + documentationName + ".");
                 generateClassDocumentation(container, name);
             }
             return container;
@@ -81,7 +85,7 @@ public class SCLDocumentationExtensionNodeHandler implements ExtensionNodeHandle
                 if(name.isEmpty())
                     continue;
                 if(!documentedTypeConstructors.add(name))
-                    System.err.println("Type constructor '" + name + "' has already been documented in " + documentationName + ".");
+                    LOGGER.warn("Type constructor '" + name + "' has already been documented in " + documentationName + ".");
                 generateDataDocumentation(container, name);
             }
             return container;
@@ -121,7 +125,7 @@ public class SCLDocumentationExtensionNodeHandler implements ExtensionNodeHandle
         if(relatedModule == null) {
             relatedModule = moduleRepository.getModule(documentationName);
             if(!relatedModule.didSucceed())
-                System.err.println("Couldn't load the module " + documentationName);
+                LOGGER.warn("Couldn't load the module " + documentationName);
         }
         if(relatedModule.didSucceed())
             return relatedModule.getResult();
@@ -135,7 +139,7 @@ public class SCLDocumentationExtensionNodeHandler implements ExtensionNodeHandle
             fm = moduleRepository.getModule(moduleName);
             moduleCache.put(moduleName, fm);
             if(!fm.didSucceed())
-                System.err.println("Couldn't load the module " + moduleName);
+                LOGGER.warn("Couldn't load the module " + moduleName);
         }
         if(fm.didSucceed())
             return fm.getResult();
@@ -164,12 +168,12 @@ public class SCLDocumentationExtensionNodeHandler implements ExtensionNodeHandle
         if(value == null) {
             StringBuilder error = new StringBuilder();
             error.append("Didn't find the value '" + name + "'.");
-            System.err.println(error);
+            LOGGER.error(error.toString());
             container.addChild(new CodeBlockNode(error));
             return;
         }
         if(value.isPrivate())
-            System.err.println("Documentation " + documentationName + " refers to a private value " + name + ".");
+            LOGGER.warn("Documentation " + documentationName + " refers to a private value " + name + ".");
         
         StringBuilder signature = new StringBuilder();
         signature.append("<div id=\"")
@@ -193,7 +197,7 @@ public class SCLDocumentationExtensionNodeHandler implements ExtensionNodeHandle
             container.addChild(parser.parseDocument(value.documentation));
         }
         else
-            System.out.println(name);
+            LOGGER.info(name);
         container.addChild(new HtmlNode("</div></div>"));
     }
     
@@ -220,7 +224,7 @@ public class SCLDocumentationExtensionNodeHandler implements ExtensionNodeHandle
         if(typeClass == null) {
             StringBuilder error = new StringBuilder();
             error.append("Didn't find the type class '" + name + "'.");
-            System.err.println(error);
+            LOGGER.error(error.toString());
             container.addChild(new CodeBlockNode(error));
             return;
         }
@@ -254,11 +258,11 @@ public class SCLDocumentationExtensionNodeHandler implements ExtensionNodeHandle
             container.addChild(parser.parseDocument(typeClass.documentation));
         }
         else
-            System.out.println(name);
+            LOGGER.info(name);
         
         for(String methodName : typeClass.methodNames) {
             if(!documentedValues.add(methodName))
-                System.err.println("Method '" + methodName + "' has already been documented in " + documentationName + ".");
+                LOGGER.warn("Method '" + methodName + "' has already been documented in " + documentationName + ".");
             generateValueDocumentation(container, module, methodName, new TypeUnparsingContext(tuc));
         }
         container.addChild(new HtmlNode("</div></div>"));
@@ -279,11 +283,10 @@ public class SCLDocumentationExtensionNodeHandler implements ExtensionNodeHandle
     }
     
     private void generateDataDocumentation(Node container, Module module, String name) {
-        TypeConstructor typeConstructor = module.getTypeConstructor(name);
-        if(typeConstructor == null) {
+        TypeDescriptor typeDescriptor = module.getTypeDescriptor(name);
+        if(typeDescriptor == null) {
             StringBuilder error = new StringBuilder();
-            error.append("Didn't find the type constructor '" + name + "'.");
-            System.err.println(error);
+            error.append("Didn't find the type " + name + ".");
             container.addChild(new CodeBlockNode(error));
             return;
         }
@@ -292,10 +295,12 @@ public class SCLDocumentationExtensionNodeHandler implements ExtensionNodeHandle
         StringBuilder signature = new StringBuilder();
         signature.append("<div class=\"code-doc-box\"><div class=\"code\">");
         signature.append("data ");
-        signature.append(typeConstructor.name.name);
-        for(TVar p : typeConstructor.parameters) {
-            signature.append(' ');
-            p.toName(tuc, signature);
+        signature.append(typeDescriptor.name.name);
+        if(typeDescriptor instanceof TypeConstructor) {
+            for(TVar p : ((TypeConstructor)typeDescriptor).parameters) {
+                signature.append(' ');
+                p.toName(tuc, signature);
+            }
         }
         String moduleName = module.getName();
         if(!moduleName.equals(documentationName)) {
@@ -304,17 +309,19 @@ public class SCLDocumentationExtensionNodeHandler implements ExtensionNodeHandle
         signature.append("</div><div class=\"doc\">");
         container.addChild(new HtmlNode(signature));
         
-        if(typeConstructor.documentation != null) {
+        if(typeDescriptor.getDocumentation() != null) {
             MarkdownParser parser = new MarkdownParser();
-            container.addChild(parser.parseDocument(typeConstructor.documentation));
+            container.addChild(parser.parseDocument(typeDescriptor.getDocumentation()));
         }
         else
-            System.out.println(name);
+            LOGGER.info(name);
         
-        for(Constructor constructor : typeConstructor.constructors) {
-            if(!documentedValues.add(constructor.name.name))
-                System.err.println("Method '" + constructor.name.name + "' has already been documented in " + documentationName + ".");
-            generateValueDocumentation(container, module, constructor.name.name, new TypeUnparsingContext(tuc));
+        if(typeDescriptor instanceof TypeConstructor) {
+            for(Constructor constructor : ((TypeConstructor)typeDescriptor).constructors) {
+                if(!documentedValues.add(constructor.name.name))
+                    LOGGER.warn("Method '" + constructor.name.name + "' has already been documented in " + documentationName + ".");
+                generateValueDocumentation(container, module, constructor.name.name, new TypeUnparsingContext(tuc));
+            }
         }
         container.addChild(new HtmlNode("</div></div>"));
     }