All files / src/abap/5_syntax/expressions type_table_key.ts

100% Statements 23/23
100% Branches 8/8
100% Functions 1/1
100% Lines 23/23

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 231x 1x 1x 1x 1x 1x 1x 235x 235x 235x 98x 19x 19x 19x 19x 2x 2x 19x 96x 235x 233x 233x 1x
import {ExpressionNode} from "../../nodes";
import {AbstractType} from "../../types/basic/_abstract_type";
import * as Expressions from "../../2_statements/expressions";
import {StructureType, TableType, UnknownType} from "../../types/basic";
 
export class TypeTableKey {
  public runSyntax(node: ExpressionNode, type: AbstractType) {
    if (type instanceof TableType) {
      const rowType = type.getRowType();
      if (rowType instanceof StructureType) {
        for (const c of node.findAllExpressions(Expressions.FieldSub)) {
          const concat = c.concatTokens().replace(/^!/, "");
          if (concat.includes("-") === false // todo, properly check sub fields
              && rowType.getComponentByName(concat) === undefined
              && concat.toUpperCase() !== "TABLE_LINE") {
            return new UnknownType(`Field ${concat} not part of structure`);
          }
        }
      }
    }
    return undefined;
  }
}