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