Search in sources :

Example 1 with SubtoolVisitor

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;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) SynopsesSection(org.eclipse.ceylon.common.tools.help.model.SynopsesSection) SubtoolVisitor(org.eclipse.ceylon.common.tools.help.model.SubtoolVisitor) Synopsis(org.eclipse.ceylon.common.tools.help.model.Synopsis)

Example 2 with SubtoolVisitor

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);
}
Also used : HashMap(java.util.HashMap) PluginToolModel(org.eclipse.ceylon.common.tool.PluginToolModel) AnnotatedToolModel(org.eclipse.ceylon.common.tool.AnnotatedToolModel) ToolModel(org.eclipse.ceylon.common.tool.ToolModel) ScriptToolModel(org.eclipse.ceylon.common.tool.ScriptToolModel) ArrayList(java.util.ArrayList) DescribedSection(org.eclipse.ceylon.common.tools.help.model.DescribedSection) SubtoolVisitor(org.eclipse.ceylon.common.tools.help.model.SubtoolVisitor)

Example 3 with SubtoolVisitor

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);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SubtoolVisitor(org.eclipse.ceylon.common.tools.help.model.SubtoolVisitor) AnnotatedToolModel(org.eclipse.ceylon.common.tool.AnnotatedToolModel) PluginToolModel(org.eclipse.ceylon.common.tool.PluginToolModel) AnnotatedToolModel(org.eclipse.ceylon.common.tool.AnnotatedToolModel) ToolModel(org.eclipse.ceylon.common.tool.ToolModel) ScriptToolModel(org.eclipse.ceylon.common.tool.ScriptToolModel) OptionsSection(org.eclipse.ceylon.common.tools.help.model.OptionsSection) OptionModel(org.eclipse.ceylon.common.tool.OptionModel) ArrayList(java.util.ArrayList) List(java.util.List) Option(org.eclipse.ceylon.common.tools.help.model.Option)

Aggregations

ArrayList (java.util.ArrayList)3 SubtoolVisitor (org.eclipse.ceylon.common.tools.help.model.SubtoolVisitor)3 HashMap (java.util.HashMap)2 List (java.util.List)2 AnnotatedToolModel (org.eclipse.ceylon.common.tool.AnnotatedToolModel)2 PluginToolModel (org.eclipse.ceylon.common.tool.PluginToolModel)2 ScriptToolModel (org.eclipse.ceylon.common.tool.ScriptToolModel)2 ToolModel (org.eclipse.ceylon.common.tool.ToolModel)2 OptionModel (org.eclipse.ceylon.common.tool.OptionModel)1 DescribedSection (org.eclipse.ceylon.common.tools.help.model.DescribedSection)1 Option (org.eclipse.ceylon.common.tools.help.model.Option)1 OptionsSection (org.eclipse.ceylon.common.tools.help.model.OptionsSection)1 SynopsesSection (org.eclipse.ceylon.common.tools.help.model.SynopsesSection)1 Synopsis (org.eclipse.ceylon.common.tools.help.model.Synopsis)1