import { OclExecutionContext } from '../OclExecutionContext' ; import { Utils } from '../Utils' ; import { ContextExpression } from './context/ContextExpression' ; import { Expression } from './Expression' ; /**
 * In order to group and organise OCL constraints, packages can be used.
 */ export class PackageDeclaration extends Expression { private readonly contexts : Array < ContextExpression > ; private labels : Array < string > ; private oclExpression : string ; constructor ( type , contexts ) { super ( ) ; this . contexts = contexts ; } accept ( visitor ) { const labelsToExecute = visitor . getLabelsToExecute ( ) ; if ( labelsToExecute . length === 0 || this . labels . length === 0 ) { return true ; } const anies = Utils . intersect ( this . labels , labelsToExecute ) ; return anies . length > 0 ; } getContexts ( ) { return this . contexts ; } setExecutionLabels ( labels ) { this . labels = labels ; } setRawOclExpression ( oclExpression ) { this . oclExpression = oclExpression ; } getRawOclExpression ( ) { return this . oclExpression ; } evaluate ( visitor ) { if ( this . accept ( visitor ) ) { const contextsToVisit = this . getContexts ( ) . filter ( ctx => ctx . accept ( visitor ) ) ; const evaluationResult = ! contextsToVisit . map ( ctx => ctx . evaluate ( visitor ) ) . some ( inv => inv === false ) ; visitor . setEvaluationResult ( evaluationResult ) ; } return this ; } }