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 90 91 92 93 94 95 96 97 98 99 100 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 7059x 7059x 7059x 7059x 7059x 7059x 7059x 1x 1x 6853x 6853x 6853x 6853x 6853x 6853x 6853x 1x 6669x 6669x 6669x 1x 1x 5196x 5196x 5196x 1x 1x 7526x 7526x 7526x 1x 1x 69x 69x 388x 67x 388x 388x 2x 2x 1x 1x 67x 67x 110x 67x 67x 110x 1x 1x 89x 89x 89x 186x 4x 186x 45x 41x 41x 4x 4x 186x 48x 48x 1x 1x 1x 77x 77x 77x 77x 77x 183x 183x 183x 26x 183x 103x 77x 77x 26x 26x 183x 106x 106x | import * as Statements from "../abap/2_statements/statements";
import {IStatement} from "../abap/2_statements/statements/_statement";
import {StatementNode} from "../abap/nodes";
import {isLoopEnd, isLoopStart} from "../abap/5_syntax/_loop_structures";
// Blocks in the flat list of statements of a file. Unlike the structure tree, the list is also there when the
// file has structure errors or macros, so rules working on it keep reporting for such files
/** METHOD, FORM, FUNCTION or MODULE */
export function startsProcedure(statement: StatementNode): boolean {
const s = statement.get();
return s instanceof Statements.MethodImplementation
|| s instanceof Statements.Form
|| s instanceof Statements.FunctionModule
|| s instanceof Statements.Module;
}
/** ENDMETHOD, ENDFORM, ENDFUNCTION or ENDMODULE */
export function endsProcedure(statement: StatementNode): boolean {
const s = statement.get();
return s instanceof Statements.EndMethod
|| s instanceof Statements.EndForm
|| s instanceof Statements.EndFunction
|| s instanceof Statements.EndModule;
}
export function isProcedureBoundary(statement: StatementNode): boolean {
return startsProcedure(statement) || endsProcedure(statement);
}
/** the first statement of a loop structure */
export function startsLoop(statement: StatementNode): boolean {
return isLoopStart(statement.get());
}
/** the last statement of a loop structure */
export function endsLoop(statement: StatementNode): boolean {
return isLoopEnd(statement.get());
}
/** index of the statement starting the procedure around the index, undefined outside of a procedure */
export function procedureStart(index: number, statements: readonly StatementNode[]): number | undefined {
for (let i = index - 1; i >= 0; i--) {
if (startsProcedure(statements[i])) {
return i;
} else if (endsProcedure(statements[i])) {
return undefined;
}
}
return undefined;
}
/** index of the statement ending the procedure around the index, the number of statements if there is none */
export function procedureEnd(index: number, statements: readonly StatementNode[]): number {
for (let i = index + 1; i < statements.length; i++) {
if (endsProcedure(statements[i])) {
return i;
}
}
return statements.length;
}
/** index of the innermost loop around the statement at the index, in the same procedure */
export function innermostLoop(index: number, statements: readonly StatementNode[]): number | undefined {
let depth = 0;
for (let i = index - 1; i >= 0 && isProcedureBoundary(statements[i]) === false; i--) {
if (endsLoop(statements[i])) {
depth++;
} else if (startsLoop(statements[i])) {
if (depth === 0) {
return i;
}
depth--;
}
}
return undefined;
}
/** index of the close statement for the block opened at the index, blocks opened by one of open in between
* are nested. Undefined if there is none, or with inProcedure if there is none before the end of the procedure */
export function findClosing(index: number, statements: readonly StatementNode[],
open: (new () => IStatement)[], close: new () => IStatement,
inProcedure: boolean): number | undefined {
let depth = 0;
for (let i = index + 1; i < statements.length; i++) {
const s = statements[i].get();
if (inProcedure === true && isProcedureBoundary(statements[i])) {
return undefined;
} else if (open.some(o => s instanceof o)) {
depth++;
} else if (s instanceof close) {
if (depth === 0) {
return i;
}
depth--;
}
}
return undefined;
}
|