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

90.32% Statements 28/31
77.77% Branches 7/9
100% Functions 1/1
90.32% Lines 28/31

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 311x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 49x 49x 150x 101x 52x 101x   49x 49x 49x 1x 1x 49x     101x 150x 45x 1x 1x
import * as Expressions from "../../2_statements/expressions";
import {ExpressionNode} from "../../nodes";
import {AbstractType} from "../../types/basic/_abstract_type";
import {CurrentScope} from "../_current_scope";
import {TypeUtils} from "../_type_utils";
import {ComponentChain} from "./component_chain";
import {Source} from "./source";
 
export class ComponentCompareSimple {
 
  public runSyntax(node: ExpressionNode, scope: CurrentScope, filename: string, rowType: AbstractType): void {
    let targetType: AbstractType | undefined = undefined;
    for (const c of node.getChildren()) {
      if (c instanceof ExpressionNode) {
        if (c.get() instanceof Expressions.ComponentChainSimple) {
          targetType = new ComponentChain().runSyntax(rowType, c, scope, filename);
        } else if (c.get() instanceof Expressions.Dynamic) {
          targetType = undefined;
        } else if (c.get() instanceof Expressions.Source) {
          const sourceType = new Source().runSyntax(c, scope, filename, targetType);
          if (targetType && new TypeUtils(scope).isAssignable(sourceType, targetType) === false) {
            throw new Error("ComponentCompareSimple, incompatible types");
          }
        } else {
          throw "ComponentCompareSimple, unexpected node";
        }
      }
    }
  }
 
}