@abaplint/core
Version:
abaplint - Core API
98 lines • 5.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FunctionModuleRecommendations = exports.FunctionModuleRecommendationsConf = void 0;
const expressions_1 = require("../abap/2_statements/expressions");
const issue_1 = require("../issue");
const _abap_rule_1 = require("./_abap_rule");
const _basic_rule_config_1 = require("./_basic_rule_config");
const _irule_1 = require("./_irule");
class FunctionModuleRecommendationsConf extends _basic_rule_config_1.BasicRuleConfig {
constructor() {
super(...arguments);
/** Tuple of Function Module Name to be replaced, the recommended alternative and
* the version from which the recommendation is valid.
* @uniqueItems true
*/
this.recommendations = [
{ name: "CALCULATE_HASH_FOR_RAW", replace: "use CL_ABAP_HMAC or CL_ABAP_MESSAGE_DIGEST" },
{ name: "CCU_TIMESTAMP_DIFFERENCE", replace: "use CL_ABAP_TSTMP" },
{ name: "CONVERT_DATE_TO_EXTERNAL", replace: "use CL_ABAP_DATFM" },
{ name: "CONVERT_TIME_INPUT", replace: "use CL_ABAP_TIMEFM" },
{ name: "ECATT_CONV_XSTRING_TO_STRING", replace: "use CL_BINARY_CONVERT" },
{ name: "F4_FILENAME", replace: "use CL_GUI_FRONTEND_SERVICES" },
{ name: "FUNCTION_EXISTS", replace: "surround with try-catch CX_SY_DYN_CALL_ILLEGAL_METHOD instead" },
{ name: "GUI_DOWNLOAD", replace: "use CL_GUI_FRONTEND_SERVICES" },
{ name: "GUI_UPLOAD", replace: "use CL_GUI_FRONTEND_SERVICES" },
{ name: "GUID_CREATE", replace: "use CL_SYSTEM_UUID" },
{ name: "IGN_TIMESTAMP_DIFFERENCE", replace: "use CL_ABAP_TSTMP" },
{ name: "IGN_TIMESTAMP_PLUSMINUS", replace: "use CL_ABAP_TSTMP" },
{ name: "ISM_SD_GET_PRICING_CONDITIONS", replace: "use CL_PRC_RESULT_FACTORY as per note 2220005" },
{ name: "JOB_CREATE", replace: "use CL_BP_ABAP_JOB" },
{ name: "JOB_SUBMIT", replace: "use CL_BP_ABAP_JOB" },
{ name: "POPUP_TO_CONFIRM_STEP", replace: "use POPUP_TO_CONFIRM" },
{ name: "POPUP_TO_DECIDE", replace: "use POPUP_TO_CONFIRM" },
{ name: "POPUP_TO_GET_VALUE", replace: "use POPUP_GET_VALUES" },
{ name: "QF05_RANDOM_INTEGER", replace: "use CL_ABAP_RANDOM_INT" },
{ name: "REUSE_ALV_GRID_DISPLAY", replace: "use CL_SALV_TABLE=>FACTORY or CL_GUI_ALV_GRID" },
{ name: "ROUND", replace: "use built in function: round()" },
{ name: "SAPGUI_PROGRESS_INDICATOR", replace: "use CL_PROGRESS_INDICATOR" },
{ name: "SCMS_BASE64_DECODE_STR", replace: "use class CL_HTTP_UTILITY methods" },
{ name: "SCMS_STRING_TO_XSTRING", replace: "use CL_BINARY_CONVERT" },
{ name: "SO_NEW_DOCUMENT_ATT_SEND_API1", replace: "use CL_BCS" },
{ name: "SSFC_BASE64_DECODE", replace: "use class CL_HTTP_UTILITY methods" },
{ name: "SSFC_BASE64_ENCODE", replace: "use class CL_HTTP_UTILITY methods" },
{ name: "SUBST_GET_FILE_LIST", replace: "see note 1686357" },
{ name: "WS_FILENAME_GET", replace: "use CL_GUI_FRONTEND_SERVICES" },
];
}
}
exports.FunctionModuleRecommendationsConf = FunctionModuleRecommendationsConf;
class FunctionModuleRecommendations extends _abap_rule_1.ABAPRule {
constructor() {
super(...arguments);
this.conf = new FunctionModuleRecommendationsConf();
}
getMetadata() {
return {
key: "function_module_recommendations",
title: "Function Module Recommendations",
shortDescription: `Suggests replacements for various function modules`,
extendedInformation: `https://docs.abapopenchecks.org/checks/53/`,
tags: [_irule_1.RuleTag.SingleFile],
};
}
getConfig() {
return this.conf;
}
setConfig(conf) {
this.conf = conf;
}
runParsed(file) {
var _a;
const issues = [];
if (!this.conf.recommendations) {
return issues;
}
const configVersion = this.reg.getConfig().getVersion();
for (const exNode of ((_a = file.getStructure()) === null || _a === void 0 ? void 0 : _a.findAllExpressions(expressions_1.FunctionName)) || []) {
const token = exNode.getFirstToken();
let funcName = token.getStr().toUpperCase();
// only check constant FM names
if (!funcName.startsWith("'")) {
continue;
}
// remove leading and trailing single quote
funcName = funcName.slice(1, funcName.length - 1);
const index = this.conf.recommendations.findIndex(i => i.name.toUpperCase() === funcName && (i.from === undefined || configVersion >= i.from));
if (index >= 0) {
issues.push(issue_1.Issue.atToken(file, token, this.getMessage(index), this.getMetadata().key, this.conf.severity));
}
}
return issues;
}
getMessage(index) {
return `Recommendation: Replace Function ${this.conf.recommendations[index].name} with: ${this.conf.recommendations[index].replace}`;
}
}
exports.FunctionModuleRecommendations = FunctionModuleRecommendations;
//# sourceMappingURL=function_module_recommendations.js.map