All files / src/abap/5_syntax/structures types.ts

97.37% Statements 37/38
83.33% Branches 20/24
100% Functions 1/1
97.37% Lines 37/38

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 51 52 53 54 55 56 571x 1x 1x 1x 1x 1x   1x 1x 1x 1x   1x   97x   97x 97x 97x 330x 330x 329x 125x 125x 125x   204x 10x 10x 3x   7x     1x 1x 1x 1x         97x 3x 94x       94x 94x   37x     94x    
import * as Expressions from "../../2_statements/expressions";
import * as Statements from "../../2_statements/statements";
import * as Structures from "../../3_structures/structures";
import {StructureNode, StatementNode} from "../../nodes";
import {TypedIdentifier} from "../../types/_typed_identifier";
import {IStructureComponent, VoidType} from "../../types/basic";
import {CurrentScope} from "../_current_scope";
import {IncludeType} from "../statements/include_type";
import {Type} from "../statements/type";
import * as Basic from "../../types/basic";
import {ScopeType} from "../_scope_type";
 
export class Types {
  public runSyntax(node: StructureNode, scope: CurrentScope, filename: string): TypedIdentifier | undefined {
    const name = node.findFirstExpression(Expressions.NamespaceSimpleName)!.getFirstToken();
 
    const components: IStructureComponent[] = [];
    let voidd: VoidType | undefined = undefined;
    for (const c of node.getChildren()) {
      const ctyp = c.get();
      if (c instanceof StatementNode) {
        if (ctyp instanceof Statements.Type) {
          const found = new Type().runSyntax(c, scope, filename);
          Eif (found) {
            components.push({name: found.getName(), type: found.getType()});
          }
        } else if (ctyp instanceof Statements.IncludeType) {
          const found = new IncludeType().runSyntax(c, scope, filename);
          if (found instanceof VoidType) {
            voidd = found;
          } else {
            components.push(...found);
          }
        }
      } else Eif (c instanceof StructureNode && ctyp instanceof Structures.Types) {
        const found = new Types().runSyntax(c, scope, filename);
        Eif (found) {
          components.push({name: found.getName(), type: found.getType()});
        }
      }
    }
 
    if (voidd) {
      return new TypedIdentifier(name, filename, voidd);
    } else Iif (components.length === 0) { // todo, remove this check
      return undefined;
    }
 
    let qualifiedName = name.getStr();
    if (scope.getType() === ScopeType.ClassDefinition
        || scope.getType() === ScopeType.Interface) {
      qualifiedName = scope.getName() + "=>" + qualifiedName;
    }
 
    return new TypedIdentifier(name, filename, new Basic.StructureType(components, qualifiedName));
  }
}