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") {
43 var ret = { '*object' : 'DocComment' };
46 ['isUserComment','src', 'meta', 'tags'].forEach(function(k) {
53 * @requires JSDOC.DocTag
55 parse : function(/**String*/comment) {
57 comment = "/** @desc */";
58 this.isUserComment = false;
62 this.src = DocComment.unwrapComment(comment);
68 if (this.src.indexOf("#") == 0) {
69 this.src.match(/#(.+[+-])([\s\S]*)$/);
70 if (RegExp.$1) this.meta = RegExp.$1;
71 if (RegExp.$2) this.src = RegExp.$2;
74 if (!/^\s*@\s*\S+/m.test(this.src)) {
75 this.isUserComment = false;
82 //if (typeof JSDOC.PluginManager != "undefined") {
83 // JSDOC.PluginManager.run("onDocCommentSrc", this);
86 this.src = DocComment.shared+"\n"+this.src;
94 .split(/(^|[\r\n])\s*@/)
95 .filter(function($){return $.match(/\S/)});
97 //println(this.tagTexts.toSource());
103 The tags found in the comment.
107 this.tags = this.tagTexts.map(function($){return new DocTag($)});
109 //println(this.tags.toSource());
110 this.tagTexts = []; // we dont need to store this..
113 //if (typeof JSDOC.PluginManager != "undefined") {
114 // JSDOC.PluginManager.run("onDocCommentTags", this);
120 If no @desc tag is provided, this function will add it.
122 fixDesc : function() {
123 if (this.meta && this.meta != "@+") return;
127 // does not have any @ lines..
128 // -- skip comments without @!!
129 if (!/^\s*@\s*\S+/.test(this.src)) {
130 this.src = "@desc "+this.src;
131 // TAGS that are not \n prefixed!! ...
132 this.src = this.src.replace(/@\s*type/g, '\n@type');
136 // kdludge for stuff...
137 //this.src = this.src.replace(/@\s*type/g, '\n@type');
139 // only apply @desc fix to classes..
140 if (!/\s*@(class|event|property)/m.test(this.src) ) {
143 // if no desc - add it on the first line that is not a @
144 var lines = this.src.split("\n");
148 for(var i =0; i < lines.length;i++) {
154 if (/^\s*[@\s]/.test(line)) { // line with @
159 nsrc += '@desc ' + line + "\n";
170 Provides a printable version of the comment.
173 toString : function() {
178 assert("testing JSDOC.DocComment#fixDesc");
179 var com = new JSDOC.DocComment();
181 assertEqual(""+com, "foo", "stringifying a comment returns the unwrapped src.");
185 Given the title of a tag, returns all tags that have that title.
190 toQDump : function(t)
192 //println(t.toSource());
193 var r = JSDOC.toQDump(t, 'JSDOC.DocComment.fromDump({', '})', {}); // send it an empty object..
199 getTag : function(/**String*/tagTitle) {
200 return this.tags.filter(function($){return (typeof($['title']) != 'undefined') && ($.title == tagTitle)});
208 XObject.extend(DocComment,
212 * Used to store the currently shared tag text.
217 * Remove slash-star comment wrapper from a raw comment string.
220 unwrapComment : function(/**String*/comment) {
221 if (!comment) return "";
222 var unwrapped = comment.replace(/(^\/\*\*|\*\/$)/g, "").replace(/^\s*\* ?/gm, "");
226 fromDump : function(t)
228 var ns = new DocComment();