Exemplo n.º 1
0
        public void TestEndToAssociationResetMultiList2MultiList()
        {
            var model   = new MutableModel();
            var factory = new PropertiesTestFactory(model);
            var assoc   = factory.Association();
            var end     = factory.AssociationEndMultiList();

            end.Association = assoc;
            Assert.True(assoc.FirstMultiList.Count == 1);
            Assert.True(assoc.SecondMultiList.Count == 1);
            Assert.Contains(end, assoc.FirstMultiList);
            Assert.Contains(end, assoc.SecondMultiList);
            Assert.Equal(assoc, end.Association);
            end.Association = null;
            Assert.True(assoc.FirstMultiList.Count == 0);
            Assert.True(assoc.SecondMultiList.Count == 0);
            Assert.Null(end.Association);
            var imodel = model.ToImmutable();
            var iassoc = assoc.ToImmutable(imodel);
            var iend   = end.ToImmutable(imodel);

            Assert.Null(iassoc.First);
            Assert.Null(iassoc.Second);
            Assert.Null(iend.Association);
        }
Exemplo n.º 2
0
        public void TestAssociationToEnd()
        {
            var model   = new MutableModel();
            var factory = new PropertiesTestFactory(model);
            var assoc   = factory.Association();
            var end1    = factory.AssociationEnd();
            var end2    = factory.AssociationEnd();

            assoc.First = end1;
            Assert.Equal(end1, assoc.First);
            Assert.Null(assoc.Second);
            Assert.Equal(assoc, end1.Association);
            Assert.Null(end2.Association);
            assoc.Second = end2;
            Assert.Equal(end1, assoc.First);
            Assert.Equal(end2, assoc.Second);
            Assert.Equal(assoc, end1.Association);
            Assert.Equal(assoc, end2.Association);
            var imodel = model.ToImmutable();
            var iassoc = assoc.ToImmutable(imodel);
            var iend1  = end1.ToImmutable(imodel);
            var iend2  = end2.ToImmutable(imodel);

            Assert.Equal(iend1, iassoc.First);
            Assert.Equal(iend2, iassoc.Second);
            Assert.Equal(iassoc, iend1.Association);
            Assert.Equal(iassoc, iend2.Association);
        }
Exemplo n.º 3
0
        public void TestAssociationToEndMultiList2MultiList()
        {
            var model   = new MutableModel();
            var factory = new PropertiesTestFactory(model);
            var assoc   = factory.Association();
            var end1    = factory.AssociationEndMultiList();
            var end2    = factory.AssociationEndMultiList();

            assoc.FirstMultiList.Add(end1);
            Assert.True(assoc.FirstMultiList.Count == 1);
            Assert.True(assoc.SecondMultiList.Count == 0);
            Assert.Contains(end1, assoc.FirstMultiList);
            Assert.Equal(assoc, end1.Association);
            Assert.Null(end2.Association);
            assoc.SecondMultiList.Add(end2);
            Assert.True(assoc.FirstMultiList.Count == 1);
            Assert.True(assoc.SecondMultiList.Count == 1);
            Assert.Contains(end1, assoc.FirstMultiList);
            Assert.Contains(end2, assoc.SecondMultiList);
            Assert.Equal(assoc, end1.Association);
            Assert.Equal(assoc, end2.Association);
            var imodel = model.ToImmutable();
            var iassoc = assoc.ToImmutable(imodel);
            var iend1  = end1.ToImmutable(imodel);
            var iend2  = end2.ToImmutable(imodel);

            Assert.Contains(iend1, iassoc.FirstMultiList);
            Assert.Contains(iend2, iassoc.SecondMultiList);
            Assert.Equal(iassoc, iend1.Association);
            Assert.Equal(iassoc, iend2.Association);
        }
Exemplo n.º 4
0
 public MutableObjectBase GetModelObject(MutableObjectBase parentObject, MutableModel model, DiagnosticBag diagnostics)
 {
     if (_modelObject == null)
     {
         lock (this) // We must lock, we do not want to create multiple symbols for the same declaration
         {
             if (_modelObject != null)
             {
                 return(_modelObject);
             }
             var modelObject = this.Kind.CreateMutable(model);
             modelObject.MName = this.Name;
             if (parentObject != null && !string.IsNullOrEmpty(this.ParentPropertyToAddTo))
             {
                 var property = parentObject.MGetProperty(this.ParentPropertyToAddTo);
                 if (property != null)
                 {
                     try
                     {
                         parentObject.MAdd(property, modelObject);
                     }
                     catch (ModelException me)
                     {
                         diagnostics.Add(ModelErrorCode.ERR_CannotSetValueToProperty, this.NameLocations[0], property, modelObject, me.ToString());
                     }
                 }
             }
             Interlocked.CompareExchange(ref _modelObject, modelObject, null);
         }
     }
     return(_modelObject);
 }
Exemplo n.º 5
0
        public void TestParentToManyChildrenReset()
        {
            var model   = new MutableModel();
            var factory = new PropertiesTestFactory(model);
            var parent  = factory.ParentMultiList();
            var child   = factory.ChildMultiList();

            parent.Children.Add(child);
            parent.Children.Add(child);
            Assert.Equal(parent, child.Parent);
            Assert.Contains(child, parent.Children);
            Assert.True(parent.Children.Count == 2);
            Assert.Equal(child, parent.Children[0]);
            Assert.Equal(child, parent.Children[1]);
            parent.Children.Remove(child);
            Assert.Equal(parent, child.Parent);
            Assert.Contains(child, parent.Children);
            Assert.True(parent.Children.Count == 1);
            Assert.Equal(child, parent.Children[0]);
            var imodel  = model.ToImmutable();
            var iparent = parent.ToImmutable(imodel);
            var ichild  = child.ToImmutable(imodel);

            Assert.Equal(iparent, ichild.Parent);
            Assert.Contains(ichild, iparent.Children);
            Assert.True(iparent.Children.Count == 1);
            Assert.Equal(ichild, iparent.Children[0]);
        }
Exemplo n.º 6
0
 public EcoreToMetaConverter(ImmutableModel ecore)
 {
     _ecore       = ecore;
     _meta        = new MutableModel();
     _factory     = new MetaFactory(_meta);
     _diagnostics = new DiagnosticBag();
     _map         = new Dictionary <ImmutableObject, MutableObject>();
 }
Exemplo n.º 7
0
        static SoalGenerator()
        {
            MutableModel xsdModel = new MutableModel("xmlschema");
            SoalFactory  f        = new SoalFactory(xsdModel);
            var          xsNs     = f.Namespace();

            xsNs.Prefix  = "xs";
            xsNs.Uri     = "http://www.w3.org/2001/XMLSchema";
            XsdNamespace = xsNs.ToImmutable();
        }
Exemplo n.º 8
0
        private static ImmutableModel CreateModel()
        {
            MutableModel model   = new MutableModel();
            MetaFactory  factory = new MetaFactory(model);

            CreateAnnotation("Import", factory);
            CreateAnnotation("Type", factory);
            CreateAnnotation("Name", factory);
            CreateAnnotation("Scope", factory);
            CreateAnnotation("BaseScope", factory);
            CreateAnnotation("LocalScope", factory);
            return(model.ToImmutable());
        }
Exemplo n.º 9
0
        internal SourceModuleSymbol(
            SourceAssemblySymbol assemblySymbol,
            MutableModel modelBuilder,
            DeclarationTable declarations,
            string moduleName)
        {
            Debug.Assert((object)assemblySymbol != null);

            _assemblySymbol = assemblySymbol;
            _modelBuilder   = modelBuilder;
            _sources        = declarations;
            _name           = moduleName;

            _csharpSymbolMap = new CSharpSymbolMap(this);

            _state = SymbolCompletionState.Create(assemblySymbol.Language);
        }
Exemplo n.º 10
0
        public void TestWifeToHusband()
        {
            var model   = new MutableModel();
            var factory = new PropertiesTestFactory(model);
            var husband = factory.Husband();
            var wife    = factory.Wife();

            wife.Husband = husband;
            Assert.Equal(wife, husband.Wife);
            Assert.Equal(husband, wife.Husband);
            var imodel   = model.ToImmutable();
            var ihusband = husband.ToImmutable(imodel);
            var iwife    = wife.ToImmutable(imodel);

            Assert.Equal(iwife, ihusband.Wife);
            Assert.Equal(ihusband, iwife.Husband);
        }
        public void TestList2SetBaseDerived()
        {
            var model    = new MutableModel();
            var factory  = new PropertiesTestFactory(model);
            var base1    = factory.BaseClass();
            var derived1 = factory.DerivedClass();
            var subs     = factory.SubsettingDerived2Base();

            subs.List2SetBase.Add(derived1);
            Assert.True(subs.List2SetDerived.Count == 0);
            Assert.Contains(derived1, subs.List2SetBase);
            var imodel    = model.ToImmutable();
            var ibase1    = base1.ToImmutable(imodel);
            var iderived1 = derived1.ToImmutable(imodel);
            var isubs     = subs.ToImmutable(imodel);

            Assert.True(isubs.List2SetDerived.Count == 0);
            Assert.Contains(iderived1, isubs.List2SetBase);
        }
        public void TestSingle2SingleBaseDerived()
        {
            var model    = new MutableModel();
            var factory  = new PropertiesTestFactory(model);
            var base1    = factory.BaseClass();
            var derived1 = factory.DerivedClass();
            var subs     = factory.SubsettingDerived2Base();

            subs.Single2SingleBase = derived1;
            Assert.Null(subs.Single2SingleDerived);
            Assert.Equal(derived1, subs.Single2SingleBase);
            var imodel    = model.ToImmutable();
            var ibase1    = base1.ToImmutable(imodel);
            var iderived1 = derived1.ToImmutable(imodel);
            var isubs     = subs.ToImmutable(imodel);

            Assert.Null(isubs.Single2SingleDerived);
            Assert.Equal(iderived1, isubs.Single2SingleBase);
        }
        public void TestSingle2List()
        {
            var model    = new MutableModel();
            var factory  = new PropertiesTestFactory(model);
            var base1    = factory.BaseClass();
            var derived1 = factory.DerivedClass();
            var subs     = factory.SubsettingDerived2Base();

            subs.Single2ListDerived.Add(derived1);
            Assert.Contains(derived1, subs.Single2ListDerived);
            Assert.Equal(derived1, subs.Single2ListBase);
            var imodel    = model.ToImmutable();
            var ibase1    = base1.ToImmutable(imodel);
            var iderived1 = derived1.ToImmutable(imodel);
            var isubs     = subs.ToImmutable(imodel);

            Assert.Contains(iderived1, isubs.Single2ListDerived);
            Assert.Equal(iderived1, isubs.Single2ListBase);
        }
        public void TestSingle2ListBaseDerived()
        {
            var model    = new MutableModel();
            var factory  = new PropertiesTestFactory(model);
            var base1    = factory.BaseClass();
            var derived1 = factory.DerivedClass();
            var subs     = factory.SubsettingBase2Derived();

            subs.Single2ListBase = derived1;
            Assert.True(subs.Single2ListDerived.Count == 0);
            Assert.Equal(derived1, subs.Single2ListBase);
            var imodel    = model.ToImmutable();
            var ibase1    = base1.ToImmutable(imodel);
            var iderived1 = derived1.ToImmutable(imodel);
            var isubs     = subs.ToImmutable(imodel);

            Assert.True(isubs.Single2ListDerived.Count == 0);
            Assert.Equal(iderived1, isubs.Single2ListBase);
        }
Exemplo n.º 15
0
        public void TestParentToChild()
        {
            var model   = new MutableModel();
            var factory = new PropertiesTestFactory(model);
            var parent  = factory.ParentSet();
            var child   = factory.ChildSet();

            parent.Children.Add(child);
            Assert.Equal(parent, child.Parent);
            Assert.Contains(child, parent.Children);
            Assert.True(parent.Children.Count == 1);
            var imodel  = model.ToImmutable();
            var iparent = parent.ToImmutable(imodel);
            var ichild  = child.ToImmutable(imodel);

            Assert.Equal(iparent, ichild.Parent);
            Assert.Contains(ichild, iparent.Children);
            Assert.True(iparent.Children.Count == 1);
        }
Exemplo n.º 16
0
        public void TestEndToAssociationMultiSet2MultiSet()
        {
            var model   = new MutableModel();
            var factory = new PropertiesTestFactory(model);
            var assoc   = factory.Association();
            var end     = factory.AssociationEndMultiSet();

            end.Association = assoc;
            Assert.Contains(end, assoc.FirstMultiSet);
            Assert.Contains(end, assoc.SecondMultiSet);
            Assert.Equal(assoc, end.Association);
            var imodel = model.ToImmutable();
            var iassoc = assoc.ToImmutable(imodel);
            var iend   = end.ToImmutable(imodel);

            Assert.Contains(iend, iassoc.FirstMultiSet);
            Assert.Contains(iend, iassoc.SecondMultiSet);
            Assert.Equal(iassoc, iend.Association);
        }
Exemplo n.º 17
0
        public void TestManyChildrenToParent()
        {
            var model   = new MutableModel();
            var factory = new PropertiesTestFactory(model);
            var parent  = factory.ParentList();
            var child   = factory.ChildList();

            child.Parent = parent;
            child.Parent = parent;
            Assert.Equal(parent, child.Parent);
            Assert.Contains(child, parent.Children);
            Assert.True(parent.Children.Count == 1);
            var imodel  = model.ToImmutable();
            var iparent = parent.ToImmutable(imodel);
            var ichild  = child.ToImmutable(imodel);

            Assert.Equal(iparent, ichild.Parent);
            Assert.Contains(ichild, iparent.Children);
            Assert.True(iparent.Children.Count == 1);
        }
Exemplo n.º 18
0
        public void TestHusbandToWifeCrossReset()
        {
            var model   = new MutableModel();
            var factory = new PropertiesTestFactory(model);
            var husband = factory.Husband();
            var wife    = factory.Wife();

            husband.Wife = wife;
            Assert.Equal(wife, husband.Wife);
            Assert.Equal(husband, wife.Husband);
            wife.Husband = null;
            Assert.Null(husband.Wife);
            Assert.Null(wife.Husband);
            var imodel   = model.ToImmutable();
            var ihusband = husband.ToImmutable(imodel);
            var iwife    = wife.ToImmutable(imodel);

            Assert.Null(ihusband.Wife);
            Assert.Null(iwife.Husband);
        }
Exemplo n.º 19
0
        public void TestChildToParentReset()
        {
            var model   = new MutableModel();
            var factory = new PropertiesTestFactory(model);
            var parent  = factory.ParentSet();
            var child   = factory.ChildSet();

            child.Parent = parent;
            Assert.Equal(parent, child.Parent);
            Assert.Contains(child, parent.Children);
            Assert.True(parent.Children.Count == 1);
            child.Parent = null;
            Assert.Null(child.Parent);
            Assert.True(parent.Children.Count == 0);
            var imodel  = model.ToImmutable();
            var iparent = parent.ToImmutable(imodel);
            var ichild  = child.ToImmutable(imodel);

            Assert.Null(ichild.Parent);
            Assert.True(iparent.Children.Count == 0);
        }
Exemplo n.º 20
0
        public void TestParentToManyChildrenCrossReset()
        {
            var model   = new MutableModel();
            var factory = new PropertiesTestFactory(model);
            var parent  = factory.ParentMultiSet();
            var child   = factory.ChildMultiSet();

            parent.Children.Add(child);
            parent.Children.Add(child);
            Assert.Equal(parent, child.Parent);
            Assert.Contains(child, parent.Children);
            Assert.True(parent.Children.Count == 2);
            child.Parent = null;
            Assert.Null(child.Parent);
            Assert.True(parent.Children.Count == 0);
            var imodel  = model.ToImmutable();
            var iparent = parent.ToImmutable(imodel);
            var ichild  = child.ToImmutable(imodel);

            Assert.Null(ichild.Parent);
            Assert.True(iparent.Children.Count == 0);
        }
        public void TestSingle2SetResetBase()
        {
            var model    = new MutableModel();
            var factory  = new PropertiesTestFactory(model);
            var base1    = factory.BaseClass();
            var derived1 = factory.DerivedClass();
            var subs     = factory.SubsettingBase2Derived();

            subs.Single2SetDerived.Add(derived1);
            Assert.Contains(derived1, subs.Single2SetDerived);
            Assert.Equal(derived1, subs.Single2SetBase);
            subs.Single2SetBase = null;
            Assert.True(subs.Single2SetDerived.Count == 0);
            Assert.Null(subs.Single2SetBase);
            var imodel    = model.ToImmutable();
            var ibase1    = base1.ToImmutable(imodel);
            var iderived1 = derived1.ToImmutable(imodel);
            var isubs     = subs.ToImmutable(imodel);

            Assert.True(isubs.Single2SetDerived.Count == 0);
            Assert.Null(isubs.Single2SetBase);
        }
Exemplo n.º 22
0
        public void TestAddToSubsetSingle()
        {
            var model    = new MutableModel();
            var factory  = new PropertiesTestFactory(model);
            var base1    = factory.BaseClass();
            var base2    = factory.BaseClass();
            var base3    = factory.BaseClass();
            var base4    = factory.BaseClass();
            var derived1 = factory.DerivedClass();
            var derived2 = factory.DerivedClass();
            var derived3 = factory.DerivedClass();
            var derived4 = factory.DerivedClass();
            var subs     = factory.UnionSingle();

            subs.Subset4 = base1;
            Assert.Equal(base1, subs.Union1);
            Assert.Single(subs.Subset1);
            Assert.Contains(base1, subs.Subset1);
            Assert.Equal(base1, subs.Subset4);
            Assert.Throws <ModelException>(() => subs.Subset1.Add(base2));
            Assert.Equal(base1, subs.Union1);
            Assert.Single(subs.Subset1);
            Assert.Contains(base1, subs.Subset1);
            Assert.Equal(base1, subs.Subset4);
            subs.Subset5 = derived1;
            Assert.Equal(derived1, subs.Union1);
            Assert.Single(subs.Subset1);
            Assert.Contains(derived1, subs.Subset1);
            Assert.Equal(derived1, subs.Subset4);
            Assert.Equal(derived1, subs.Subset5);
            Assert.Throws <ModelException>(() => subs.Subset1.Add(base2));
            subs.Subset5 = derived1;
            Assert.Equal(derived1, subs.Union1);
            Assert.Single(subs.Subset1);
            Assert.Contains(derived1, subs.Subset1);
            Assert.Equal(derived1, subs.Subset4);
            Assert.Equal(derived1, subs.Subset5);
        }
Exemplo n.º 23
0
        public void TestAddToSubset()
        {
            var model    = new MutableModel();
            var factory  = new PropertiesTestFactory(model);
            var base1    = factory.BaseClass();
            var base2    = factory.BaseClass();
            var base3    = factory.BaseClass();
            var base4    = factory.BaseClass();
            var derived1 = factory.DerivedClass();
            var derived2 = factory.DerivedClass();
            var derived3 = factory.DerivedClass();
            var derived4 = factory.DerivedClass();
            var subs     = factory.UnionSet();

            Assert.Throws <ModelException>(() => subs.Union1.Add(base1));
            subs.Subset1.Add(base1);
            Assert.Single(subs.Union1);
            Assert.Contains(base1, subs.Union1);
            Assert.Single(subs.Subset1);
            Assert.Contains(base1, subs.Subset1);
            subs.Subset1.Add(base1);
            Assert.Single(subs.Union1);
            Assert.Contains(base1, subs.Union1);
            Assert.Single(subs.Subset1);
            Assert.Contains(base1, subs.Subset1);
            subs.Subset2.Add(base1);
            Assert.Single(subs.Union1);
            Assert.Contains(base1, subs.Union1);
            Assert.Single(subs.Subset1);
            Assert.Contains(base1, subs.Subset1);
            Assert.Single(subs.Subset2);
            Assert.Contains(base1, subs.Subset2);
            subs.Subset3.Add(base1);
            Assert.Single(subs.Union1);
            Assert.Contains(base1, subs.Union1);
            Assert.Single(subs.Subset1);
            Assert.Contains(base1, subs.Subset1);
            Assert.Single(subs.Subset2);
            Assert.Contains(base1, subs.Subset2);
            Assert.Single(subs.Subset3);
            Assert.Contains(base1, subs.Subset3);
            subs.Subset3.Add(base2);
            Assert.True(subs.Union1.Count == 2);
            Assert.Contains(base1, subs.Union1);
            Assert.Contains(base2, subs.Union1);
            Assert.True(subs.Subset1.Count == 2);
            Assert.Contains(base1, subs.Subset1);
            Assert.Contains(base2, subs.Subset1);
            Assert.Single(subs.Subset2);
            Assert.Contains(base1, subs.Subset2);
            Assert.True(subs.Subset3.Count == 2);
            Assert.Contains(base1, subs.Subset3);
            Assert.Contains(base2, subs.Subset3);
            subs.Subset4.Add(derived1);
            Assert.True(subs.Union1.Count == 3);
            Assert.Contains(base1, subs.Union1);
            Assert.Contains(base2, subs.Union1);
            Assert.True(subs.Subset1.Count == 3);
            Assert.Contains(base1, subs.Subset1);
            Assert.Contains(base2, subs.Subset1);
            Assert.Contains(derived1, subs.Subset1);
            Assert.Single(subs.Subset2);
            Assert.Contains(base1, subs.Subset2);
            Assert.True(subs.Subset3.Count == 2);
            Assert.Contains(base1, subs.Subset3);
            Assert.Contains(base2, subs.Subset3);
            Assert.Single(subs.Subset4);
            Assert.Contains(derived1, subs.Subset4);
            Assert.Throws <ModelException>(() => subs.Union1.Add(base1));
        }