PageRenderTime 40ms CodeModel.GetById 16ms app.highlight 20ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/jsdoc_toolkit-1.3.3/app/Symbol.js

http://jsdoc-toolkit.googlecode.com/
JavaScript | 244 lines | 198 code | 30 blank | 16 comment | 71 complexity | 27f2dbcdb4063115410489389bccf94c MD5 | raw file
  1/**
  2 * @fileOverview
  3 * @name Symbol
  4 * @author Michael Mathews micmath@gmail.com
  5 * @url $HeadURL: http://jsdoc-toolkit.googlecode.com/svn/tags/jsdoc_toolkit-1.3.3/app/Symbol.js $
  6 * @revision $Id: Symbol.js 260 2007-10-03 22:18:38Z micmath $
  7 * @license <a href="http://en.wikipedia.org/wiki/MIT_License">X11/MIT License</a>
  8 *          (See the accompanying README file for full details.)
  9 */
 10
 11SYM = {
 12	OBJECT:			"OBJECT",
 13	FUNCTION:		"FUNCTION",
 14	CONSTRUCTOR:	"CONSTRUCTOR",
 15	VIRTUAL:		"VIRTUAL",
 16    EVENT:          "EVENT"
 17};
 18
 19/**
 20	@class Represents an atomic unit of code.
 21	@constructor
 22*/
 23function Symbol(name, params, isa, comment) {
 24	this.name = name;
 25	this.params = (params || []);
 26	this.isa = (isa || SYM.OBJECT);
 27	this.type = "";
 28	this.alias = name;
 29	this.desc = "";
 30	this.classDesc = "";
 31	this.memberof = "";
 32	this.augments = [];
 33	this.inherits = [];
 34	this.properties = [];
 35	this.methods = [];
 36	this.file = {};
 37	this.returns = [];
 38	this.exceptions = [];
 39    this.events= [];
 40	this.doc = new Doclet(comment);
 41	
 42	// move certain data out of the tags and into the Symbol
 43	var overviews;
 44	if ((overviews = this.doc.getTag("overview")) && overviews.length) {
 45		var libraries;
 46		if ((libraries = this.doc.getTag("name")) && libraries.length) {
 47			this.name = libraries[0].desc;
 48			this.doc._dropTag("name");
 49		}
 50		else {
 51			this.name = Util.fileName(this.alias)
 52		}
 53		
 54		this.desc = overviews[0].desc;
 55		this.doc._dropTag("overview");
 56	}
 57	else {
 58		var descs;
 59		if ((descs = this.doc.getTag("desc")) && descs.length) {
 60			this.desc = descs[0].desc;
 61			this.doc._dropTag("desc");
 62		}
 63		
 64		var params;
 65		if ((params = this.doc.getTag("param")) && params.length) { // user defined params override those defined by parser
 66			this.params = params;
 67			this.doc._dropTag("param");
 68		}
 69		else { // promote parser params into DocTag objects
 70			for (var i = 0; i < this.params.length; i++) {
 71				this.params[i] = new DocTag("param "+this.params[i]);
 72			}
 73		}
 74		
 75		var constructors;
 76		if ((constructors = this.doc.getTag("constructor")) && constructors.length) {
 77			this.isa = SYM.CONSTRUCTOR;
 78			this.doc._dropTag("constructor");
 79		}
 80		
 81		var functions;
 82		if ((functions = this.doc.getTag("function")) && functions.length) {
 83			this.isa = SYM.FUNCTION;
 84			this.doc._dropTag("function");
 85		}
 86        
 87        var events;
 88		if ((events = this.doc.getTag("event")) && events.length) {
 89			this.isa = SYM.EVENT;
 90			this.doc._dropTag("event");
 91		}
 92		
 93		var methods;
 94		if ((functions = this.doc.getTag("method")) && functions.length) {
 95			this.isa = SYM.FUNCTION;
 96			this.doc._dropTag("method");
 97		}
 98		
 99		var names;
100		if ((names = this.doc.getTag("name")) && names.length) {
101			this.name = names[0].desc;
102			this.doc._dropTag("name");
103		}
104		
105		var properties;
106		if ((properties = this.doc.getTag("property")) && properties.length) {
107			for (var i = 0; i < properties.length; i++) {
108				properties[i].alias = this.alias+"."+properties[i].name;
109				this.properties.push(properties[i]);
110			}
111			this.doc._dropTag("property");
112		}
113		
114		var returns;
115		if ((returns = this.doc.getTag("return")) && returns.length) {
116			for (var i = 0; i < returns.length; i++) {
117				this.returns.push(returns[i]);
118			}
119			this.doc._dropTag("return");
120		}
121		
122		var exceptions;
123		if ((exceptions = this.doc.getTag("throws")) && exceptions.length) {
124			for (var i = 0; i < exceptions.length; i++) {
125				this.exceptions.push(exceptions[i]);
126			}
127			this.doc._dropTag("throws");
128		}
129		
130		if (this.is("VIRTUAL")) this.isa = SYM.OBJECT;
131		
132		var types;
133		if ((types = this.doc.getTag("type")) && types.length) {
134			if (this.is("OBJECT"))
135				this.type = (types[0].desc || ""); // multiple type tags are ignored
136			this.doc._dropTag("type");
137		}
138		
139		if (this.doc.getTag("static").length > 0) {
140			this.isStatic = true;
141			this.doc._dropTag("static");
142		}
143		
144		if (this.doc.getTag("private").length > 0) {
145			this.isPrivate = true;
146			this.doc._dropTag("private");
147		}
148			
149		var classes;
150		if ((classes = this.doc.getTag("class")) && classes.length) {
151			if (this.doc.getTag("static").length > 0) this.isStatic = true;
152			this.isa = "CONSTRUCTOR"; // a class tag implies a conctuctor doclet
153			
154			this.classDesc += "\n"+classes[0].desc; // multiple class tags are concatenated
155			if (this.desc == "") this.desc = this.classDesc; // the first class description will be used when there is no constructor description
156			this.doc._dropTag("class");
157		}
158		
159		var inherits;
160		if ((inherits = this.doc.getTag("inherits")) && inherits.length) {
161			for (var i = 0; i < inherits.length; i++) {
162				this.inherits.push(inherits[i].desc);
163			}
164			this.doc._dropTag("inherits");
165		}
166		
167		var augments;
168		if ((augments = this.doc.getTag("augments")) && augments.length) {
169			for (var i = 0; i < augments.length; i++) {
170				this.augments.push(augments[i].desc);
171			}
172			this.doc._dropTag("augments");
173		}
174		
175		Symbol.index[this.alias] = this;
176	}
177}
178
179Symbol.index = {};
180
181Symbol.prototype.is = function(what) {
182    return this.isa === SYM[what];
183}
184
185/** Generate a comma separated list of the parameters. */
186Symbol.prototype.signature = function() {
187    var result = [];
188    for (var i = 0; i < this.params.length; i++) {
189    	if (this.params[i].name.indexOf(".") == -1) // config information does not appear in the signature
190    		result.push(this.params[i].name);
191    }
192    return result.join(", ");
193}
194
195Symbol.prototype.hasMethod = function(name) {
196    for (var i = 0; i < this.methods.length; i++) {
197    	if (this.methods[i].name == name) return true
198    }
199    return false;
200}
201
202Symbol.prototype.hasEvent = function(name) {
203    for (var i = 0; i < this.events.length; i++) {
204    	if (this.events[i].name == name) return true
205    }
206    return false;
207}
208
209Symbol.prototype.hasProperty = function(name) {
210    for (var i = 0; i < this.properties.length; i++) {
211    	if (this.properties[i].name == name) return true
212    }
213    return false;
214}
215
216Symbol.prototype.getInheritedMethods = function(r) {
217	var inherited = [];
218	for(var i = 0; i < this.inherits.length; i++) {
219		inherited.push(this.file.fileGroup.getSymbol(this.inherits[i]));
220	}
221	var result = this.methods.concat(inherited);
222	for(var i = 0; i < this.augments.length; i++) {
223		var contributer = this.file.fileGroup.getSymbol(this.augments[i]);
224		if (contributer) {
225			result = result.concat(contributer.getInheritedMethods(true));
226		}
227	}
228	// remove overridden
229	for (var i = 0; i < result.length; i++) {
230		var j = i; 
231		while (++j < result.length) {
232			if (result[j].name == result[i].name) result.splice(j, 1);
233		}
234	}
235	
236	if (!r) { // not recursing
237		var s = this;
238		function notLocal(element, index, array) {
239			return (!s.hasMethod(element.name));
240		}
241		result = result.filter(notLocal);
242	}
243	return result;
244}