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

82.22% Statements 37/45
78.57% Branches 11/14
100% Functions 1/1
82.22% Lines 37/45

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 461x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1246x 1246x 192x 192x 1054x 1054x 1054x 1054x 1054x 1x 1x 1x 1x 1053x 1054x 14x 14x 14x 7x 7x 7x 7x 14x 1046x 1046x 1046x                 1x  
import {StatementNode} from "../../nodes";
import {BasicTypes} from "../basic_types";
import {TypedIdentifier} from "../../types/_typed_identifier";
import {PackedType, UnknownType, VoidType} from "../../types/basic";
import * as Expressions from "../../2_statements/expressions";
import {TypeTable} from "../expressions/type_table";
import {CheckSyntaxKey, SyntaxInput, syntaxIssue} from "../_syntax_input";
 
export class Type {
  public runSyntax(node: StatementNode, input: SyntaxInput, qualifiedNamePrefix?: string): TypedIdentifier | undefined {
    const tt = node.findFirstExpression(Expressions.TypeTable);
    if (tt) {
      return TypeTable.runSyntax(node, input, qualifiedNamePrefix);
    }
 
    const found = new BasicTypes(input).simpleType(node, qualifiedNamePrefix);
    if (found) {
      if (found?.getType().isGeneric() === true
          && found?.getType().containsVoid() === false) {
        const message = "TYPES definition cannot be generic, " + found.getName();
        input.issues.push(syntaxIssue(input, node.getFirstToken(), message));
        return new TypedIdentifier(found.getToken(), input.filename, VoidType.get(CheckSyntaxKey));
      }
 
      if (input.scope.isAnyOO() && found.getType() instanceof PackedType) {
        const concat = node.concatTokens().toUpperCase();
        if ((concat.includes(" TYPE P ") || concat.includes(" TYPE P."))
            && concat.includes(" DECIMALS ") === false) {
          const message = "Specify DECIMALS in OO context for packed";
          input.issues.push(syntaxIssue(input, node.getFirstToken(), message));
          return new TypedIdentifier(found.getToken(), input.filename, VoidType.get(CheckSyntaxKey));
        }
      }
 
      return found;
    }

    const fallback = node.findFirstExpression(Expressions.NamespaceSimpleName);
    if (fallback) {
      return new TypedIdentifier(fallback.getFirstToken(), input.filename, new UnknownType("Type, fallback"));
    }

    return undefined;
  }
}