Ejemplo n.º 1
0
 private Indexer(Indexer iiToCopyFrom)
     : base(null)
 {
     iiToCopyFrom.CloneInto(this);
     DataType = iiToCopyFrom.DataType.Clone();
     foreach (Parameter p in iiToCopyFrom.Parameters)
     {
         var clone = (Parameter)p.Clone();
         Parameters.Add(clone);
         clone.Parent = this;
     }
 }
        public void Indexer_Changed_ReturnType()
        {
            string expectedResult = String.Format("{0} this []", DataType2);
            DataType type1 = new DataType(controller, DataType1);
            DataType type2 = new DataType(controller, DataType2);

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

            Indexer changing = new Indexer(controller, type2);
            Indexer unchanging = new Indexer(controller, type1);

            Merge_And_Assert(merged1, merged2, merged3, changing, unchanging, expectedResult);
        }
        public void Indexer()
        {
            Indexer item = new Indexer(controller);
            item.Parameters.Add(new Parameter(controller, "float", "f"));
            item.Parameters.Add(new Parameter(controller, "InputObject", "j"));
            Assert.That(item.FullyQualifiedDisplayName, Is.EqualTo("Indexer [float, InputObject]"));

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

            Assert.That(item.FullyQualifiedDisplayName, Is.EqualTo("Class1.Indexer [float, InputObject]"));
        }
Ejemplo n.º 4
0
        private bool IsTheSame(Indexer comparisonIndexer, ComparisonDepth depth)
        {
            if (comparisonIndexer == null)
                return false;

            if (Name == comparisonIndexer.Name &&
                DataType == comparisonIndexer.DataType &&
                Parameters.Count == comparisonIndexer.Parameters.Count)
            {
                for (int i = 0; i < Parameters.Count; i++)
                {
                    if (Parameters[i].Name != comparisonIndexer.Parameters[i].Name ||
                        Parameters[i].DataType != comparisonIndexer.Parameters[i].DataType)
                    {
                        return false;
                    }
                }
                // Function names are the same, so now compare the class names
                // TODO: Parent object comparison
                //if (ParentObject.IsTheSame(comparisonIndexer.ParentObject))
                {
                    if (depth == ComparisonDepth.Signature)
                    {
                        return true;
                    }

                    if (!base.IsTheSame(comparisonIndexer, depth))
                    {
                        return false;
                    }

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

                    if (!GetAccessor.IsTheSame(comparisonIndexer.GetAccessor))
                    {
                        ComparisonDifference += GetType().Name + ".GetAccessor";
                        return false;
                    }
                    if (!SetAccessor.IsTheSame(comparisonIndexer.SetAccessor))
                    {
                        ComparisonDifference += GetType().Name + ".SetAccessor";
                        return false;
                    }
                    return true;
                }
            }
            return false;
        }
        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);
        }
Ejemplo n.º 6
0
 private bool IsTheSame(Indexer comparisonFunction)
 {
     return IsTheSame(comparisonFunction, ComparisonDepth.Signature);
 }
Ejemplo n.º 7
0
 private bool IsTheSame(Indexer comparisonFunction)
 {
     return(IsTheSame(comparisonFunction, ComparisonDepth.Signature));
 }
Ejemplo n.º 8
0
 public IndexerPrinter(Indexer obj)
     : base(obj)
 {
     this.obj = obj;
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Removes the given child object from this object.
        /// </summary>
        /// <param name="child"></param>
        /// <exception cref="InvalidOperationException">If the child type is unsupported (the parent doesn't have any of those objects) then an
        /// InvalidOperationExeception is thrown.</exception>
        /// <exception cref="ArgumentException">If the child's parent is not this object, then an ArgumentException is thrown.</exception>
        protected override void RemoveChildObjectInternal(BaseConstruct child)
        {
            /*
             * Constant
             * Field
             * Function
             * Property
             * Event
             * Indexer
             * Operator
             * Constructor
             * Class
             * Struct
             * Enumeration
             * Interface
             * Delegate
             * RegionStart
             */

            if (child is Constant)
            {
                if (constants.Remove(child as Constant) == false)
                {
                    throw new ArgumentException("object is not a member of this class");
                }
            }
            else if (child is Field)
            {
                if (fields.Remove(child as Field) == false)
                {
                    throw new ArgumentException("object is not a member of this class");
                }
            }
            else if (child is Function)
            {
                if (functions.Remove(child as Function) == false)
                {
                    throw new ArgumentException("object is not a member of this class");
                }
            }
            else if (child is Property)
            {
                if (properties.Remove(child as Property) == false)
                {
                    throw new ArgumentException("object is not a member of this class");
                }
            }
            else if (child is Event)
            {
                if (events.Remove(child as Event) == false)
                {
                    throw new ArgumentException("object is not a member of this class");
                }
            }
            else if (child is Indexer)
            {
                if (classIndexer == child as Indexer)
                {
                    classIndexer = null;
                }
                else
                {
                    throw new ArgumentException("object is not a member of this class");
                }
            }
            else if (child is Operator)
            {
                if (operators.Remove(child as Operator) == false)
                {
                    throw new ArgumentException("object is not a member of this class");
                }
            }
            else if (child is Constructor)
            {
                if (constructors.Remove(child as Constructor) == false)
                {
                    throw new ArgumentException("object is not a member of this class");
                }
            }
            else if (child is Class)
            {
                if (innerClasses.Remove(child as Class) == false)
                {
                    throw new ArgumentException("object is not a member of this class");
                }
            }
            else if (child is Struct)
            {
                if (structs.Remove(child as Struct) == false)
                {
                    throw new ArgumentException("object is not a member of this class");
                }
            }
            else if (child is Enumeration)
            {
                if (enums.Remove(child as Enumeration) == false)
                {
                    throw new ArgumentException("object is not a member of this class");
                }
            }
            else if (child is Interface)
            {
                if (interfaces.Remove(child as Interface) == false)
                {
                    throw new ArgumentException("object is not a member of this class");
                }
            }
            else if (child is Delegate)
            {
                if (delegates.Remove(child as Delegate) == false)
                {
                    throw new ArgumentException("object is not a member of this class");
                }
            }
            else if (child is Region)
            {
                if (regions.Remove(child as Region) == false)
                {
                    throw new ArgumentException("object is not a member of this class");
                }
            }
            else
            {
                base.RemoveChildObjectInternal(child);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Adds a new child to this IBaseConstruct.
        /// </summary>
        /// <param name="child"></param>
        protected override void AddChildInternal(BaseConstruct child)
        {
            if (child == null)
            {
                throw new InvalidOperationException("Cannot add null child");
            }

            if (child is Constant)
            {
                constants.Add(child as Constant);
            }
            else if (child is Field)
            {
                fields.Add(child as Field);
            }
            else if (child is Function)
            {
                functions.Add(child as Function);
            }
            else if (child is Property)
            {
                properties.Add(child as Property);
            }
            else if (child is Event)
            {
                events.Add(child as Event);
            }
            else if (child is Indexer)
            {
                classIndexer = child as Indexer;
            }
            else if (child is Operator)
            {
                operators.Add(child as Operator);
            }
            else if (child is Constructor)
            {
                constructors.Add(child as Constructor);
            }
            else if (child is Destructor)
            {
                destructors.Add(child as Destructor);
            }
            else if (child is Class)
            {
                innerClasses.Add(child as Class);
            }
            else if (child is Struct)
            {
                structs.Add(child as Struct);
            }
            else if (child is Enumeration)
            {
                enums.Add(child as Enumeration);
            }
            else if (child is Interface)
            {
                interfaces.Add(child as Interface);
            }
            else if (child is Delegate)
            {
                delegates.Add(child as Delegate);
            }
            else if (child is Region)
            {
                regions.Add(child as Region);
            }
            else
            {
                throw new InvalidOperationException("Cannot add child of type " + child.GetType());
            }
        }
Ejemplo n.º 11
0
        private void Process_Property_Declaration(PropertyDeclaration node)
        {
            if (node == null) throw new ArgumentNullException("node");

            if (node.IsIndexer)
            {
                Indexer inter = new Indexer(controller);
                inter.DataType = FormatterUtility.GetDataTypeFromTypeReference(node.ReturnType, document, controller);

                foreach (ParameterDeclaration paramNode in node.Parameters)
                {
                    inter.Parameters.Add(GetParameterFromParameterDeclaration(document, controller, paramNode));
                }

                SetupBaseConstruct(node, inter);

                if (node.GetAccessor != null)
                {
                    Process_Property_Accessor(node, PropertyAccessor.AccessorTypes.Get);
                }
                if (node.SetAccessor != null)
                {
                    Process_Property_Accessor(node, PropertyAccessor.AccessorTypes.Set);
                }
            }
            else
            {
                Property inter = new Property(controller);
                inter.Name = node.Name.Text;
                inter.DataType = FormatterUtility.GetDataTypeFromTypeReference(node.ReturnType, document, controller);
                inter.Modifiers.AddRange(FormatterUtility.GetModifiersFromEnum(node.Modifiers));

                SetupBaseConstruct(node, inter);

                if (node.GetAccessor != null)
                {
                    Process_Property_Accessor(node, PropertyAccessor.AccessorTypes.Get);
                }
                if (node.SetAccessor != null)
                {
                    Process_Property_Accessor(node, PropertyAccessor.AccessorTypes.Set);
                }
            }
        }
        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);
        }
Ejemplo n.º 13
0
 public VBIndexerPrinter(Indexer obj)
 {
     this.obj = obj;
 }