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

93.54% Statements 58/62
75% Branches 12/16
100% Functions 1/1
93.54% Lines 58/62

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 621x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 60x 60x 2x 2x 60x 60x 60x 60x 60x 57x 1x 1x 1x 1x 56x 56x 57x 57x 53x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 53x 60x 3x 3x 3x         60x 60x 60x 1x
import * as Expressions from "../../2_statements/expressions";
import {StatementNode} from "../../nodes";
import {Target} from "../expressions/target";
import {Dynamic} from "../expressions/dynamic";
import {StatementSyntax} from "../_statement_syntax";
import {AnyType, TableAccessType, TableType, UnknownType, VoidType} from "../../types/basic";
import {SyntaxInput, syntaxIssue} from "../_syntax_input";
import {ComponentChain} from "../expressions/component_chain";
 
export class Sort implements StatementSyntax {
  public runSyntax(node: StatementNode, input: SyntaxInput): void {
 
    for (const s of node.findDirectExpressions(Expressions.Dynamic)) {
      Dynamic.runSyntax(s, input);
    }
 
    const tnode = node.findDirectExpression(Expressions.Target);
    if (tnode) {
      const ttype = Target.runSyntax(tnode, input);
      if (ttype instanceof TableType) {
        if (ttype.getOptions()?.primaryKey?.type === TableAccessType.sorted) {
          const message = `Sorted table, already sorted`;
          input.issues.push(syntaxIssue(input, tnode.getFirstToken(), message));
          return;
        }
        const rowType = ttype.getRowType();
        if (!(rowType instanceof VoidType)
            && !(rowType instanceof UnknownType)
            && !(rowType instanceof AnyType)) {
          for (const component of node.findAllExpressions(Expressions.ComponentChain)) {
            ComponentChain.runSyntax(rowType, component, input);
            /*
            if (component.getChildren().length > 1) {
              continue;
            }
            const cname = component.concatTokens().toUpperCase();
            if (cname === "TABLE_LINE") {
              continue;
            } else if (!(rowType instanceof StructureType)) {
              const message = "SORT, table row is not structured";
              input.issues.push(syntaxIssue(input, tnode.getFirstToken(), message));
              return;
            } else if (rowType.getComponentByName(cname) === undefined) {
              const message = `Field ${cname} does not exist in table row structure`;
              input.issues.push(syntaxIssue(input, node.getFirstToken(), message));
              return;
            }
              */
          }
        }
      } else if (ttype !== undefined
          && !(ttype instanceof VoidType)
          && !(ttype instanceof UnknownType)
          && !(ttype instanceof AnyType)) {
        const message = "SORT, must be a internal table";
        input.issues.push(syntaxIssue(input, tnode.getFirstToken(), message));
        return;
      }
    }
 
  }
}