@abaplint/core
Version:
abaplint - Core API
81 lines (80 loc) • 3.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExpandMacros = exports.ExpandMacrosConf = void 0;
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");
const edit_helper_1 = require("../edit_helper");
const _statement_1 = require("../abap/2_statements/statements/_statement");
const virtual_position_1 = require("../virtual_position");
class ExpandMacrosConf extends _basic_rule_config_1.BasicRuleConfig {
}
exports.ExpandMacrosConf = ExpandMacrosConf;
class ExpandMacros extends _abap_rule_1.ABAPRule {
constructor() {
super(...arguments);
this.conf = new ExpandMacrosConf();
}
getMetadata() {
return {
key: "expand_macros",
title: "Expand Macros",
shortDescription: `Allows expanding macro calls with quick fixes`,
extendedInformation: `Macros: https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abenmacros_guidl.htm
Note that macros/DEFINE cannot be used in the ABAP Cloud programming model`,
badExample: `DEFINE _hello.
WRITE 'hello'.
END-OF-DEFINITION.
_hello.`,
goodExample: `WRITE 'hello'.`,
tags: [_irule_1.RuleTag.Styleguide, _irule_1.RuleTag.Quickfix, _irule_1.RuleTag.Upport],
};
}
getConfig() {
return this.conf;
}
setConfig(conf) {
this.conf = conf;
}
runParsed(file) {
const issues = [];
const message = "Expand macro call";
const statements = file.getStatements();
for (let i = 0; i < statements.length; i++) {
const statementNode = statements[i];
const statement = statementNode.get();
if (!(statement instanceof _statement_1.MacroCall)) {
continue;
}
let replace = "";
for (let j = i + 1; j < statements.length; j++) {
const sub = statements[j];
if (sub.getFirstToken().getStart() instanceof virtual_position_1.VirtualPosition) {
if (sub.get() instanceof _statement_1.MacroCall) {
continue;
}
if (replace !== "") {
replace += "\n";
}
replace += sub.concatTokensVirtual();
}
else {
break;
}
}
if (statementNode.getColon()) {
replace += "\n";
}
const fix1 = edit_helper_1.EditHelper.deleteStatement(file, statementNode);
const fix2 = edit_helper_1.EditHelper.insertAt(file, statementNode.getStart(), replace);
const fix = edit_helper_1.EditHelper.merge(fix1, fix2);
issues.push(issue_1.Issue.atStatement(file, statementNode, message, this.getMetadata().key, this.conf.severity, fix));
// only one fix at a time per file
break;
}
return issues;
}
}
exports.ExpandMacros = ExpandMacros;
//# sourceMappingURL=expand_macros.js.map