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;
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;
public class SCLDocumentationExtensionNodeHandler implements ExtensionNodeHandler {
+ private static final Logger LOGGER = LoggerFactory.getLogger(SCLDocumentationExtensionNodeHandler.class);
final ModuleRepository moduleRepository;
final String documentationName;
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;
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;
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;
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();
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();
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=\"")
.append(HtmlEscape.escape(name))
- .append("\" class=\"code-doc-box\"><div class=\"code\">");
+ .append("\" class=\"code-doc-box\"><div class=\"code value\">");
char firstChar = name.charAt(0);
if(!Character.isAlphabetic(firstChar) && firstChar != '_')
name = "(" + name + ")";
container.addChild(parser.parseDocument(value.documentation));
}
else
- System.out.println(name);
+ LOGGER.info(name);
container.addChild(new HtmlNode("</div></div>"));
}
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;
}
TypeUnparsingContext tuc = new TypeUnparsingContext();
StringBuilder signature = new StringBuilder();
- signature.append("<div class=\"code-doc-box\"><div class=\"code\">");
+ signature.append("<div id=\"class-")
+ .append(HtmlEscape.escape(name))
+ .append("\" class=\"code-doc-box\"><div class=\"code class\">");
signature.append("class ");
if(typeClass.context.length > 0) {
signature.append('(');
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>"));
}
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;
}
TypeUnparsingContext tuc = new TypeUnparsingContext();
StringBuilder signature = new StringBuilder();
- signature.append("<div class=\"code-doc-box\"><div class=\"code\">");
+ signature.append("<div id=\"data-")
+ .append(HtmlEscape.escape(name))
+ .append("\" class=\"code-doc-box\"><div class=\"code data\">");
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)) {
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>"));
}