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

83.33% Statements 30/36
50% Branches 4/8
100% Functions 1/1
83.33% Lines 30/36

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 371x 1x 1x 1x 1x 1x 1x 1x 1x 1x 95x 95x     95x 95x 95x     95x 95x 95x 95x 95x 95x 3x 3x 3x 95x 95x 95x 95x     95x 1x  
import {ExpressionNode} from "../../nodes";
import * as Expressions from "../../2_statements/expressions";
import {TypedIdentifier, IdentifierMeta} from "../../types/_typed_identifier";
import {UnknownType} from "../../types/basic";
import {BasicTypes} from "../basic_types";
import {SyntaxInput, syntaxIssue} from "../_syntax_input";
import {AssertError} from "../assert_error";
 
export class MethodDefReturning {
  public static runSyntax(node: ExpressionNode, input: SyntaxInput, meta: IdentifierMeta[]): TypedIdentifier {
    const name = node.findDirectExpression(Expressions.MethodParamName);
    if (name === undefined) {
      throw new AssertError("method_parameter.ts, todo, handle pass by value and reference");
    }
 
    const type = node.findDirectExpression(Expressions.TypeParam);
    if (type === undefined) {
      throw new AssertError("method_parameter.ts, unexpected structure");
    }
 
    let found = new BasicTypes(input).parseType(type);
 
    const message = "RETURNING parameter must be fully specified";
    const typeText = type.concatTokens().toUpperCase();
    if (found?.isGeneric() === true || typeText === "TYPE X" || typeText === "TYPE C") {
      input.issues.push(syntaxIssue(input, type.getFirstToken(), message));
      found = new UnknownType(message);
    }
 
    if (found) {
      return new TypedIdentifier(name.getFirstToken(), input.filename, found, meta);
    } else {
      return new TypedIdentifier(name.getFirstToken(), input.filename, new UnknownType("method param, todo"), meta);
    }
  }
}