7 package com.google.appinventor.components.scripts;
11 import javax.tools.Diagnostic;
12 import javax.tools.FileObject;
13 import java.io.IOException;
14 import java.io.Writer;
29 private static final String OUTPUT_FILE_NAME =
"component-doc.html";
34 private String getComponentOutputString(String componentName, String componentDescription) {
35 return String.format(
"\n<h2 id=\"%1$s\">%1$s</h2>\n\n" +
37 componentName, componentDescription);
43 private String getPropertyDefinition(String name, String description,
44 boolean isUserVisible,
boolean isReadable,
boolean isWritable) {
47 return String.format(
" <dt><code>%s</code> (designer only)</dt>\n <dd>%s</dd>\n",
50 else if (isReadable && !isWritable) {
51 return String.format(
" <dt><code><em>%s</em></code></dt>\n <dd>%s</dd>\n",
54 return String.format(
" <dt><code>%s</code></dt>\n <dd>%s</dd>\n",
61 private String getEventDefinition(String name, String parameters, String description) {
62 return String.format(
" <dt><code>%s(%s)</code></dt>\n <dd>%s</dd>\n",
63 name, parameters, description);
70 private String getMethodDefinition(String name, String parameters, String returnType,
72 return String.format(
" <dt><code>%s%s%s(%s)</code></dt>\n <dd>%s</dd>\n",
73 returnType, returnType.isEmpty() ?
"" :
" ",
74 name, parameters, description);
79 FileObject src = createOutputFileObject(OUTPUT_FILE_NAME);
80 Writer writer = src.openWriter();
83 outputCategories(writer);
88 outputComponent(writer, component);
94 messager.printMessage(Diagnostic.Kind.NOTE,
"Wrote file " + src.toUri());
104 private void outputComponent(Writer writer, ComponentInfo component)
throws IOException {
106 writer.write(getComponentOutputString(component.name,
107 component.description));
110 outputProperties(writer, component);
111 outputEvents(writer, component);
112 outputMethods(writer, component);
118 private void outputCategories(Writer writer)
119 throws java.io.IOException {
121 writer.write(
"<table style=\"border-color: rgb(136, 136, 136); border-width: 0px; " +
122 "border-collapse: collapse;\" border=\"0\" bordercolor=\"#888888\" " +
123 "cellpadding=\"5\" cellspacing=\"5\">\n");
124 writer.write(
"<tbody valign=\"top\">\n");
125 writer.write(
"<tr>\n");
128 final ComponentCategory[][] categories = {
131 ComponentCategory.USERINTERFACE,
132 ComponentCategory.LAYOUT,
133 ComponentCategory.MEDIA,
134 ComponentCategory.ANIMATION,
135 ComponentCategory.SOCIAL
139 ComponentCategory.STORAGE,
140 ComponentCategory.CONNECTIVITY,
141 ComponentCategory.SENSORS,
142 ComponentCategory.LEGOMINDSTORMS,
148 for (
int column = 0; column < java.lang.reflect.Array.getLength(categories); column++) {
149 writer.write(
"<td>");
150 for (
int row = 0; row < java.lang.reflect.Array.getLength(categories[column]); row++) {
152 String categoryName = categories[column][row].getName();
153 writer.write(String.format(
"<b><font size=\"5\">%s</font></b>\n<ul>\n",
154 categoryName.replace(
"\u00AE",
"©")));
159 for (Map.Entry<String, ComponentInfo> entry :
components.entrySet()) {
160 ComponentInfo component = entry.getValue();
161 if (categoryName.equals(component.getCategory())) {
162 writer.write(String.format(
" <li><a href=\"#%1$s\">%1$s</a></li>\n",
166 writer.write(
"</ul>\n");
168 writer.write(
"</td>\n");
170 writer.write(
"<td style=\"width: 60px;\"><b><font size=\"5\"><br/></font></b></td>");
174 writer.write(
"</tr>\n</tbody>\n</table>\n");
177 private void outputProperties(Writer writer, ComponentInfo component)
178 throws java.io.IOException {
179 writer.write(
"<h3>Properties</h3>\n");
181 boolean definitionWritten =
false;
182 for (Map.Entry<String, Property> entry : component.properties.entrySet()) {
183 Property
property = entry.getValue();
184 if (property.isDeprecated())
continue;
185 if (property.isUserVisible() || component.designerProperties.containsKey(property.name)) {
186 if (!definitionWritten) {
187 writer.write(
"<dl>\n");
189 writer.write(getPropertyDefinition(property.name,
190 property.getDescription(),
191 property.isUserVisible(),
192 property.isReadable(),
193 property.isWritable()));
194 definitionWritten =
true;
197 if (definitionWritten) {
198 writer.write(
"</dl>\n\n");
200 writer.write(
"none\n\n");
204 private void outputEvents(Writer writer, ComponentInfo component)
throws java.io.IOException {
205 writer.write(
"<h3>Events</h3>\n");
207 boolean definitionWritten =
false;
208 for (Map.Entry<String, Event> entry : component.events.entrySet()) {
209 Event
event = entry.getValue();
210 if (event.deprecated)
continue;
211 if (event.userVisible) {
212 if (!definitionWritten) {
213 writer.write(
"<dl>\n");
215 writer.write(getEventDefinition(event.name, event.toParameterString(),
event.description));
216 definitionWritten =
true;
219 if (definitionWritten) {
220 writer.write(
"</dl>\n\n");
222 writer.write(
"none\n\n");
226 private void outputMethods(Writer writer, ComponentInfo component)
throws java.io.IOException {
227 writer.write(
"<h3>Methods</h3>\n");
229 boolean definitionWritten =
false;
230 for (Map.Entry<String, Method> entry : component.methods.entrySet()) {
231 Method method = entry.getValue();
232 if (method.deprecated)
continue;
233 if (method.userVisible) {
234 if (!definitionWritten) {
235 writer.write(
"<dl>\n");
237 String returnType = method.getReturnType();
238 writer.write(getMethodDefinition(
239 method.name, method.toParameterString(),
240 returnType ==
null ?
"" : javaTypeToYailType(returnType),
241 method.description));
242 definitionWritten =
true;
245 if (definitionWritten) {
246 writer.write(
"</dl>\n\n");
248 writer.write(
"none\n\n");