@abaplint/core
Version:
abaplint - Core API
92 lines • 3.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DDICReferences = void 0;
class DDICReferences {
constructor() {
this.nameTypeIndex = {};
this.filenameIndex = {};
}
setUsing(obj, using) {
this.clear(obj);
for (const u of using) {
this.addUsing(obj, u);
}
}
addUsing(obj, using) {
if (using === undefined) {
return;
}
// add to name and type index
const newName = obj.getName().toUpperCase();
const newType = obj.getType();
if (this.nameTypeIndex[newName] === undefined) {
this.nameTypeIndex[newName] = {};
}
if (this.nameTypeIndex[newName][newType] === undefined) {
this.nameTypeIndex[newName][newType] = [];
}
this.nameTypeIndex[newName][newType].push(using);
// add to filename index
if (using.filename && using.token) {
if (this.filenameIndex[using.filename] === undefined) {
this.filenameIndex[using.filename] = {};
}
if (this.filenameIndex[using.filename][using.token.getRow()] === undefined) {
this.filenameIndex[using.filename][using.token.getRow()] = [];
}
this.filenameIndex[using.filename][using.token.getRow()].push(using);
}
}
clear(obj) {
var _a, _b;
// remove from filenameIndex first
for (const u of this.listUsing(obj)) {
if (u.filename && u.token) {
const found = (_a = this.filenameIndex[u.filename]) === null || _a === void 0 ? void 0 : _a[u.token.getRow()];
if (found) {
found.pop(); // TODODOD, this assumes there is max one reference on each line
}
}
}
// remove from name + type index
const name = obj.getName().toUpperCase();
const type = obj.getType();
if ((_b = this.nameTypeIndex[name]) === null || _b === void 0 ? void 0 : _b[type]) {
this.nameTypeIndex[name][type] = [];
}
}
listByFilename(filename, line) {
var _a;
return ((_a = this.filenameIndex[filename]) === null || _a === void 0 ? void 0 : _a[line]) || [];
}
listUsing(obj) {
var _a;
const newName = obj.getName().toUpperCase();
const newType = obj.getType();
const found = (_a = this.nameTypeIndex[newName]) === null || _a === void 0 ? void 0 : _a[newType];
if (found !== undefined) {
return found;
}
else {
return [];
}
}
listWhereUsed(obj) {
// todo, add reverse index, this is slow
const ret = [];
const searchName = obj.getName().toUpperCase();
const searchType = obj.getType();
for (const name in this.nameTypeIndex) {
for (const type in this.nameTypeIndex[name]) {
for (const f of this.nameTypeIndex[name][type]) {
if (f.object && f.object.getType() === searchType && f.object.getName() === searchName) {
ret.push({ type, name, token: f.token, filename: f.filename });
}
}
}
}
return ret;
}
}
exports.DDICReferences = DDICReferences;
//# sourceMappingURL=ddic_references.js.map