UNPKG

@abaplint/core

Version:
64 lines 2.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MethodLengthStats = void 0; const Statements = require("../abap/2_statements/statements"); const Expressions = require("../abap/2_statements/expressions"); const expressions_1 = require("../abap/2_statements/expressions"); const _abap_object_1 = require("../objects/_abap_object"); const _statement_1 = require("../abap/2_statements/statements/_statement"); class MethodLengthStats { static run(obj) { var _a; const res = []; let pos = undefined; let methodName = ""; let count = 0; let method = false; if (!(obj instanceof _abap_object_1.ABAPObject)) { return []; } for (const file of obj.getABAPFiles()) { let className = ""; for (const stat of file.getStatements()) { const type = stat.get(); if (type instanceof Statements.MethodImplementation) { pos = stat.getFirstToken().getStart(); methodName = this.findName(stat); method = true; count = 0; } else if (type instanceof Statements.ClassImplementation) { className = ((_a = stat.findFirstExpression(Expressions.ClassName)) === null || _a === void 0 ? void 0 : _a.concatTokens()) || "INTERNAL_ERROR"; } else if (type instanceof Statements.EndMethod) { if (pos) { res.push({ name: methodName, className, count, file, pos }); } else { continue; } method = false; } else if (method === true && !(type instanceof _statement_1.Comment) && !(type instanceof _statement_1.Empty)) { count = count + 1; } } } return res; } static findName(stat) { let name = ""; const nameExpr = stat.findFirstExpression(expressions_1.MethodName); if (nameExpr) { name = nameExpr.getFirstToken().getStr(); } else { throw new Error("MethodLength, findName, expected MethodName"); } return name; } } exports.MethodLengthStats = MethodLengthStats; //# sourceMappingURL=method_length_stats.js.map