SourceDatabase.subclass('AnotherSourceDatabase', {
constructor: function AnotherSourceDatabase(){ Class.initializer.apply(this, arguments) },
isPropertyOnIgnoreList: function (prop) {
return this.doNotSerialize.include(prop) || this.isPropertyOnIgnoreListInClassHierarchy(prop, this.constructor);
},
isPropertyOnIgnoreListInClassHierarchy: function (prop, klass) {
if (klass === Object)
return false;
return (klass.prototype.doNotSerialize && klass.prototype.doNotSerialize.include(prop)) || this.isPropertyOnIgnoreListInClassHierarchy(prop, klass.superclass);
},
initialize: function ($super) {
this.editHistory = {};
this.modules = {};
this.registeredBrowsers = [];
},
ensureRealModuleName: function (moduleName) { // for migration to new module names
if (moduleName.endsWith('.js'))
throw dbgOn(new Error('Old module name usage: ' + moduleName));
},
rootFragmentForModule: function (fileName) {
if (!Object.isString(fileName))
throw dbgOn(new Error('Don\'t know what to do with ' + fileName));
var moduleWrapper = this.findModuleWrapperForFileName(fileName);
var root = moduleWrapper && moduleWrapper.ast();
// if (!root)
// throw dbgOn(new Error('Cannot find parsed source for ' + fileName));
return root;
},
allModules: function () {
return Object.values(this.modules)
.select(function(ea) { return ea instanceof lively.ide.ModuleWrapper });
},
findModuleWrapperForFileName: function (fileName) {
return this.allModules().detect(function(ea) { return ea.fileName() == fileName })
},
createModuleWrapperForFileName: function (fileName) {
return lively.ide.ModuleWrapper.forFile(fileName);
},
addModule: function (fileName, source) {
var moduleWrapper = this.findModuleWrapperForFileName(fileName);
if (moduleWrapper) return moduleWrapper;
var moduleWrapper = this.createModuleWrapperForFileName(fileName);
if (source) moduleWrapper.setCachedSource(source);
moduleWrapper.retrieveSourceAndParse(this);
return this.modules[fileName] = moduleWrapper;
},
reparseModule: function (fileName, readAgain) {
if (readAgain)
delete this.modules[fileName];
var moduleWrapper = this.findModuleWrapperForFileName(fileName)
if (moduleWrapper) {
moduleWrapper.retrieveSourceAndParse(this);
return moduleWrapper;
}
return this.addModule(fileName);
},
parseCompleteFile: function (fileName, newFileString) {
var moduleWrapper = this.findModuleWrapperForFileName(fileName)
if (!moduleWrapper)
throw dbgOn(new Error('Cannot parse for ' + fileName + ' because module is not in SourceControl'));
var root = newFileString ? moduleWrapper.parse(newFileString, this) : moduleWrapper.retrieveSourceAndParse(this);
return root;
},
putSourceCodeFor: function (fileFragment, newFileString) {
this.putSourceCodeForFile(fileFragment.fileName, newFileString);
},
putSourceCodeForFile: function (fileName, content) {
if (!fileName)
throw dbgOn(new Error('No filename when tryinh to put source'));
var moduleWrapper = this.findModuleWrapperForFileName(fileName) || this.createModuleWrapperForFileName(fileName);
content = content.replace(/\r/gi, '\n'); // change all CRs to LFs
console.log("Saving " + fileName + "...");
moduleWrapper.setSource(content);
console.log("... " + content.length + " bytes saved.");
},
getCachedText: function (fileName) { // Return full text of the named file
var moduleWrapper = this.findModuleWrapperForFileName(fileName);
if (!moduleWrapper)
// throw dbgOn(new Error('Cannot retrieve source code for ' + fileName + ' because module is not in SourceControl'));
return '';
return moduleWrapper.getSource();
},
searchFor: function (str) {
// search modules
var roots = Object.values(lively.ide.SourceControl.modules).collect(function(ea) { return ea.ast() });
var allFragments = roots.inject([], function(all, ea) { return all.concat(ea.flattened().uniq()) });
// search local code
allFragments = allFragments.concat(ChangeSet.current().flattened());
return allFragments.select(function(ea) {
return ea.getSourceCodeWithoutSubElements().include(str)
});
},
scanLKFiles: function ($super, beSync) {
var ms = new Date().getTime();
this.interestingLKFileNames(URL.codeBase.withFilename('lively/')).each(function(fileName) {
this.addModule(fileName, fileString);
}, this);
console.log('Altogether: ' + (new Date().getTime()-ms)/1000 + ' s');
},
allFiles: function () {
if (!this._allFiles)
this._allFiles = this.interestingLKFileNames(this.codeBaseURL).uniq();
return this._allFiles;
},
registerBrowser: function (browser) {
if (this.registeredBrowsers.include(browser)) return;
this.registeredBrowsers.push(browser);
},
unregisterBrowser: function (browser) {
this.registeredBrowsers = this.registeredBrowsers.without(browser);
},
updateBrowsers: function (changedBrowser, changedNode) {
var msStart = new Date().getTime();
this.registeredBrowsers.without(changedBrowser).forEach(function(ea) { ea.allChanged(true, changedNode) });
console.log('updated ' + this.registeredBrowsers.length + ' browsers in ' + (new Date().getTime()-msStart)/1000 + 's')
},
update: function () {
this._allFiles = null;
},
addFile: function (filename) {
this._allFiles.push(filename);
},
removeFile: function (fileName) {
var moduleWrapper = this.findModuleWrapperForFileName(fileName);
if (!moduleWrapper) {
console.log('Trying to remove ' + fileName + ' bot no module found?');
return;
}
moduleWrapper.remove();
},
switchCodeBase: function (newCodeBaseURL) {
this.codeBaseURL = new URL(newCodeBaseURL.withRelativePartsResolved());
this._allFiles = new WebResource(newCodeBaseURL).getSubElements().subDocuments.collect(function(ea) { return ea.getName() });
},
prepareForMockModule: function (fileName, src) { // This is just used for testing!!!
this.modules[fileName] = lively.ide.ModuleWrapper.forFile(fileName);
this.modules[fileName].setCachedSource(src);
this.putSourceCodeFor = function(fileFragment, newFileString) {
this.modules[fileName].setCachedSource(newFileString)
}.bind(this);
var root = this.reparseModule(fileName).ast();
root.flattened().forEach(function(ea) { ea.sourceControl = this }, this);
return root
},
createSymbolList: function () {
// is a list of names of classes, proto and static methods, objects, and functions defined
// in all currently loaded namespaces
var allClasses = Global.classes(true)
allClasses.length
var allClassNames = allClasses.collect(function(klass) { return klass.name /*local name*/ })
var namespaces = [Global].concat(Global.subNamespaces(true))
var namespaceNames = namespaces.pluck('namespaceIdentifier')
// both proto and static
var allMethodNames = allClasses
.collect(function(klass) { return klass.localFunctionNames().concat(Functions.own(klass)) })
.flatten()
var functionAndObjectNames = namespaces
.collect(function(ns) {
var propNames = [];
for (var name in ns) {
var value = ns[name];
if (!value || Class.isClass(value) || value.namespaceIdentifier) continue;
propNames.push(name)
}
return propNames })
.flatten();
var symbolList = allClassNames.concat(namespaceNames).concat(allMethodNames).concat(functionAndObjectNames);
return symbolList;
},
});
truetruetruefalse