Example #1
0
 public override object Clone(PSMPath newContainingPath)
 {
     return(new ClassLiteralStep(newContainingPath)
     {
         ClassLiteralExpression = this.ClassLiteralExpression
     });
 }
Example #2
0
 public override object Clone(PSMPath newContainingPath)
 {
     return(new TuplePartStep(newContainingPath)
     {
         TupleExpresion = this.TupleExpresion, TuplePart = this.TuplePart
     });
 }
Example #3
0
 public override object Clone(PSMPath newContainingPath)
 {
     return(new PSMPathAttributeStep(newContainingPath)
     {
         Attribute = this.Attribute
     });
 }
Example #4
0
 public override object Clone(PSMPath newContainingPath)
 {
     return(new PSMPathVariableStep(newContainingPath)
     {
         VariableExp = this.VariableExp
     });
 }
Example #5
0
 public override object Clone(PSMPath newContainingPath)
 {
     return(new PSMPathAssociationStep(newContainingPath)
     {
         Association = this.Association, From = this.From, To = this.To, IsUp = this.IsUp
     });
 }
Example #6
0
 public override object Clone(PSMPath newContainingPath)
 {
     return(new TupleLiteralStep(newContainingPath)
     {
         TupleExpresion = this.TupleExpresion
     });
 }
Example #7
0
 public override object Clone(PSMPath newContainingPath)
 {
     return(new GeneralSubexpressionStep(newContainingPath)
     {
         OclExpression = this.OclExpression
     });
 }
Example #8
0
 public override object Clone(PSMPath newContainingPath)
 {
     return(new PSMEvolutionPrevStep(newContainingPath)
     {
         PSMAssociationMemberTargetVersion = this.PSMAssociationMemberTargetVersion,
         PSMAssociationMemberSourceVersion = this.PSMAssociationMemberSourceVersion,
         StepAssociationNewVersion = this.StepAssociationNewVersion,
         StepAttributeNewVersion = this.StepAttributeNewVersion
     });
 }
Example #9
0
        public object Clone()
        {
            PSMPath clone = new PSMPath();

            clone.Context = Context;
            foreach (PSMPathStep navigationStep in Steps)
            {
                PSMPathStep stepClone = (PSMPathStep)navigationStep.Clone(clone);
                clone.Steps.Add(stepClone);
            }
            return(clone);
        }
Example #10
0
        private OclExpression CreateExpressionFromPath(PSMPath psmPath)
        {
            VariableExp   startVarExp      = new VariableExp(psmPath.StartingVariableExp.referredVariable);
            OclExpression result           = startVarExp;
            Classifier    sourceClassifier = startVarExp.Type;

            foreach (PSMPathStep step in psmPath.Steps)
            {
                if (step is PSMPathVariableStep)
                {
                    continue;
                }
                Property referredProperty;
                if (step is PSMPathAssociationStep)
                {
                    PSMPathAssociationStep pathAssociationStep = ((PSMPathAssociationStep)step);
                    referredProperty = sourceClassifier.LookupProperty(pathAssociationStep.Association.Name);
                    if (referredProperty == null)
                    {
                        if (pathAssociationStep.IsUp)
                        {
                            referredProperty = sourceClassifier.LookupProperty(PSMBridgeAssociation.PARENT_STEP);
                        }
                        else
                        {
                            referredProperty = sourceClassifier.LookupProperty(string.Format(PSMBridgeAssociation.CHILD_N_STEP,
                                                                                             pathAssociationStep.From.ChildPSMAssociations.IndexOf(pathAssociationStep.Association)));
                        }
                    }
                }
                else if (step is PSMPathAttributeStep)
                {
                    referredProperty = sourceClassifier.LookupProperty(((PSMPathAttributeStep)step).Attribute.Name);
                }
                else
                {
                    throw new NotImplementedException();
                }

                Property        navigationSource = null;
                OclExpression   qualifier        = null;
                PropertyCallExp propertyCallExp  = new PropertyCallExp(result, false, navigationSource, qualifier, referredProperty);
                result = propertyCallExp;

                if (step is PSMPathAssociationStep)
                {
                    sourceClassifier = psmBridge.Find(((PSMPathAssociationStep)step).To);
                }
                // else => no other steps
            }
            return(result);
        }
Example #11
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);
        }
Example #12
0
        public override OclExpression Visit(PropertyCallExp node)
        {
            PIMPath pimPath = PIMPathBuilder.BuildPIMPath(node);

            #region failure check

            if (!PathMappings.ContainsKey(pimPath) || PathMappings[pimPath].Count == 0)
            {
                isSuitable = false;
                notConvertibleExpression = node;
                throw new OclSubexpressionNotConvertible(notConvertibleExpression);
            }

            #endregion
            PSMPath psmPath = PathMappings[pimPath].First();

            OclExpression result = CreateExpressionFromPath(psmPath);
            return(result);
        }
Example #13
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);
        }
Example #14
0
        private bool FindNavigationsForPIMNavigationRecursive(PIMPath pimPath, int stepIndex, PSMAssociationMember currentMember, PSMPath builtPath, bool canGoToParent, ref List <PSMPath> result, PSMAssociation associationUsedAlready)
        {
            if (stepIndex == pimPath.Steps.Count)
            {
                result.Add(builtPath);
                return(true);
            }

            PIMPathStep currentStep = pimPath.Steps[stepIndex];

            if (currentStep is PIMPathAssociationStep)
            {
                Debug.Assert(currentMember != null);
                PIMPathAssociationStep      nextStep   = (PIMPathAssociationStep)currentStep;
                List <PSMAssociationMember> candidates = currentMember.ChildPSMAssociations.Where(a => allowNonTree || !a.IsNonTreeAssociation).Select(a => a.Child).ToList();

                /*
                 * we forbid non-tree associations for now,
                 * it certainly makes thinks easier and I am not sure
                 * whether it is really a restriction
                 */
                List <PSMAssociation> candidatesAssociations = currentMember.ChildPSMAssociations.Where(a => allowNonTree || !a.IsNonTreeAssociation).ToList();
                PSMAssociationMember  parent = currentMember.ParentAssociation != null ? currentMember.ParentAssociation.Parent : null;

                if (parent != null && canGoToParent && !(parent is PSMSchemaClass))
                {
                    bool candidateParent = true;
                    if (currentMember.ParentAssociation.Interpretation != null)
                    {
                        PIMAssociation    interpretedAssociation = (PIMAssociation)currentMember.ParentAssociation.Interpretation;
                        PIMAssociationEnd interpretedEnd         = currentMember.ParentAssociation.InterpretedAssociationEnd;
                        PIMAssociationEnd oppositeEnd            = interpretedAssociation.PIMAssociationEnds.Single(e => e != interpretedEnd);

                        // upwards navigation on ends with upper cardinality > 1 breaks semantics of the expression
                        if (oppositeEnd.Upper > 1)
                        {
                            candidateParent = false;
                        }
                    }

                    if (candidateParent)
                    {
                        candidates.Add(parent);
                        candidatesAssociations.Add(currentMember.ParentAssociation);
                    }
                }
                bool found = false;
                for (int index = 0; index < candidates.Count; index++)
                {
                    PSMAssociationMember candidate            = candidates[index];
                    PSMAssociation       candidateAssociation = candidatesAssociations[index];
                    bool parentStep = candidate == parent && !candidateAssociation.IsNonTreeAssociation;
                    // forbid traversing the same association several times
                    if (associationUsedAlready == candidateAssociation)
                    {
                        continue;
                    }

                    int nextStepIndex = stepIndex;

                    bool interpretedClassSatisfies = candidateAssociation.Interpretation != null &&
                                                     candidate.DownCastSatisfies <PSMClass>(c => c.Interpretation == nextStep.Class);
                    if (candidate.Interpretation == null || interpretedClassSatisfies)
                    {
                        PSMPath nextBuiltPath = (PSMPath)builtPath.Clone();
                        nextBuiltPath.Steps.Add(new PSMPathAssociationStep(nextBuiltPath)
                        {
                            Association = candidateAssociation, To = candidate, From = currentMember,
                            IsUp        = candidateAssociation.Parent == candidate
                        });

                        if (interpretedClassSatisfies)
                        {
                            nextStepIndex++;
                        }

                        found |= FindNavigationsForPIMNavigationRecursive(pimPath, nextStepIndex, candidate, nextBuiltPath,
                                                                          canGoToParent && !parentStep, ref result, parentStep ? candidateAssociation : null);
                    }
                }
                return(found);
            }
            else if (currentStep is PIMPathVariableStep)
            {
                Debug.Assert(currentMember == null);
                PIMPathVariableStep    pathVariableStep = (PIMPathVariableStep)currentStep;
                IEnumerable <PSMClass> candidates       = TargetPSMSchema.PSMClasses.Where(c => c.Interpretation == pimPath.StartingClass);
                if (!VariableClassMappings.ContainsKey(pathVariableStep.Variable))
                {
                    return(false);
                }
                candidates = candidates.Intersect(VariableClassMappings[pathVariableStep.Variable]);
                bool            found = false;
                List <PSMClass> eliminatedCandidates = new List <PSMClass>();
                eliminatedCandidates.AddRange(VariableClassMappings[pathVariableStep.Variable].Except(candidates));
                foreach (PSMClass candidate in candidates)
                {
                    PSMBridgeClass startType = psmBridge.Find(candidate);
                    builtPath = new PSMPath();
                    VariableDeclaration vd;
                    if (!variableTranslations.ContainsKey(pathVariableStep.Variable))
                    {
                        vd = new VariableDeclaration(pathVariableStep.Variable.Name, startType, null);
                        variableTranslations[pathVariableStep.Variable] = vd;
                    }
                    else
                    {
                        vd = variableTranslations[pathVariableStep.Variable];
                    }

                    builtPath.Steps.Add(new PSMPathVariableStep(builtPath)
                    {
                        VariableExp = new VariableExp(vd)
                    });
                    bool candidateUsable = FindNavigationsForPIMNavigationRecursive(pimPath, stepIndex + 1, candidate, builtPath, true, ref result, null);
                    if (!candidateUsable)
                    {
                        eliminatedCandidates.Add(candidate);
                    }
                    found |= candidateUsable;
                }
                VariableClassMappings[pathVariableStep.Variable].RemoveAll(eliminatedCandidates.Contains);
                if (PathMappings.ContainsKey(pimPath))
                {
                    PathMappings[pimPath].RemoveAll(p => eliminatedCandidates.Contains(p.StartingClass));
                }
                return(found);
            }
            else if (currentStep is PIMPathAttributeStep)
            {
                PIMPathAttributeStep pathAttributeStep = (PIMPathAttributeStep)currentStep;
                Debug.Assert(currentMember is PSMClass);

                bool found = false;
                foreach (PSMAttribute psmAttribute in ((PSMClass)currentMember).PSMAttributes)
                {
                    if (psmAttribute.Interpretation == pathAttributeStep.Attribute)
                    {
                        PSMPath nextBuiltPath = (PSMPath)builtPath.Clone();
                        nextBuiltPath.Steps.Add(new PSMPathAttributeStep(nextBuiltPath)
                        {
                            Attribute = psmAttribute
                        });
                        result.Add(nextBuiltPath);
                        found |= true;
                    }
                }
                return(found);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Example #15
0
 protected PSMPathStep(PSMPath path)
 {
     Path = path;
 }
Example #16
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);
        }
Example #17
0
 public PSMPathVariableStep(PSMPath path) : base(path)
 {
 }
Example #18
0
 public PSMEvolutionPrevStep(PSMPath path) : base(path)
 {
 }
Example #19
0
 public PSMPathAttributeStep(PSMPath path) : base(path)
 {
 }
Example #20
0
 public PSMPathAssociationStep(PSMPath path) : base(path)
 {
 }
Example #21
0
 public TuplePartStep(PSMPath path) : base(path)
 {
 }
Example #22
0
 public abstract object Clone(PSMPath newContainingPath);
Example #23
0
 public GeneralSubexpressionStep(PSMPath path)
     : base(path)
 {
 }
Example #24
0
 public TupleLiteralStep(PSMPath path) : base(path)
 {
 }
Example #25
0
 public ClassLiteralStep(PSMPath path)
     : base(path)
 {
 }