1 //<Script type="text/javascript">
3 XObject = imports.XObject.XObject;
5 DocTag = imports.DocTag.DocTag;
8 * Create a new DocComment. This takes a raw documentation comment,
9 * and wraps it in useful accessors.
10 * @class Represents a documentation comment object.
15 DocComment = XObject.define(
17 function(/**String*/comment) {
18 this.isUserComment = true;
22 this.tags = []; // array of doctags..
23 if (typeof comment != "undefined") {
29 this.isUserComment = true;
43 switch (typeof(this[i])) {
51 ret[i] = this[i]; continue;
53 print("unknown type:" + typeof(this[i]));
60 * @requires JSDOC.DocTag
62 parse : function(/**String*/comment) {
64 comment = "/** @desc */";
65 this.isUserComment = false;
69 this.src = DocComment.unwrapComment(comment);
75 if (this.src.indexOf("#") == 0) {
76 this.src.match(/#(.+[+-])([\s\S]*)$/);
77 if (RegExp.$1) this.meta = RegExp.$1;
78 if (RegExp.$2) this.src = RegExp.$2;
81 if (!/^\s*@\s*\S+/m.test(this.src)) {
82 this.isUserComment = false;
89 //if (typeof JSDOC.PluginManager != "undefined") {
90 // JSDOC.PluginManager.run("onDocCommentSrc", this);
93 this.src = DocComment.shared+"\n"+this.src;
101 .split(/(^|[\r\n])\s*@/)
102 .filter(function($){return $.match(/\S/)});
104 //println(this.tagTexts.toSource());
110 The tags found in the comment.
114 this.tags = this.tagTexts.map(function($){return new DocTag($)});
116 //println(this.tags.toSource());
117 this.tagTexts = []; // we dont need to store this..
120 //if (typeof JSDOC.PluginManager != "undefined") {
121 // JSDOC.PluginManager.run("onDocCommentTags", this);
127 If no @desc tag is provided, this function will add it.
129 fixDesc : function() {
130 if (this.meta && this.meta != "@+") return;
134 // does not have any @ lines..
135 // -- skip comments without @!!
136 if (!/^\s*@\s*\S+/.test(this.src)) {
137 this.src = "@desc "+this.src;
138 // TAGS that are not \n prefixed!! ...
139 this.src = this.src.replace(/@\s*type/g, '\n@type');
143 // kdludge for stuff...
144 //this.src = this.src.replace(/@\s*type/g, '\n@type');
146 // only apply @desc fix to classes..
147 if (!/\s*@(class|event|property)/m.test(this.src) ) {
150 // if no desc - add it on the first line that is not a @
151 var lines = this.src.split("\n");
155 for(var i =0; i < lines.length;i++) {
161 if (/^\s*[@\s]/.test(line)) { // line with @
166 nsrc += '@desc ' + line + "\n";
177 Provides a printable version of the comment.
180 toString : function() {
185 assert("testing JSDOC.DocComment#fixDesc");
186 var com = new JSDOC.DocComment();
188 assertEqual(""+com, "foo", "stringifying a comment returns the unwrapped src.");
192 Given the title of a tag, returns all tags that have that title.
197 toQDump : function(t)
199 //println(t.toSource());
200 var r = JSDOC.toQDump(t, 'JSDOC.DocComment.fromDump({', '})', {}); // send it an empty object..
206 getTag : function(/**String*/tagTitle) {
207 return this.tags.filter(function($){return (typeof($['title']) != 'undefined') && ($.title == tagTitle)});
215 XObject.extend(DocComment,
219 * Used to store the currently shared tag text.
224 * Remove slash-star comment wrapper from a raw comment string.
227 unwrapComment : function(/**String*/comment) {
228 if (!comment) return "";
229 var unwrapped = comment.replace(/(^\/\*\*|\*\/$)/g, "").replace(/^\s*\* ?/gm, "");
233 fromDump : function(t)
235 var ns = new DocComment();