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

93.65% Statements 59/63
92.59% Branches 25/27
100% Functions 1/1
93.65% Lines 59/63

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 1x 1x 1x 1x 21x 21x 21x 21x 21x 21x 17x 17x 13x 17x 3x 3x 4x 1x 1x 17x 20x 20x 21x 96x 96x 4x 4x 4x 4x 4x 2x 2x 4x 94x 94x 18x 18x 18x 21x 1x 1x 1x 1x 18x 21x 2x 2x 21x     21x     18x 18x 1x
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);
    }
 
  }
}