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

88.89% Statements 32/36
75% Branches 6/8
100% Functions 1/1
88.89% Lines 32/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 361x 1x 1x 1x 1x 1x 1x 1x 1x 1x 189x 189x 189x 50x 50x 189x     189x 189x 189x 189x 50x 50x 50x 23x 23x 50x 189x 189x 189x     188x 188x 1x
import {ExpressionNode, StatementNode} from "../../nodes";
import {CurrentScope} from "../_current_scope";
import {TypedIdentifier} from "../../types/_typed_identifier";
import {BasicTypes} from "../basic_types";
import * as Expressions from "../../2_statements/expressions";
import {UnknownType} from "../../types/basic";
import {ScopeType} from "../_scope_type";
 
export class TypeTable {
  public runSyntax(node: ExpressionNode | StatementNode, scope: CurrentScope, filename: string): TypedIdentifier | undefined {
    // todo, input is currently the statement, but should be the expression?
    let nameExpr = node.findFirstExpression(Expressions.DefinitionName);
    if (nameExpr === undefined) {
      nameExpr = node.findFirstExpression(Expressions.NamespaceSimpleName);
    }
    if (nameExpr === undefined) {
      return undefined;
    }
    const name = nameExpr.getFirstToken();
 
    let qualifiedName = "";
    if (node.getFirstToken().getStr().toUpperCase() === "TYPES") {
      qualifiedName = name.getStr();
      if (scope.getType() === ScopeType.ClassDefinition
          || scope.getType() === ScopeType.Interface) {
        qualifiedName = scope.getName() + "=>" + qualifiedName;
      }
    }
 
    const type = new BasicTypes(filename, scope).parseTable(node, qualifiedName);
    if (type === undefined) {
      return new TypedIdentifier(name, filename, new UnknownType("TableType, fallback"));
    }
    return new TypedIdentifier(name, filename, type);
  }
}