A Tree object which contains symbols.
function (){
this.symbols = {global:[]};
}
Adds a symbol to this tree.
ArgumentsArray
function (name){
var ret = this.symbols[name];
if (!ret) {
ret = this.symbols[name] = [];
}
return ret;
}
Entry point to add the symbol
ArgumentsString : the path of the symbol. i.e the memberof property of a symbol
function (symbol){
var nameParts = utils.splitName(symbol.fullName);
var path = nameParts.memberof, name = nameParts.name;
if (path === "global") {
path = name;
}
var sym = this.getSymbol(path);
sym.push(symbol);
}
Returns all classes in the tree. The following properties are added to each class symbol.
Array
function (){
var symbols = this.symbols,
objects = [],
keys = Object.keys(this.symbols);
keys.forEach(function (k) {
objects = objects.concat(symbols[k].filter(function (s) {
return s.isConstructor;
}));
});
return objects.map(function (s) {
var name = s.fullName;
var statics = symbols[name] || [];
var instance = symbols[name + ".prototype"] || [];
var borrowedMethods = [], borrowedProperties = [], staticBorrowedMethods = [], staticBorrowedProperties = [];
s.borrows.map(function (b) {
var borrows = b.borrows;
var symbol = symbols[borrows.memberof || "global"].filter(function (s) {
return s.name === borrows.name;
});
if (symbol.length) {
symbol = symbol[0];
var memberof = b.isStatic ? name : name + ".prototype";
var newSymb = new Symbol(utils.merge({}, symbol, {name:b.as, isStatic:b.isStatic, fullName:memberof + "." + b.as, memberof:memberof}));
if (b.isStatic) {
if (s.isFunction) {
staticBorrowedMethods.push(newSymb);
} else {
staticBorrowedProperties.push(newSymb);
}
} else {
if (s.isFunction) {
borrowedMethods.push(newSymb);
} else {
borrowedProperties.push(newSymb);
}
}
}
});
s.name = name;
s.staticMethods = statics.filter(
function (s) {
return s.isFunction && !s.isConstructor;
}).concat(staticBorrowedMethods);
s.staticProperties = statics.filter(
function (s) {
return !s.isFunction && !s.isNamespace;
}).concat(staticBorrowedProperties);
s.instanceMethods = instance.filter(
function (s) {
return s.isFunction && !s.isConstructor;
}).concat(borrowedMethods);
s.instanceProperties = instance.filter(
function (s) {
return !s.isFunction && !s.isNamespace;
}).concat(s.properties || []).concat(borrowedProperties);
return s;
});
}
Gets all members( coddoc.Symbol) for a particular path.
ArgumentsArray and array of symbols.
function (path){
var symbols = this.symbols,
namespaces = [],
keys = Object.keys(this.symbols);
keys.forEach(function (k) {
namespaces = namespaces.concat(symbols[k].filter(function (s) {
return !s.isNamespace && !s.isConstructor && s.memberof === path;
}));
});
return namespaces;
}
Returns all namespaces in this tree. This method also adds the following values to the namespace.
Array array of namespaces
function (){
var symbols = this.symbols,
namespaces = [],
keys = Object.keys(this.symbols);
keys.forEach(function (k) {
namespaces = namespaces.concat(symbols[k].filter(function (s) {
return s.isNamespace;
}));
});
return namespaces.map(function (s) {
var realName = s.memberof && s.memberof !== "global" ? [s.memberof, s.name].join(".") : s.name;
var members = this.getMembers(realName);
s.name = realName;
s.properties = s.properties.concat(members.filter(function (m) {
return !m.isFunction;
}));
s.methods = members.filter(function (m) {
return m.isFunction;
});
return s;
}, this);
}
Returns a symbol from this tree. The Tree will create the symbol if it does not exist.
ArgumentsArray the array for the symbol.
function (name){
return this._addSymbol(name);
}
Returns true if this tree contains a symbol.
ArgumentsBoolean true if the tree contains the symbol.
function (name){
var parts = name.split(".");
return !!this.symbols[name];
}
MIT LICENSE
Code: git clone git://github.com/pollenware/coddoc.git