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

84.31% Statements 43/51
83.33% Branches 10/12
100% Functions 1/1
84.31% Lines 43/51

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 511x 1x 1x 1x 1x 1x 1x 1x 1x 1x 107x 107x 107x 107x 107x 107x         107x 107x 107x         107x 107x 107x 81x 81x 83x 83x 82x 82x 3x 3x 3x 3x 82x 83x 78x 107x 12x 12x 104x 104x 104x 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 {SyntaxInput, syntaxIssue} from "../_syntax_input";
import {Source} from "./source";
 
export class FieldAssignment {
 
  public static runSyntax(
    node: ExpressionNode | StatementNode,
    input: SyntaxInput,
    targetType: AbstractType | undefined): void {
 
    const fieldSub = node.findDirectExpression(Expressions.FieldSub);
    if (fieldSub === undefined) {
      const message = "FieldAssignment, FieldSub node not found";
      input.issues.push(syntaxIssue(input, node.getFirstToken(), message));
      return;
    }
 
    const s = node.findDirectExpression(Expressions.Source);
    if (s === undefined) {
      const message = "FieldAssignment, Source node not found";
      input.issues.push(syntaxIssue(input, node.getFirstToken(), message));
      return;
    }
 
    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) {
            const message = `field ${text} does not exist in structure`;
            input.issues.push(syntaxIssue(input, node.getFirstToken(), message));
            return;
          }
        }
      }
      type = context;
    } else if (targetType instanceof VoidType) {
      type = targetType;
    }
 
    Source.runSyntax(s, input, type);
  }
 
}