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

90.24% Statements 37/41
88.88% Branches 8/9
100% Functions 1/1
90.24% Lines 37/41

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 421x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 99x 99x 99x 99x 99x 99x 99x         99x 99x 99x 99x 92x 92x 92x 3x 3x 3x 3x 3x 92x 89x 89x 92x 99x 1x 1x  
import * as Expressions from "../../2_statements/expressions";
import {ExpressionNode} from "../../nodes";
import {AbstractType} from "../../types/basic/_abstract_type";
import {SyntaxInput, syntaxIssue} from "../_syntax_input";
import {ComponentChain} from "./component_chain";
import {ComponentName} from "./component_name";
import {Source} from "./source";
 
export class ComponentCompare {
 
  public static runSyntax(
    node: ExpressionNode,
    input: SyntaxInput,
    leftType?: AbstractType,
    rightType?: AbstractType): void {
 
    const chain = node.findDirectExpression(Expressions.ComponentChainSimple);
    if (chain === undefined) {
      const message = "ComponentCompare, chain not found";
      input.issues.push(syntaxIssue(input, node.getFirstToken(), message));
      return;
    }
 
    const fieldType = ComponentChain.runSyntax(leftType, chain, input);
 
    for (const s of node.findDirectExpressions(Expressions.Source)) {
      const fieldChain = s.findDirectExpression(Expressions.FieldChain);
      const first = fieldChain?.getFirstChild();
      if (rightType && fieldChain && first) {
        let sourceType: AbstractType | undefined = rightType;
        if (first.concatTokens().toUpperCase() !== "TABLE_LINE") {
          sourceType = ComponentName.runSyntax(sourceType, first, input);
        }
        ComponentChain.runSyntax(sourceType, fieldChain, input);
      } else {
        Source.runSyntax(s, input, fieldType);
      }
    }
  }
 
}