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;
23 if (typeof comment != "undefined") {
33 * @requires JSDOC.DocTag
35 parse : function(/**String*/comment) {
37 comment = "/** @desc */";
38 this.isUserComment = false;
42 this.src = DocComment.unwrapComment(comment);
48 if (this.src.indexOf("#") == 0) {
49 this.src.match(/#(.+[+-])([\s\S]*)$/);
50 if (RegExp.$1) this.meta = RegExp.$1;
51 if (RegExp.$2) this.src = RegExp.$2;
54 if (!/^\s*@\s*\S+/m.test(this.src)) {
55 this.isUserComment = false;
62 //if (typeof JSDOC.PluginManager != "undefined") {
63 // JSDOC.PluginManager.run("onDocCommentSrc", this);
66 this.src = DocComment.shared+"\n"+this.src;
74 .split(/(^|[\r\n])\s*@/)
75 .filter(function($){return $.match(/\S/)});
77 //println(this.tagTexts.toSource());
83 The tags found in the comment.
87 this.tags = this.tagTexts.map(function($){return new DocTag($)});
89 //println(this.tags.toSource());
90 this.tagTexts = []; // we dont need to store this..
93 //if (typeof JSDOC.PluginManager != "undefined") {
94 // JSDOC.PluginManager.run("onDocCommentTags", this);
100 If no @desc tag is provided, this function will add it.
102 fixDesc : function() {
103 if (this.meta && this.meta != "@+") return;
107 // does not have any @ lines..
108 // -- skip comments without @!!
109 if (!/^\s*@\s*\S+/.test(this.src)) {
110 this.src = "@desc "+this.src;
111 // TAGS that are not \n prefixed!! ...
112 this.src = this.src.replace(/@\s*type/g, '\n@type');
116 // kdludge for stuff...
117 //this.src = this.src.replace(/@\s*type/g, '\n@type');
119 // only apply @desc fix to classes..
120 if (!/\s*@(class|event|property)/m.test(this.src) ) {
123 // if no desc - add it on the first line that is not a @
124 var lines = this.src.split("\n");
128 for(var i =0; i < lines.length;i++) {
134 if (/^\s*[@\s]/.test(line)) { // line with @
139 nsrc += '@desc ' + line + "\n";
150 Provides a printable version of the comment.
153 toString : function() {
158 assert("testing JSDOC.DocComment#fixDesc");
159 var com = new JSDOC.DocComment();
161 assertEqual(""+com, "foo", "stringifying a comment returns the unwrapped src.");
165 Given the title of a tag, returns all tags that have that title.
170 toQDump : function(t)
172 //println(t.toSource());
173 var r = JSDOC.toQDump(t, 'JSDOC.DocComment.fromDump({', '})', {}); // send it an empty object..
179 getTag : function(/**String*/tagTitle) {
180 return this.tags.filter(function($){return (typeof($['title']) != 'undefined') && ($.title == tagTitle)});
188 XObject.extend(DocComment,
192 * Used to store the currently shared tag text.
197 * Remove slash-star comment wrapper from a raw comment string.
200 unwrapComment : function(/**String*/comment) {
201 if (!comment) return "";
202 var unwrapped = comment.replace(/(^\/\*\*|\*\/$)/g, "").replace(/^\s*\* ?/gm, "");
206 fromDump : function(t)
208 var ns = new DocComment();