Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 11581x 11581x 11581x 11581x 11581x 34576x 34576x 34576x 34576x 34576x 34576x 34576x 34576x 34576x 34576x 34576x 34576x 34576x 34576x 34576x 11581x 11581x 11071x 11071x 11581x 11581x 236x 236x 11581x 11581x 264x 264x 264x 264x 264x 1467x 1467x 1467x 1467x 1457x 1457x 10x 10x 1467x 15x 15x 12x 1x 1x 12x 2x 2x 11x 15x 3x 3x 15x 1467x 3x 3x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 264x 264x 264x 11581x 11581x | import {Issue} from "../issue";
import {ABAPRule} from "./_abap_rule";
import {BasicRuleConfig} from "./_basic_rule_config";
import {IRuleMetadata, RuleTag} from "./_irule";
import {ABAPFile} from "../abap/abap_file";
import {EditHelper} from "../edit_helper";
import {MacroCall} from "../abap/2_statements/statements/_statement";
import {VirtualPosition} from "../virtual_position";
export class ExpandMacrosConf extends BasicRuleConfig {
}
export class ExpandMacros extends ABAPRule {
private conf = new ExpandMacrosConf();
public getMetadata(): IRuleMetadata {
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: [RuleTag.Styleguide, RuleTag.Quickfix, RuleTag.Upport],
};
}
public getConfig() {
return this.conf;
}
public setConfig(conf: ExpandMacrosConf) {
this.conf = conf;
}
public runParsed(file: ABAPFile) {
const issues: Issue[] = [];
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 MacroCall)) {
continue;
}
let replace = "";
for (let j = i + 1; j < statements.length; j++) {
const sub = statements[j];
if (sub.getFirstToken().getStart() instanceof VirtualPosition) {
if (sub.get() instanceof MacroCall) {
continue;
}
if (replace !== "") {
replace += "\n";
}
replace += sub.concatTokensVirtual();
} else {
break;
}
}
if (statementNode.getColon()) {
replace += "\n";
}
const fix1 = EditHelper.deleteStatement(file, statementNode);
const fix2 = EditHelper.insertAt(file, statementNode.getStart(), replace);
const fix = EditHelper.merge(fix1, fix2);
issues.push(Issue.atStatement(file, statementNode, message, this.getMetadata().key, this.conf.severity, fix));
// only one fix at a time per file
break;
}
return issues;
}
}
|