コード例 #1
0
        public static PIMPath BuildPIMPath(PropertyCallExp node)
        {
            PIMPath path = new PIMPath();

            OclExpression s;

            if (node.ReferredProperty.Tag is PIMAssociationEnd)
            {
                s = node;
            }
            else
            {
                PIMAttribute a = (PIMAttribute)node.ReferredProperty.Tag;

                PIMPathAttributeStep pathAttributeStep = new PIMPathAttributeStep {
                    Attribute = a
                };
                path.Steps.Add(pathAttributeStep);
                s = node.Source;
            }

            while (!(s is VariableExp))
            {
                PIMPathAssociationStep step = new PIMPathAssociationStep();
                step.AssociationEnd = (PIMAssociationEnd)((PropertyCallExp)s).ReferredProperty.Tag;
                path.Steps.Insert(0, step);
                s = ((PropertyCallExp)s).Source;
            }

            PIMPathVariableStep pathVariableStep = new PIMPathVariableStep();

            pathVariableStep.VariableExp = (VariableExp)s;
            path.Steps.Insert(0, pathVariableStep);
            return(path);
        }
コード例 #2
0
        public virtual void Visit(PropertyCallExp node, bool isOperationArgument)
        {
            AssignIsPartOfIteratorBody(node);
            PSMPath psmPath = PSMPathBuilder.BuildPSMPath(node, OclContext, VariableNamer, buildPathParams);
            string  xpath   = psmPath.ToXPath(delayFirstVariableStep: true);

            if (!isOperationArgument)
            {
                string wrapString = OperationHelper.WrapAtomicOperand(node, null, 0);
                xpath = string.Format(wrapString, xpath);
            }

            var steps = psmPath.Steps.OfType <IPSMPathStepWithCardinality>().Where(s => s.Lower == 0);

            if (steps.Any())
            {
                Log.AddWarningTaggedFormat("Navigation using '{0}' may result in 'null', which will be an empty sequence in XPath. ", node, steps.ConcatWithSeparator(s => s.ToXPath(), ","));
            }

            TranslationOption option = new TranslationOption();

            if (psmPath.StartingVariableExp != null)
            {
                option.ContextVariableSubstitution = true;
                option.StartingVariable            = psmPath.StartingVariableExp.referredVariable;
            }
            option.FormatString = xpath;
            SubexpressionTranslations.AddTranslationOption(node, option, psmPath.SubExpressions.ToArray());
        }
コード例 #3
0
        protected void checkImplicitSource(PropertyCallExp exp, String varName, String varType)
        {
            Assert.IsTrue(exp.getSource() is VariableExp);
            VariableExp varExp = (VariableExp)exp.getSource();

            Assert.AreEqual(varType, exp.getSource().getType().getName());
            Assert.AreEqual(varName, varExp.getReferredVariable().getVarName());
        }
コード例 #4
0
ファイル: PrintVisitor.cs プロジェクト: mff-uk/exolutio
 public void Visit(PropertyCallExp node)
 {
     if (node.Source != null)
     {
         node.Source.Accept(this);
         sb.Append(".");
     }
     sb.Append(node.ReferredProperty.Name);
 }
コード例 #5
0
        public void Visit(PropertyCallExp node)
        {
            PSMPath path = PSMPathBuilder.BuildPSMPath(node, null, VariableNamer,
                                                       new BuildPSMPathParams(TupleLiteralToXPathCallback, ClassLiteralToXPathCallback, GenericExpressionToXPathCallback, GetRelativeXPathEvolutionCallback));

            if (path.StartingVariableExp != null)
            {
                ReferredVariables.AddIfNotContained(path.StartingVariableExp.referredVariable);
            }
        }
コード例 #6
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);
        }
コード例 #7
0
        public override bool Visit(PropertyCallExp node)
        {
            /* It is necessary to find out, whether the property (attribute)
             * is represented in PSM schema by a PSM attribute */

            // check is perfomed by building a PIM path
            PIMPath path = PIMPathBuilder.BuildPIMPath(node);
            // and testing suitability of the path
            List <PSMPath> psmNavigations
                = FindNavigationsForPIMNavigation(path);

            return(psmNavigations.Count > 0);
        }
コード例 #8
0
ファイル: PSMPath.cs プロジェクト: mff-uk/exolutio
        private static bool IsEvolutionPrevStep(PropertyCallExp node)
        {
            OperationCallExp operationCallExp = node.Source as OperationCallExp;

            if (operationCallExp != null)
            {
                if (operationCallExp.ReferredOperation.Tag is PrevOperationTag)
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #9
0
 private void    removeAllLinks()
 {
     appliedProperty     = null;
     initializedVariable = null;
     loopExp             = null;
     navigationCallExp   = null;
     parentOperation     = null;
     ifExp           = null;
     thenClause      = null;
     elseClause      = null;
     letExp          = null;
     collectionRange = null;
     collectionItem  = null;
 }
コード例 #10
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);
        }
コード例 #11
0
        private IExpression GetExpression(SelectContext context, PropertyCallExp propertyCall)
        {
            switch (propertyCall.Source)
            {
            case VariableExp variableRef:
                var table = context.Variables[variableRef.ReferredVariable.Name];
                return(new Column
                {
                    Table = new Table
                    {
                        Name = table,
                        Alias = new Alias
                        {
                            Name = variableRef.ReferredVariable.Name
                        }
                    },
                    Name = propertyCall.ReferredProperty.Name
                });

            default:
                throw new NotSupportedException();
            }
        }
コード例 #12
0
 public virtual void Visit(PropertyCallExp node)
 {
     AssignIsPartOfIteratorBody(node);
     Visit(node, false);
 }
コード例 #13
0
 /**
  * @param appliedProperty The appliedProperty to set.
  */
 public void setAppliedProperty(PropertyCallExp appliedProperty)
 {
     removeAllLinks();
     this.appliedProperty = appliedProperty;
 }
コード例 #14
0
 public abstract TType Visit(PropertyCallExp node);
コード例 #15
0
ファイル: PSMPath.cs プロジェクト: mff-uk/exolutio
        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);
        }