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") {
40 function array2object(a)
43 a.forEach(function(e) {
49 ['isUserComment','src', 'meta', 'tags'].forEach(function(k) {
52 ret.tags = array2object(this.tags,true);
57 * @requires JSDOC.DocTag
59 parse : function(/**String*/comment) {
61 comment = "/** @desc */";
62 this.isUserComment = false;
66 this.src = DocComment.unwrapComment(comment);
72 if (this.src.indexOf("#") == 0) {
73 this.src.match(/#(.+[+-])([\s\S]*)$/);
74 if (RegExp.$1) this.meta = RegExp.$1;
75 if (RegExp.$2) this.src = RegExp.$2;
78 if (!/^\s*@\s*\S+/m.test(this.src)) {
79 this.isUserComment = false;
86 //if (typeof JSDOC.PluginManager != "undefined") {
87 // JSDOC.PluginManager.run("onDocCommentSrc", this);
90 this.src = DocComment.shared+"\n"+this.src;
98 .split(/(^|[\r\n])\s*@/)
99 .filter(function($){return $.match(/\S/)});
101 //println(this.tagTexts.toSource());
107 The tags found in the comment.
111 this.tags = this.tagTexts.map(function($){return new DocTag($)});
113 //println(this.tags.toSource());
114 this.tagTexts = []; // we dont need to store this..
117 //if (typeof JSDOC.PluginManager != "undefined") {
118 // JSDOC.PluginManager.run("onDocCommentTags", this);
124 If no @desc tag is provided, this function will add it.
126 fixDesc : function() {
127 if (this.meta && this.meta != "@+") return;
131 // does not have any @ lines..
132 // -- skip comments without @!!
133 if (!/^\s*@\s*\S+/.test(this.src)) {
134 this.src = "@desc "+this.src;
135 // TAGS that are not \n prefixed!! ...
136 this.src = this.src.replace(/@\s*type/g, '\n@type');
140 // kdludge for stuff...
141 //this.src = this.src.replace(/@\s*type/g, '\n@type');
143 // only apply @desc fix to classes..
144 if (!/\s*@(class|event|property)/m.test(this.src) ) {
147 // if no desc - add it on the first line that is not a @
148 var lines = this.src.split("\n");
152 for(var i =0; i < lines.length;i++) {
158 if (/^\s*[@\s]/.test(line)) { // line with @
163 nsrc += '@desc ' + line + "\n";
174 Provides a printable version of the comment.
177 toString : function() {
182 assert("testing JSDOC.DocComment#fixDesc");
183 var com = new JSDOC.DocComment();
185 assertEqual(""+com, "foo", "stringifying a comment returns the unwrapped src.");
189 Given the title of a tag, returns all tags that have that title.
194 toQDump : function(t)
196 //println(t.toSource());
197 var r = JSDOC.toQDump(t, 'JSDOC.DocComment.fromDump({', '})', {}); // send it an empty object..
203 getTag : function(/**String*/tagTitle) {
204 return this.tags.filter(function($){return (typeof($['title']) != 'undefined') && ($.title == tagTitle)});
212 XObject.extend(DocComment,
216 * Used to store the currently shared tag text.
221 * Remove slash-star comment wrapper from a raw comment string.
224 unwrapComment : function(/**String*/comment) {
225 if (!comment) return "";
226 var unwrapped = comment.replace(/(^\/\*\*|\*\/$)/g, "").replace(/^\s*\* ?/gm, "");
230 fromDump : function(t)
232 var ns = new DocComment();