All files / src/cds/expressions cds_extend_view.ts

100% Statements 48/48
100% Branches 1/1
100% Functions 1/1
100% Lines 48/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 48 491x 1x 1x 1x 1x 1x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 1x  
import {CDSAnnotation, CDSAs, CDSAssociation, CDSComposition, CDSCondition, CDSElement, CDSName, CDSPrefixedName, CDSType, CDSWithParameters} from ".";
import {Expression, str, seq, star, opt, optPrio, plus, alt, altPrio} from "../../abap/2_statements/combi";
import {IStatementRunnable} from "../../abap/2_statements/statement_runnable";
 
export class CDSExtendView extends Expression {
  public getRunnable(): IStatementRunnable {
 
    const namedot = seq(CDSName, optPrio(seq(".", CDSName)), optPrio(CDSAs));
    const valueNested = seq("{", namedot, star(seq(",", namedot)), "}");
 
    const redefineAssoc = seq(
      "REDEFINE", "ASSOCIATION", CDSPrefixedName, optPrio(seq("[", CDSCondition, "]")),
      opt(CDSAs),
      "REDIRECTED", "TO",
      optPrio(altPrio(seq("COMPOSITION", "CHILD"), "PARENT")),
      CDSName,
    );
 
    const elementList = seq(CDSElement, star(seq(",", CDSElement)), opt(","));
    const elementNested = seq("{", altPrio("*", elementList), "}");
 
    const extendView = seq(
      star(CDSAnnotation),
      str("EXTEND VIEW"), opt(str("ENTITY")), CDSName, str("WITH"), opt(CDSName),
      star(redefineAssoc),
      star(CDSAssociation),
      altPrio(elementNested, valueNested),
      opt(";"),
    );
 
    const field = seq(star(CDSAnnotation), optPrio(str("KEY")), CDSName, ":", CDSType, ";");
    const assocOrComp = seq(star(CDSAnnotation), CDSName, ":", alt(CDSComposition, CDSAssociation), ";");
    const entityBody = seq("{", plus(alt(field, assocOrComp)), "}");
    const extendAbstractOrCustom = seq(
      star(CDSAnnotation),
      "EXTEND",
      alt("ABSTRACT", "CUSTOM"),
      "ENTITY",
      CDSName,
      opt(CDSWithParameters),
      "WITH",
      entityBody,
      opt(";"),
    );
 
    return alt(extendAbstractOrCustom, extendView);
  }
}