All files / src/cds/expressions cds_extend_view.ts

100% Statements 75/75
100% Branches 1/1
100% Functions 1/1
100% Lines 75/75

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 761x 1x 1x 1x 1x 1x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 1x  
import {CDSAnnotation, CDSAs, CDSAssociation, CDSComposition, CDSCondition, CDSElement, CDSGroupBy, CDSInteger, CDSName, CDSPrefixedName, CDSString, CDSType, CDSWithParameters} from ".";
import {Expression, str, seq, star, starPrio, 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 redefineCard = altPrio(
      "EXACT ONE TO EXACT ONE", "EXACT ONE TO MANY", "EXACT ONE TO ONE",
      "MANY TO EXACT ONE", "MANY TO MANY", "MANY TO ONE",
      "ONE TO EXACT ONE", "ONE TO MANY", "ONE TO ONE",
      "TO EXACT ONE", "TO ONE", "TO MANY",
      CDSInteger, "*",
    );
    const redefineAssocFilter = seq("[", optPrio(seq(redefineCard, ":")), CDSCondition, "]");
    const redefineAssoc = seq(
      "REDEFINE", "ASSOCIATION", CDSPrefixedName, optPrio(redefineAssocFilter),
      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 unionElemList = seq(CDSElement, star(seq(",", CDSElement)), opt(","));
    const unionBranchBody = seq(star(altPrio(CDSAssociation, CDSComposition)), "{", altPrio("*", unionElemList), "}", optPrio(CDSGroupBy));
    const parenUnionBody = seq("(",
                               star(altPrio(CDSAssociation, CDSComposition)),
                               "{", seq(CDSElement, star(seq(",", CDSElement)), opt(",")), "}",
                               star(seq("UNION", opt("ALL"), star(altPrio(CDSAssociation, CDSComposition)), "{", seq(CDSElement, star(seq(",", CDSElement)), opt(",")), "}")),
                               ")");
    const unionSuffix = seq(
      optPrio(CDSGroupBy),
      star(seq("UNION", opt("ALL"), altPrio(parenUnionBody, unionBranchBody))),
    );
 
    const typedLiteralVal = seq(CDSType, CDSString);
    const aspectValue = altPrio(typedLiteralVal, CDSString, CDSPrefixedName);
    const aspectBinding = seq(CDSPrefixedName, "=", ">", aspectValue);
    const bindAspect = seq("BIND", "ASPECT", CDSName, "(", aspectBinding, starPrio(seq(",", aspectBinding)), ")", optPrio(seq("AS", CDSName)));
 
    const extendView = seq(
      star(CDSAnnotation),
      str("EXTEND VIEW"), opt(str("ENTITY")), CDSName, str("WITH"), opt(CDSName),
      star(redefineAssoc),
      star(altPrio(CDSAssociation, CDSComposition)),
      starPrio(bindAspect),
      altPrio(parenUnionBody, elementNested, valueNested),
      unionSuffix,
      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);
  }
}