All files / src/objects cds_metadata_extension.ts

48.27% Statements 28/58
100% Branches 2/2
28.57% Functions 2/7
48.27% Lines 28/58

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 591x 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  
import {ExpressionNode} from "../abap/nodes";
import {CDSParser} from "../cds/cds_parser";
import {AbstractObject} from "./_abstract_object";
import {IParseResult} from "./_iobject";
 
export type ParsedMetadataExtension = {
  tree: ExpressionNode | undefined;
};
 
 
export class CDSMetadataExtension extends AbstractObject {
  private parserError: boolean | undefined = undefined;
  private parsedData: ParsedMetadataExtension | undefined = undefined;
 
  public getType(): string {
    return "DDLX";
  }
 
  public getAllowedNaming() {
    return {
      maxLength: 40,
      allowNamespace: true,
    };
  }
 
  public hasParserError() {
    return this.parserError;
  }
 
  public parse(): IParseResult {
    if (this.isDirty() === false) {
      return {updated: false, runtime: 0};
    }

    const start = Date.now();

    this.parsedData = {
      tree: undefined,
    };

    this.parsedData.tree = new CDSParser().parse(this.findSourceFile());
    if (this.parsedData.tree === undefined) {
      this.parserError = true;
    }

    this.dirty = false;
    return {updated: true, runtime: Date.now() - start};
  }
 
  public getDescription(): string | undefined {
    // todo
    return undefined;
  }
 
  public findSourceFile() {
    return this.getFiles().find(f => f.getFilename().endsWith(".asddlxs") || f.getFilename().endsWith(".acds"));
  }
}