Search in sources :

Example 1 with Option

use of org.eclipse.ceylon.common.tools.help.model.Option 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)1 HashMap (java.util.HashMap)1 List (java.util.List)1 AnnotatedToolModel (org.eclipse.ceylon.common.tool.AnnotatedToolModel)1 OptionModel (org.eclipse.ceylon.common.tool.OptionModel)1 PluginToolModel (org.eclipse.ceylon.common.tool.PluginToolModel)1 ScriptToolModel (org.eclipse.ceylon.common.tool.ScriptToolModel)1 ToolModel (org.eclipse.ceylon.common.tool.ToolModel)1 Option (org.eclipse.ceylon.common.tools.help.model.Option)1 OptionsSection (org.eclipse.ceylon.common.tools.help.model.OptionsSection)1 SubtoolVisitor (org.eclipse.ceylon.common.tools.help.model.SubtoolVisitor)1