@abaplint/core
Version:
abaplint - Core API
47 lines • 2.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CyclomaticComplexityStats = void 0;
const Expressions = require("../abap/2_statements/expressions");
const Statements = require("../abap/2_statements/statements");
const Structures = require("../abap/3_structures/structures");
const _abap_object_1 = require("../objects/_abap_object");
class CyclomaticComplexityStats {
static run(obj) {
var _a, _b, _c;
const res = [];
if (!(obj instanceof _abap_object_1.ABAPObject)) {
return [];
}
for (const file of obj.getABAPFiles()) {
for (const m of ((_a = file.getStructure()) === null || _a === void 0 ? void 0 : _a.findAllStructures(Structures.Method)) || []) {
let count = 0;
for (const s of m.findAllStatementNodes()) {
const type = s.get();
if (type instanceof Statements.Assert
|| type instanceof Statements.Check
|| type instanceof Statements.ElseIf
|| type instanceof Statements.If
|| type instanceof Statements.While
|| type instanceof Statements.Case
|| type instanceof Statements.SelectLoop
|| type instanceof Statements.Catch
|| type instanceof Statements.Cleanup
|| type instanceof Statements.EndAt
|| type instanceof Statements.Loop) {
count += 1;
}
}
const name = (_c = (_b = m.findDirectStatement(Statements.MethodImplementation)) === null || _b === void 0 ? void 0 : _b.findDirectExpression(Expressions.MethodName)) === null || _c === void 0 ? void 0 : _c.getFirstToken().getStr();
res.push({
file,
pos: m.getFirstToken().getStart(),
name: name ? name : "Error!",
count,
});
}
}
return res;
}
}
exports.CyclomaticComplexityStats = CyclomaticComplexityStats;
//# sourceMappingURL=cyclomatic_complexity_stats.js.map