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

90.63% Statements 29/32
55.56% Branches 5/9
100% Functions 1/1
90.63% Lines 29/32

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 321x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x     2x 2x 2x 2x 2x   2x 1x 1x 1x 1x 1x 2x 2x 1x 1x 2x 1x
import * as Expressions from "../../2_statements/expressions";
import {StatementNode} from "../../nodes";
import {CurrentScope} from "../_current_scope";
import {ObjectReferenceType, VoidType} from "../../types/basic";
import {InlineData} from "../expressions/inline_data";
import {AbstractType} from "../../types/basic/_abstract_type";
import {StatementSyntax} from "../_statement_syntax";
 
export class WhenType implements StatementSyntax {
  public runSyntax(node: StatementNode, scope: CurrentScope, filename: string): void {
    const nameToken = node.findFirstExpression(Expressions.ClassName)?.getFirstToken();
    if (nameToken === undefined) {
      return undefined;
    }
 
    let type: AbstractType | undefined = undefined;
    const className = nameToken.getStr();
    const found = scope.findObjectDefinition(className);
    if (found === undefined && scope.getDDIC().inErrorNamespace(className) === false) {
      type = new VoidType(className);
    } else if (found === undefined) {
      throw new Error("Class " + className + " not found");
    } else {
      type = new ObjectReferenceType(found);
    }
 
    const inline = node?.findDirectExpression(Expressions.InlineData);
    if (inline) {
      new InlineData().runSyntax(inline, scope, filename, type);
    }
  }
}