|
| 1 | +import { AstUtils, DefaultScopeProvider, ReferenceInfo, Scope } from 'langium' |
| 2 | +import { |
| 3 | + AbstractStakeholder, |
| 4 | + Aggregate, |
| 5 | + DomainPart, |
| 6 | + isContextMappingModel, |
| 7 | + isStakeholderGroup, StakeholderGroup |
| 8 | +} from '../generated/ast.js' |
| 9 | + |
| 10 | +export class ContextMapperDslScopeProvider extends DefaultScopeProvider { |
| 11 | + override getScope (context: ReferenceInfo): Scope { |
| 12 | + const referenceType = this.reflection.getReferenceType(context) |
| 13 | + const model = AstUtils.getContainerOfType(context.container, isContextMappingModel)! |
| 14 | + |
| 15 | + if (referenceType === DomainPart) { |
| 16 | + const domainPartDescriptions = model.domains.map(d => this.descriptions.createDescription(d, d.name)) |
| 17 | + .concat( |
| 18 | + model.domains.flatMap(d => d.subdomains) |
| 19 | + .map(sd => this.descriptions.createDescription(sd, sd.name)) |
| 20 | + ) |
| 21 | + return this.createScope(domainPartDescriptions) |
| 22 | + } |
| 23 | + |
| 24 | + if (referenceType === Aggregate) { |
| 25 | + const aggregateDescriptions = model.boundedContexts.flatMap(bc => bc.aggregates) |
| 26 | + .map(a => this.descriptions.createDescription(a, a.name)) |
| 27 | + .concat( |
| 28 | + model.boundedContexts.flatMap(bc => bc.modules) |
| 29 | + .flatMap(m => m.aggregates) |
| 30 | + .map(a => this.descriptions.createDescription(a, a.name)) |
| 31 | + ) |
| 32 | + return this.createScope(aggregateDescriptions) |
| 33 | + } |
| 34 | + |
| 35 | + if (referenceType === AbstractStakeholder) { |
| 36 | + const stakeholderDescriptions = model.stakeholders.flatMap(s => s.stakeholders) |
| 37 | + .map(s => this.descriptions.createDescription(s, s.name)) |
| 38 | + .concat( |
| 39 | + model.stakeholders.flatMap(s => s.stakeholders) |
| 40 | + .filter(s => isStakeholderGroup(s)) |
| 41 | + .flatMap(sg => (sg as StakeholderGroup).stakeholders) |
| 42 | + .map(s => this.descriptions.createDescription(s, s.name)) |
| 43 | + ) |
| 44 | + return this.createScope(stakeholderDescriptions) |
| 45 | + } |
| 46 | + |
| 47 | + return super.getScope(context) |
| 48 | + } |
| 49 | +} |
0 commit comments