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

91.3% Statements 42/46
84.61% Branches 11/13
100% Functions 1/1
91.3% Lines 42/46

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 54x 54x 54x 54x 54x 54x 54x     54x 54x 54x     54x 54x 54x 39x 39x 41x 41x 40x 40x 2x 2x 40x 41x 37x 54x 8x 8x 52x 52x 52x 1x 1x
import * as Expressions from "../../2_statements/expressions";
import {ExpressionNode, StatementNode} from "../../nodes";
import {StructureType, VoidType} from "../../types/basic";
import {AbstractType} from "../../types/basic/_abstract_type";
import {CurrentScope} from "../_current_scope";
import {Source} from "./source";
 
export class FieldAssignment {
 
  public runSyntax(
    node: ExpressionNode | StatementNode,
    scope: CurrentScope,
    filename: string,
    targetType: AbstractType | undefined): void {
 
    const fieldSub = node.findDirectExpression(Expressions.FieldSub);
    if (fieldSub === undefined) {
      throw new Error("FieldAssignment, FieldSub node not found");
    }
 
    const s = node.findDirectExpression(Expressions.Source);
    if (s === undefined) {
      throw new Error("FieldAssignment, Source node not found");
    }
 
    let type: AbstractType | undefined = undefined;
    if (targetType instanceof StructureType) {
      let context: AbstractType | undefined = targetType;
      for (const c of fieldSub.getChildren()) {
        const text = c.concatTokens();
        if (text !== "-" && context instanceof StructureType) {
          context = context.getComponentByName(text);
          if (context === undefined && targetType.containsVoid() === false) {
            throw new Error(`field ${text} does not exist in structure`);
          }
        }
      }
      type = context;
    } else if (targetType instanceof VoidType) {
      type = targetType;
    }
 
    new Source().runSyntax(s, scope, filename, type);
  }
 
}