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

94.12% Statements 32/34
100% Branches 29/29
100% Functions 1/1
94.12% Lines 32/34

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 62 631x 1x   1x 1x 1x   1x   1x         20x 20x 20x 16x 16x 13x 3x 2x 2x   1x       19x 19x 91x   4x 4x       2x     89x       17x 17x 1x 1x       17x 2x   17x     17x          
import * as Expressions from "../../2_statements/expressions";
import {ExpressionNode, StatementNode} from "../../nodes";
import {CurrentScope} from "../_current_scope";
import {Source} from "../expressions/source";
import {IReferenceExtras, ReferenceType} from "../_reference";
import {ObjectReferenceType, VoidType} from "../../types/basic";
import {StatementSyntax} from "../_statement_syntax";
import {MessageSource} from "../expressions/message_source";
 
export class Raise implements StatementSyntax {
  public runSyntax(node: StatementNode, scope: CurrentScope, filename: string): void {
 
// todo
 
    const classTok = node.findDirectExpression(Expressions.ClassName)?.getFirstToken();
    const classNam = classTok?.getStr();
    if (classNam) {
      const found = scope.existsObject(classNam);
      if (found.found === true && found.id) {
        scope.addReference(classTok, found.id, found.type, filename);
      } else if (scope.getDDIC().inErrorNamespace(classNam) === false) {
        const extra: IReferenceExtras = {ooName: classNam, ooType: "Void"};
        scope.addReference(classTok, undefined, ReferenceType.ObjectOrientedVoidReference, filename, extra);
      } else {
        throw new Error("RAISE, unknown class " + classNam);
      }
    }
 
    let prev = "";
    for (const c of node.getChildren()) {
      if (c instanceof ExpressionNode
          && (c.get() instanceof Expressions.SimpleSource2 || c.get() instanceof Expressions.Source)) {
        const type = new Source().runSyntax(c, scope, filename);
        if (prev === "EXCEPTION"
            && type
            && !(type instanceof VoidType)
            && !(type instanceof ObjectReferenceType)) {
          throw new Error("RAISE EXCEPTION, must be object reference, got " + type.constructor.name);
        }
      }
      prev = c.concatTokens().toUpperCase();
    }
 
    // todo, check parameters vs constructor
    const param = node.findDirectExpression(Expressions.ParameterListS);
    if (param) {
      for (const s of param.findAllExpressions(Expressions.Source)) {
        new Source().runSyntax(s, scope, filename);
      }
    }
 
    for (const s of node.findDirectExpressions(Expressions.Source)) {
      new Source().runSyntax(s, scope, filename);
    }
    for (const s of node.findDirectExpressions(Expressions.SimpleSource2)) {
      new Source().runSyntax(s, scope, filename);
    }
    for (const s of node.findDirectExpressions(Expressions.MessageSource)) {
      new MessageSource().runSyntax(s, scope, filename);
    }
 
  }
}