Exemple #1
0
 private Field(Field fieldToCopyFrom)
     : base(null)
 {
     fieldToCopyFrom.CloneInto(this);
     DataType = fieldToCopyFrom.DataType.Clone();
     Modifiers = new List<string>(fieldToCopyFrom.Modifiers);
     InitialValue = fieldToCopyFrom.InitialValue;
 }
Exemple #2
0
        protected CodeRoot CreateFieldAndClass(string fieldName, out Field createdField)
        {
            createdField      = new Field(controller);
            createdField.Name = fieldName;
            createdField.Modifiers.Add("public");
            createdField.DataType     = new DataType(controller, "int");
            createdField.InitialValue = "5";

            CodeRoot userRoot = CreateClassAndNamespace(createdField);

            return(userRoot);
        }
Exemple #3
0
        public void Field()
        {
            Field inter = new Field(controller);

            inter.Name = "i";
            inter.Modifiers.Add("public");
            inter.DataType     = new DataType(controller, "int");
            inter.InitialValue = "1";
            CodeRoot root = CreateClassAndNamespace(inter);

            CodeRootMap map = new CodeRootMap();

            map.AddCodeRoot(root, Version.User);
            map.AddCodeRoot(root, Version.NewGen);
            map.AddCodeRoot(root, Version.PrevGen);

            string result = map.GetMergedCodeRoot().ToString();

            Assert.That(result, Is.EqualTo(root.ToString()));
            Assertions.StringContains(result, "class Class1");
            Assertions.StringContains(result, "[Serializable(true)]");
            Assertions.StringContains(result, "namespace ArchAngel.Tests");
            Assertions.StringContains(result, "public int i = 1");
        }
 private static void ApplyTypeChanges(Field existingField, Field exampleField, Actions actions)
 {
     if (exampleField.DataType != null && existingField.DataType.Equals(exampleField.DataType) == false)
     {
         // Change datatype
         actions.AddAction(new ChangeTypeOfFieldAction(existingField, exampleField.DataType));
     }
 }
        private static void ApplyModifierChanges(Field existingField, Field exampleField, Actions actions)
        {
            if (existingField.Modifiers.UnorderedEqual(exampleField.Modifiers) == false)
            {
                string modifierString = "";

                foreach (var mod in existingField.Modifiers)
                    modifierString += mod + " ";

                modifierString = modifierString.Trim();
                actions.AddAction(new RemoveModifierFromFieldAction(existingField, modifierString));

                foreach (var modifier in exampleField.Modifiers)
                    actions.AddAction(new AddModifierToFieldAction(existingField, modifier, false));
            }
        }
 private static void ApplyFieldDeletion(Actions actions, Field existingField)
 {
     actions.AddAction(new RemoveFieldFromClassAction(existingField));
 }
Exemple #7
0
 private bool IsTheSame(Field comparisonField)
 {
     return IsTheSame(comparisonField, ComparisonDepth.Signature);
 }
 public ChangeTypeOfFieldAction(Field fieldToChange, DataType newName)
 {
     FieldToChange = fieldToChange;
     NewType = newName;
 }
Exemple #9
0
        private void Process_Field_Declaration(FieldDeclaration node)
        {
            if (node == null) throw new ArgumentNullException("node");

            foreach (IAstNode comment in node.Comments)
            {
                comments.Add(comment.StartOffset, (Comment)comment);
            }

            foreach (IAstNode fieldNode in node.Variables)
            {
                VariableDeclarator v = fieldNode as VariableDeclarator;
                if (v != null && v.ReturnType.TextRange.EndOffset > v.ReturnType.TextRange.StartOffset)
                {
                    Field field = new Field(controller);
                    field.Name = v.Name.Text;
                    field.Modifiers.AddRange(FormatterUtility.GetModifiersFromEnum(v.Modifiers));
                    if (v.IsConstant)
                    {
                        field.Modifiers.Add("const");
                    }
                    field.InitialValue = formatter.FormatExpression(v.Initializer);
                    //try
                    //{
                    field.DataType = FormatterUtility.GetDataTypeFromTypeReference(v.ReturnType, document, controller);
                    //}
                    //catch
                    //{
                    //    // Do nothing, DataType should be empty string
                    //}
                    SetupBaseConstruct(v.StartOffset, v.EndOffset, v.DocumentationProvider.Documentation, field, node.AttributeSections);
                    // Pop the stack here as there may be multiple Field declarations.
                    objectStack.Pop();
                }
            }
        }
Exemple #10
0
        private void Process_Field_Declaration(FieldDeclaration node)
        {
            if (node == null) throw new ArgumentNullException("node");

            foreach (IAstNode comment in node.Comments)
                comments.Add(comment.StartOffset, (Comment)comment);

            int counter = 0;

            for (int i = 0; i < node.Variables.Count; i++)
            {
                IAstNode fieldNode = node.Variables[i];
                VariableDeclarator v = fieldNode as VariableDeclarator;

                if (v != null)
                {
                    Field field = new Field(controller);
                    field.Name = v.Name.Text;
                    field.Modifiers.AddRange(FormatterUtility.GetModifiersFromEnum(v.Modifiers));
                    if (v.IsConstant)
                    {
                        field.Modifiers.Add("const");
                    }
                    field.InitialValue = formatter.FormatExpression(v.Initializer);
                    field.DataType = FormatterUtility.GetDataTypeFromTypeReference(v.ReturnType, document, controller);

                    if (counter == 0)
                        SetupBaseConstruct(node.TextRange.StartOffset, v.EndOffset, v.DocumentationProvider.Documentation, field, node.AttributeSections);
                    else
                        SetupBaseConstruct(v.StartOffset, v.EndOffset, v.DocumentationProvider.Documentation, field, node.AttributeSections);

                    counter++;
                    // Pop the stack here as there may be multiple Field declarations.
                    objectStack.Pop();
                }
            }
        }
        protected CodeRoot CreateFieldAndClass(string fieldName, out Field createdField)
        {
            createdField = new Field(controller);
            createdField.Name = fieldName;
            createdField.Modifiers.Add("public");
            createdField.DataType = new DataType(controller, "int");
            createdField.InitialValue = "5";

            CodeRoot userRoot = CreateClassAndNamespace(createdField);
            return userRoot;
        }
        public void Field()
        {
            Field inter = new Field(controller);
            inter.Name = "i";
            inter.Modifiers.Add("public");
            inter.DataType = new DataType(controller,"int");
            inter.InitialValue = "1";
            CodeRoot root = CreateClassAndNamespace(inter);

            CodeRootMap map = new CodeRootMap();
            map.AddCodeRoot(root, Version.User);
            map.AddCodeRoot(root, Version.NewGen);
            map.AddCodeRoot(root, Version.PrevGen);

            string result = map.GetMergedCodeRoot().ToString();
            Assert.That(result, Is.EqualTo(root.ToString()));
            Assertions.StringContains(result, "class Class1");
            Assertions.StringContains(result, "[Serializable(true)]");
            Assertions.StringContains(result, "namespace ArchAngel.Tests");
            Assertions.StringContains(result, "public int i = 1");
        }
 public VBFieldPrinter(Field obj)
 {
     this.obj = obj;
 }
 public ChangeNameOfFieldAction(Field fieldToChange, string newName)
 {
     FieldToChange = fieldToChange;
     NewName = newName;
 }
 public RemoveModifierFromFieldAction(Field fieldToChange, string modifierToRemove)
 {
     FieldToChange = fieldToChange;
     ModifierToRemove = modifierToRemove;
 }
 public RemoveFieldFromClassAction(Field fieldToDelete)
 {
     FieldToDelete = fieldToDelete;
 }
        public void Field_Changed_Return_Type()
        {
            const string name = "MyField1";
            string expectedResult = String.Format("{0} {1} {2}", Modifier1, DataType2, name);
            DataType type1 = new DataType(controller, DataType1);
            DataType type2 = new DataType(controller, DataType2);

            Field merged1 = new Field(controller);
            Field merged2 = new Field(controller);
            Field merged3 = new Field(controller);

            Field changing = new Field(controller, type2, name, Modifier1);

            Field unchanging = new Field(controller, type1, name, Modifier1);

            Merge_And_Assert(merged1, merged2, merged3, changing, unchanging, expectedResult);
        }
        public void Field()
        {
            Field inter = new Field(controller);
            inter.Name = "i";
            inter.Modifiers.Add("public");
            inter.DataType = new DataType(controller, "int");
            inter.InitialValue = "1";

            Assert.That(inter.IsTheSame(inter.Clone(), ComparisonDepth.Outer), Is.True);
        }
 public AddAttributeToFieldAction(Field fieldToAddTo, Attribute attributeToAdd)
 {
     FieldToAddTo = fieldToAddTo;
     AttributeToAdd = attributeToAdd;
 }
        public void Field()
        {
            Field item = new Field(controller, new DataType(controller, "int"), "Field1", "public");
            Assert.That(item.FullyQualifiedDisplayName, Is.EqualTo("Field1"));

            Class cl = new Class(controller, "Class1");
            cl.AddChild(item);

            Assert.That(item.FullyQualifiedDisplayName, Is.EqualTo("Class1.Field1"));
        }
 public AddModifierToFieldAction(Field fieldToChange, string newModifier, bool insertAtStart)
 {
     FieldToChange = fieldToChange;
     NewModifier = newModifier;
     InsertAtStart = insertAtStart;
 }
 public static int GetFieldNameIndex(string textToSearch, Field baseConstruct, int searchStart, int searchEnd)
 {
     //searchEnd = textToSearch.IndexOf('{', searchStart);
     return textToSearch.IndexOf(baseConstruct.Name, searchStart, searchEnd - searchStart);
 }
Exemple #23
0
        private bool IsTheSame(Field comparisonField, ComparisonDepth depth)
        {
            if (comparisonField == null)
                return false;

            if (Name == comparisonField.Name)
            {
                // TODO: Why are these checks on parents here?
                //                if (ParentObject.IsTheSame(comparisonField.ParentObject))
                {
                    if (depth == ComparisonDepth.Signature)
                    {
                        return true;
                    }

                    if (!base.IsTheSame(comparisonField, depth))
                    {
                        return false;
                    }
                    if (!Utility.StringCollectionsAreTheSame(Modifiers, comparisonField.Modifiers))
                    {
                        ComparisonDifference += GetType().Name + ".Modifiers";
                        return false;
                    }

                    if (DataType != comparisonField.DataType)
                        return false;

                    if (depth == ComparisonDepth.Outer)
                    {
                        return true;
                    }

                    if (InitialValue != comparisonField.InitialValue)
                    {
                        ComparisonDifference += GetType().Name + ".InitialValue";
                        return false;
                    }
                    return true;
                }
            }
            return false;
        }
 public ChangeInitialValueOfFieldAction(Field fieldToChange, string newInitialValue)
 {
     FieldToChange = fieldToChange;
     NewInitialValue = newInitialValue;
 }
 private static void ApplyFieldChanges(Actions actions, Field existingField, Field exampleField)
 {
     ApplyNameChanges(existingField, exampleField, actions);
     ApplyModifierChanges(existingField, exampleField, actions);
     ApplyInitialValueChanges(existingField, exampleField, actions);
     ApplyTypeChanges(existingField, exampleField, actions);
 }
        public void Field_Added_Modifier()
        {
            const string name = "MyField1";
            DataType type1 = new DataType(controller, DataType1);
            string expectedResult = String.Format("{0} {1} {2} {3}", Modifier1, Modifier2, type1, name);

            Field merged1 = new Field(controller);
            Field merged2 = new Field(controller);
            Field merged3 = new Field(controller);

            Field changing = new Field(controller, type1, name, Modifier1);
            changing.Modifiers.Add(Modifier2);
            Field unchanging = new Field(controller, type1, name, Modifier1);

            Merge_And_Assert(merged1, merged2, merged3, changing, unchanging, expectedResult);
        }
 private static void ApplyInitialValueChanges(Field existingField, Field exampleField, Actions actions)
 {
     if (exampleField.InitialValue != null && existingField.InitialValue.Equals(exampleField.InitialValue) == false)
     {
         // Change initial value
         actions.AddAction(new ChangeInitialValueOfFieldAction(existingField, exampleField.InitialValue));
     }
 }
        public void Field_Added_Preceeding_Comments()
        {
            const string name = "MyField1";
            const string comment1 = "My first comment goes here...";
            const string comment2 = "My second comment goes here...";
            const string comment3 = "My third comment goes here...";
            string expectedResult = String.Format("{0}\n{1}\n{2}".Replace("\n",Environment.NewLine),comment1,comment2,comment3);
            DataType type1 = new DataType(controller, DataType1);

            Field merged1 = new Field(controller);
            Field merged2 = new Field(controller);
            Field merged3 = new Field(controller);

            Field changing = new Field(controller, type1, name, Modifier1);
            changing.Comments.PreceedingComments.Add(comment1);
            changing.Comments.PreceedingComments.Add(comment2);
            changing.Comments.PreceedingComments.Add(comment3);
            Field unchanging = new Field(controller, type1, name, Modifier1);

            Merge_And_Assert(merged1, merged2, merged3, changing, unchanging, expectedResult);
        }
 private static void ApplyNameChanges(Field existingField, Field exampleField, Actions actions)
 {
     if (existingField.Name != exampleField.Name)
     {
         // Change name
         actions.AddAction(new ChangeNameOfFieldAction(existingField, exampleField.Name));
     }
 }
        public void Field_Added_Trailing_Comment()
        {
            const string name = "MyField1";
            const string comment = "My comment goes here...";
            DataType type1 = new DataType(controller, DataType1);

            Field merged1 = new Field(controller);
            Field merged2 = new Field(controller);
            Field merged3 = new Field(controller);

            Field changing = new Field(controller, type1, name, Modifier1);
            changing.Comments.TrailingComment = comment;
            Field unchanging = new Field(controller, type1, name, Modifier1);

            Merge_And_Assert(merged1, merged2, merged3, changing, unchanging, comment);
        }
        private Field Construct(Class @class)
        {
            Field field = new Field(@class.Controller);
            field.Name = _name;
            field.Modifiers.AddRange(_Modifiers);
            field.DataType = new DataType(@class.Controller, _typeName);
            field.InitialValue = _initialValue;

            return field;
        }
 public AddFieldToClassAction(Field fieldToAdd, AdditionPoint additionPoint, Class classToAddTo)
 {
     ConstructToAdd = FieldToAdd = fieldToAdd;
     AdditionPoint = additionPoint;
     ClassToAddTo = classToAddTo;
 }