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

92.31% Statements 24/26
83.33% Branches 15/18
100% Functions 1/1
92.31% Lines 24/26

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 541x 1x   1x 1x 1x 1x 1x   1x       9x   8x 8x 8x 3x 5x 3x 2x 2x 2x 2x     2x   1x 1x       2x 2x                                    
import * as Expressions from "../../2_statements/expressions";
import {ExpressionNode} from "../../nodes";
import {CurrentScope} from "../_current_scope";
import {Dynamic} from "./dynamic";
import {MethodCallChain} from "./method_call_chain";
import {ObjectReferenceType, VoidType} from "../../types/basic";
import {ClassDefinition} from "../../types";
import {IReferenceExtras, ReferenceType} from "../_reference";
 
export class MethodSource {
 
  public runSyntax(node: ExpressionNode, scope: CurrentScope, filename: string) {
 
    const context = new MethodCallChain().runSyntax(node, scope, filename);
 
    const last = node.getLastChild();
    const first = node.getFirstChild();
    if (first instanceof ExpressionNode && first.get() instanceof Expressions.Dynamic) {
      new Dynamic().runSyntax(first!, scope, filename);
    } else if (last instanceof ExpressionNode && last.get() instanceof Expressions.MethodName) {
      if (context instanceof ObjectReferenceType) {
        const id = context.getIdentifier();
        Eif (id instanceof ClassDefinition) {
          const method = id.getMethodDefinitions().getByName(last.concatTokens());
          const extra: IReferenceExtras = {
            ooName: id.getName(),
            ooType: "CLAS"};
          scope.addReference(last.getFirstToken(), method, ReferenceType.MethodReference, filename, extra);
        }
      } else Eif (context instanceof VoidType) {
        return;
      } else {
        throw new Error("MethodSource, not a object reference, " + node.concatTokens());
      }
    } else Eif (last instanceof ExpressionNode && last.get() instanceof Expressions.Dynamic) {
      new Dynamic().runSyntax(last!, scope, filename);
    } else {
      throw new Error("MethodSource, unexpected node");
    }
 
    /*
    const chain = node.findDirectExpression(Expressions.FieldChain);
    if (chain) {
      new FieldChain().runSyntax(chain, scope, filename, ReferenceType.DataReadReference);
    }
 
    for (const d of node.findAllExpressions(Expressions.Dynamic)) {
      new Dynamic().runSyntax(d, scope, filename);
    }
    */
 
  }
 
}