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

86.36% Statements 19/22
77.78% Branches 14/18
100% Functions 1/1
86.36% Lines 19/22

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    1x   1x   72x 6x     66x   66x 55x 55x 3x   52x     11x 11x 11x 3x 8x   8x 8x 8x     8x              
import {INode} from "../../nodes/_inode";
import {AbstractType} from "../../types/basic/_abstract_type";
import * as Basic from "../../types/basic";
 
export class ComponentName {
  public runSyntax(context: AbstractType | undefined, node: INode): AbstractType | undefined {
    if (context instanceof Basic.VoidType) {
      return context;
    }
 
    const name = node.getFirstToken().getStr();
 
    if (context instanceof Basic.StructureType) {
      const ret = context.getComponentByName(name);
      if (ret === undefined) {
        throw new Error("Component \"" + name + "\" not found in structure");
      }
      return ret;
    }
 
    Eif (context instanceof Basic.TableType && context.isWithHeader() === true) {
      const rowType = context.getRowType();
      if (rowType instanceof Basic.VoidType) {
        return context;
      } else Iif (name.toUpperCase() === "TABLE_LINE") {
        return rowType;
      } else Eif (rowType instanceof Basic.StructureType) {
        const ret = rowType.getComponentByName(name);
        Iif (ret === undefined) {
          throw new Error("Component \"" + name + "\" not found in structure");
        }
        return ret;
      }
    }
 
    throw new Error("Not a structure, ComponentName, \"" + name + "\"");
  }
 
}