@abaplint/core
Version:
abaplint - Core API
93 lines (92 loc) • 3.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ImplicitStartOfSelection = exports.ImplicitStartOfSelectionConf = void 0;
const issue_1 = require("../issue");
const _abap_rule_1 = require("./_abap_rule");
const _basic_rule_config_1 = require("./_basic_rule_config");
const Structures = require("../abap/3_structures/structures");
const _irule_1 = require("./_irule");
const objects_1 = require("../objects");
const nodes_1 = require("../abap/nodes");
const selection_events_1 = require("../abap/flow/selection_events");
class ImplicitStartOfSelectionConf extends _basic_rule_config_1.BasicRuleConfig {
}
exports.ImplicitStartOfSelectionConf = ImplicitStartOfSelectionConf;
class ImplicitStartOfSelection extends _abap_rule_1.ABAPRule {
constructor() {
super(...arguments);
this.conf = new ImplicitStartOfSelectionConf();
}
getMetadata() {
return {
key: "implicit_start_of_selection",
title: "Implicit START-OF-SELECTION",
shortDescription: `Add explicit selection screen event handling`,
extendedInformation: `Only runs for executable programs
https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-us/abapstart-of-selection.htm`,
tags: [_irule_1.RuleTag.SingleFile],
badExample: `REPORT zfoo.
WRITE 'hello'.`,
goodExample: `
START-OF-SELECTION.
WRITE 'hello'.`,
};
}
getConfig() {
return this.conf;
}
setConfig(conf) {
this.conf = conf;
}
runParsed(file, obj) {
const issues = [];
if (!(obj instanceof objects_1.Program) || obj.isInclude()) {
return issues;
}
const stru = file.getStructure();
if (stru === undefined) {
return [];
}
let inEvent = false;
let collected = [];
for (const s of stru.getChildren() || []) {
if (selection_events_1.SELECTION_EVENTS.some(f => s.get() instanceof f)) {
if (inEvent === false && collected.length > 0) {
// implicit START-OF-SELECTION
let first = collected[0];
if (first instanceof nodes_1.StructureNode) {
first = first.getFirstStatement();
}
issues.push(issue_1.Issue.atStatement(file, first, "Implicit START-OF-SELECTION", this.getMetadata().key, this.getConfig().severity));
}
collected = [];
inEvent = true;
}
else if (s.get() instanceof Structures.Normal) {
const stru = s;
// ignore declaration stuff
if (selection_events_1.DECLARATION_STUFF.some(d => { var _a; return ((_a = stru.getFirstStatement()) === null || _a === void 0 ? void 0 : _a.get()) instanceof d; })) {
continue;
}
collected.push(s);
}
else {
if (inEvent === true) {
inEvent = false;
}
collected = [];
}
}
if (inEvent === false && collected.length > 0) {
// implicit START-OF-SELECTION
let first = collected[0];
if (first instanceof nodes_1.StructureNode) {
first = first.getFirstStatement();
}
issues.push(issue_1.Issue.atStatement(file, first, "Implicit START-OF-SELECTION", this.getMetadata().key, this.getConfig().severity));
}
return issues;
}
}
exports.ImplicitStartOfSelection = ImplicitStartOfSelection;
//# sourceMappingURL=implicit_start_of_selection.js.map