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") {
41 var ret = { _object : 'DocComment' };
44 ['isUserComment','src', 'meta', 'tags'].forEach(function(k) {
47 ret.tags = array2object(this.tags,true);
52 * @requires JSDOC.DocTag
54 parse : function(/**String*/comment) {
56 comment = "/** @desc */";
57 this.isUserComment = false;
61 this.src = DocComment.unwrapComment(comment);
67 if (this.src.indexOf("#") == 0) {
68 this.src.match(/#(.+[+-])([\s\S]*)$/);
69 if (RegExp.$1) this.meta = RegExp.$1;
70 if (RegExp.$2) this.src = RegExp.$2;
73 if (!/^\s*@\s*\S+/m.test(this.src)) {
74 this.isUserComment = false;
81 //if (typeof JSDOC.PluginManager != "undefined") {
82 // JSDOC.PluginManager.run("onDocCommentSrc", this);
85 this.src = DocComment.shared+"\n"+this.src;
93 .split(/(^|[\r\n])\s*@/)
94 .filter(function($){return $.match(/\S/)});
96 //println(this.tagTexts.toSource());
102 The tags found in the comment.
106 this.tags = this.tagTexts.map(function($){return new DocTag($)});
108 //println(this.tags.toSource());
109 this.tagTexts = []; // we dont need to store this..
112 //if (typeof JSDOC.PluginManager != "undefined") {
113 // JSDOC.PluginManager.run("onDocCommentTags", this);
119 If no @desc tag is provided, this function will add it.
121 fixDesc : function() {
122 if (this.meta && this.meta != "@+") return;
126 // does not have any @ lines..
127 // -- skip comments without @!!
128 if (!/^\s*@\s*\S+/.test(this.src)) {
129 this.src = "@desc "+this.src;
130 // TAGS that are not \n prefixed!! ...
131 this.src = this.src.replace(/@\s*type/g, '\n@type');
135 // kdludge for stuff...
136 //this.src = this.src.replace(/@\s*type/g, '\n@type');
138 // only apply @desc fix to classes..
139 if (!/\s*@(class|event|property)/m.test(this.src) ) {
142 // if no desc - add it on the first line that is not a @
143 var lines = this.src.split("\n");
147 for(var i =0; i < lines.length;i++) {
153 if (/^\s*[@\s]/.test(line)) { // line with @
158 nsrc += '@desc ' + line + "\n";
169 Provides a printable version of the comment.
172 toString : function() {
177 assert("testing JSDOC.DocComment#fixDesc");
178 var com = new JSDOC.DocComment();
180 assertEqual(""+com, "foo", "stringifying a comment returns the unwrapped src.");
184 Given the title of a tag, returns all tags that have that title.
189 toQDump : function(t)
191 //println(t.toSource());
192 var r = JSDOC.toQDump(t, 'JSDOC.DocComment.fromDump({', '})', {}); // send it an empty object..
198 getTag : function(/**String*/tagTitle) {
199 return this.tags.filter(function($){return (typeof($['title']) != 'undefined') && ($.title == tagTitle)});
207 XObject.extend(DocComment,
211 * Used to store the currently shared tag text.
216 * Remove slash-star comment wrapper from a raw comment string.
219 unwrapComment : function(/**String*/comment) {
220 if (!comment) return "";
221 var unwrapped = comment.replace(/(^\/\*\*|\*\/$)/g, "").replace(/^\s*\* ?/gm, "");
225 fromDump : function(t)
227 var ns = new DocComment();