Search in sources :

Example 1 with AnnotatedToolModel

use of org.eclipse.ceylon.common.tool.AnnotatedToolModel in project ceylon by eclipse.

the class DocBuilder method getDescription.

public static String getDescription(ToolModel<?> model) {
    if (model instanceof ScriptToolModel) {
        return invokeScript((ScriptToolModel<?>) model, "--_print-description");
    }
    AnnotatedToolModel<?> amodel = (AnnotatedToolModel<?>) model;
    ResourceBundle toolBundle = getToolBundle(model);
    String msg = msg(toolBundle, "description");
    if (msg.isEmpty()) {
        Description description = amodel.getToolClass().getAnnotation(Description.class);
        if (description != null) {
            msg = description.value();
        }
    }
    return msg;
}
Also used : Description(org.eclipse.ceylon.common.tool.Description) AnnotatedToolModel(org.eclipse.ceylon.common.tool.AnnotatedToolModel) ResourceBundle(java.util.ResourceBundle) ScriptToolModel(org.eclipse.ceylon.common.tool.ScriptToolModel)

Example 2 with AnnotatedToolModel

use of org.eclipse.ceylon.common.tool.AnnotatedToolModel in project ceylon by eclipse.

the class DocBuilder method getToolBundle.

private static ResourceBundle getToolBundle(ToolModel<?> model) {
    if (!(model instanceof AnnotatedToolModel))
        return null;
    AnnotatedToolModel<?> amodel = (AnnotatedToolModel<?>) model;
    ResourceBundle toolBundle;
    try {
        toolBundle = ResourceBundle.getBundle(amodel.getToolClass().getName());
    } catch (MissingResourceException e) {
        toolBundle = null;
    }
    return toolBundle;
}
Also used : AnnotatedToolModel(org.eclipse.ceylon.common.tool.AnnotatedToolModel) MissingResourceException(java.util.MissingResourceException) ResourceBundle(java.util.ResourceBundle)

Example 3 with AnnotatedToolModel

use of org.eclipse.ceylon.common.tool.AnnotatedToolModel in project ceylon by eclipse.

the class DocBuilder method buildDoc.

public Doc buildDoc(ToolModel<?> model, boolean specialRoot) {
    checkModel(model);
    boolean rootHack = specialRoot && (model instanceof AnnotatedToolModel) && CeylonTool.class.isAssignableFrom(((AnnotatedToolModel<?>) model).getToolClass());
    Doc doc = new Doc();
    doc.setVersion(Versions.CEYLON_VERSION);
    doc.setToolModel(model);
    doc.setInvocation(getCeylonInvocation(model));
    doc.setSummary(buildSummary(model));
    doc.setSynopses(rootHack ? buildRootSynopsis(model) : buildSynopsis(model));
    doc.setDescription(rootHack ? buildRootDescription(model) : buildDescription(model));
    doc.setOptions(buildOptions(model));
    if (model.getSubtoolModel() != null) {
    // doc.setSubcommands(buildSubcommands(model));
    }
    doc.setAdditionalSections(buildAdditionalSections(model));
    return doc;
}
Also used : AnnotatedToolModel(org.eclipse.ceylon.common.tool.AnnotatedToolModel) Doc(org.eclipse.ceylon.common.tools.help.model.Doc) CeylonTool(org.eclipse.ceylon.common.tools.CeylonTool)

Example 4 with AnnotatedToolModel

use of org.eclipse.ceylon.common.tool.AnnotatedToolModel 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)

Example 5 with AnnotatedToolModel

use of org.eclipse.ceylon.common.tool.AnnotatedToolModel in project ceylon by eclipse.

the class DocBuilder method getSections.

private String getSections(ToolModel<?> model) {
    if (!(model instanceof AnnotatedToolModel))
        return null;
    AnnotatedToolModel<?> amodel = (AnnotatedToolModel<?>) model;
    ResourceBundle toolBundle = getToolBundle(model);
    String msg = msg(toolBundle, "sections.remaining");
    if (msg.isEmpty()) {
        RemainingSections sections = amodel.getToolClass().getAnnotation(RemainingSections.class);
        if (sections != null) {
            msg = sections.value();
        }
    }
    return msg;
}
Also used : AnnotatedToolModel(org.eclipse.ceylon.common.tool.AnnotatedToolModel) RemainingSections(org.eclipse.ceylon.common.tool.RemainingSections) ResourceBundle(java.util.ResourceBundle)

Aggregations

AnnotatedToolModel (org.eclipse.ceylon.common.tool.AnnotatedToolModel)6 ResourceBundle (java.util.ResourceBundle)3 ScriptToolModel (org.eclipse.ceylon.common.tool.ScriptToolModel)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 MissingResourceException (java.util.MissingResourceException)1 CeylonBaseTool (org.eclipse.ceylon.common.tool.CeylonBaseTool)1 Description (org.eclipse.ceylon.common.tool.Description)1 NoSuchToolException (org.eclipse.ceylon.common.tool.NoSuchToolException)1 OptionModel (org.eclipse.ceylon.common.tool.OptionModel)1 PluginToolModel (org.eclipse.ceylon.common.tool.PluginToolModel)1 RemainingSections (org.eclipse.ceylon.common.tool.RemainingSections)1 Tool (org.eclipse.ceylon.common.tool.Tool)1 ToolModel (org.eclipse.ceylon.common.tool.ToolModel)1 CeylonTool (org.eclipse.ceylon.common.tools.CeylonTool)1 Doc (org.eclipse.ceylon.common.tools.help.model.Doc)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