Search in sources :

Example 1 with ToolModel

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

the class HtmlVisitor method describedSection.

private void describedSection(int depth, DescribedSection describedSection) {
    String sectionId = null;
    if (depth == 0) {
        if (describedSection.getRole() == Role.DESCRIPTION) {
            html.open("div class='section section-description'").text("\n");
            sectionId = "section-description";
        } else {
            html.open("div class='section'").text("\n");
        }
        addTableStart(html, sectionId, describedSection.getTitle(), 1);
        html.open("tr", "td").markdown(describedSection.getDescription());
    } else {
        if (describedSection.getAbout() instanceof ToolModel) {
            html.open("div id='" + idSubtool((ToolModel<?>) describedSection.getAbout()) + "'");
        } else {
            html.open("div");
        }
        html.markdown(describedSection.getTitle());
        html.markdown(describedSection.getDescription());
    }
    for (DescribedSection subsection : describedSection.getSubsections()) {
        describedSection(depth + 1, subsection);
    }
    if (depth != 0) {
        html.close("div");
    } else {
        html.close("td", "tr");
        addTableEnd(html);
        html.close("div").text("\n");
    }
}
Also used : ToolModel(org.eclipse.ceylon.common.tool.ToolModel) DescribedSection(org.eclipse.ceylon.common.tools.help.model.DescribedSection)

Example 2 with ToolModel

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

use of org.eclipse.ceylon.common.tool.ToolModel 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 4 with ToolModel

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

the class CeylonBashCompletionTool method run.

@Override
public void run() throws Exception {
    // we don't care about arg0
    arguments.remove(0);
    cword--;
    final CompletionResults results;
    if (cword == 0) {
        // We're completing the name of the tool to run
        results = completeToolNames(arguments.isEmpty() ? "" : arguments.get(cword));
    } else if (cword < arguments.size()) {
        String argument = arguments.get(cword);
        CeylonTool main = new CeylonTool();
        main.setArgs(arguments);
        main.setToolLoader(toolLoader);
        ToolModel<?> tool = main.getToolModel();
        if (!afterEoo()) {
            if (argument.startsWith("--")) {
                if (argument.contains("=")) {
                    results = completeLongOptionArgument(tool, argument);
                } else {
                    results = completeLongOption(tool, argument);
                }
            } else if (argument.startsWith("-")) {
                /*TODO for (OptionModel<?> option : tool.getOptions()) {
                        if (argument.charAt(argument.length()-1) == option.getShortName()) {
                            complete
                        }
                    }*/
                results = new CompletionResults();
            } else {
                // TODO it's argument completion unless the previous argument was a
                // non-pure short option
                results = new CompletionResults();
            }
        } else {
            // TODO else it must be argument completion
            results = new CompletionResults();
        }
    } else {
        // TODO we don't know what we're completing.
        // First assume it's an argument...
        // ... but if the tool doesn't have any arguments (or all the
        // arguments are already specified) then assume it's an option
        results = new CompletionResults();
    }
    results.emitCompletions();
}
Also used : ToolModel(org.eclipse.ceylon.common.tool.ToolModel) CeylonTool(org.eclipse.ceylon.common.tools.CeylonTool)

Aggregations

ToolModel (org.eclipse.ceylon.common.tool.ToolModel)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)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 DescribedSection (org.eclipse.ceylon.common.tools.help.model.DescribedSection)2 SubtoolVisitor (org.eclipse.ceylon.common.tools.help.model.SubtoolVisitor)2 List (java.util.List)1 OptionModel (org.eclipse.ceylon.common.tool.OptionModel)1 CeylonTool (org.eclipse.ceylon.common.tools.CeylonTool)1 Option (org.eclipse.ceylon.common.tools.help.model.Option)1 OptionsSection (org.eclipse.ceylon.common.tools.help.model.OptionsSection)1