private void FillOptionsForConstructs() { IBaseConstruct construct = currentNode.GetFirstValidBaseConstruct(); if (construct == null && missingObjects != MissingObject.All) { throw new InvalidOperationException( "The MapInfoType we are trying to match on is invalid - " + "it has at least one object mapped but none of them is a BaseConstruct. This is an invalid state."); } userOptions.Clear(); templateOptions.Clear(); prevgenOptions.Clear(); SetDefaultChoices(); //if((missingObjects & MissingObject.User) != 0) { userOptions.AddRange(currentNode.GetSiblingsOfSameType(Controller.Version.User)); } //if ((missingObjects & MissingObject.NewGen) != 0) { templateOptions.AddRange(currentNode.GetSiblingsOfSameType(Controller.Version.NewGen)); } //if ((missingObjects & MissingObject.PrevGen) != 0) { prevgenOptions.AddRange(currentNode.GetSiblingsOfSameType(Controller.Version.PrevGen)); } }
public override Image GetImageForBaseConstruct(IBaseConstruct bc, Status status) { if (!(bc is ArchAngel.Providers.CodeProvider.DotNet.BaseConstruct)) { throw new ArgumentException("Given BaseConstruct is not a CSharp construct"); } CSharpConstructType consType = GetConsType(bc); if (combinedImages.ContainsKey(consType) == false) { // Construct the new image combinedImages[consType] = new Dictionary <Status, Image>(); Bitmap image = CreateImage(consType, status); combinedImages[consType].Add(status, image); return(image); } else { Dictionary <Status, Image> dict = combinedImages[consType]; if (dict.ContainsKey(status)) { return(dict[status]); } Bitmap image = CreateImage(consType, status); combinedImages[consType].Add(status, image); return(image); } }
private static IBaseConstruct GetBaseConstructfromUID(string uniqueIdentifier, ICodeRoot codeRoot) { if (string.IsNullOrEmpty(uniqueIdentifier)) { return(null); } string[] identifiers = BaseConstructConstants.SplitFullyQualifiedIdentifier(uniqueIdentifier); IBaseConstruct baseConstruct = codeRoot.FindChild(identifiers[0]); if (baseConstruct == null) { return(null); } for (int i = 1; i < identifiers.Length; i++) { baseConstruct = baseConstruct.FindChild(identifiers[i]); if (baseConstruct == null) { return(null); } } if (baseConstruct == null) { throw new ArgumentException("Could not find the object by unique id."); } return(baseConstruct); }
/// <summary> /// Adds a new child to this IBaseConstruct. /// </summary> /// <param name="childBC">The child object to add</param> public void AddChild(IBaseConstruct childBC) { if (childBC == this) { throw new ArgumentException("Cannot add an object as a child of itself"); } // Cannot add non C# BaseConstructs. if (!(childBC is BaseConstruct)) { throw new ArgumentException("Cannot add an non C# BaseConstruct as a child of a C# BaseConstruct"); } BaseConstruct bc = (BaseConstruct)childBC; bc.ParentObject = this; bc.Controller = Controller; // No longer treating attributes as children. //if(childBC is Attribute) //{ // Attributes.Add(childBC as Attribute); //} if (childBC is EmptyPlaceholder) { emptyPlaceholders.Add(childBC as EmptyPlaceholder); } else { AddChildInternal(bc); } }
/// <summary> /// Returns every base construct in the tree of the type given. /// </summary> /// <param name="type">The type of base construct to look for.</param> /// <param name="versionToGet">The Version that we are matching against. Only objects from that version will be added.</param> /// <returns>A list of the base constructs in the tree with the given type.</returns> public ReadOnlyCollection <IBaseConstruct> GetChildrenOfType(Type type, Version versionToGet) { List <IBaseConstruct> childrenRetVal = new List <IBaseConstruct>(); foreach (CodeRootMapNode child in AllNodes) { IBaseConstruct bc = child.GetFirstValidBaseConstruct(); if (bc == null || !type.IsInstanceOfType(bc)) { continue; } if (versionToGet == Version.NewGen && child.NewGenObj != null) { childrenRetVal.Add(child.NewGenObj); } else if (versionToGet == Version.PrevGen && child.PrevGenObj != null) { childrenRetVal.Add(child.PrevGenObj); } else if (versionToGet == Version.User && child.UserObj != null) { childrenRetVal.Add(child.UserObj); } } return(childrenRetVal.AsReadOnly()); }
public void Map_Contains_CodeRoot() { CodeRootMap map = new CodeRootMap(); ICodeRoot coderoot = mocks.StrictMock <ICodeRoot>(); IBaseConstruct bc1 = mocks.DynamicMock <IBaseConstruct>(); IBaseConstruct bc2 = mocks.DynamicMock <IBaseConstruct>(); Utility.SetupBaseConstructs(mocks, bc1, bc2, coderoot); using (mocks.Playback()) { map.AddCodeRoot(coderoot, Version.User); } Assert.That(map.ChildNodes, Has.Count(1)); Assert.That(map.AllNodes, Has.Count(2)); Assert.That(map.ChildNodes[0], Is.Not.Null); Assert.That(map.ChildNodes[0].IsTreeRoot, Is.False); Assert.That(map.ChildNodes[0].UserObj, Is.SameAs(bc1)); Assert.That(map.ChildNodes[0].Omit, Is.False); Assert.That(map.ChildNodes[0].ParentNode, Is.SameAs(map)); Assert.That(map.ChildNodes[0].ParentTree, Is.SameAs(map)); CodeRootMapNode node = map.ChildNodes[0].ChildNodes[0]; Assert.That(node, Is.Not.Null); Assert.That(node.IsTreeRoot, Is.False); Assert.That(node.UserObj, Is.SameAs(bc2)); Assert.That(node.Omit, Is.False); Assert.That(node.ParentNode, Is.SameAs(map.ChildNodes[0])); Assert.That(node.ParentTree, Is.SameAs(map)); }
public bool IsTheSameAsAny(IBaseConstruct otherbc) { if (otherbc == null) { return(false); } IBaseConstruct thisbc = baseConstructs.NewGen; if (thisbc != null && thisbc.IsTheSame(otherbc)) { return(true); } thisbc = baseConstructs.PrevGen; if (thisbc != null && thisbc.IsTheSame(otherbc)) { return(true); } thisbc = baseConstructs.User; if (thisbc != null && thisbc.IsTheSame(otherbc)) { return(true); } return(false); }
internal void AddBaseConstruct(IBaseConstruct bc, Version t) { baseConstructs.SetObject(bc, t); foreach (IBaseConstruct bcChild in bc.WalkChildren()) { bool found = false; foreach (CodeRootMapNode crChild in children) { if (!crChild.IsTheSame(bcChild)) { continue; } crChild.AddBaseConstruct(bcChild, t); found = true; break; } if (!found) { AddBaseConstructAsNewChild(bcChild, t); } } }
public override Image GetImageForBaseConstruct(IBaseConstruct bc, Status status) { if (!(bc is ArchAngel.Providers.CodeProvider.DotNet.BaseConstruct)) throw new ArgumentException("Given BaseConstruct is not a CSharp construct"); CSharpConstructType consType = GetConsType(bc); if(combinedImages.ContainsKey(consType) == false) { // Construct the new image combinedImages[consType] = new Dictionary<Status, Image>(); Bitmap image = CreateImage(consType, status); combinedImages[consType].Add(status, image); return image; } else { Dictionary<Status, Image> dict = combinedImages[consType]; if(dict.ContainsKey(status)) { return dict[status]; } Bitmap image = CreateImage(consType, status); combinedImages[consType].Add(status, image); return image; } }
/// <summary> /// /// </summary> /// <param name="userUID"></param> /// <param name="newgenUID"></param> /// <param name="prevgenUID"></param> /// <returns></returns> public virtual bool MatchConstructs(string userUID, string newgenUID, string prevgenUID) { if (string.IsNullOrEmpty(userUID) && string.IsNullOrEmpty(newgenUID) && string.IsNullOrEmpty(prevgenUID)) { throw new ArgumentException("Cannot match 3 null objects!"); } // Get Base Constructs. Make sure we can find the ones we are given. IBaseConstruct userBC = GetBaseConstructfromUID(userUID, UserCodeRoot); IBaseConstruct newgenBC = GetBaseConstructfromUID(newgenUID, NewGenCodeRoot); IBaseConstruct prevgenBC = GetBaseConstructfromUID(prevgenUID, PrevGenCodeRoot); if (userBC == null && newgenBC == null && prevgenBC == null) { throw new ArgumentException("Could not find any of the elements specified"); } CodeRootMapNode parent = GetExactNode(userBC ?? newgenBC ?? prevgenBC).ParentNode; if ((newgenBC != null && parent != GetExactNode(newgenBC).ParentNode) || (prevgenBC != null && parent != GetExactNode(prevgenBC).ParentNode)) { throw new ArgumentException("The 3 nodes specified do not belong to the same parent and thus cannot be matched."); } MatchConstructs(parent, userBC, newgenBC, prevgenBC); return(true); }
internal void RemoveBaseConstruct(IBaseConstruct bc, bool cleanUpTree) { if (bc == null) { return; } if (UserObj == bc) { UserObj = null; } else if (NewGenObj == bc) { NewGenObj = null; } else if (PrevGenObj == bc) { PrevGenObj = null; } else { return; } foreach (IBaseConstruct child in bc.WalkChildren()) { GetChildNode(child).RemoveBaseConstruct(child, false); } if (cleanUpTree) { ParentTree.CleanUpTree(); } }
public virtual void RemoveChildObject(IBaseConstruct child) { if (child is BaseConstruct == false) { throw new ArgumentException("Cannot remove child as it is not a C# construct."); } RemoveChildObjectInternal(child as BaseConstruct); }
/// <summary> /// Compares this IBaseConstruct against the one provided, and returns true if they are the same. /// </summary> /// <param name="comparisonObject">The object to compare against.</param> /// <returns>True if the objects are the same, false if they are different.</returns> public bool IsTheSame(IBaseConstruct comparisonObject) { if (comparisonObject is BaseConstruct) { return(IsTheSame(comparisonObject as BaseConstruct)); } return(false); }
private bool IsTheSame(IBaseConstruct otherbc) { IBaseConstruct thisbc = baseConstructs.GetFirstNonNullObject(); if (thisbc == null || otherbc == null) { return(false); } return(thisbc.IsTheSame(otherbc)); }
private static string GetObjectText(IBaseConstruct obj) { string text = obj.IsLeaf ? obj.GetFullText() : obj.GetOuterText(); text = Common.Utility.StandardizeLineBreaks(text, Common.Utility.LineBreaks.Unix); if (text.IndexOf('\n') == 0) { text = text.Remove(0, 1); } return(text); }
/// <summary> /// Searches through all of the nodes in the tree and returns the node that contains the /// given base construct. It uses reference equality to determine this, so if the base construct /// is not in the tree it will return null. /// </summary> /// <param name="baseConstruct">The base construct to search for in the tree.</param> /// <returns>The matched node.</returns> public CodeRootMapNode GetExactNode(IBaseConstruct baseConstruct) { foreach (CodeRootMapNode node in allNodes) { if (node.IsTheSameReference(baseConstruct)) { return(node); } } return(null); }
/// <summary> /// </summary> /// <param name="baseConstruct">The IBaseConstruct to find.</param> /// <returns> /// Finds the given IBaseConstruct in this node's children, and returns the node it belongs to. If /// it does not exist in any of this nodes children, returns null. /// </returns> public virtual CodeRootMapNode GetChildNode(IBaseConstruct baseConstruct) { foreach (CodeRootMapNode child in children) { if (child.IsTheSameReference(baseConstruct)) { return(child); } } return(null); }
public void AddBaseConstructAsChild(IBaseConstruct bc, Version t) { foreach (CodeRootMapNode child in children) { if (child.IsTheSame(bc)) { child.AddBaseConstruct(bc, t); return; } } AddBaseConstructAsNewChild(bc, t); }
public override ActionResult ApplyActionTo(StringBuilder sb) { if (AdditionPoint == AdditionPoint.EndOfParent) { IBaseConstruct lastSibling = ClassToAddTo.WalkChildren().OfType <Function>() .OrderBy(bc => bc.TextRange.EndOffset).LastOrDefault(); ClassToAddTo.AddChild(FunctionToAdd); return(InsertAtEndOfParent(sb, lastSibling)); } return(new ActionResult()); }
public void A_UsingStatement_Is_Created() { const string code = "using System;"; CSharpParser parser = new CSharpParser(); IBaseConstruct bc = parser.ParseSingleConstruct(code, BaseConstructType.UsingDirective); Assert.That(bc, Is.Not.Null); Assert.That(bc, Is.InstanceOfType(typeof(UsingStatement))); UsingStatement con = (UsingStatement)bc; Assert.That(con.Value, Is.EqualTo("System")); }
public void A_Structure_Is_Created() { const string code = "public struct Structure1 { }"; CSharpParser parser = new CSharpParser(); IBaseConstruct bc = parser.ParseSingleConstruct(code, BaseConstructType.StructureDeclaration); Assert.That(bc, Is.Not.Null); Assert.That(bc, Is.InstanceOfType(typeof(Struct))); Struct con = (Struct)bc; Assert.That(con.Name, Is.EqualTo("Structure1")); }
public void A_Namespace_Is_Created() { const string code = "namespace Namespace1 { }"; CSharpParser parser = new CSharpParser(); IBaseConstruct bc = parser.ParseSingleConstruct(code, BaseConstructType.NamespaceDeclaration); Assert.That(bc, Is.Not.Null); Assert.That(bc, Is.InstanceOfType(typeof(Namespace))); Namespace con = (Namespace)bc; Assert.That(con.Name, Is.EqualTo("Namespace1")); }
/// <summary> /// Compares this IBaseConstruct against the one provided, and returns true if they are the same. /// </summary> /// <param name="depth">The depth of the comparison we do.</param> /// <param name="comparisonObject">The object to compare against.</param> /// <returns>True if the objects are the same, false if they are different.</returns> public bool IsTheSame(IBaseConstruct comparisonObject, ComparisonDepth depth) { if (comparisonObject is BaseConstruct) { if (depth == ComparisonDepth.Complete && !Utility.BaseContructCollectionsAreTheSame(_Attributes.ToArray(), ((BaseConstruct)comparisonObject)._Attributes.ToArray())) { ComparisonDifference += GetType().Name + ".Attributes"; return(false); } return(IsTheSame(comparisonObject as BaseConstruct, depth)); } return(false); }
/// <summary> /// Adds the give base construct as a child of this code root. /// </summary> /// <param name="child">The chidl object to add.</param> public void AddChild(IBaseConstruct child) { if (child == null) { throw new ArgumentNullException("child"); } if (child is Namespace) { Namespaces.Add(child as Namespace); } else if (child is Struct) { Structs.Add(child as Struct); } else if (child is Interface) { Interfaces.Add(child as Interface); } else if (child is Enumeration) { Enums.Add(child as Enumeration); } else if (child is Delegate) { Delegates.Add(child as Delegate); } else if (child is UsingStatement) { UsingStatements.Add(child as UsingStatement); _usingStatementsAreSorted = false; } else if (child is AttributeSection) { Attributes.Add(child as AttributeSection); } else if (child is Class) { Classes.Add(child as Class); } else { throw new InvalidOperationException("Could not add child of type " + child.GetType()); } if (child is BaseConstruct) { ((BaseConstruct)child).Controller = controller; } }
protected ActionResult InsertAtEndOfParent(StringBuilder sb, IBaseConstruct insertAfter) { if (insertAfter == null) { return(InsertAtStartOfParent(sb)); } int lastSiblingStartOffset = insertAfter.TextRange.StartOffset; int lastSiblingEndOffset = insertAfter.TextRange.EndOffset; int endIndex = ClassToAddTo.TextRange.EndOffset; string text = sb.ToString(); if (lastSiblingEndOffset < 0 || string.IsNullOrWhiteSpace(text)) { return(InsertAtStartOfParent(sb)); } int firstNewLine; if (endIndex > lastSiblingEndOffset) { firstNewLine = text.IndexOf('\n', lastSiblingEndOffset, (endIndex - lastSiblingEndOffset)); } else { firstNewLine = text.IndexOf('\n', lastSiblingEndOffset); } int newStartIndex = firstNewLine + 1; int numTabs = InsertionHelpers.GetIndentationInFrontOf(sb, lastSiblingStartOffset); ConstructToAdd.Controller.IndentLevel = numTabs; ConstructToAdd.PreceedingBlankLines = -1; string newPropertyText = ConstructToAdd.ToString(); // The "+ numTabs" is account for the tabs that are at the start // of the new text. If we don't trim those off the text range, then it will // include the whitespace before the actual property, which the objects which have actually // been parsed will not have. If this number is wrong, the next object to be placed after it // will not be able to get the tabs correctly. ConstructToAdd.TextRange.StartOffset = newStartIndex + numTabs; ConstructToAdd.TextRange.EndOffset = newStartIndex + numTabs + newPropertyText.Trim().Length; ConstructToAdd.Index = newStartIndex + numTabs; BeforeInsert(newStartIndex, newPropertyText); sb.Insert(newStartIndex, newPropertyText); return(new ActionResult(ConstructToAdd.TextRange.StartOffset, newPropertyText.Length, new[] { ConstructToAdd })); }
public void An_InterfaceEvent_Is_Created() { const string code = "event Delegate1 Event1;"; CSharpParser parser = new CSharpParser(); IBaseConstruct bc = parser.ParseSingleConstruct(code, BaseConstructType.InterfaceEventDeclaration); Assert.That(bc, Is.Not.Null); Assert.That(bc, Is.InstanceOfType(typeof(InterfaceEvent))); InterfaceEvent con = (InterfaceEvent)bc; Assert.That(con.Name, Is.EqualTo("Event1")); Assert.That(con.DataType.Name, Is.EqualTo("Delegate1")); }
public void An_InterfaceMethod_Is_Created() { const string code = "void Method1();"; CSharpParser parser = new CSharpParser(); IBaseConstruct bc = parser.ParseSingleConstruct(code, BaseConstructType.InterfaceMethodDeclaration); Assert.That(bc, Is.Not.Null); Assert.That(bc, Is.InstanceOfType(typeof(InterfaceMethod))); InterfaceMethod con = (InterfaceMethod)bc; Assert.That(con.Name, Is.EqualTo("Method1")); Assert.That(con.ReturnType.Name, Is.EqualTo("void")); }
/// <summary> /// Matches the 3 given nodes for diff and merge purposes. Does not modify the CodeRoots, just rewires the /// CodeRootMap. Only works if the base constructs being matched have the same parent. They may have the same /// parent if their parent has been matched with somthing else. /// </summary> /// <param name="parentNode">The parent CodeRootMapNode of the 3 base constructs. If the BCs were functions, this would /// be the CodeRootMapNode that holds their parent class.</param> /// <param name="userObj">The user object to map.</param> /// <param name="newGenObj">The template object to map.</param> /// <param name="prevGenObj">The prevgen object to map.</param> public void MatchConstructs(CodeRootMapNode parentNode, IBaseConstruct userObj, IBaseConstruct newGenObj, IBaseConstruct prevGenObj) { if (userObj != null) { CodeRootMapNode childNode = parentNode.GetChildNode(userObj); if (childNode == null) { throw new Exception("UserObject not part of this tree"); } childNode.RemoveBaseConstruct(userObj, false); } if (newGenObj != null) { CodeRootMapNode childNode = parentNode.GetChildNode(newGenObj); if (childNode == null) { throw new Exception("NewGen not part of this tree"); } childNode.RemoveBaseConstruct(newGenObj, false); } if (prevGenObj != null) { CodeRootMapNode childNode = parentNode.GetChildNode(prevGenObj); if (childNode == null) { throw new Exception("PrevGen not part of this tree"); } childNode.RemoveBaseConstruct(prevGenObj, false); } CleanUpTree(); CodeRootMapNode newNode = new CodeRootMapNode(parentNode.ParentTree, parentNode); newNode.IsCustomMatch = true; if (userObj != null) { newNode.AddBaseConstruct(userObj, Version.User); } if (newGenObj != null) { newNode.AddBaseConstruct(newGenObj, Version.NewGen); } if (prevGenObj != null) { newNode.AddBaseConstruct(prevGenObj, Version.PrevGen); } }
public void A_Destructor_Is_Created() { // This should not be the name of the class const string code = "public ~MadeUpClassName() { }"; CSharpParser parser = new CSharpParser(); IBaseConstruct bc = parser.ParseSingleConstruct(code, BaseConstructType.DestructorDeclaration); Assert.That(bc, Is.Not.Null); Assert.That(bc, Is.InstanceOfType(typeof(Destructor))); Destructor con = (Destructor)bc; Assert.That(con.Name, Is.EqualTo("MadeUpClassName")); Assert.That(con.BodyText, Is.EqualTo("{\n}\n".Replace("\n", Environment.NewLine))); }
public void A_Class_Is_Created() { const string code = "public class Class1 { }"; CSharpParser parser = new CSharpParser(); IBaseConstruct bc = parser.ParseSingleConstruct(code, BaseConstructType.ClassDeclaration); Assert.That(bc, Is.Not.Null); Assert.That(bc, Is.InstanceOfType(typeof(Class))); Class con = (Class)bc; Assert.That(con.Name, Is.EqualTo("Class1")); Assert.That(con.Modifiers.Count, Is.EqualTo(1)); Assert.That(con.Modifiers[0], Is.EqualTo("public")); }
public void An_Interface_Is_Created() { const string code = "public interface Interface1 { }"; CSharpParser parser = new CSharpParser(); IBaseConstruct bc = parser.ParseSingleConstruct(code, BaseConstructType.InterfaceDeclaration); Assert.That(bc, Is.Not.Null); Assert.That(bc, Is.InstanceOfType(typeof(Interface))); Interface con = (Interface)bc; Assert.That(con.Name, Is.EqualTo("Interface1")); Assert.That(con.Modifiers.Count, Is.EqualTo(1)); Assert.That(con.Modifiers[0], Is.EqualTo("public")); }
protected ActionResult InsertAtEndOfParent(StringBuilder sb, IBaseConstruct insertAfter) { if (insertAfter == null) return InsertAtStartOfParent(sb); int lastSiblingStartOffset = insertAfter.TextRange.StartOffset; int lastSiblingEndOffset = insertAfter.TextRange.EndOffset; int endIndex = ClassToAddTo.TextRange.EndOffset; string text = sb.ToString(); if (lastSiblingEndOffset < 0 || string.IsNullOrWhiteSpace(text)) return InsertAtStartOfParent(sb); int firstNewLine; if (endIndex > lastSiblingEndOffset) firstNewLine = text.IndexOf('\n', lastSiblingEndOffset, (endIndex - lastSiblingEndOffset)); else firstNewLine = text.IndexOf('\n', lastSiblingEndOffset); int newStartIndex = firstNewLine + 1; int numTabs = InsertionHelpers.GetIndentationInFrontOf(sb, lastSiblingStartOffset); ConstructToAdd.Controller.IndentLevel = numTabs; ConstructToAdd.PreceedingBlankLines = -1; string newPropertyText = ConstructToAdd.ToString(); // The "+ numTabs" is account for the tabs that are at the start // of the new text. If we don't trim those off the text range, then it will // include the whitespace before the actual property, which the objects which have actually // been parsed will not have. If this number is wrong, the next object to be placed after it // will not be able to get the tabs correctly. ConstructToAdd.TextRange.StartOffset = newStartIndex + numTabs; ConstructToAdd.TextRange.EndOffset = newStartIndex + numTabs + newPropertyText.Trim().Length; ConstructToAdd.Index = newStartIndex + numTabs; BeforeInsert(newStartIndex, newPropertyText); sb.Insert(newStartIndex, newPropertyText); return new ActionResult(ConstructToAdd.TextRange.StartOffset, newPropertyText.Length, new[] { ConstructToAdd }); }
private static CSharpConstructType GetConsType(IBaseConstruct bc) { CSharpConstructType consType; if (bc is ArchAngel.Providers.CodeProvider.DotNet.Namespace) { consType = CSharpConstructType.Namespace; } else if (bc is ArchAngel.Providers.CodeProvider.DotNet.Class) { consType = CSharpConstructType.Class; } else if (bc is ArchAngel.Providers.CodeProvider.DotNet.Field) { consType = CSharpConstructType.Field; } else if (bc is ArchAngel.Providers.CodeProvider.DotNet.Delegate) { consType = CSharpConstructType.Delegate; } else if (bc is ArchAngel.Providers.CodeProvider.DotNet.Event) { consType = CSharpConstructType.Event; } else if (bc is ArchAngel.Providers.CodeProvider.DotNet.Enumeration) { consType = CSharpConstructType.Enum; } else if (bc is ArchAngel.Providers.CodeProvider.DotNet.Function) { consType = CSharpConstructType.Method; } else if (bc is ArchAngel.Providers.CodeProvider.DotNet.Constructor) { consType = CSharpConstructType.Method; } else if (bc is ArchAngel.Providers.CodeProvider.DotNet.InterfaceMethod) { consType = CSharpConstructType.Method; } else if (bc is ArchAngel.Providers.CodeProvider.DotNet.Constant) { consType = CSharpConstructType.Constant; } else if (bc is ArchAngel.Providers.CodeProvider.DotNet.Interface) { consType = CSharpConstructType.Interface; } else if (bc is ArchAngel.Providers.CodeProvider.DotNet.InterfaceProperty) { consType = CSharpConstructType.Property; } else if (bc is ArchAngel.Providers.CodeProvider.DotNet.PropertyAccessor) { consType = CSharpConstructType.Property; } else if (bc is ArchAngel.Providers.CodeProvider.DotNet.Operator) { consType = CSharpConstructType.Operator; } else if (bc is ArchAngel.Providers.CodeProvider.DotNet.Struct) { consType = CSharpConstructType.Struct; } else { consType = CSharpConstructType.Field; } return consType; }
public override IBaseConstruct CreateBaseConstruct(string code, IBaseConstruct originalConstruct) { throw new System.NotImplementedException(); }
protected CodeRoot CreateNamespaceAndInterface(IBaseConstruct inter) { Interface interface1 = new Interface(controller, "Interface1"); interface1.Modifiers.Add("public"); interface1.AddChild(inter); AttributeSection attrs = new AttributeSection(controller); Attribute attr = new Attribute(controller); attr.PositionalArguments.Add("true"); attr.Name = "Serializable"; attrs.AddAttribute(attr); interface1.AddAttributeSection(attrs); Namespace ns = new Namespace(controller); ns.Name = "ArchAngel.Tests"; ns.AddChild(interface1); CodeRoot root = new CodeRoot(controller); root.AddChild(ns); return root; }
protected CodeRoot ConstructRootWithClass(IBaseConstruct childOfClass) { Class cl = new Class(controller, "Class1"); cl.AddChild(childOfClass); AttributeSection attrs = new AttributeSection(controller); Attribute attr = new Attribute(controller); attr.PositionalArguments.Add("true"); attr.Name = "Serializable"; attrs.AddAttribute(attr); cl.AddAttributeSection(attrs); Namespace ns = new Namespace(controller); ns.Name = "ArchAngel.Tests"; ns.AddChild(cl); CodeRoot root = new CodeRoot(controller); root.AddChild(ns); return root; }
protected CodeRoot CreateClassAndNamespace(IBaseConstruct child) { return CreateClassAndNamespace(new[]{child}); }
public static void SetupBaseConstructs(MockRepository mocks, IBaseConstruct bc1, IBaseConstruct bc2, ICodeRoot coderoot) { using(mocks.Record()) { Expect.Call(bc1.ShortName).Repeat.Any().Return("bc1"); Expect.Call(bc2.ShortName).Repeat.Any().Return("bc2"); Expect.Call(bc1.IsTheSame(bc1)).Repeat.Any().Return(true); Expect.Call(bc2.IsTheSame(bc2)).Repeat.Any().Return(true); Expect.Call(bc2.WalkChildren()).Repeat.AtLeastOnce().Return(new List<IBaseConstruct>().AsReadOnly()); List<IBaseConstruct> bc1Children = new List<IBaseConstruct>(); bc1Children.Add(bc2); Expect.Call(bc1.WalkChildren()).Repeat.AtLeastOnce().Return(bc1Children.AsReadOnly()); List<IBaseConstruct> rootChildren = new List<IBaseConstruct>(); rootChildren.Add(bc1); Expect.On(coderoot).Call(coderoot.WalkChildren()).Repeat.AtLeastOnce().Return(rootChildren.AsReadOnly()); } }
private static string GetObjectText(IBaseConstruct obj) { string text = obj.IsLeaf ? obj.GetFullText() : obj.GetOuterText(); text = Common.Utility.StandardizeLineBreaks(text, Common.Utility.LineBreaks.Unix); if (text.IndexOf('\n') == 0) text = text.Remove(0, 1); return text; }
public abstract Image GetImageForBaseConstruct(IBaseConstruct bc, Status status);