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");
}
}
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);
}
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);
}
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();
}
Aggregations