use of org.eclipse.ceylon.common.tools.help.model.SubtoolVisitor in project ceylon by eclipse.
the class DocBuilder method buildSynopsis.
// private DescribedSection buildSubcommands(ToolModel<?> model) {
// /*
// DescribedSection section = null;
// if (!description.isEmpty()) {
// SubtoolModel<?> subtool = model.getSubtoolModel();
// for (String toolName : subtool.getToolLoader().getToolNames()) {
// ToolModel<Tool> subtoolModel = subtool.getToolLoader().loadToolModel(toolName);
// }
// / *
// * Here I need to build up the markdown something like as follows
// *
// The command `ceylon config` takes various subcommands
//
// ## SUBCOMMANDS
//
// ### `ceylon config foo`
//
// summary
//
// description
//
// options
//
// ### `ceylon config bar baz`
//
// summary
//
// description
//
// options
//
// * /
// section = new DescribedSection();
// section.setRole(Role.SUBCOMMANDS);
// section.setDescription(Markdown.markdown(
// "##" + sectionsBundle.getString("section.SUBCOMMANDS") + "\n\n" +
// description));
// }
// return section;*/
// return null;
// }
private SynopsesSection buildSynopsis(ToolModel<?> model) {
// Synopsis synopsis = out.startSynopsis(bundle.getString("section.SYNOPSIS"));
// TODO Make auto generated SYNOPSIS better -- we need to know which options
// form groups, or should we just have a @Synopses({@Synopsis(""), ...})
SynopsesSection synopsesSection = new SynopsesSection();
synopsesSection.setTitle(CeylonHelpToolMessages.msg("section.SYNOPSIS"));
final List<Synopsis> synopsisList = new ArrayList<>();
new SubtoolVisitor(model) {
@Override
protected void visit(ToolModel<?> model, SubtoolModel<?> subtoolModel) {
if (model.getSubtoolModel() == null) {
// a leaf
Synopsis synopsis = new Synopsis();
synopsis.setInvocation(getCeylonInvocationForSynopsis(root));
List<Object> optionsAndArguments;
if (ancestors.isEmpty()) {
optionsAndArguments = optionsAndArguments(model);
} else {
optionsAndArguments = new ArrayList<>();
for (SubtoolVisitor.ToolModelAndSubtoolModel ancestor : ancestors) {
List<Object> subOptAndArgs = optionsAndArguments(ancestor.getModel());
if (ancestor.getModel() != root) {
// Don't treat the foo in `ceylon foo` as a subtool
subOptAndArgs.add(0, ancestor);
}
optionsAndArguments.addAll(subOptAndArgs);
}
List<Object> subOptAndArgs = optionsAndArguments(model);
subOptAndArgs.add(0, new SubtoolVisitor.ToolModelAndSubtoolModel(model, subtoolModel));
optionsAndArguments.addAll(subOptAndArgs);
}
synopsis.setOptionsAndArguments(optionsAndArguments);
synopsisList.add(synopsis);
}
}
}.accept();
synopsesSection.setSynopses(synopsisList);
return synopsesSection;
}
use of org.eclipse.ceylon.common.tools.help.model.SubtoolVisitor in project ceylon by eclipse.
the class DocBuilder method buildDescription.
private DescribedSection buildDescription(ToolModel<?> model) {
final HashMap<ToolModel<?>, DescribedSection> map = new HashMap<ToolModel<?>, DescribedSection>();
new SubtoolVisitor(model) {
@Override
protected void visit(ToolModel<?> model, SubtoolModel<?> subtoolModel) {
if (model == root) {
map.put(model, buildDescription(model, getDescription(model)));
} else if (model.getSubtoolModel() == null) {
// leaf
DescribedSection section = new DescribedSection();
section.setRole(Role.DESCRIPTION);
StringBuilder sb = new StringBuilder();
for (SubtoolVisitor.ToolModelAndSubtoolModel subtool : ancestors.subList(1, ancestors.size())) {
sb.append(subtool.getModel().getName()).append(" ");
}
sb.append(model.getName());
section.setTitle(Markdown.markdown("###" + CeylonHelpToolMessages.msg("section.DESCRIPTION.sub", sb.toString())));
section.setDescription(Markdown.markdown(getDescription(model)));
section.setAbout(model);
List<DescribedSection> rootSubsections = new ArrayList<>(map.get(root).getSubsections());
rootSubsections.add(section);
map.get(root).setSubsections(rootSubsections);
}
}
}.accept();
return map.get(model);
}
use of org.eclipse.ceylon.common.tools.help.model.SubtoolVisitor in project ceylon by eclipse.
the class DocBuilder method buildOptions.
private OptionsSection buildOptions(ToolModel<?> model) {
if (!(model instanceof AnnotatedToolModel))
return null;
final HashMap<ToolModel<?>, OptionsSection> map = new HashMap<>();
new SubtoolVisitor(model) {
@Override
protected void visit(ToolModel<?> model, SubtoolModel<?> subtoolModel) {
OptionsSection optionsSection = new OptionsSection();
map.put(model, optionsSection);
if (model == root) {
optionsSection.setTitle(Markdown.markdown("##" + CeylonHelpToolMessages.msg("section.OPTIONS")));
} else {
optionsSection.setTitle(Markdown.markdown("###" + CeylonHelpToolMessages.msg("section.OPTIONS.sub", model.getName())));
}
List<Option> options = new ArrayList<>();
for (OptionModel<?> opt : sortedOptions(model.getOptions())) {
Option option = new Option();
option.setOption(opt);
String descriptionMd = getOptionDescription(model, opt);
if (descriptionMd == null || descriptionMd.isEmpty()) {
descriptionMd = CeylonHelpToolMessages.msg("option.undocumented");
}
option.setDescription(Markdown.markdown(descriptionMd));
options.add(option);
}
optionsSection.setOptions(options);
if (model != root && !options.isEmpty()) {
OptionsSection parent = map.get(ancestors.lastElement().getModel());
ArrayList<OptionsSection> parentSubsections = new ArrayList<OptionsSection>(parent.getSubsections());
parentSubsections.add(optionsSection);
parent.setSubsections(parentSubsections);
}
}
}.accept();
return map.get(model);
}
Aggregations