All files / src/abap/5_syntax/statements method_implementation.ts

91.66% Statements 44/48
76.92% Branches 10/13
100% Functions 1/1
91.66% Lines 44/48

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 481x 1x 1x 1x 1x 1x 1x 1x 1x 1x 279x 279x 279x 279x 279x 279x 279x 279x     279x 279x 279x 5x 5x 274x 279x 215x 215x 215x 274x 274x 274x 274x 274x 274x 279x 31x 16x 16x 15x 31x     15x 15x 274x 1x
import {StatementNode} from "../../nodes";
import {CurrentScope} from "../_current_scope";
import * as Expressions from "../../2_statements/expressions";
import {ObjectOriented} from "../_object_oriented";
import {ScopeType} from "../_scope_type";
import {ReferenceType} from "../_reference";
import {StatementSyntax} from "../_statement_syntax";
 
export class MethodImplementation implements StatementSyntax {
  public runSyntax(node: StatementNode, scope: CurrentScope, filename: string): void {
    const helper = new ObjectOriented(scope);
 
    const className = scope.getName();
    const methodToken = node.findFirstExpression(Expressions.MethodName)!.getFirstToken();
    const methodName = methodToken?.getStr();
 
    const classDefinition = scope.findClassDefinition(className);
    if (classDefinition === undefined) {
      throw new Error("Class definition for \"" + className + "\" not found");
    }
 
    const {method: methodDefinition} = helper.searchMethodName(classDefinition, methodName);
    if (methodDefinition === undefined) {
      throw new Error("Method definition \"" + methodName + "\" not found");
    }
 
    if (methodDefinition.isStatic() === false) {
      scope.push(ScopeType.MethodInstance, methodName, node.getFirstToken().getStart(), filename);
      scope.addList(classDefinition.getAttributes().getInstance());
    }
 
    scope.push(ScopeType.Method, methodName, node.getFirstToken().getStart(), filename);
 
    scope.addReference(methodToken, methodDefinition, ReferenceType.MethodImplementationReference, filename);
    scope.addList(methodDefinition.getParameters().getAll());
 
    for (const i of helper.findInterfaces(classDefinition)) {
      if (methodName.toUpperCase().startsWith(i.name.toUpperCase() + "~") === false) {
        continue;
      }
      const idef = scope.findInterfaceDefinition(i.name);
      if (idef === undefined) {
        continue;
      }
      scope.addReference(methodToken, idef, ReferenceType.ObjectOrientedReference, filename);
    }
  }
}