📄 object-info.js
字号:
var emptyDocEntry = new (function(){
for(n in DocEntry.prototype){
this[n] = DocEntry.prototype[n];
}
this.tagAttributes = {'constructor':null};
this.sourceAttributes = {'constructor':null};
this.getStaticMemberMap = this.getInstanceMemberMap = function(){return {};};
})();
function ObjectInfo(fileInfo,name,obj,doc){
obj = obj || fileInfo.getObject(name);
doc = doc || fileInfo.getDocEntry(name);
if(obj == null){
if(doc){
var c = doc.getInstanceof();
var t = doc.getTypeof();
if(t == 'function' || (t == null && c == 'Function')){
if(doc.isConstructor()){
return new ConstructorInfo(fileInfo,name,obj,doc);
}else{
return new FunctionInfo(fileInfo,name,obj,doc);
}
}
if(c || t == 'object'){
this.fileInfo = fileInfo;
this.name = name;
this.object = obj;
this.docEntry = doc;
}else if(t){
return new PrimitiveInfo(fileInfo,name,obj,doc);
}else{
return new UnknowInfo(fileInfo,name,obj,doc);
}
}else{
return new UnknowInfo(fileInfo,name,obj,emptyDocEntry);
}
}else if(obj instanceof Function){
for(var x in obj.prototype){
return new ConstructorInfo(fileInfo,name,obj,doc||emptyDocEntry);
}
if(doc && doc.isConstructor()){
return new ConstructorInfo(fileInfo,name,obj,doc);
}
return new FunctionInfo(fileInfo,name,obj,doc||emptyDocEntry);
}else if(obj instanceof Object){
//some IE native function is object
if(doc && doc.isConstructor()){
return new ConstructorInfo(fileInfo,name,obj,doc);
}
this.fileInfo = fileInfo;
this.name = name;
this.object = obj;
this.docEntry = doc||emptyDocEntry;
}else{
return new PrimitiveInfo(fileInfo,name,obj,doc||emptyDocEntry);
}
}
ObjectInfo.prototype.getDescription = function(){
return this.docEntry.getDescription();
}
ObjectInfo.prototype.getShortDescription = function(){
if(!('_shortDescription' in this)){
var sd = this.getDescription();
if(sd){
this._shortDescription = sd.replace(/^([^\.\r\u3002$]+)[\s\S]+$/,'$1.')
}else{
this._shortDescription = '';
}
}
return this._shortDescription;
}
ObjectInfo.prototype.getType = function(){
if(this.object){
if(this.object instanceof RegExp){//firefox bug?
return "object";
}else{
return (typeof this.object);
}
}else{
//alert(this.docEntry);
return this.docEntry.getTypeof()||'undefined'
}
};
ObjectInfo.prototype.getConstructorInfo = function(){
if(!('_constructorInfo' in this)){
var c = this.docEntry.getInstanceof();
if(c){
this._constructorInfo = this.fileInfo.getAvailableObjectInfo(c.trim());
}
if(!this._constructorInfo){
if(this.object == window || this.object.constructor == Object){
this._constructorInfo = null;
}else{
this._constructorInfo = this.getLowestConstructorInfo(this.object);
}
}
}
return this._constructorInfo;
};
ObjectInfo.prototype.getLowestConstructorInfo = function(o){
var omap = this.fileInfo.getAvailableObjectMap();
var pl = [];
for(var n in omap){
var s = omap[n];
if((s.prototype instanceof Object) && s!=this.object && (o instanceof s) && o!=Object){
var k = 0;
for(var n2 in s.prototype){
k++;
}
if(pl.length){
var ok = pl[pl.length-1].k;
if(k<ok){
continue;
}else if(k>ok){
pl.length = 0;
}
}
pl.push({n:n,k:k,o:s});
}
}
if(pl.length == 0){
return null;
}
function tc(){};
for(var i =0;i<pl.length;i++){
var c = pl[i].o;
tc.prototype = c.prototype;
var o = new tc();
for(var j =0;j<pl.length;j++){
var s = pl[j].o;
if(c!=s && (o instanceof s)){
pl.splice(j,1);
if(j<=i){
i--;
}
j--;
}
}
}
return this.fileInfo.getAvailableObjectInfo(pl[0].n);
}
ObjectInfo.prototype.getDeclaredStaticInfos = function(){
if(!this._declaredStaticInfos){
var si = this.getStaticInfos();
var dsi = [];
for(var i=0;i<si.length;i++){
var n = si[i];
var o = si[n];
if(o.getPlace() == this){
dsi.push(n);
dsi[n] = o;
}
}
this._declaredStaticInfos = dsi;
}
return this._declaredStaticInfos;
}
ObjectInfo.prototype._buildStaticInfos = function(){
var infos = [];
if(!this.object){
return infos;
}
var infomap = this.fileInfo.getObjectInfoMap();
var ci = this.getConstructorInfo();
if(ci && ci.object){
var pobj = ci.object.prototype;
}
pobj = pobj || {};
var constr = this.getConstructorInfo();
if(constr){
var inherits = constr.getInheritList();
}else{
var inherits = [];
}
for(var n in this.object){
var an = this.name + "."+n;
var o = infomap[an];
if(!o){
o = new ObjectInfo(this.fileInfo,an,this.object[n]);
}
var info = new MemberInfo(this,n,o,inherits,true);
if(n in pobj){
if(pobj[n] == this.object[n]){
info.attributeType = 'prototype';
}else{
info.attributeType = 'override';
}
}else{
info.attributeType = 'instance';
}
infos.push(n);
infos[n] = info;
}
var map = this.docEntry.getStaticMemberMap();
for(var n in map){
if(!(n in this.object)){
var an = this.name + "."+n;
var o = new ObjectInfo(this.fileInfo,an,null,map[n]);
var info = new MemberInfo(this,n,o,inherits,true);
info.attributeType = 'instance';
infos.push(n);
infos[n] = info;
}
}
infos.sort();
return infos;
};
function MemberInfo(obj,mn,mo,inhs,s){
this.objInfo = obj;
this.name = mn;
this.memberInfo = mo;
this.inherits = inhs;
this['static'] = s;
}
MemberInfo.prototype.getPlace = function(){
if(!this.place){
if(this.attributeType.indexOf('instance')>=0){
this.place = this.objInfo;
}
for(var i = this.inherits.length-1;i>=0;i--){
if(this.name in this.inherits[i].object.prototype){
this.place = this.inherits[i];
}
}
if(!this.place){
this.place = this.objInfo;
}
}
return this.place;
}
ObjectInfo.prototype.getStaticInfos = function(){
if(!this._staticInfos){
this._staticInfos = this._buildStaticInfos();
}
return this._staticInfos;
}
ObjectInfo.prototype.toString = function(){
return this.getType()+this.name;
};
ObjectInfo.prototype.getAccess = function(){
if(this.docEntry){
return this.docEntry.getAccess() || '';
}
};
/**
* @extend ObjectInfo
*/
function UnknowInfo(fileInfo,name,obj,doc){
this.fileInfo = fileInfo;
this.name = name;
this.object = obj;
this.docEntry = doc||emptyDocEntry;
}
$JSI.extend(UnknowInfo,ObjectInfo);
UnknowInfo.prototype.getConstructorInfo = function(){return null;};
/**
* @extend ObjectInfo
*/
function PrimitiveInfo(fileInfo,name,obj,doc){
this.fileInfo = fileInfo;
this.name = name;
this.object = obj;
this.docEntry = doc;
}
$JSI.extend(PrimitiveInfo,ObjectInfo);
PrimitiveInfo.prototype.getConstructorInfo = function(){return null;};
/**
* @extend ObjectInfo
*/
function FunctionInfo(fileInfo,name,obj,doc){
this.fileInfo = fileInfo;
this.name = name;
this.object = obj;
this.docEntry = doc;
}
FunctionInfo.prototype.getStaticInfos = function(){
if(!this._staticInfos){
this._staticInfos = this._buildStaticInfos();
for(var i=0;i<this._staticInfos.length;i++){
if(this._staticInfos[i] == 'prototype'){
this._staticInfos.splice(i,1);
delete this._staticInfos['prototype'];
}
}
}
return this._staticInfos;
}
$JSI.extend(FunctionInfo,ObjectInfo);
FunctionInfo.prototype.getConstructorInfo = function(){return functionInfo;};
FunctionInfo.prototype.getParams = function(){
if(this._params){
return this._params;
}
var params = this.docEntry.getParams();
if(!params){
if(this.object instanceof Function){
try{
params = /\(([^\(\)]*)\)/.exec(this.object.toString())[1].split(/\s*,\s*/);
}catch(e){
params = [];
}
}else{
params = [];
}
}
var ps = [];
if(params.length){
for(var i = 0;i<params.length;i++){
if(params[i]){
ps.push(new TypeInfomation(params[i]));
}
}
}
return this._params = ps
};
FunctionInfo.prototype.getArguments = function(){
return this.docEntry.getArguments();
};
FunctionInfo.prototype.getReturnInfo = function(){
if(!this._returnInfo){
var r = this.docEntry.getReturn();
r = new TypeInfomation(r);
r.type = this.docEntry.getReturnType() || r.type||"void";
r.description = (r.name||"") + (r.description||"")
this._returnInfo = r;
}
return this._returnInfo;
};
function TypeInfomation(text){
}
/**
* eg:{ClassA} ca infomation
* @private
*/
function TypeInfomation(text){
var m = /^\s*([\w\$]+)?\s*(\{|<)/.exec(text);
if(m){
i = m[0].length;
if(m[0][i-1] == '{'){
var j = this.searchEnd(text,i,'{','}')
}else{
var j = this.searchEnd(text,i,'<','>')
}
if(j){
this.type = text.substring(i,j);
if(m[1]){
this.name = m[1];
this.description = text.substr(j+1);
return;
}else{
text = text.substr(j+1);
}
}
}
if(!this.name){
m = /^\s*([\w\$]+)(?:\s+|$)([\s\S]*)?$/.exec(text);
if(m){
this.name = m[1];// || dn;
this.description = m[2];
}else{
this.description = text;
}
}
}
TypeInfomation.prototype.searchEnd = function(text,i,b,e){
var d = 0;
while(++i<text.length){
switch(text.charAt(i)){
case b:
d++;
break;
case e:
if(d == 0){
return i;
}else if(d<0){
return null;
}
d--;
}
}
return null;
};
$JSI.extend(FunctionInfo,ObjectInfo);
/**
* @extend FunctionInfo
*/
function ConstructorInfo(fileInfo,name,obj,doc){
this.fileInfo = fileInfo;
this.name = name;
this.object = obj;
this.docEntry = doc;
}
ConstructorInfo.prototype.findSuperInfo = function(){
var omap = this.fileInfo.getAvailableObjectMap();
var tc = function(){};
tc.prototype = this.object.prototype;
var o = new tc();
return this.getLowestConstructorInfo(o);
}
ConstructorInfo.prototype.getSuperInfo = function(){
if(!('_superInfo' in this)){
var s = this.docEntry.getExtend();
if(s){
this._superInfo = this.fileInfo.getAvailableObjectInfo(s);
}
if(this._superInfo){
return this._superInfo;
}else if(this.object instanceof Function){
var p = this.object.prototype;
var sub = false;
for(var n in p){
if(n == 'constructor'){
sub = true;//(p[n] instanceof Function);
}
}
if(sub || p instanceof Object && p.constructor != this.object){
this._superInfo = this.findSuperInfo();
}else{
this._superInfo = null;
}
}else{
this._superInfo = null;
}
}
return this._superInfo;
}
ConstructorInfo.prototype.getDeclaredInstanceInfos = function(){
if(!this._declaredInstanceInfos){
var ii = this.getInstanceInfos();
var dii = [];
for(var i=0;i<ii.length;i++){
var n = ii[i];
var o = ii[n];
if(o.getPlace() == this){
dii.push(n);
dii[n] = o;
}
}
this._declaredInstanceInfos = dii;
}
return this._declaredInstanceInfos;
}
ConstructorInfo.prototype.getInheritList = function(){
if(!this._inheritList){
var cs = [];
var c = this;
do{
cs.push(c);
}while(c = c.getSuperInfo())
this._inheritList = cs.reverse();
}
return this._inheritList;
}
ConstructorInfo.prototype.getStaticInfos = function(){
if(!this._staticInfos){
this._staticInfos = this._buildStaticInfos();
for(var i=0;i<this._staticInfos.length;i++){
var n = this._staticInfos[i];
if(n == 'prototype' || n == 'bind'){
this._staticInfos.splice(i,1);
delete this._staticInfos[n];
i--;
}
}
}
return this._staticInfos;
}
ConstructorInfo.prototype.getInstanceInfos = function(){
if(!this._instanceInfos){
this._instanceInfos = [];
if(!this.object){
return this._instanceInfos;
}
var infomap = this.fileInfo.getObjectInfoMap();
var proto = this.object.prototype;
var pobj = this.getSuperInfo();
pobj = pobj?pobj.object.prototype:{};
var inherits = this.getInheritList();
for(var n in proto){
var an = this.name + ".prototype."+n;
var o = infomap[an];
if(!o){
o = new ObjectInfo(this.fileInfo,an,proto[n]);
}
var info = new MemberInfo(this,n,o,inherits,false);
var t = this.docEntry.getAttributeType();
if(t){
info.attributeType = t;
}else{
if(n in pobj){
if(pobj[n] == this.object[n]){
info.attributeType = 'inherited';
}else{
info.attributeType = o.docEntry.instanceAttribute?
'instance override':'prototype override';
}
}else{
info.attributeType = o.docEntry.instanceAttribute?
'instance':'prototype';
}
}
this._instanceInfos.push(n);
this._instanceInfos[n] = info;
}
var map = this.docEntry.getInstanceMemberMap();
for(var n in map){
if(!(n in proto)){
var an = this.name + ".prototype."+n;
var o = new ObjectInfo(this.fileInfo,an,null,map[n]);
var info = new MemberInfo(this,n,o,inherits,false);
info.attributeType = 'instance';
this._instanceInfos.push(n);
this._instanceInfos[n] = info;
}
}
this._instanceInfos.sort();
}
return this._instanceInfos;
}
$JSI.extend(ConstructorInfo,FunctionInfo);
ConstructorInfo.prototype.getType = function(){return 'constructor';};
var functionInfo = new (function(){
for(n in ConstructorInfo.prototype){
this[n] = ConstructorInfo.prototype[n];
}
this.object = Function;
this.docEntry = emptyDocEntry;
})();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -