Exemplo n.º 1
0
        protected CodeRoot CreateIndexer(string parameterName)
        {
            Indexer inter = new Indexer(controller);

            inter.Name     = "File";
            inter.DataType = new DataType(controller, "int");
            Parameter param = new Parameter(controller);

            param.Name     = parameterName;
            param.DataType = "int";
            inter.Parameters.Add(param);

            PropertyAccessor acc = new PropertyAccessor(controller);

            acc.Modifier     = "public";
            acc.BodyText     = "{ return file[i]; }";
            acc.AccessorType = PropertyAccessor.AccessorTypes.Get;
            inter.AddChild(acc);

            acc              = new PropertyAccessor(controller);
            acc.Modifier     = "protected";
            acc.BodyText     = "{ file[i] = value; }";
            acc.AccessorType = PropertyAccessor.AccessorTypes.Set;
            inter.AddChild(acc);

            return(CreateClassAndNamespace(inter));
        }
Exemplo n.º 2
0
        public void Constructor()
        {
            Constructor constructor = new Constructor(controller);

            constructor.Modifiers.Add("public");
            constructor.Name     = "Class1";
            constructor.BodyText = "{ }";
            Parameter param = new Parameter(controller);

            param.Name     = "i";
            param.DataType = "int";
            constructor.Parameters.Add(param);

            CodeRoot root = CreateClassAndNamespace(constructor);

            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 Class1");
            Assertions.StringContains(result, "{ }");
        }
Exemplo n.º 3
0
        public void Delegate()
        {
            Delegate inter = new Delegate(controller);

            inter.Name = "File";
            inter.Modifiers.Add("public");
            inter.ReturnType = new DataType(controller, "int");
            Parameter param = new Parameter(controller);

            param.Name     = "i";
            param.DataType = "int";
            inter.Parameters.Add(param);

            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 delegate int File");
        }
Exemplo n.º 4
0
 public Function(Controller controller, String functionName, DataType returnType, Parameter param)
     : base(controller)
 {
     Name = functionName;
     ReturnType = returnType;
     Parameters.Add(param);
 }
Exemplo n.º 5
0
 private Parameter(Parameter paramToCopyFrom)
     : base(null)
 {
     paramToCopyFrom.CloneInto(this);
     PreceedingBlankLines = -1;
     DataType = paramToCopyFrom.DataType;
     IsParams = paramToCopyFrom.IsParams;
     Modifiers = new List<string>(paramToCopyFrom.Modifiers);
 }
        public void Constructor()
        {
            Constructor inter = new Constructor(controller);
            inter.Modifiers.Add("public");
            inter.Name = "Class1";
            Parameter param = new Parameter(controller);
            param.Name = "i";
            param.DataType = "int";
            inter.Parameters.Add(param);

            Assert.That(inter.IsTheSame(inter.Clone(), ComparisonDepth.Outer), Is.True);
        }
Exemplo n.º 7
0
        protected CodeRoot CreateInterfaceAndMethod(string parameterName)
        {
            InterfaceMethod inter = new InterfaceMethod(controller, "Method1");

            inter.ReturnType = new DataType(controller, "int");
            Parameter param = new Parameter(controller);

            param.Name     = parameterName;
            param.DataType = "int";
            inter.Parameters.Add(param);

            return(CreateNamespaceAndInterface(inter));
        }
Exemplo n.º 8
0
        protected ArchAngel.Providers.CodeProvider.DotNet.Function CreateFunction(string functionName, string functionParameterName, int index)
        {
            ArchAngel.Providers.CodeProvider.DotNet.Function createdFunction = new ArchAngel.Providers.CodeProvider.DotNet.Function(controller);
            createdFunction.Name  = functionName;
            createdFunction.Index = index;
            createdFunction.Modifiers.Add(Modifier);
            createdFunction.ReturnType = new DataType(controller, ReturnType);
            createdFunction.BodyText   = BodyText;
            Parameter param = new Parameter(controller);

            param.Name     = functionParameterName;
            param.DataType = DataType;
            createdFunction.Parameters.Add(param);
            return(createdFunction);
        }
Exemplo n.º 9
0
        protected CodeRoot CreateClassAndOperator(string secondParameterName)
        {
            Operator inter = new Operator(controller);

            inter.Modifiers.Add("public");
            inter.Modifiers.Add("static");
            inter.Name     = "+";
            inter.DataType = new DataType(controller, "int");
            Parameter param = new Parameter(controller);

            param.Name     = "self";
            param.DataType = "Class1";
            inter.Parameters.Add(param);
            param          = new Parameter(controller);
            param.Name     = secondParameterName;
            param.DataType = "int";
            inter.Parameters.Add(param);
            inter.BodyText = "{ return 5; }";

            return(CreateClassAndNamespace(inter));
        }
Exemplo n.º 10
0
        public void PrevGen_Is_Missing_Others_Are_Different_BodyText()
        {
            CodeRootMap map = new CodeRootMap();

            Function inter = new Function(controller);

            inter.Name = "GetVal";
            inter.Modifiers.Add("public");
            inter.ReturnType = new DataType(controller, "int");
            inter.BodyText   = "{ return 5; }";
            Parameter param = new Parameter(controller);

            param.Name     = "i";
            param.DataType = "int";
            inter.Parameters.Add(param);

            CodeRoot root = ConstructRootWithClass(inter);

            map.AddCodeRoot(root, Version.User);

            inter      = new Function(controller);
            inter.Name = "GetVal";
            inter.Modifiers.Add("public");
            inter.ReturnType = new DataType(controller, "int");
            inter.BodyText   = "{ return 6; }"; // Modified Body Text
            param            = new Parameter(controller);
            param.Name       = "i";
            param.DataType   = "int";
            inter.Parameters.Add(param);

            root = ConstructRootWithClass(inter);

            map.AddCodeRoot(root, Version.NewGen);

            Assert.That(map.Diff(), Is.EqualTo(TypeOfDiff.Conflict));
        }
        public void PrevGen_Is_Missing_Others_Are_Different_BodyText()
        {
            CodeRootMap map = new CodeRootMap();

            Function inter = new Function(controller);
            inter.Name = "GetVal";
            inter.Modifiers.Add("public");
            inter.ReturnType = new DataType(controller,"int");
            inter.BodyText = "{ return 5; }";
            Parameter param = new Parameter(controller);
            param.Name = "i";
            param.DataType = "int";
            inter.Parameters.Add(param);

            CodeRoot root = ConstructRootWithClass(inter);

            map.AddCodeRoot(root, Version.User);

            inter = new Function(controller);
            inter.Name = "GetVal";
            inter.Modifiers.Add("public");
            inter.ReturnType = new DataType(controller,"int");
            inter.BodyText = "{ return 6; }"; // Modified Body Text
            param = new Parameter(controller);
            param.Name = "i";
            param.DataType = "int";
            inter.Parameters.Add(param);

            root = ConstructRootWithClass(inter);

            map.AddCodeRoot(root, Version.NewGen);

            Assert.That(map.Diff(), Is.EqualTo(TypeOfDiff.Conflict));
        }
        protected CodeRoot CreateClassAndOperator(string secondParameterName)
        {
            Operator inter = new Operator(controller);
            inter.Modifiers.Add("public");
            inter.Modifiers.Add("static");
            inter.Name = "+";
            inter.DataType = new DataType(controller, "int");
            Parameter param = new Parameter(controller);
            param.Name = "self";
            param.DataType = "Class1";
            inter.Parameters.Add(param);
            param = new Parameter(controller);
            param.Name = secondParameterName;
            param.DataType = "int";
            inter.Parameters.Add(param);
            inter.BodyText = "{ return 5; }";

            return CreateClassAndNamespace(inter);
        }
Exemplo n.º 13
0
 public VBParameterPrinter(Parameter obj)
 {
     this.obj = obj;
 }
 protected ArchAngel.Providers.CodeProvider.DotNet.Function CreateFunction(string functionName, string functionParameterName, int index)
 {
     ArchAngel.Providers.CodeProvider.DotNet.Function createdFunction = new ArchAngel.Providers.CodeProvider.DotNet.Function(controller);
     createdFunction.Name = functionName;
     createdFunction.Index = index;
     createdFunction.Modifiers.Add(Modifier);
     createdFunction.ReturnType = new DataType(controller, ReturnType);
     createdFunction.BodyText = BodyText;
     Parameter param = new Parameter(controller);
     param.Name = functionParameterName;
     param.DataType = DataType;
     createdFunction.Parameters.Add(param);
     return createdFunction;
 }
        public void Indexer()
        {
            Indexer inter = new Indexer(controller);
            inter.Name = "File";
            inter.DataType = new DataType(controller, "int");
            Parameter param = new Parameter(controller);
            param.Name = "i";
            param.DataType = "int";
            inter.Parameters.Add(param);

            Assert.That(inter.IsTheSame(inter.Clone(), ComparisonDepth.Outer), Is.True);
        }
        public void Constructor()
        {
            Constructor constructor = new Constructor(controller);
            constructor.Modifiers.Add("public");
            constructor.Name = "Class1";
            constructor.BodyText = "{ }";
            Parameter param = new Parameter(controller);
            param.Name = "i";
            param.DataType = "int";
            constructor.Parameters.Add(param);

            CodeRoot root = CreateClassAndNamespace(constructor);

            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 Class1");
            Assertions.StringContains(result, "{ }");
        }
        public void Parameter_Change_IsParams()
        {
            Function merged1 = new Function(controller);
            Function merged2 = new Function(controller);
            Function merged3 = new Function(controller);

            const string Name = "MyFunction1";
            DataType dataType = new DataType(controller, DataType1);
            Parameter param = new Parameter(controller, "int", "i");
            string expectedResult = string.Format("{0} {1}(params int i)", new object[]{DataType1,Name});

            Function unchanging = new Function(controller, Name, dataType, param);
            Function changing = new Function(controller, Name, dataType, param);
            changing.Parameters[0].IsParams = true;

            Merge_And_Assert(merged1, merged2, merged3, changing, unchanging, expectedResult);
        }
        public void Parameter_Add_DataType()
        {
            Function merged1 = new Function(controller);
            Function merged2 = new Function(controller);
            Function merged3 = new Function(controller);

            const string name = "MyFunction1";
            const string parameterName = "i";
            DataType returnType = new DataType(controller, "void");
            Parameter param = new Parameter(controller, "int", parameterName);
            string expectedResult = string.Format("void {0}({1} {2})", new object[] { name, DataType1, parameterName });

            Function unchanging = new Function(controller, name, returnType, param);
            Function changing = new Function(controller, name, returnType, new Parameter(controller, DataType1, parameterName));

            Merge_And_Assert(merged1, merged2, merged3, changing, unchanging, expectedResult);
        }
        protected CodeRoot CreateInterfaceAndMethod(string parameterName)
        {
            InterfaceMethod inter = new InterfaceMethod(controller, "Method1");
            inter.ReturnType = new DataType(controller, "int");
            Parameter param = new Parameter(controller);
            param.Name = parameterName;
            param.DataType = "int";
            inter.Parameters.Add(param);

            return CreateNamespaceAndInterface(inter);
        }
        protected CodeRoot CreateIndexer(string parameterName)
        {
            Indexer inter = new Indexer(controller);
            inter.Name = "File";
            inter.DataType = new DataType(controller, "int");
            Parameter param = new Parameter(controller);
            param.Name = parameterName;
            param.DataType = "int";
            inter.Parameters.Add(param);

            PropertyAccessor acc = new PropertyAccessor(controller);
            acc.Modifier = "public";
            acc.BodyText = "{ return file[i]; }";
            acc.AccessorType = PropertyAccessor.AccessorTypes.Get;
            inter.AddChild(acc);

            acc = new PropertyAccessor(controller);
            acc.Modifier = "protected";
            acc.BodyText = "{ file[i] = value; }";
            acc.AccessorType = PropertyAccessor.AccessorTypes.Set;
            inter.AddChild(acc);

            return CreateClassAndNamespace(inter);
        }
        public void Parameter()
        {
            Parameter inter = new Parameter(controller);
            inter.Name = "i";
            inter.DataType = "int";
            inter.IsParams = true;

            Assert.That(inter.IsTheSame(inter.Clone(), ComparisonDepth.Outer), Is.True);
        }
        public void Operator()
        {
            Operator inter = new Operator(controller);
            inter.Modifiers.Add("public");
            inter.Name = "File";
            inter.DataType = new DataType(controller, "int");
            Parameter param = new Parameter(controller);
            param.Name = "i";
            param.DataType = "int";
            inter.Parameters.Add(param);
            inter.BodyText = "asdfasdfasdfasdf";

            Assert.That(inter.IsTheSame(inter.Clone(), ComparisonDepth.Outer), Is.True);
            Assert.That(string.IsNullOrEmpty(((Operator)inter.Clone()).BodyText), Is.True);
        }
        public void Parameter_Change_Modifiers()
        {
            Function merged1 = new Function(controller);
            Function merged2 = new Function(controller);
            Function merged3 = new Function(controller);

            const string name = "MyFunction1";
            DataType dataType = new DataType(controller, DataType1);
            Parameter param = new Parameter(controller, "int", "i");
            string expectedResult = string.Format("{0} {1}({2} {3} int i)", new object[] { DataType1, name, Modifier1, Modifier2 });

            Function changing = new Function(controller, name, dataType, param);
            Function unchanging = new Function(controller, name, dataType, param);
            changing.Parameters[0].Modifiers.Add(Modifier1);
            changing.Parameters[0].Modifiers.Add(Modifier2);

            Merge_And_Assert(merged1, merged2, merged3, changing, unchanging, expectedResult);
        }
        public void Delegate()
        {
            Delegate inter = new Delegate(controller);
            inter.Name = "File";
            inter.Modifiers.Add("public");
            inter.ReturnType = new DataType(controller,"int");
            Parameter param = new Parameter(controller);
            param.Name = "i";
            param.DataType = "int";
            inter.Parameters.Add(param);

            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 delegate int File");
        }
Exemplo n.º 25
0
        private bool IsTheSame(Parameter comparisonParameter, ComparisonDepth depth)
        {
            if (comparisonParameter == null)
                return false;

            if (Name != comparisonParameter.Name)
            {
                ComparisonDifference += GetType().Name + ".Name";
                return false;
            }

            if (depth == ComparisonDepth.Signature) return true;

            if (DataType != comparisonParameter.DataType)
            {
                ComparisonDifference += GetType().Name + ".DataType";
                return false;
            }

            if (!ArchAngel.Providers.CodeProvider.CSharp.Utility.BaseContructCollectionsAreTheSame(Attributes.ToArray(), comparisonParameter.Attributes.ToArray()))
            {
                ComparisonDifference += GetType().Name + ".Attributes";
                return false;
            }

            return true;
        }
        public void Delegate()
        {
            Delegate inter = new Delegate(controller);
            inter.Name = "File";
            inter.Modifiers.Add("public");
            inter.ReturnType = new DataType(controller,"int");
            Parameter param = new Parameter(controller);
            param.Name = "i";
            param.DataType = "int";
            inter.Parameters.Add(param);

            Assert.That(inter.IsTheSame(inter.Clone(), ComparisonDepth.Outer), Is.True);
        }
Exemplo n.º 27
0
        internal static Parameter GetParameterFromParameterDeclaration(Document document, Controller controller, ParameterDeclaration node)
        {
            Parameter param = new Parameter(controller);
            param.Name = node.Name;
            param.Modifiers.AddRange(FormatterUtility.GetModifiersFromEnum(node.Modifiers));
            param.DataType = FormatterUtility.GetDataTypeFromTypeReference(node.ParameterType, document, controller).ToString();
            param.Index = node.StartOffset;

            return param;
        }