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

94.02% Statements 63/67
89.47% Branches 17/19
100% Functions 1/1
94.02% Lines 63/67

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 57 58 59 60 61 62 63 64 65 66 67 681x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 455x 455x 455x 455x 455x 446x 446x 455x 455x 1734x 1734x 1725x 796x 796x 796x 1x 1x 796x 796x 1725x 19x 19x 6x 19x 13x 13x 19x 1734x 9x 9x 9x     9x 9x 9x 1734x 455x 455x 6x 455x     449x 449x 449x 455x 92x 92x 449x 449x 449x 1x  
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 {IncludeType} from "../statements/include_type";
import {Type} from "../statements/type";
import * as Basic from "../../types/basic";
import {ScopeType} from "../_scope_type";
import {SyntaxInput, syntaxIssue} from "../_syntax_input";
 
export class Types {
  public runSyntax(node: StructureNode, input: SyntaxInput, qualifiedNamePrefix?: string): TypedIdentifier | undefined {
    const name = node.findFirstExpression(Expressions.NamespaceSimpleName)!.getFirstToken();
    const components: IStructureComponent[] = [];
    let voidd: VoidType | Basic.UnknownType | undefined = undefined;
 
    if (qualifiedNamePrefix === undefined) {
      qualifiedNamePrefix = "";
    }
 
    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, input, qualifiedNamePrefix + name.getStr() + "-");
          if (found) {
            if (found.getName().length > 30) {
              input.issues.push(syntaxIssue(input, found.getToken(), "Structure field name longer than 30 characters"));
            }
            components.push({name: found.getName(), type: found.getType()});
          }
        } else if (ctyp instanceof Statements.IncludeType) {
          const found = new IncludeType().runSyntax(c, input);
          if (found instanceof VoidType || found instanceof Basic.UnknownType) {
            voidd = found;
          } else {
            components.push(...found);
          }
        }
      } else if (c instanceof StructureNode && ctyp instanceof Structures.Types) {
        const found = new Types().runSyntax(c, input, qualifiedNamePrefix + name.getStr() + "-");
        if (found) {
          if (found.getName().length > 30) {
            input.issues.push(syntaxIssue(input, found.getToken(), "Structure field name longer than 30 characters"));
          }
          components.push({name: found.getName(), type: found.getType()});
        }
      }
    }
 
    if (voidd) {
      return new TypedIdentifier(name, input.filename, voidd);
    } else if (components.length === 0) { // todo, remove this check
      return undefined;
    }
 
    let qualifiedName = qualifiedNamePrefix + name.getStr();
    if (input.scope.getType() === ScopeType.ClassDefinition
        || input.scope.getType() === ScopeType.Interface) {
      qualifiedName = input.scope.getName() + "=>" + qualifiedName;
    }
 
    return new TypedIdentifier(name, input.filename, new Basic.StructureType(components, qualifiedName));
  }
}