All files / src/abap/types class_implementation.ts

46.15% Statements 18/39
100% Branches 0/0
0% Functions 0/3
46.15% Lines 18/39

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 391x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                 1x 1x             1x 1x               1x 1x
import {Identifier} from "../4_file_information/_identifier";
import {StructureNode} from "../nodes";
import * as Structures from "../3_structures/structures";
import * as Statements from "../2_statements/statements";
import * as Expressions from "../2_statements/expressions";
import {MethodImplementation} from "./method_implementation";
import {IClassImplementation} from "./_class_implementation";
 
export class ClassImplementation extends Identifier implements IClassImplementation {
  private readonly node: StructureNode;
 
  public constructor(node: StructureNode, filename: string) {
    if (!(node.get() instanceof Structures.ClassImplementation)) {
      throw new Error("ClassImplementation, unexpected node type");
    }
    const name = node.findFirstStatement(Statements.ClassImplementation)!.findFirstExpression(Expressions.ClassName)!.getFirstToken();
    super(name, filename);

    this.node = node;
  }
 
  public getMethodImplementations(): MethodImplementation[] {
    const ret: MethodImplementation[] = [];
    for (const method of this.node.findAllStructures(Structures.Method)) {
      ret.push(new MethodImplementation(method, this.filename));
    }
    return ret;
  }
 
  public getMethodImplementation(name: string): MethodImplementation | undefined {
    for (const impl of this.getMethodImplementations()) {
      if (impl.getName().toUpperCase() === name.toUpperCase()) {
        return impl;
      }
    }
    return undefined;
  }
 
}