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

82.61% Statements 19/23
80% Branches 24/30
100% Functions 1/1
82.61% Lines 19/23

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    1x 1x 1x 1x     1x   50x   50x   10x 10x 10x 10x 10x 8x         10x     40x   20x     20x 20x 20x                  
import {ExpressionNode} from "../../nodes";
import {CurrentScope} from "../_current_scope";
import {TypedIdentifier, IdentifierMeta} from "../../types/_typed_identifier";
import {AnyType, UnknownType} from "../../types/basic";
import {FormParamName, NamespaceSimpleName} from "../../2_statements/expressions";
import {BasicTypes} from "../basic_types";
import {AbstractType} from "../../types/basic/_abstract_type";
 
export class FormParam {
  public runSyntax(node: ExpressionNode, scope: CurrentScope, filename: string): TypedIdentifier {
    const nameToken = node.findFirstExpression(FormParamName)?.getFirstToken();
 
    if (node.findDirectTokenByText("STRUCTURE") && nameToken) {
      // STRUCTURES typing
      const typeName = node.findDirectExpression(NamespaceSimpleName)?.getFirstToken().getStr();
      let type: AbstractType | TypedIdentifier | undefined = undefined;
      Eif (typeName) {
        type = scope.findType(typeName)?.getType();
        if (type === undefined) {
          type = scope.getDDIC().lookupTableOrView(typeName);
        }
      } else {
        type = new UnknownType("todo, FORM STRUCTURES typing");
      }
      return new TypedIdentifier(nameToken, filename, type, [IdentifierMeta.FormParameter]);
    }
 
    if (node.getChildren().length === 1 && nameToken) {
      // untyped FORM parameter
      return new TypedIdentifier(nameToken, filename, new AnyType(), [IdentifierMeta.FormParameter]);
    }
 
    const bfound = new BasicTypes(filename, scope).parseType(node);
    Eif (nameToken && bfound) {
      return new TypedIdentifier(nameToken, filename, bfound, [IdentifierMeta.FormParameter]);
    }
 
    if (nameToken) {
      return new TypedIdentifier(nameToken, filename, new UnknownType("FormParam, todo"), [IdentifierMeta.FormParameter]);
    }
 
    throw new Error("FormParam, unexpected node");
  }
}