///<summary> /// Registers a single node. /// When we resolve later, we'll be able to use this node as a source. ///</summary> public static void Register(TydCollection colNode) { //If the node has no handle, and no source, we can ignore it since it's not connected to inheritance at all. var nodeHandle = colNode.AttributeHandle; var nodeSource = colNode.AttributeSource; if (nodeHandle == null && nodeSource == null) { return; } //Ensure we're don't have two _nodes of the same handle if (nodeHandle != null && nodesByHandle.ContainsKey(nodeHandle)) { throw new Exception(string.Format("Tyd error: Multiple Tyd _nodes with the same handle {0}.", nodeHandle)); } //Make an inheritance node for the Tyd node var newNode = new InheritanceNode(colNode); nodesUnresolved.Add(newNode); if (nodeHandle != null) { nodesByHandle.Add(nodeHandle, newNode); } }
///<summary> /// Registers a single node. /// When we resolve later, we'll be able to use this node as a source. ///</summary> public static void Register(TydCollection node) { if (!initialized) { throw new Exception("Used Tyd.Inheritance when it was not initialized."); } //If the node has no handle, and no source, we can ignore it since it's not connected to inheritance at all. var nodeHandle = node.AttributeHandle; var nodeSource = node.AttributeSource; if (nodeHandle == null && nodeSource == null) { return; } //Ensure we're don't have two nodes of the same handle if (nodeHandle != null && nodesByHandle.ContainsKey(nodeHandle)) { throw new Exception("Tyd error: Multiple Tyd nodes with the same handle " + nodeHandle + "."); } //Make an inheritance node for the Tyd node var newNode = new InheritanceNode(node); nodesUnresolved.Add(newNode); if (nodeHandle != null) { nodesByHandle.Add(nodeHandle, newNode); } }
public void AddHeir(InheritanceNode n) { if (heirs == null) { heirs = new List <InheritanceNode>(); } heirs.Add(n); }
///<summary> /// Resolves given node and then all its heir _nodes recursively using DFS. ///</summary> private static void ResolveInheritanceNodeAndHeirs(InheritanceNode node) { //Error check // if we've reached a resolved node by traversing the tree, then it means // that there's a cycle, note that we're not reporting the full cycle in // the error message here, but only the last node which created a cycle if (node.Resolved) { throw new Exception(string.Format("Cyclic inheritance detected for Tyd node:\n{0}", node.TydNode.FullTyd)); } //Resolve this node { if (node.Source == null) { // No source - Just use the original node node.Resolved = true; } else { //Source exists - We now inherit from it //We must use source's RESOLVED node here because our source can have its own source. if (!node.Source.Resolved) { throw new Exception(string.Format( "Tried to resolve Tyd inheritance node {0} whose source has not been resolved yet. This means that this method was called in incorrect order.", node)); } CheckForDuplicateNodes(node.TydNode); node.Resolved = true; //Write resolved node's class attribute //Original takes precedence over source; source takes precedence over default var attClass = node.TydNode.AttributeClass ?? node.Source.TydNode.AttributeClass; node.TydNode.SetAttribute("class", attClass); //Apply inheritance from source to node ApplyInheritance(node.Source.TydNode, node.TydNode); } } //Recur to the heirs and resolve them too for (var i = 0; i < node.HeirCount; i++) { ResolveInheritanceNodeAndHeirs(node.GetHeir(i)); } }
public virtual Value evaluate(Context cx, InheritanceNode node) { output("<InheritanceNode position=\"" + node.pos() + "\">"); indent_Renamed_Field++; if (node.baseclass != null) { node.baseclass.evaluate(cx, this); } if (node.interfaces != null) { node.interfaces.evaluate(cx, this); } indent_Renamed_Field--; output("</InheritanceNode>"); return(null); }
///<summary> /// Resolves given node and then all its heir nodes recursively using DFS. ///</summary> private static void ResolveInheritanceNodeAndHeirs(InheritanceNode node) { //Error check // if we've reached a resolved node by traversing the tree, then it means // that there's a cycle, note that we're not reporting the full cycle in // the error message here, but only the last node which created a cycle if (node.resolved) { throw new Exception("Cyclic inheritance detected for Tyd node:\n" + node.tydNode.FullTyd); } //Resolve this node { if (node.source == null) { // No source - Just use the original node node.resolved = true; } else { //Source exists - We now inherit from it //We must use source's RESOLVED node here because our source can have its own source. if (!node.source.resolved) { throw new Exception("Tried to resolve Tyd inheritance node " + node + " whose source has not been resolved yet. This means that this method was called in incorrect order."); } CheckForDuplicateNodes(node.tydNode); node.resolved = true; //Apply inheritance from source to node ApplyInheritance(node.source.tydNode, node.tydNode); } } //Recur to the heirs and resolve them too for (int i = 0; i < node.HeirCount(); i++) { ResolveInheritanceNodeAndHeirs(node.GetHeir(i)); } }
/// <summary> /// Adds a new inheritance relationship instance. Needs to be called within a modeling transaction. /// </summary> /// <param name="source">Derived class</param> /// <param name="target">Base class</param> public static void AddNewInheritanceRelationship(DomainClassReferencesBaseClass con, DomainClass source, DomainClass target, bool bTargetElementHolder) { if (ImmutabilityExtensionMethods.GetLocks(target) != Locks.None) { return; } // tree nodes // 1. find the element holder node for source // 2. add new InheritanceNode TreeNode elementHolderNode = null; foreach (TreeNode node in target.DomainModelTreeNodes) { if (node.IsElementHolder) { elementHolderNode = node; break; } } if (elementHolderNode == null) { throw new ArgumentNullException("elementHolderNode"); } InheritanceNode inhNode = new InheritanceNode(source.Store); inhNode.DomainElement = source; inhNode.IsElementHolder = bTargetElementHolder; if (!inhNode.IsElementHolder) { inhNode.IsExpanded = false; } inhNode.InhRelationshipId = con.Id; con.InhNodeId = inhNode.Id; source.ModelContext.ViewContext.DomainModelTreeView.ModelTreeNodes.Add(inhNode); elementHolderNode.InheritanceNodes.Add(inhNode); }
// helper functions: // ================= // helper to convert the recoursive inheritance tree to a flattened graph private InheritanceGraph Tree2Graph(InheritanceGraph graph, InheritanceNode tree, IHNode groupNode, IHNode baseTypeNode) { ClassDeclarationSyntax classDecl = tree.GetBaseClass(); string nodeName = codeAnalysis.GetClassId(classDecl); // add the type node IHNode typeNode = new IHNode(groupNode.Id + ":" + nodeName, nodeName, classDecl, !codeAnalysis.IsClassAbstract(classDecl)); graph.AddNode(typeNode); // link the type node to the method group graph.AddLink(new IHLink(groupNode.Id, typeNode.Id, true)); // link the type node to it's base type if it has one if (baseTypeNode != null) { graph.AddLink(new IHLink(typeNode.Id, baseTypeNode.Id, false)); } foreach (var subClass in tree.GetSubClasses()) { graph = Tree2Graph(graph, subClass, groupNode, typeNode); } return(graph); }
public override void ElementDeleting(ElementDeletingEventArgs e) { if (e.ModelElement != null) { if (e.ModelElement.Store.TransactionManager.CurrentTransaction != null) { if (e.ModelElement.Store.TransactionManager.CurrentTransaction.IsSerializing) { return; } } } if (e.ModelElement == null) { return; } if (ImmutabilityExtensionMethods.GetLocks(e.ModelElement) != Locks.None) { return; } TreeNodeReferencesInheritanceNodes con = e.ModelElement as TreeNodeReferencesInheritanceNodes; if (con != null) { InheritanceNode node = con.InheritanceNode; if (node != null) { /* * // since this node still exists, it isnt included in the deletion process * // --> move to root node if this node is the element holder, as its parent has been deleted * if (node.IsElementHolder) * { * RootNode rootNode = new RootNode(node.Store); * rootNode.DomainElement = node.DomainElement; * * node.EmbeddingModelTreeViewModel.RootNodes.Add(rootNode); * node.EmbeddingModelTreeViewModel.ModelTreeNodes.Add(rootNode); * * // copy sub tree * for (int i = node.EmbeddingRSNodes.Count - 1; i >= 0; i--) * node.EmbeddingRSNodes[i].TreeNode = rootNode; * * for (int i = node.ReferenceRSNodes.Count - 1; i >= 0; i--) * node.ReferenceRSNodes[i].TreeNode = rootNode; * * for (int i = node.InheritanceNodes.Count - 1; i >= 0; i--) * node.InheritanceNodes[i].TreeNode = rootNode; * * for (int i = node.ShapeClassNodes.Count - 1; i >= 0; i--) * node.ShapeClassNodes[i].TreeNode = rootNode; * * rootNode.IsElementHolder = true; * rootNode.IsEmbeddingTreeExpanded = node.IsEmbeddingTreeExpanded; * rootNode.IsExpanded = true; * rootNode.IsInheritanceTreeExpanded = node.IsInheritanceTreeExpanded; * rootNode.IsReferenceTreeExpanded = node.IsReferenceTreeExpanded; * rootNode.IsShapeMappingTreeExpanded = node.IsShapeMappingTreeExpanded; * } * * node.Delete();*/ } } }
public override void RolePlayerChanged(RolePlayerChangedEventArgs e) { if (e.ElementLink != null) { if (e.ElementLink.Store.TransactionManager.CurrentTransaction != null) { if (e.ElementLink.Store.TransactionManager.CurrentTransaction.IsSerializing) { return; } } } if (e.ElementLink == null) { return; } if (ImmutabilityExtensionMethods.GetLocks(e.ElementLink) != Locks.None) { return; } DomainClassReferencesBaseClass con = e.ElementLink as DomainClassReferencesBaseClass; if (con != null) { if (con.BaseClass != null) { TreeNode elementHolderNode = null; foreach (TreeNode node in con.BaseClass.DomainModelTreeNodes) { if (node.IsElementHolder) { elementHolderNode = node; break; } } if (elementHolderNode == null) { throw new ArgumentNullException("elementHolderNode"); } // we need to delte the old inheritance node and add a new one for the changed inheritance relationship InheritanceNode inhNodeOld = con.Store.ElementDirectory.FindElement(con.InhNodeId) as InheritanceNode; if (inhNodeOld == null) { return; } // create new inheritance node InheritanceNode inhNode = new InheritanceNode(con.Store); inhNode.DomainElement = con.DerivedClass; inhNode.IsElementHolder = inhNodeOld.IsElementHolder; inhNode.IsExpanded = inhNodeOld.IsExpanded; inhNode.InhRelationshipId = con.Id; inhNode.IsEmbeddingTreeExpanded = inhNodeOld.IsEmbeddingTreeExpanded; inhNode.IsInheritanceTreeExpanded = inhNodeOld.IsInheritanceTreeExpanded; inhNode.IsReferenceTreeExpanded = inhNodeOld.IsReferenceTreeExpanded; inhNode.IsShapeMappingTreeExpanded = inhNodeOld.IsShapeMappingTreeExpanded; con.InhNodeId = inhNode.Id; // copy sub tree for (int i = inhNodeOld.EmbeddingRSNodes.Count - 1; i >= 0; i--) { inhNodeOld.EmbeddingRSNodes[i].TreeNode = inhNode; } for (int i = inhNodeOld.ReferenceRSNodes.Count - 1; i >= 0; i--) { inhNodeOld.ReferenceRSNodes[i].TreeNode = inhNode; } for (int i = inhNodeOld.InheritanceNodes.Count - 1; i >= 0; i--) { inhNodeOld.InheritanceNodes[i].TreeNode = inhNode; } for (int i = inhNodeOld.ShapeClassNodes.Count - 1; i >= 0; i--) { inhNodeOld.ShapeClassNodes[i].TreeNode = inhNode; } elementHolderNode.InheritanceNodes.Add(inhNode); con.DerivedClass.ModelContext.ViewContext.DomainModelTreeView.ModelTreeNodes.Add(inhNode); inhNodeOld.Delete(); } } }
public override void ElementAdded(ElementAddedEventArgs e) { if (e.ModelElement != null) { if (e.ModelElement.Store.TransactionManager.CurrentTransaction != null) { if (e.ModelElement.Store.TransactionManager.CurrentTransaction.IsSerializing) { return; } } } if (e.ModelElement == null) { return; } if (ImmutabilityExtensionMethods.GetLocks(e.ModelElement) != Locks.None) { return; } DomainClassReferencesBaseClass con = e.ModelElement as DomainClassReferencesBaseClass; if (con != null) { if (con.BaseClass != null) { InheritanceNode inhNode = con.Store.ElementDirectory.FindElement(con.InhNodeId) as InheritanceNode; if (inhNode == null && ImmutabilityExtensionMethods.GetLocks(con.BaseClass) == Locks.None) { // connection was created using the property window and not the menu item, so create a new // inheritance node to display the inheritance relationship TreeNode elementHolderNode = null; foreach (TreeNode node in con.BaseClass.DomainModelTreeNodes) { if (node.IsElementHolder) { elementHolderNode = node; break; } } if (elementHolderNode == null) { throw new ArgumentNullException("elementHolderNode"); } // create new inheritance node inhNode = new InheritanceNode(con.Store); inhNode.DomainElement = con.DerivedClass; inhNode.IsElementHolder = false; inhNode.IsExpanded = false; inhNode.InhRelationshipId = con.Id; con.InhNodeId = inhNode.Id; elementHolderNode.InheritanceNodes.Add(inhNode); con.DerivedClass.ModelContext.ViewContext.DomainModelTreeView.ModelTreeNodes.Add(inhNode); } } } DomainRelationshipReferencesBaseRelationship conRef = e.ModelElement as DomainRelationshipReferencesBaseRelationship; if (conRef != null) { if (conRef.BaseRelationship is ReferenceRelationship && conRef.DerivedRelationship is ReferenceRelationship) { ReferenceRelationship rBase = conRef.BaseRelationship as ReferenceRelationship; ReferenceRelationship rDer = conRef.DerivedRelationship as ReferenceRelationship; if (rBase.SerializedReferenceRelationship != null && rDer.SerializedReferenceRelationship != null) { if (rBase.SerializedReferenceRelationship.IsInFullSerialization) { if (!rDer.SerializedReferenceRelationship.IsInFullSerialization) { // we have to automatically change the serialization mode of the derived class to full serialization mode rDer.SerializedReferenceRelationship.IsInFullSerialization = true; } } } } else if (conRef.BaseRelationship is EmbeddingRelationship && conRef.DerivedRelationship is EmbeddingRelationship) { EmbeddingRelationship rBase = conRef.BaseRelationship as EmbeddingRelationship; EmbeddingRelationship rDer = conRef.DerivedRelationship as EmbeddingRelationship; if (rBase.SerializedEmbeddingRelationship != null && rDer.SerializedEmbeddingRelationship != null) { if (rBase.SerializedEmbeddingRelationship.IsInFullSerialization) { if (!rDer.SerializedEmbeddingRelationship.IsInFullSerialization) { // we have to automatically change the serialization mode of the derived class to full serialization mode rDer.SerializedEmbeddingRelationship.IsInFullSerialization = true; } } } } } }
/// <summary> /// Constuctor. /// </summary> /// <param name="viewModelStore">The store this view model belongs to.</param> /// <param name="inheritanceNode">Inheritance node.</param> /// <param name="parent">Parent.</param> public InheritanceNodeViewModel(ViewModelStore viewModelStore, InheritanceNode inheritanceNode, TreeNodeViewModel parent) : base(viewModelStore, inheritanceNode, parent) { }
public override void ElementDeleting(ElementDeletingEventArgs e) { if (e.ModelElement != null) { if (e.ModelElement.Store.TransactionManager.CurrentTransaction != null) { if (e.ModelElement.Store.TransactionManager.CurrentTransaction.IsSerializing) { return; } } } if (e.ModelElement == null) { return; } if (ImmutabilityExtensionMethods.GetLocks(e.ModelElement) != Locks.None) { return; } ReferenceRelationship referenceRelationship = e.ModelElement as ReferenceRelationship; if (referenceRelationship != null) { if (referenceRelationship.ReferenceRSNode != null) { referenceRelationship.ReferenceRSNode.Delete(); } } EmbeddingRelationship embeddingRelationship = e.ModelElement as EmbeddingRelationship; if (embeddingRelationship != null) { if (embeddingRelationship.EmbeddingRSNode != null) { embeddingRelationship.EmbeddingRSNode.Delete(); } } DomainClassReferencesBaseClass inhRelationship = e.ModelElement as DomainClassReferencesBaseClass; if (inhRelationship != null) { InheritanceNode node = inhRelationship.Store.ElementDirectory.FindElement(inhRelationship.InhNodeId) as InheritanceNode; if (node != null) { if (node.IsElementHolder) { RootNode rootNode = new RootNode(node.Store); rootNode.DomainElement = node.DomainElement; rootNode.IsElementHolder = true; rootNode.IsEmbeddingTreeExpanded = node.IsEmbeddingTreeExpanded; rootNode.IsExpanded = true; rootNode.IsInheritanceTreeExpanded = node.IsInheritanceTreeExpanded; rootNode.IsReferenceTreeExpanded = node.IsReferenceTreeExpanded; rootNode.IsShapeMappingTreeExpanded = node.IsShapeMappingTreeExpanded; // copy sub tree for (int i = node.EmbeddingRSNodes.Count - 1; i >= 0; i--) { node.EmbeddingRSNodes[i].TreeNode = rootNode; } for (int i = node.ReferenceRSNodes.Count - 1; i >= 0; i--) { node.ReferenceRSNodes[i].TreeNode = rootNode; } for (int i = node.InheritanceNodes.Count - 1; i >= 0; i--) { node.InheritanceNodes[i].TreeNode = rootNode; } for (int i = node.ShapeClassNodes.Count - 1; i >= 0; i--) { node.ShapeClassNodes[i].TreeNode = rootNode; } node.DomainElement.ParentModelContext.ViewContext.DomainModelTreeView.RootNodes.Add(rootNode); node.DomainElement.ParentModelContext.ViewContext.DomainModelTreeView.ModelTreeNodes.Add(rootNode); } // connection was deleted using the property window and not the menu item, so delete the rs and the // node here //if (inhNode.IsElementHolder) // TreeOperations.SplitTree(inhNode); node.Delete(); } } }
/// <summary> /// Deletes the inheritance view model that is hosting the given inheritance node. /// </summary> /// <param name="node">Inheritance node.</param> public void DeleteInheritanceNode(InheritanceNode node) { if (node == null) return; for (int i = this.inheritanceNodeVMs.Count - 1; i >= 0; i--) if (this.inheritanceNodeVMs[i].InheritanceNode.Id == node.Id) { this.inheritanceNodeVMs[i].Dispose(); this.inheritanceNodeVMs.RemoveAt(i); } foreach (InheritanceNodeViewModel vm in this.inheritanceNodeVMs) vm.UpdateNodePosition(); OnPropertyChanged("HasInheritanceNodes"); }
/// <summary> /// Adds a new inheritance view model for the given inheritance node. /// </summary> /// <param name="node">Inheritance node.</param> public void AddInheritanceNode(InheritanceNode node) { if (node == null) return; if (node.DomainElement == null) return; // verify that node hasnt been added yet foreach (InheritanceNodeViewModel viewModel in this.inheritanceNodeVMs) if (viewModel.InheritanceNode.Id == node.Id) return; InheritanceNodeViewModel newVm = new InheritanceNodeViewModel(this.ViewModelStore, node, this); this.inheritanceNodeVMs.Add(newVm); foreach (InheritanceNodeViewModel vm in this.inheritanceNodeVMs) vm.UpdateNodePosition(); OnPropertyChanged("HasInheritanceNodes"); }
public virtual Value evaluate(Context cx, InheritanceNode node) { output("<InheritanceNode position=\"" + node.pos() + "\">"); indent_Renamed_Field++; if (node.baseclass != null) { node.baseclass.evaluate(cx, this); } if (node.interfaces != null) { node.interfaces.evaluate(cx, this); } indent_Renamed_Field--; output("</InheritanceNode>"); return null; }