Beispiel #1
0
        public static PSMPath BuildPSMPath(VariableExp variableExp, IConstraintsContext constraintsContext, VariableNamer variableNamer, BuildPSMPathParams buildPsmPathParams)
        {
            PSMPath path = new PSMPath();

            path.Context.ConstraintContext        = constraintsContext;
            path.Context.VariableNamer            = variableNamer;
            path.TupleLiteralToXPathCallback      = buildPsmPathParams.TupleLiteralToXPathCallback;
            path.GenericExpressionToXPathCallback = buildPsmPathParams.GenericExpressionToXPathCallback;
            path.ClassLiteralToXPathCallback      = buildPsmPathParams.ClassLiteralToXPathCallback;

            PSMPathVariableStep pathVariableStep = new PSMPathVariableStep(path)
            {
                VariableExp = variableExp
            };

            if (string.IsNullOrEmpty(variableExp.referredVariable.Name))
            {
                variableExp.referredVariable.Name = path.Context.VariableNamer.GetName(variableExp.referredVariable.PropertyType);
            }
            path.Steps.Insert(0, pathVariableStep);
            return(path);
        }
Beispiel #2
0
        public static PSMPath BuildPSMPath(ClassLiteralExp classLiteral, IConstraintsContext constraintsContext, VariableNamer variableNamer, BuildPSMPathParams buildPsmPathParams)
        {
            PSMPath path = new PSMPath();

            path.Context.ConstraintContext        = constraintsContext;
            path.Context.VariableNamer            = variableNamer;
            path.TupleLiteralToXPathCallback      = buildPsmPathParams.TupleLiteralToXPathCallback;
            path.ClassLiteralToXPathCallback      = buildPsmPathParams.ClassLiteralToXPathCallback;
            path.GenericExpressionToXPathCallback = buildPsmPathParams.GenericExpressionToXPathCallback;

            ClassLiteralStep classLiteralStep = new ClassLiteralStep(path)
            {
                ClassLiteralExpression = classLiteral
            };

            path.Steps.Insert(0, classLiteralStep);
            return(path);
        }
Beispiel #3
0
        public static PSMPath BuildPSMPath(PropertyCallExp node, IConstraintsContext constraintsContext, VariableNamer variableNamer, BuildPSMPathParams buildPsmPathParams)
        {
            PSMPath path = new PSMPath();

            path.TupleLiteralToXPathCallback       = buildPsmPathParams.TupleLiteralToXPathCallback;
            path.GenericExpressionToXPathCallback  = buildPsmPathParams.GenericExpressionToXPathCallback;
            path.GetRelativeXPathEvolutionCallback = buildPsmPathParams.GetRelativeXPathEvolutionCallback;
            path.Context.ConstraintContext         = constraintsContext;
            path.Context.VariableNamer             = variableNamer;

            OclExpression s;

            if (buildPsmPathParams.Evolution && IsEvolutionPrevStep(node))
            {
                PSMEvolutionPrevStep prevStep = new PSMEvolutionPrevStep(path);
                if (node.ReferredProperty is PSMBridgeAttribute)
                {
                    prevStep.StepAttributeNewVersion = ((PSMBridgeAttribute)node.ReferredProperty).SourceAttribute;
                }
                else if (node.ReferredProperty is PSMBridgeAssociation)
                {
                    prevStep.StepAssociationNewVersion = ((PSMBridgeAssociation)node.ReferredProperty).SourceAsscociation;
                }
                else
                {
                    throw new InvalidOperationException();
                }
                PrevOperationTag tag = (PrevOperationTag)((OperationCallExp)node.Source).ReferredOperation.Tag;
                prevStep.PSMAssociationMemberTargetVersion = (PSMAssociationMember)tag.TargetVersionClassifier.Tag;
                prevStep.PSMAssociationMemberSourceVersion = (PSMAssociationMember)tag.SourceVersionClassifier.Tag;
                path.Steps.Add(prevStep);
                OclExpression prevSource = ((OperationCallExp)node.Source).Source;
                if (prevSource is VariableExp && ((VariableExp)prevSource).referredVariable == constraintsContext.Self)
                {
                    s = null;
                }
                else
                {
                    s = prevSource;
                }
            }
            else if (node.ReferredProperty is PSMBridgeAssociation)
            {
                s = node;
            }
            else if (node.Source is TupleLiteralExp)
            {
                TuplePartStep tuplePartStep = new TuplePartStep(path)
                {
                    TupleExpresion = (TupleLiteralExp)node.Source
                };
                tuplePartStep.TuplePart = tuplePartStep.TupleExpresion.Parts[node.ReferredProperty.Name];
                path.Steps.Add(tuplePartStep);
                s = node.Source;
            }
            else
            {
                PSMAttribute         a = (PSMAttribute)node.ReferredProperty.Tag;
                PSMPathAttributeStep pathAttributeStep = new PSMPathAttributeStep(path)
                {
                    Attribute = a
                };
                path.Steps.Add(pathAttributeStep);
                s = node.Source;
            }

            while (s is PropertyCallExp)
            {
                PSMPathAssociationStep step = new PSMPathAssociationStep(path);
                var sp = ((PropertyCallExp)s);
                // HACK: WFJT turn class tag into association tag
                PSMBridgeAssociation bridgeAssociation = (PSMBridgeAssociation)sp.ReferredProperty;
                step.Association = bridgeAssociation.SourceAsscociation;
                if (bridgeAssociation.Direction == PSMBridgeAssociation.AssociationDirection.Down)
                {
                    step.From = bridgeAssociation.SourceAsscociation.Parent;
                    step.To   = bridgeAssociation.SourceAsscociation.Child;
                    step.IsUp = false;
                }
                else
                {
                    step.From = bridgeAssociation.SourceAsscociation.Child;
                    step.To   = bridgeAssociation.SourceAsscociation.Parent;
                    step.IsUp = true;
                }
                path.Steps.Insert(0, step);
                s = sp.Source;
            }

            if (s is VariableExp)
            {
                VariableExp         variableExp      = (VariableExp)s;
                PSMPathVariableStep pathVariableStep = new PSMPathVariableStep(path)
                {
                    VariableExp = variableExp
                };
                if (string.IsNullOrEmpty(variableExp.referredVariable.Name))
                {
                    variableExp.referredVariable.Name =
                        path.Context.VariableNamer.GetName(variableExp.referredVariable.PropertyType);
                }
                path.Steps.Insert(0, pathVariableStep);
            }
            else if (s is TupleLiteralExp)
            {
                TupleLiteralExp  tupleLiteralExp  = (TupleLiteralExp)s;
                TupleLiteralStep tupleLiteralStep = new TupleLiteralStep(path);
                tupleLiteralStep.TupleExpresion = tupleLiteralExp;
                path.Steps.Insert(0, tupleLiteralStep);
            }
            else if (node.Source is ClassLiteralExp)
            {
                ClassLiteralExp  classLiteralExp  = (ClassLiteralExp)s;
                ClassLiteralStep tupleLiteralStep = new ClassLiteralStep(path);
                tupleLiteralStep.ClassLiteralExpression = classLiteralExp;
                path.Steps.Insert(0, tupleLiteralStep);
            }
            else if (s == null)
            {
                // do nothing
            }
            else
            {
                GeneralSubexpressionStep generalSubexpressionStep = new GeneralSubexpressionStep(path);
                generalSubexpressionStep.OclExpression = s;
                path.Steps.Insert(0, generalSubexpressionStep);
            }

            return(path);
        }