All files / src/abap artifacts.ts

45.19% Statements 47/104
100% Branches 2/2
11.11% Functions 1/9
45.19% Lines 47/104

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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 1041x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x                   1x 1x     1x 1x               1x 1x       1x 1x 1x 1x                       1x 1x                       1x 1x 1x 1x 1x 1x 293x 293x 293x 293x 1x 1x 1x 1x 1x                         1x 1x
import * as Statements from "./2_statements/statements";
import * as Expressions from "./2_statements/expressions";
import {Combi, Expression} from "./2_statements/combi";
import {IStatement} from "./2_statements/statements/_statement";
import * as Structures from "./3_structures/structures";
import {IStructure} from "./3_structures/structures/_structure";
 
export interface IKeyword {
  word: string;
  source: string[];
}
 
class List {
  private readonly words: IKeyword[];
 
  public constructor() {
    this.words = [];
  }
 
  public add(keywords: string[], source: string): void {
    for (const w of keywords) {
      const index = this.find(w);
      if (index >= 0) {
        this.words[index].source.push(source);
      } else {
        this.words.push({word: w, source: [source]});
      }
    }
  }
 
  public get(): IKeyword[] {
    return this.words;
  }
 
  private find(keyword: string): number {
    for (let i = 0; i < this.words.length; i++) {
      if (this.words[i].word === keyword) {
        return i;
      }
    }
    return -1;
  }
}
 
function className(cla: any) {
  return cla.constructor.name;
}
 
export class Artifacts {
 
  public static getStructures(): IStructure[] {
    const ret: IStructure[] = [];

    const list: any = Structures;
    for (const key in Structures) {
      if (typeof list[key] === "function") {
        ret.push(new list[key]());
      }
    }

    return ret;
  }
 
  public static getExpressions(): (new () => Expression)[] {
    const ret: (new () => Expression)[] = [];

    const list: any = Expressions;
    for (const key in Expressions) {
      if (typeof list[key] === "function") {
        ret.push(list[key]);
      }
    }

    return ret;
  }
 
  public static getStatements(): IStatement[] {
    const ret: IStatement[] = [];
 
    const list: any = Statements;
    for (const key in Statements) {
      if (typeof list[key] === "function") {
        ret.push(new list[key]());
      }
    }
 
    return ret;
  }
 
  public static getKeywords(): IKeyword[] {
    const list: List = new List();

    for (const stat of this.getStatements()) {
      list.add(Combi.listKeywords(stat.getMatcher()), "statement_" + className(stat));
    }

    for (const expr of this.getExpressions()) {
      list.add(Combi.listKeywords(new expr().getRunnable()), "expression_" + className(expr));
    }

    return list.get();
  }
 
}