All files / src/abap/5_syntax/statements sort.ts

82.97% Statements 39/47
78.57% Branches 11/14
100% Functions 1/1
82.97% Lines 39/47

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 471x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 1x 1x 4x 4x 4x 4x 4x 3x 3x 3x 3x 2x 3x     3x 3x 1x 3x   2x 1x 1x 3x 1x 4x           4x 4x 4x 1x
import * as Expressions from "../../2_statements/expressions";
import {StatementNode} from "../../nodes";
import {CurrentScope} from "../_current_scope";
import {Target} from "../expressions/target";
import {Dynamic} from "../expressions/dynamic";
import {StatementSyntax} from "../_statement_syntax";
import {AnyType, StructureType, TableType, UnknownType, VoidType} from "../../types/basic";
 
export class Sort implements StatementSyntax {
  public runSyntax(node: StatementNode, scope: CurrentScope, filename: string): void {
 
    for (const s of node.findDirectExpressions(Expressions.Dynamic)) {
      new Dynamic().runSyntax(s, scope, filename);
    }
 
    const tnode = node.findDirectExpression(Expressions.Target);
    if (tnode) {
      const ttype = new Target().runSyntax(tnode, scope, filename);
      if (ttype instanceof TableType) {
        const rowType = ttype.getRowType();
        if (!(rowType instanceof VoidType)
            && !(rowType instanceof UnknownType)
            && !(rowType instanceof AnyType)) {
          for (const component of node.findAllExpressions(Expressions.ComponentChain)) {
            if (component.getChildren().length > 1) {
              continue;
            }
            const cname = component.concatTokens().toUpperCase();
            if (cname === "TABLE_LINE") {
              continue;
            } else if (!(rowType instanceof StructureType)) {
              throw new Error("SORT, table row is not structured");
            } else if (rowType.getComponentByName(cname) === undefined) {
              throw new Error(`Field ${cname} does not exist in table row structure`);
            }
          }
        }
      } else if (ttype !== undefined
          && !(ttype instanceof VoidType)
          && !(ttype instanceof UnknownType)
          && !(ttype instanceof AnyType)) {
        throw new Error("SORT, must be a internal table");
      }
    }
 
  }
}