1 //<Script type="text/javascript">
3 const XObject = imports.XObject.XObject;
5 const 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 const 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) {
51 * @requires JSDOC.DocTag
53 parse : function(/**String*/comment) {
55 comment = "/** @desc */";
56 this.isUserComment = false;
60 this.src = DocComment.unwrapComment(comment);
66 if (this.src.indexOf("#") == 0) {
67 this.src.match(/#(.+[+-])([\s\S]*)$/);
68 if (RegExp.$1) this.meta = RegExp.$1;
69 if (RegExp.$2) this.src = RegExp.$2;
72 if (!/^\s*@\s*\S+/m.test(this.src)) {
73 this.isUserComment = false;
80 //if (typeof JSDOC.PluginManager != "undefined") {
81 // JSDOC.PluginManager.run("onDocCommentSrc", this);
84 this.src = DocComment.shared+"\n"+this.src;
92 .split(/(^|[\r\n])\s*@/)
93 .filter(function($){return $.match(/\S/)});
95 //println(this.tagTexts.toSource());
101 The tags found in the comment.
105 this.tags = this.tagTexts.map(function($){return new DocTag($)});
107 //println(this.tags.toSource());
108 this.tagTexts = []; // we dont need to store this..
111 //if (typeof JSDOC.PluginManager != "undefined") {
112 // JSDOC.PluginManager.run("onDocCommentTags", this);
118 If no @desc tag is provided, this function will add it.
120 fixDesc : function() {
121 if (this.meta && this.meta != "@+") return;
125 // does not have any @ lines..
126 // -- skip comments without @!!
127 if (!/^\s*@\s*\S+/.test(this.src)) {
128 this.src = "@desc "+this.src;
129 // TAGS that are not \n prefixed!! ...
130 this.src = this.src.replace(/@\s*type/g, '\n@type');
134 // kdludge for stuff...
135 //this.src = this.src.replace(/@\s*type/g, '\n@type');
137 // only apply @desc fix to classes..
138 if (!/\s*@(class|event|property)/m.test(this.src) ) {
141 // if no desc - add it on the first line that is not a @
142 var lines = this.src.split("\n");
146 for(var i =0; i < lines.length;i++) {
152 if (/^\s*[@\s]/.test(line)) { // line with @
157 nsrc += '@desc ' + line + "\n";
168 Provides a printable version of the comment.
171 toString : function() {
176 assert("testing JSDOC.DocComment#fixDesc");
177 var com = new JSDOC.DocComment();
179 assertEqual(""+com, "foo", "stringifying a comment returns the unwrapped src.");
183 Given the title of a tag, returns all tags that have that title.
188 toQDump : function(t)
190 //println(t.toSource());
191 var r = JSDOC.toQDump(t, 'JSDOC.DocComment.fromDump({', '})', {}); // send it an empty object..
197 getTag : function(/**String*/tagTitle) {
198 return this.tags.filter(function($){return (typeof($['title']) != 'undefined') && ($.title == tagTitle)});
206 XObject.extend(DocComment,
210 * Used to store the currently shared tag text.
215 * Remove slash-star comment wrapper from a raw comment string.
218 unwrapComment : function(/**String*/comment) {
219 if (!comment) return "";
220 var unwrapped = comment.replace(/(^\/\*\*|\*\/$)/g, "").replace(/^\s*\* ?/gm, "");
224 fromDump : function(t)
226 var ns = new DocComment();