@@ -20,29 +20,57 @@ class CdsFacade extends API::Node {
2020/**
2121 * A call to `entities` on a CDS facade.
2222 */
23- class CdsEntitiesCall extends API:: Node {
24- CdsEntitiesCall ( ) { exists ( CdsFacade cds | this = cds .getMember ( "entities" ) ) }
23+ class CdsEntitiesCall extends DataFlow:: CallNode {
24+ CdsEntitiesCall ( ) { exists ( CdsFacade cds | this = cds .getMember ( "entities" ) .getACall ( ) ) }
25+
26+ /**
27+ * Gets the namespace that this entity belongs to.
28+ */
29+ string getNamespace ( ) {
30+ result = this .getArgument ( 0 ) .getALocalSource ( ) .asExpr ( ) .( StringLiteral ) .getValue ( )
31+ }
2532}
2633
2734/**
28- * An entity instance obtained by the entity's namespace,
29- * via `cds.entities`
35+ * An entity object that belongs to a service.
36+ *
3037 * ```javascript
3138 * // Obtained through `cds.entities`
3239 * const { Service1 } = cds.entities("sample.application.namespace");
40+ * // Obtained through `Service.entities`, in this case the `Service`
41+ * // being a `this` variable of the service.
42+ * const { Service1 } = this.entities;
3343 * ```
3444 */
35- class EntityEntry extends DataFlow:: CallNode {
36- EntityEntry ( ) { exists ( CdsEntitiesCall c | c .getACall ( ) = this ) }
45+ abstract class EntityEntry instanceof PropRead {
46+ Location getLocation ( ) { result = PropRead .super .getLocation ( ) }
47+
48+ string toString ( ) { result = PropRead .super .toString ( ) }
3749
3850 /**
39- * Gets the namespace that this entity belongs to.
51+ * Gets the definition of the service to which this entity belongs to.
4052 */
41- string getNamespace ( ) {
42- result = this .getArgument ( 0 ) .getALocalSource ( ) .asExpr ( ) .( StringLiteral ) .getValue ( )
53+ abstract UserDefinedApplicationService getServiceDefinition ( ) ;
54+ }
55+
56+ private class EntityEntryFromCdsEntities extends EntityEntry {
57+ CdsEntitiesCall cdsEntities ;
58+
59+ EntityEntryFromCdsEntities ( ) { this = cdsEntities .getAPropertyRead ( ) }
60+
61+ override UserDefinedApplicationService getServiceDefinition ( ) {
62+ result .getServiceName ( ) = cdsEntities .getNamespace ( )
4363 }
4464}
4565
66+ private class EntityEntryFromServiceInstance extends EntityEntry {
67+ ServiceInstance srv ;
68+
69+ EntityEntryFromServiceInstance ( ) { this = srv .getAPropertyRead ( "entities" ) .getAPropertyRead ( ) }
70+
71+ override UserDefinedApplicationService getServiceDefinition ( ) { result = srv .getDefinition ( ) }
72+ }
73+
4674/**
4775 * A call to `serve` on a CDS facade.
4876 */
0 commit comments