summaryrefslogtreecommitdiff
path: root/webapps/qooxdoo-0.6.3-sdk/frontend/api/source/class/api/TreeUtil.js
blob: bb90bfd6efeb7581a929f80877232b14e696a773 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
/*
#module(api)
*/

/**
 * A util class for handling the documentation tree.
 */
qx.OO.defineClass("api.TreeUtil", qx.core.Object,
function () {
  qx.core.Object.call(this);
});


/**
 * Gets the child of a doc node having a certain type.
 *
 * @param docNode {Map} the doc node to get the child of.
 * @param childType {string} the type of the child to get.
 * @return {Map} the wanted child or <code>null</code> if <code>docNode</code>
 *         is <code>null</code> or has no such child.
 */
qx.Class.getChild = function(docNode, childType) {
  if (docNode != null && docNode.children != null) {
    for (var i = 0; i < docNode.children.length; i++) {
      if (docNode.children[i].type == childType) {
        return docNode.children[i];
      }
    }
  }

  return null;
}


/**
 * Gets the child of a doc node having a certain attribute value.
 *
 * @param docNode {Map} the doc node to get the child of.
 * @param attributeName {string} the name of the attribute the wanted child must have.
 * @param attributeValue {string} the value of the attribute the wanted child must have.
 * @return {Map} the wanted child or <code>code</code> if there is no such child.
 */
qx.Class.getChildByAttribute = function(docNode, attributeName, attributeValue) {
  if (docNode.children != null) {
    for (var i = 0; i < docNode.children.length; i++) {
      var node = docNode.children[i];
      if (node.attributes && node.attributes[attributeName] == attributeValue) {
        return node;
      }
    }
  }

  return null;
}


/**
 * Searches the doc node of a item. Only use this method if you don't know the
 * type of the item.
 *
 * @param classNode {Map} the class node the item belongs to.
 * @param itemName {string} the name of the item to search.
 * @return {Map} the doc node of the item or <code>null</code> if the class has
 *         no such item.
 */
qx.Class.getItemDocNode = function(classNode, itemName) {
  var TreeUtil = api.TreeUtil;

  // Go through the item lists and check whether one contains the wanted item
  for (var i = 0; i < TreeUtil.ITEM_LIST_ARR.length; i++) {
    var listNode = TreeUtil.getChild(classNode, TreeUtil.ITEM_LIST_ARR[i]);
    if (listNode) {
      var itemNode = TreeUtil.getChildByAttribute(listNode, "name", itemName);
      if (itemNode) {
        return itemNode;
      }
    }
  }

  // Nothing found
  return null;
}


/**
 * Gets the doc node of a class.
 *
 * @param docTree {Map} the documentation tree.
 * @param className {string} the name of the class.
 * @return {Map} the doc node of the class.
 */
qx.Class.getClassDocNode = function(docTree, className) {
  var splits = className.split(".");
  var currNode = docTree;
  for (var i = 0; i < splits.length && currNode != null; i++) {
    if (i < splits.length - 1) {
      // The current name is a package name
      var packages = this.getChild(currNode, "packages");
      currNode = packages ? this.getChildByAttribute(packages, "name", splits[i]) : null;
    } else {
      // The current name is a class name
      var classes = this.getChild(currNode, "classes");
      currNode = classes ? this.getChildByAttribute(classes, "name", splits[i]) : null;
    }
  }

  return currNode;
}


/**
 * Gets the icon URL of a doc node.
 *
 * @param node {Map} the node to get the icon for.
 * @param inherited {boolean,false} whether the node was inherited.
 * @return {var} the URL of the icon. May be a string or an array of string
 *         (in case of an overlay icon).
 */
qx.Class.getIconUrl = function(node, inherited) {
  var constName;
  switch (node.type) {
    case "package":
      constName = "ICON_PACKAGE";
      break;
    case "class":
      constName = "ICON_CLASS";

      if (node.attributes.isStatic) {
        constName += "_STATIC";
      } else if (node.attributes.isAbstract) {
        constName += "_ABSTRACT";
      }

      break;
    case "property":
      constName = "ICON_PROPERTY";
      break;
    case "event":
      constName = "ICON_EVENT";
      break;
    case "method":
      var isCtor = node.attributes.name == null;
      var isPublic = isCtor || (node.attributes.name.charAt(0) != "_");

      constName = "ICON_METHOD" + (isPublic ? "_PUB" : "_PROT");

      if (isCtor) {
        constName += "_CTOR";
      } else if (node.attributes.isStatic) {
        constName += "_STATIC";
      } else if (node.attributes.isAbstract) {
        constName += "_ABSTRACT";
      }

      break;
    case "constant":
      constName = "ICON_CONSTANT";
      break;
    default: throw new Error("Unknown node type: " + node.type);
  }

  if (inherited) {
    constName += "_INHERITED";
  } else if (node.attributes.overriddenFrom) {
    constName += "_OVERRIDDEN";
  }

  if (node.attributes.hasError) {
    constName += "_ERROR";
  } else if (node.attributes.hasWarning) {
    constName += "_WARN";
  }

  var iconUrl = api.TreeUtil[constName];
  if (iconUrl == null) {
    throw new Error("Unknown img constant: " + constName);
  }
  return iconUrl;
}


/** {string[]} The names of lists containing items. */
qx.Class.ITEM_LIST_ARR = [ "constants", "properties", "methods-pub", "methods-pub",
                        "methods-static-prot", "methods-static-prot" ];


/** {string} The URL of the overlay "abstract". */
qx.Class.OVERLAY_ABSTRACT   = "api/overlay_abstract18.gif";
/** {string} The URL of the overlay "error". */
qx.Class.OVERLAY_ERROR      = "api/overlay_error18.gif";
/** {string} The URL of the overlay "inherited". */
qx.Class.OVERLAY_INHERITED  = "api/overlay_inherited18.gif";
/** {string} The URL of the overlay "overridden". */
qx.Class.OVERLAY_OVERRIDDEN = "api/overlay_overridden18.gif";
/** {string} The URL of the overlay "static". */
qx.Class.OVERLAY_STATIC     = "api/overlay_static18.gif";
/** {string} The URL of the overlay "warning". */
qx.Class.OVERLAY_WARN       = "api/overlay_warning18.gif";


/** {string} The icon URL of a package. */
qx.Class.ICON_PACKAGE      = "api/package18.gif";
/** {string} The icon URL of a package with warning. */
qx.Class.ICON_PACKAGE_WARN = "api/package_warning18.gif";


/** {string} The icon URL of a class. */
qx.Class.ICON_CLASS       = "api/class18.gif";
/** {string} The icon URL of a class with warning. */
qx.Class.ICON_CLASS_WARN  = "api/class_warning18.gif";
/** {string} The icon URL of a class with error. */
qx.Class.ICON_CLASS_ERROR = "api/class_warning18.gif";

/** {string} The icon URL of a static class. */
qx.Class.ICON_CLASS_STATIC       = "api/class_static18.gif";
/** {string} The icon URL of a static class with warning. */
qx.Class.ICON_CLASS_STATIC_WARN  = "api/class_static_warning18.gif";
/** {string} The icon URL of a static class with error. */
qx.Class.ICON_CLASS_STATIC_ERROR = "api/class_static_warning18.gif";

/** {string} The icon URL of an abstract class. */
qx.Class.ICON_CLASS_ABSTRACT       = "api/class_abstract18.gif";
/** {string} The icon URL of an abstract class with warning. */
qx.Class.ICON_CLASS_ABSTRACT_WARN  = "api/class_abstract_warning18.gif";
/** {string} The icon URL of an abstract class with error. */
qx.Class.ICON_CLASS_ABSTRACT_ERROR = "api/class_abstract_warning18.gif";


/** {string} The icon URL of a property. */
qx.Class.ICON_PROPERTY       = "api/property18.gif";
/** {string[]} The icon URL of a property with warning. */
qx.Class.ICON_PROPERTY_WARN  = [ qx.Class.ICON_PROPERTY, qx.Class.OVERLAY_WARN ];
/** {string[]} The icon URL of a property with error. */
qx.Class.ICON_PROPERTY_ERROR = [ qx.Class.ICON_PROPERTY, qx.Class.OVERLAY_ERROR ];

/** {string[]} The icon URL of an inherited property. */
qx.Class.ICON_PROPERTY_INHERITED       = [ qx.Class.ICON_PROPERTY, qx.Class.OVERLAY_INHERITED ];
/** {string[]} The icon URL of an inherited property with warning. */
qx.Class.ICON_PROPERTY_INHERITED_WARN  = [ qx.Class.ICON_PROPERTY, qx.Class.OVERLAY_INHERITED, qx.Class.OVERLAY_WARN ];
/** {string[]} The icon URL of an inherited property with error. */
qx.Class.ICON_PROPERTY_INHERITED_ERROR = [ qx.Class.ICON_PROPERTY, qx.Class.OVERLAY_INHERITED, qx.Class.OVERLAY_ERROR ];

/** {string[]} The icon URL of an overridden property. */
qx.Class.ICON_PROPERTY_OVERRIDDEN       = [ qx.Class.ICON_PROPERTY, qx.Class.OVERLAY_OVERRIDDEN ];
/** {string[]} The icon URL of an overridden property with warning. */
qx.Class.ICON_PROPERTY_OVERRIDDEN_WARN  = [ qx.Class.ICON_PROPERTY, qx.Class.OVERLAY_OVERRIDDEN, qx.Class.OVERLAY_WARN ];
/** {string[]} The icon URL of an overridden property with error. */
qx.Class.ICON_PROPERTY_OVERRIDDEN_ERROR = [ qx.Class.ICON_PROPERTY, qx.Class.OVERLAY_OVERRIDDEN, qx.Class.OVERLAY_ERROR ];


/** {string} The icon URL of an event. */
qx.Class.ICON_EVENT = "api/event18.gif";

/** {string[]} The icon URL of an inherited event. */
qx.Class.ICON_EVENT_INHERITED = [ qx.Class.ICON_EVENT, qx.Class.OVERLAY_INHERITED ];


/** {string} The icon URL of a public method. */
qx.Class.ICON_METHOD_PUB       = "api/method_public18.gif";
/** {string[]} The icon URL of a public method with warning. */
qx.Class.ICON_METHOD_PUB_WARN  = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_ERROR ];
/** {string[]} The icon URL of a public method with error. */
qx.Class.ICON_METHOD_PUB_ERROR = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_ERROR ];

/** {string[]} The icon URL of an inherited public method. */
qx.Class.ICON_METHOD_PUB_INHERITED       = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_INHERITED ];
/** {string[]} The icon URL of an inherited public method with warning. */
qx.Class.ICON_METHOD_PUB_INHERITED_WARN  = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_INHERITED, qx.Class.OVERLAY_WARN ];
/** {string[]} The icon URL of an inherited public method with error. */
qx.Class.ICON_METHOD_PUB_INHERITED_ERROR = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_INHERITED, qx.Class.OVERLAY_ERROR ];

/** {string[]} The icon URL of an overridden public method. */
qx.Class.ICON_METHOD_PUB_OVERRIDDEN       = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_OVERRIDDEN ];
/** {string[]} The icon URL of an overridden public method with warning. */
qx.Class.ICON_METHOD_PUB_OVERRIDDEN_WARN  = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_OVERRIDDEN, qx.Class.OVERLAY_WARN ];
/** {string[]} The icon URL of an overridden public method with error. */
qx.Class.ICON_METHOD_PUB_OVERRIDDEN_ERROR = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_OVERRIDDEN, qx.Class.OVERLAY_ERROR ];

/** {string[]} The icon URL of a public static method. */
qx.Class.ICON_METHOD_PUB_STATIC       = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_STATIC ];
/** {string[]} The icon URL of a public static method with error. */
qx.Class.ICON_METHOD_PUB_STATIC_ERROR = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_STATIC, qx.Class.OVERLAY_ERROR ];

/** {string[]} The icon URL of a public abstract method. */
qx.Class.ICON_METHOD_PUB_ABSTRACT       = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_ABSTRACT ];
/** {string[]} The icon URL of a public abstract method with warning. */
qx.Class.ICON_METHOD_PUB_ABSTRACT_WARN  = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_ABSTRACT, qx.Class.OVERLAY_WARN ];
/** {string[]} The icon URL of a public abstract method with error. */
qx.Class.ICON_METHOD_PUB_ABSTRACT_ERROR = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_ABSTRACT, qx.Class.OVERLAY_ERROR ];

/** {string[]} The icon URL of an overridden public abstract method. */
qx.Class.ICON_METHOD_PUB_ABSTRACT_OVERRIDDEN       = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_ABSTRACT, qx.Class.OVERLAY_OVERRIDDEN ];
/** {string[]} The icon URL of an overridden public abstract method with warning. */
qx.Class.ICON_METHOD_PUB_ABSTRACT_OVERRIDDEN_WARN  = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_ABSTRACT, qx.Class.OVERLAY_OVERRIDDEN, qx.Class.OVERLAY_WARN ];
/** {string[]} The icon URL of an overridden public abstract method with error. */
qx.Class.ICON_METHOD_PUB_ABSTRACT_OVERRIDDEN_ERROR = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_ABSTRACT, qx.Class.OVERLAY_OVERRIDDEN, qx.Class.OVERLAY_ERROR ];

/** {string[]} The icon URL of an inherited public abstract method. */
qx.Class.ICON_METHOD_PUB_ABSTRACT_INHERITED       = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_ABSTRACT, qx.Class.OVERLAY_INHERITED ];
/** {string[]} The icon URL of an inherited public abstract method with warning. */
qx.Class.ICON_METHOD_PUB_ABSTRACT_INHERITED_WARN  = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_ABSTRACT, qx.Class.OVERLAY_INHERITED, qx.Class.OVERLAY_WARN ];
/** {string[]} The icon URL of an inherited public abstract method with error. */
qx.Class.ICON_METHOD_PUB_ABSTRACT_INHERITED_ERROR = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_ABSTRACT, qx.Class.OVERLAY_INHERITED, qx.Class.OVERLAY_ERROR ];


/** {string} The icon URL of a constructor. */
qx.Class.ICON_METHOD_PUB_CTOR       = "api/constructor18.gif";
/** {string[]} The icon URL of a constructor with error. */
qx.Class.ICON_METHOD_PUB_CTOR_ERROR = [ qx.Class.ICON_METHOD_PUB_CTOR, qx.Class.OVERLAY_ERROR ];


/** {string} The icon URL of a protected method. */
qx.Class.ICON_METHOD_PROT       = "api/method_protected18.gif";
/** {string[]} The icon URL of a protected method with warning. */
qx.Class.ICON_METHOD_PROT_WARN  = [ qx.Class.ICON_METHOD_PROT, qx.Class.OVERLAY_ERROR ];
/** {string[]} The icon URL of a protected method with error. */
qx.Class.ICON_METHOD_PROT_ERROR = [ qx.Class.ICON_METHOD_PROT, qx.Class.OVERLAY_ERROR ];

/** {string[]} The icon URL of an inherited protected method. */
qx.Class.ICON_METHOD_PROT_INHERITED       = [ qx.Class.ICON_METHOD_PROT, qx.Class.OVERLAY_INHERITED ];
/** {string[]} The icon URL of an inherited protected method with warning. */
qx.Class.ICON_METHOD_PROT_INHERITED_WARN  = [ qx.Class.ICON_METHOD_PROT, qx.Class.OVERLAY_INHERITED, qx.Class.OVERLAY_WARN ];
/** {string[]} The icon URL of an inherited protected method with error. */
qx.Class.ICON_METHOD_PROT_INHERITED_ERROR = [ qx.Class.ICON_METHOD_PROT, qx.Class.OVERLAY_INHERITED, qx.Class.OVERLAY_ERROR ];

/** {string[]} The icon URL of an overridden protected method. */
qx.Class.ICON_METHOD_PROT_OVERRIDDEN       = [ qx.Class.ICON_METHOD_PROT, qx.Class.OVERLAY_OVERRIDDEN ];
/** {string[]} The icon URL of an overridden protected method with warning. */
qx.Class.ICON_METHOD_PROT_OVERRIDDEN_WARN  = [ qx.Class.ICON_METHOD_PROT, qx.Class.OVERLAY_OVERRIDDEN, qx.Class.OVERLAY_WARN ];
/** {string[]} The icon URL of an overridden protected method with error. */
qx.Class.ICON_METHOD_PROT_OVERRIDDEN_ERROR = [ qx.Class.ICON_METHOD_PROT, qx.Class.OVERLAY_OVERRIDDEN, qx.Class.OVERLAY_ERROR ];

/** {string[]} The icon URL of a protected static method. */
qx.Class.ICON_METHOD_PROT_STATIC       = [ qx.Class.ICON_METHOD_PROT, qx.Class.OVERLAY_STATIC ];
/** {string[]} The icon URL of a protected static method with error. */
qx.Class.ICON_METHOD_PROT_STATIC_ERROR = [ qx.Class.ICON_METHOD_PROT, qx.Class.OVERLAY_STATIC, qx.Class.OVERLAY_ERROR ];

/** {string[]} The icon URL of an abstract protected method. */
qx.Class.ICON_METHOD_PROT_ABSTRACT       = [ qx.Class.ICON_METHOD_PROT, qx.Class.OVERLAY_ABSTRACT ];
/** {string[]} The icon URL of an abstract protected method with warning. */
qx.Class.ICON_METHOD_PROT_ABSTRACT_WARN  = [ qx.Class.ICON_METHOD_PROT, qx.Class.OVERLAY_ABSTRACT, qx.Class.OVERLAY_WARN ];
/** {string[]} The icon URL of an abstract protected method with error. */
qx.Class.ICON_METHOD_PROT_ABSTRACT_ERROR = [ qx.Class.ICON_METHOD_PROT, qx.Class.OVERLAY_ABSTRACT, qx.Class.OVERLAY_ERROR ];

/** {string[]} The icon URL of an inherited abstract protected method. */
qx.Class.ICON_METHOD_PROT_ABSTRACT_INHERITED       = [ qx.Class.ICON_METHOD_PROT, qx.Class.OVERLAY_ABSTRACT, qx.Class.OVERLAY_INHERITED ];
/** {string[]} The icon URL of an inherited abstract protected method with warning. */
qx.Class.ICON_METHOD_PROT_ABSTRACT_INHERITED_WARN  = [ qx.Class.ICON_METHOD_PROT, qx.Class.OVERLAY_ABSTRACT, qx.Class.OVERLAY_INHERITED, qx.Class.OVERLAY_WARN ];
/** {string[]} The icon URL of an inherited abstract protected method with error. */
qx.Class.ICON_METHOD_PROT_ABSTRACT_INHERITED_ERROR = [ qx.Class.ICON_METHOD_PROT, qx.Class.OVERLAY_ABSTRACT, qx.Class.OVERLAY_INHERITED, qx.Class.OVERLAY_ERROR ];


/** {string} The icon URL of a constant. */
qx.Class.ICON_CONSTANT       = "api/constant18.gif";
/** {string[]} The icon URL of a constant with error. */
qx.Class.ICON_CONSTANT_ERROR = [ qx.Class.ICON_CONSTANT, qx.Class.OVERLAY_ERROR ];