原名JSPackager
源代码在线查看: package-info.js
$JSI.addCacheScript('org/xidea/jsdoc/package-info.js',function(){this.hook = function(s){return eval(s);};eval(this.varText);function PackageInfo(name, pkg) {PackageInfo.packageMap[name] = this;this.name = name;this.pkg = pkg;if (this.pkg.name != name) {this.implementation = this.pkg.name;return;}this.fileInfos = [];for (var file in this.pkg.scriptObjectMap) {var info = new FileInfo(this, file);this.fileInfos.push(info);this.fileInfos[file] = info;}this.fileInfos.sort();}PackageInfo.packageMap = {};PackageInfo.require = function (name) {if (name) {if (this.packageMap[name]) {return this.packageMap[name];} else {var pkg = $JSI.Package.require(name);if (pkg) { return new PackageInfo(name, pkg);} else {return null;}}} else {if (this.rootInfo) {return this.rootInfo;} else {return this.rootInfo = new RootInfo();}}};PackageInfo.prototype.getInitializers = function () {function gen(fi) {return function () {fi.getObjectInfoMap();};}var rtvs = [];for (var i = 0; i < this.fileInfos.length; i++) {rtvs.push(gen(this.fileInfos[i]));}return rtvs;};PackageInfo.prototype.getDescription = function () {return this.getSourceEntry().getDescription();};PackageInfo.prototype.getSourceEntry = function () {if (!this._sourceParser) {this._sourceParser = SourceEntry.require(this.pkg.scriptBase + "__$package.js"); }return this._sourceParser;};PackageInfo.prototype.getObjectInfoMap = function () {if (this._objectInfoMap) {return this._objectInfoMap;} else {this._objectInfoMap = {};for (var i = 0; i < this.fileInfos.length; i++) {var m = this.fileInfos[i].getObjectInfoMap();for (var o in m) {this._objectInfoMap[o] = m[o];}}return this._objectInfoMap;}};PackageInfo.prototype.getObjectInfos = function (map) {if (this._objectInfos) {return this._objectInfos;} else {this._objectInfos = [];var m = this.getObjectInfoMap();for (var n in m) {this._objectInfos.push(n);}this._objectInfos.sort();for (var i = 0; i < this._objectInfos.length; i++) {this._objectInfos[i] = m[this._objectInfos[i]];}return this._objectInfos;}};function FileInfo(pkginf, fileName) {this.pkgInfo = pkginf;this.pkg = pkginf.pkg;this.name = fileName;this.dependences = this.pkg.scriptDependenceMap[fileName] || [];this.objects = [];var osm = this.pkg.objectScriptMap;for (var o in osm) {if (osm[o] == fileName) {this.objects.push(o);}}}FileInfo.prototype.getLoadtimeInfos = function () {if (!this.loadtimeInfos) {this.loadtimeInfos = [];for (var i = 0; i < this.dependences.length; i++) {var di = this.dependences[i]; if (di.beforeLoad) {var pkginf = PackageInfo.require(di.packageName);var objects = pkginf.fileInfos[di.fileName].objects;var path = di.packageName.replace(/\./g, "/") + "/" + di.fileName;var info = {objects:objects, path:path, packageName:pkginf.name, fileName:di.fileName};this.loadtimeInfos.push(info);this.loadtimeInfos[path] = info;}}this.loadtimeInfos.sort();}return this.loadtimeInfos;};FileInfo.prototype.buildIndirectDependenceInfos = function (directDeps) {var ids = [];var deps = directDeps.slice(0);while (deps.length) {var d = deps.pop();var pkginf = PackageInfo.require(d.packageName);var f = pkginf.fileInfos[d.fileName];var li = f.getLoadtimeInfos();var ri = f.getRuntimeInfos(); do {for (var i = 0; i < li.length; i++) {var d = li[i];if (d.path in deps || d.path in ids) {continue;}deps.push(d);deps[d.path] = d;if (!(d.path in directDeps)) {ids.push(d);ids[d.path] = d;}}if (li == ri) {break;} else {li = ri;}} while (true);}return ids;};FileInfo.prototype.getIndirectLoadtimeInfos = function () {if (!this.indirectLoadtimeInfos) {this.indirectLoadtimeInfos = this.buildIndirectDependenceInfos(this.getLoadtimeInfos());this.indirectLoadtimeInfos.sort();}return this.indirectLoadtimeInfos;};FileInfo.prototype.getRuntimeInfos = function () {if (!this.runtimeInfos) { this.runtimeInfos = [];for (var i = 0; i < this.dependences.length; i++) {var di = this.dependences[i];if (!di.loadtime) {var pkginf = PackageInfo.require(di.packageName);var objects = pkginf.fileInfos[di.fileName].objects;var path = di.packageName.replace(/\./g, "/") + "/" + di.fileName;var info = {objects:objects, path:path, packageName:pkginf.name, fileName:di.fileName};this.runtimeInfos.push(info);this.runtimeInfos[path] = info;}}this.runtimeInfos.sort();}return this.runtimeInfos;};FileInfo.prototype.getIndirectRuntimeInfos = function () {if (!this.indirectRuntimeInfos) {this.indirectRuntimeInfos = this.buildIndirectDependenceInfos(this.getRuntimeInfos());this.indirectRuntimeInfos.sort();}return this.indirectRuntimeInfos;};FileInfo.prototype.getDescription = function () { return this.getSourceEntry().getDescription();};FileInfo.prototype.getSourceEntry = function () {if (!this._sourceEntry) {this._sourceEntry = SourceEntry.require(this.name, this.pkg.name);}return this._sourceEntry;};FileInfo.prototype.getDocEntry = function (name) {return this.getSourceEntry().getDocEntry(name);};FileInfo.prototype.getObject = function (name) {return this.getObjectMap()[name];};FileInfo.prototype.getObjectInfo = function (name) {return this.getObjectInfoMap()[name];};FileInfo.prototype.getObjectInfoMap = function () { if (this._objectInfoMap) {return this._objectInfoMap;}try {this._objectInfoMap = {};for (var i = 0; i < this.objects.length; i++) {this._objectInfoMap[this.objects[i]] = new ObjectInfo(this, this.objects[i]);}return this._objectInfoMap;}catch (e) {$log.error(e);}};FileInfo.prototype.getObjectInfos = function () {if (this._objectInfos) {return this._objectInfos;} else {this._objectInfos = [];var m = this.getObjectInfoMap();for (var n in m) {this._objectInfos.push(n);}this._objectInfos.sort();for (var i = 0; i < this._objectInfos.length; i++) {this._objectInfos[i] = m[this._objectInfos[i]];}return this._objectInfos; }};FileInfo.prototype.getObjectMap = function () {if (this._objectMap) {return this._objectMap;}try {this._objectMap = {};this.pkg.prepareScript(this.name, false);for (var i = 0; i < this.objects.length; i++) {this._objectMap[this.objects[i]] = getObject(this.objects[i], this.pkg.objectMap);}}catch (e) {$log.error(e);}return this._objectMap;};FileInfo.prototype.getAvailableObjectInfo = function (name) {var file = this.getAvailableObjectFileMap()[name];if (file) {return file.getObjectInfo(name);}};FileInfo.prototype.getAvailableObjectMap = function (name) {if (!this._availableMap) {var map = this.getAvailableObjectFileMap();var omap = {};for (var n in map) {omap[n] = map[n].getObject(n);}this._availableMap = omap;}return this._availableMap;};FileInfo.prototype.getAvailableObjectFileMap = function (name) {if (!this._availableOFMap) {this._availableOFMap = {};var infos = this.getLoadtimeInfos();infos = infos.concat(this.getRuntimeInfos());var fis = [];for (var i = 0; i < infos.length; i++) {var fi = PackageInfo.require(infos[i].packageName).fileInfos[infos[i].fileName]; fis.push(fi);}fis.push(this);for (var i = 0; i < fis.length; i++) {var os = fis[i].objects;for (var j = 0; j < os.length; j++) {this._availableOFMap[os[j]] = fis[i];}}}return this._availableOFMap;};function RootInfo() {var scripts = document.getElementsByTagName("script");var freeScript = [];var scriptMap = {};for (var i = 0; i < scripts.length; i++) {var s = scripts[i];if (s.src) {freeScript.push(s.src);scriptMap[s.src] = true;}}for (var i = 0; i < scripts.length; i++) {var s = scripts[i];while (s = s.nextSibling) {if (s.nodeType == 1) {if (s.tagName == "SCRIPT") {if (s.src) {if (scriptMap[s.src]) {break;} else {freeScript.push(s.src);scriptMap[s.src] = true;}}} else {break;}}}}for (var i = 0; i < freeScript.length; i++) {freeScript[i] = $JSI.computeURL(freeScript[i]); }this.fileInfos = [];for (var i = 0; i < freeScript.length; i++) {try {var info = new FreeFileInfo(this, freeScript[i]);this.fileInfos.push(info);this.fileInfos[freeScript[i]] = info;}catch (e) {}}this.fileInfos.sort();this.name = "";this.dependences = [];}RootInfo.prototype.getAvailableObjectFileMap = function () {if (!this._availableOFMap) {this._availableOFMap = {};var fis = this.fileInfos;for (var i = 0; i < fis.length; i++) {var os = fis[i].objects;for (var j = 0; j < os.length; j++) { this._availableOFMap[os[j]] = fis[i];}}}return this._availableOFMap;};RootInfo.prototype.getDocEntry = function (name) {for (var i = this.fileInfos.length - 1; i >= 0; i--) {var d = this.fileInfos[i]._sourceEntry.getDocEntry(name);if (d) {return d;}}};$JSI.extend(RootInfo, PackageInfo);function FreeFileInfo(rootInfo, fileName) {this.name = fileName;this.pkgInfo = rootInfo;this.objects = [];this.dependences = [];this._sourceEntry = SourceEntry.require(fileName);this.topDocEntries = this._sourceEntry.getTopDocEntries(); for (var i = 0; i < this.topDocEntries.length; i++) {var name = this.topDocEntries[i].getId();this.objects.push(name);}}FreeFileInfo.prototype.getObjectInfoMap = function () {if (this._objectInfoMap) {return this._objectInfoMap;}try {this._objectInfoMap = {};for (var i = 0; i < this.objects.length; i++) {this._objectInfoMap[this.objects[i]] = new ObjectInfo(this, this.objects[i]);}return this._objectInfoMap;}catch (e) {$log.error(e);}};FreeFileInfo.prototype.getAvailableObjectFileMap = function () {return this.pkgInfo.getAvailableObjectFileMap();};FreeFileInfo.prototype.getObjectMap = function () {if (this._objectMap) {return this._objectMap;}try {this._objectMap = {};for (var i = 0; i < this.objects.length; i++) {this._objectMap[this.objects[i]] = getObject(this.objects[i], window);}}catch (e) {$log.error(e);}return this._objectMap;};FreeFileInfo.prototype.getDocEntry = function (name) {return this.pkgInfo.getDocEntry(name);};FreeFileInfo.prototype.getObject = function (name) { return this.getObjectMap()[name];};$JSI.extend(FreeFileInfo, FileInfo);function getObject(name, map) {var name = name.split(".");for (var i = 0; map != null && i < name.length; i++) {map = map[name[i]];}return map;}});