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

84.61% Statements 33/39
66.66% Branches 8/12
100% Functions 1/1
84.61% Lines 33/39

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 391x 1x 1x 1x 1x 1x 1x 1x 1x 13x 13x 13x 13x     13x 13x 13x 13x 13x 4x 4x 13x 13x 13x 13x     13x 9x 13x 4x 4x     9x 9x 9x 1x
import * as Expressions from "../../2_statements/expressions";
import {StatementNode} from "../../nodes";
import {CurrentScope} from "../_current_scope";
import {IStructureComponent, StructureType, VoidType} from "../../types/basic";
import {BasicTypes} from "../basic_types";
import {TypedIdentifier} from "../../types/_typed_identifier";
 
export class IncludeType {
  public runSyntax(node: StatementNode, scope: CurrentScope, filename: string): IStructureComponent[] | VoidType {
    const components: IStructureComponent[] = [];
 
    const iname = node.findFirstExpression(Expressions.TypeName);
    if (iname === undefined) {
      throw new Error("IncludeType, unexpected node structure");
    }
    const name = iname.getFirstToken().getStr();
 
    let ityp = new BasicTypes(filename, scope).parseType(iname);
    const as = node.findExpressionAfterToken("AS")?.concatTokens();
    if (as && ityp instanceof StructureType) {
      ityp = new StructureType(ityp.getComponents().concat([{name: as, type: ityp}]));
    }
 
    if (ityp
        && ityp instanceof TypedIdentifier
        && ityp.getType() instanceof StructureType) {
      const stru = ityp.getType() as StructureType;
      components.push(...stru.getComponents());
    } else if (ityp && ityp instanceof StructureType) {
      components.push(...ityp.getComponents());
    } else if (scope.getDDIC().inErrorNamespace(name) === false) {
      return new VoidType(name);
    } else {
      throw new Error("IncludeType, type not found \"" + iname.concatTokens() + "\"");
    }
 
    return components;
  }
}