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

84% Statements 42/50
77.77% Branches 14/18
100% Functions 1/1
84% Lines 42/50

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 511x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 28848x 28848x     28848x 28848x 28848x     28848x 28848x 28848x 21x 21x 21x     21x 28848x 28848x 28848x 28x 28848x 6x 28820x 5x 28814x 10x 10x 28799x 28799x 28799x 28799x 28848x     28848x 1x  
import {ExpressionNode} from "../../nodes";
import {TypedIdentifier, IdentifierMeta} from "../../types/_typed_identifier";
import {NGenericType, PGenericType, UnknownType, XGenericType} from "../../types/basic";
import {BasicTypes} from "../basic_types";
import * as Expressions from "../../2_statements/expressions";
import {Default} from "./default";
import {CGenericType} from "../../types/basic/cgeneric_type";
import {SyntaxInput} from "../_syntax_input";
import {AssertError} from "../assert_error";
 
export class MethodParam {
  public static runSyntax(node: ExpressionNode, input: SyntaxInput, meta: IdentifierMeta[]): TypedIdentifier {
    const name = node.findDirectExpression(Expressions.MethodParamName);
    if (name === undefined) {
      throw new AssertError("MethodParam, todo, handle pass by value and reference");
    }
 
    const type = node.findDirectExpression(Expressions.TypeParam);
    if (type === undefined) {
      throw new AssertError("MethodParam, unexpected structure");
    }
 
    const def = type.findDirectExpression(Expressions.Default);
    if (def) {
      try {
        Default.runSyntax(def, input);
      } catch (e) {
        return new TypedIdentifier(name.getFirstToken(), input.filename, new UnknownType(e.toString()), meta);
      }
    }
 
    const concat = type.concatTokens().toUpperCase();
    if (concat === "TYPE C" || concat.startsWith("TYPE C ")) {
      return new TypedIdentifier(name.getFirstToken(), input.filename, CGenericType.get(), meta);
    } else if (concat === "TYPE X" || concat.startsWith("TYPE X ")) {
      return new TypedIdentifier(name.getFirstToken(), input.filename, XGenericType.get(), meta);
    } else if (concat === "TYPE P" || concat.startsWith("TYPE P ")) {
      return new TypedIdentifier(name.getFirstToken(), input.filename, PGenericType.get(), meta);
    } else if (concat === "TYPE N" || concat.startsWith("TYPE N ")) {
      return new TypedIdentifier(name.getFirstToken(), input.filename, NGenericType.get(), meta);
    }
 
    const found = new BasicTypes(input).parseType(type);
    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);
    }
  }
}