/tags/jsdoc_toolkit-1.3.3/app/Symbol.js

http://jsdoc-toolkit.googlecode.com/ · JavaScript · 244 lines · 198 code · 30 blank · 16 comment · 71 complexity · 27f2dbcdb4063115410489389bccf94c MD5 · raw file

  1. /**
  2. * @fileOverview
  3. * @name Symbol
  4. * @author Michael Mathews micmath@gmail.com
  5. * @url $HeadURL: http://jsdoc-toolkit.googlecode.com/svn/tags/jsdoc_toolkit-1.3.3/app/Symbol.js $
  6. * @revision $Id: Symbol.js 260 2007-10-03 22:18:38Z micmath $
  7. * @license <a href="http://en.wikipedia.org/wiki/MIT_License">X11/MIT License</a>
  8. * (See the accompanying README file for full details.)
  9. */
  10. SYM = {
  11. OBJECT: "OBJECT",
  12. FUNCTION: "FUNCTION",
  13. CONSTRUCTOR: "CONSTRUCTOR",
  14. VIRTUAL: "VIRTUAL",
  15. EVENT: "EVENT"
  16. };
  17. /**
  18. @class Represents an atomic unit of code.
  19. @constructor
  20. */
  21. function Symbol(name, params, isa, comment) {
  22. this.name = name;
  23. this.params = (params || []);
  24. this.isa = (isa || SYM.OBJECT);
  25. this.type = "";
  26. this.alias = name;
  27. this.desc = "";
  28. this.classDesc = "";
  29. this.memberof = "";
  30. this.augments = [];
  31. this.inherits = [];
  32. this.properties = [];
  33. this.methods = [];
  34. this.file = {};
  35. this.returns = [];
  36. this.exceptions = [];
  37. this.events= [];
  38. this.doc = new Doclet(comment);
  39. // move certain data out of the tags and into the Symbol
  40. var overviews;
  41. if ((overviews = this.doc.getTag("overview")) && overviews.length) {
  42. var libraries;
  43. if ((libraries = this.doc.getTag("name")) && libraries.length) {
  44. this.name = libraries[0].desc;
  45. this.doc._dropTag("name");
  46. }
  47. else {
  48. this.name = Util.fileName(this.alias)
  49. }
  50. this.desc = overviews[0].desc;
  51. this.doc._dropTag("overview");
  52. }
  53. else {
  54. var descs;
  55. if ((descs = this.doc.getTag("desc")) && descs.length) {
  56. this.desc = descs[0].desc;
  57. this.doc._dropTag("desc");
  58. }
  59. var params;
  60. if ((params = this.doc.getTag("param")) && params.length) { // user defined params override those defined by parser
  61. this.params = params;
  62. this.doc._dropTag("param");
  63. }
  64. else { // promote parser params into DocTag objects
  65. for (var i = 0; i < this.params.length; i++) {
  66. this.params[i] = new DocTag("param "+this.params[i]);
  67. }
  68. }
  69. var constructors;
  70. if ((constructors = this.doc.getTag("constructor")) && constructors.length) {
  71. this.isa = SYM.CONSTRUCTOR;
  72. this.doc._dropTag("constructor");
  73. }
  74. var functions;
  75. if ((functions = this.doc.getTag("function")) && functions.length) {
  76. this.isa = SYM.FUNCTION;
  77. this.doc._dropTag("function");
  78. }
  79. var events;
  80. if ((events = this.doc.getTag("event")) && events.length) {
  81. this.isa = SYM.EVENT;
  82. this.doc._dropTag("event");
  83. }
  84. var methods;
  85. if ((functions = this.doc.getTag("method")) && functions.length) {
  86. this.isa = SYM.FUNCTION;
  87. this.doc._dropTag("method");
  88. }
  89. var names;
  90. if ((names = this.doc.getTag("name")) && names.length) {
  91. this.name = names[0].desc;
  92. this.doc._dropTag("name");
  93. }
  94. var properties;
  95. if ((properties = this.doc.getTag("property")) && properties.length) {
  96. for (var i = 0; i < properties.length; i++) {
  97. properties[i].alias = this.alias+"."+properties[i].name;
  98. this.properties.push(properties[i]);
  99. }
  100. this.doc._dropTag("property");
  101. }
  102. var returns;
  103. if ((returns = this.doc.getTag("return")) && returns.length) {
  104. for (var i = 0; i < returns.length; i++) {
  105. this.returns.push(returns[i]);
  106. }
  107. this.doc._dropTag("return");
  108. }
  109. var exceptions;
  110. if ((exceptions = this.doc.getTag("throws")) && exceptions.length) {
  111. for (var i = 0; i < exceptions.length; i++) {
  112. this.exceptions.push(exceptions[i]);
  113. }
  114. this.doc._dropTag("throws");
  115. }
  116. if (this.is("VIRTUAL")) this.isa = SYM.OBJECT;
  117. var types;
  118. if ((types = this.doc.getTag("type")) && types.length) {
  119. if (this.is("OBJECT"))
  120. this.type = (types[0].desc || ""); // multiple type tags are ignored
  121. this.doc._dropTag("type");
  122. }
  123. if (this.doc.getTag("static").length > 0) {
  124. this.isStatic = true;
  125. this.doc._dropTag("static");
  126. }
  127. if (this.doc.getTag("private").length > 0) {
  128. this.isPrivate = true;
  129. this.doc._dropTag("private");
  130. }
  131. var classes;
  132. if ((classes = this.doc.getTag("class")) && classes.length) {
  133. if (this.doc.getTag("static").length > 0) this.isStatic = true;
  134. this.isa = "CONSTRUCTOR"; // a class tag implies a conctuctor doclet
  135. this.classDesc += "\n"+classes[0].desc; // multiple class tags are concatenated
  136. if (this.desc == "") this.desc = this.classDesc; // the first class description will be used when there is no constructor description
  137. this.doc._dropTag("class");
  138. }
  139. var inherits;
  140. if ((inherits = this.doc.getTag("inherits")) && inherits.length) {
  141. for (var i = 0; i < inherits.length; i++) {
  142. this.inherits.push(inherits[i].desc);
  143. }
  144. this.doc._dropTag("inherits");
  145. }
  146. var augments;
  147. if ((augments = this.doc.getTag("augments")) && augments.length) {
  148. for (var i = 0; i < augments.length; i++) {
  149. this.augments.push(augments[i].desc);
  150. }
  151. this.doc._dropTag("augments");
  152. }
  153. Symbol.index[this.alias] = this;
  154. }
  155. }
  156. Symbol.index = {};
  157. Symbol.prototype.is = function(what) {
  158. return this.isa === SYM[what];
  159. }
  160. /** Generate a comma separated list of the parameters. */
  161. Symbol.prototype.signature = function() {
  162. var result = [];
  163. for (var i = 0; i < this.params.length; i++) {
  164. if (this.params[i].name.indexOf(".") == -1) // config information does not appear in the signature
  165. result.push(this.params[i].name);
  166. }
  167. return result.join(", ");
  168. }
  169. Symbol.prototype.hasMethod = function(name) {
  170. for (var i = 0; i < this.methods.length; i++) {
  171. if (this.methods[i].name == name) return true
  172. }
  173. return false;
  174. }
  175. Symbol.prototype.hasEvent = function(name) {
  176. for (var i = 0; i < this.events.length; i++) {
  177. if (this.events[i].name == name) return true
  178. }
  179. return false;
  180. }
  181. Symbol.prototype.hasProperty = function(name) {
  182. for (var i = 0; i < this.properties.length; i++) {
  183. if (this.properties[i].name == name) return true
  184. }
  185. return false;
  186. }
  187. Symbol.prototype.getInheritedMethods = function(r) {
  188. var inherited = [];
  189. for(var i = 0; i < this.inherits.length; i++) {
  190. inherited.push(this.file.fileGroup.getSymbol(this.inherits[i]));
  191. }
  192. var result = this.methods.concat(inherited);
  193. for(var i = 0; i < this.augments.length; i++) {
  194. var contributer = this.file.fileGroup.getSymbol(this.augments[i]);
  195. if (contributer) {
  196. result = result.concat(contributer.getInheritedMethods(true));
  197. }
  198. }
  199. // remove overridden
  200. for (var i = 0; i < result.length; i++) {
  201. var j = i;
  202. while (++j < result.length) {
  203. if (result[j].name == result[i].name) result.splice(j, 1);
  204. }
  205. }
  206. if (!r) { // not recursing
  207. var s = this;
  208. function notLocal(element, index, array) {
  209. return (!s.hasMethod(element.name));
  210. }
  211. result = result.filter(notLocal);
  212. }
  213. return result;
  214. }