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

90.24% Statements 37/41
68.75% Branches 11/16
100% Functions 1/1
90.24% Lines 37/41

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 421x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 6x 6x     6x 6x 6x 6x 6x 4x 4x 6x 1x 1x 1x 1x 1x 1x 1x 5x 6x 6x 6x 5x 6x     6x 1x  
import * as Expressions from "../../2_statements/expressions";
import {StatementNode} from "../../nodes";
import {ObjectReferenceType, VoidType} from "../../types/basic";
import {InlineData} from "../expressions/inline_data";
import {AbstractType} from "../../types/basic/_abstract_type";
import {StatementSyntax} from "../_statement_syntax";
import {Target} from "../expressions/target";
import {ReferenceType} from "../_reference";
import {SyntaxInput, syntaxIssue} from "../_syntax_input";
 
export class WhenType implements StatementSyntax {
  public runSyntax(node: StatementNode, input: SyntaxInput): void {
    const nameToken = node.findFirstExpression(Expressions.ClassName)?.getFirstToken();
    if (nameToken === undefined) {
      return undefined;
    }
 
    let type: AbstractType | undefined;
    const className = nameToken.getStr().toUpperCase();
    const found = input.scope.existsObject(className);
    if (found?.id) {
      type = new ObjectReferenceType(found.id);
      input.scope.addReference(nameToken, found.id, ReferenceType.ObjectOrientedReference, input.filename);
    } else if (input.scope.getDDIC().inErrorNamespace(className) === false) {
      type = VoidType.get(className);
      input.scope.addReference(nameToken, undefined, ReferenceType.ObjectOrientedVoidReference, input.filename, {ooName: className, ooType: "Void"});
    } else {
      const message = "Class " + className + " not found";
      input.issues.push(syntaxIssue(input, nameToken, message));
      return;
    }
 
    const target = node?.findDirectExpression(Expressions.Target);
    const inline = target?.findDirectExpression(Expressions.InlineData);
    if (inline) {
      InlineData.runSyntax(inline, input, type);
    } else if (target) {
      Target.runSyntax(target, input);
    }
  }
}