import { InitExpression } from '../InitExpression' ; import { DeriveExpression } from '../DeriveExpression' ; import { Utils } from '../../Utils' ; import { OclExecutionContext } from '../../OclExecutionContext' ; import { DefExpression } from '../DefExpression' ; import { ContextExpression } from './ContextExpression' ; oclExpression export class PropertyContextExpression extends ContextExpression { private readonly derived : any ; private readonly inits : any ; private readonly propertyName : any ; constructor ( targetType , rules ) { super ( ) ; const split = targetType . split ( '::' ) ; this . targetType = split [ 0 ] ; this . propertyName = split [ 1 ] ; if ( ! ( rules instanceof Array ) ) { rules = [ rules ] ; } this . inits = rules . filter ( i => i instanceof InitExpression ) ; this . derived = rules . filter ( i => i instanceof DeriveExpression ) ; } getInits ( ) { return this . inits ; } getDerived ( ) { return this . derived ; } getPropertyName ( ) { return this . propertyName ; } accept ( visitor ) { return Utils . getClassName ( visitor . getObjectToEvaluate ( ) ) === this . targetType ; } evaluate ( visitor ) { super . evaluate ( visitor ) ; this . getInits ( ) . forEach ( init => { visitor . getObjectToEvaluate ( ) [ this . getPropertyName ( ) ] = init . evaluate ( visitor ) ; } ) ; this . getDerived ( ) . forEach ( derive => { visitor . getObjectToEvaluate ( ) [ this . getPropertyName ( ) ] = derive . evaluate ( visitor ) ; } ) ; return true ; } }