@abaplint/core
Version:
abaplint - Core API
81 lines • 3.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.IntfReferencingClas = exports.IntfReferencingClasConf = void 0;
const issue_1 = require("../issue");
const _basic_rule_config_1 = require("./_basic_rule_config");
const objects_1 = require("../objects");
const syntax_1 = require("../abap/5_syntax/syntax");
const _reference_1 = require("../abap/5_syntax/_reference");
const ddic_1 = require("../ddic");
class IntfReferencingClasConf extends _basic_rule_config_1.BasicRuleConfig {
constructor() {
super(...arguments);
/** List of classes allowed to be referenced, regex, case insensitive
* @uniqueItems true
*/
this.allow = [];
}
}
exports.IntfReferencingClasConf = IntfReferencingClasConf;
class IntfReferencingClas {
constructor() {
this.conf = new IntfReferencingClasConf();
}
getMetadata() {
return {
key: "intf_referencing_clas",
title: "INTF referencing CLAS",
shortDescription: `Interface contains references to class`,
extendedInformation: `Only global interfaces are checked.
Only first level references are checked.
Exception class references are ignored.
Void references are ignored.`,
};
}
getConfig() {
if (this.conf.allow === undefined) {
this.conf.allow = [];
}
return this.conf;
}
setConfig(conf) {
this.conf = conf;
}
initialize(reg) {
this.reg = reg;
return this;
}
run(obj) {
if (!(obj instanceof objects_1.Interface)) {
return [];
}
return this.traverse(new syntax_1.SyntaxLogic(this.reg, obj).run().spaghetti.getTop());
}
////////////////
traverse(node) {
var _a, _b;
let ret = [];
const message = "Referencing CLAS: ";
const ddic = new ddic_1.DDIC(this.reg);
for (const r of node.getData().references) {
if (r.referenceType === _reference_1.ReferenceType.ObjectOrientedReference
&& ((_a = r.extra) === null || _a === void 0 ? void 0 : _a.ooType) === "CLAS"
&& ((_b = r.extra) === null || _b === void 0 ? void 0 : _b.ooName) !== undefined) {
const found = this.reg.getObject("CLAS", r.extra.ooName) || undefined;
if (found && ddic.isException(found.getClassDefinition(), found)) {
continue;
}
else if (this.getConfig().allow.some(reg => new RegExp(reg, "i").test(r.extra.ooName))) {
continue;
}
ret.push(issue_1.Issue.atIdentifier(r.position, message + r.extra.ooName, this.getMetadata().key, this.conf.severity));
}
}
for (const c of node.getChildren()) {
ret = ret.concat(this.traverse(c));
}
return ret;
}
}
exports.IntfReferencingClas = IntfReferencingClas;
//# sourceMappingURL=intf_referencing_clas.js.map