예제 #1
0
        public override string GetEnumMemberName(string member)
        {
            string retVal = SwiftNameHelper.convertToValidSwiftTypeName(base.GetEnumMemberName(member));

            retVal = retVal.Replace(" ", "");
            return(retVal);
        }
예제 #2
0
        public string FieldsForValidation()
        {
            var indented   = new IndentedStringBuilder("    ");
            var properties = Properties.Cast <PropertySwift>().ToList();

            if (BaseModelType != null)
            {
                indented.Append(((CompositeTypeSwift)BaseModelType).FieldWriter.FieldsForValidation());
            }

            // Emit each property, except for named Enumerated types, as a pointer to the type
            foreach (var property in properties)
            {
                if (property.ModelType == null)
                {
                    continue;
                }

                if (property.IsPolymorphicDiscriminator)
                {
                    continue;
                }

                var propName         = SwiftNameHelper.convertToValidSwiftTypeName(property.Name.RawValue);
                var modelType        = property.ModelType;
                var modelDeclaration = modelType.Name;
                var serializeName    = SwiftNameHelper.convertToValidSwiftTypeName(property.SerializedName);
                if (modelType is IVariableType &&
                    !string.IsNullOrEmpty(((IVariableType)modelType).DecodeTypeDeclaration(property.IsRequired)))
                {
                }
                else
                {
                }
            }

            return(indented.ToString());
        }
예제 #3
0
        private void TransformEnumTypes(CodeModelSwift cmg)
        {
            // fix up any enum types that are missing a name.
            // NOTE: this must be done before the next code block
            foreach (var mt in cmg.ModelTypes)
            {
                foreach (var property in mt.Properties)
                {
                    if (property.ModelType is EnumTypeSwift)
                    {
                        var enumType = property.ModelType as EnumTypeSwift;

                        if (!enumType.IsNamed)
                        {
                            enumType.SetName(property.Name);
                        }
                    }
                }
            }

            // fix up any enum types that are missing a name.
            // NOTE: this must be done before the next code block
            foreach (var method in cmg.Methods)
            {
                foreach (var parameter in method.Parameters)
                {
                    if (parameter.ModelType is EnumTypeSwift)
                    {
                        var enumType = parameter.ModelType as EnumTypeSwift;

                        if (!enumType.IsNamed)
                        {
                            var typeName = SwiftNameHelper.convertToValidSwiftTypeName(parameter.Name);
                            enumType.SetName($"{method.Name}{typeName}");
                            enumType.UnNamedEnumRelatedType = new EnumTypeSwift(enumType);
                            cmg.Add(enumType.UnNamedEnumRelatedType);
                        }
                    }
                }
            }

            // And add any others with a defined name and value list (but not already located)
            foreach (var mt in cmg.ModelTypes)
            {
                var namedEnums = mt.Properties.Where(p => p.ModelType is EnumTypeSwift && (p.ModelType as EnumTypeSwift).IsNamed);
                foreach (var p in namedEnums)
                {
                    if (!cmg.EnumTypes.Any(etm => etm.Equals(p.ModelType)))
                    {
                        ((EnumTypeSwift)p.ModelType).UnNamedEnumRelatedType = new EnumTypeSwift(p.ModelType as EnumType);
                        cmg.Add(((EnumTypeSwift)p.ModelType).UnNamedEnumRelatedType);
                    }
                }
                ;
            }


            // now normalize the names
            // NOTE: this must be done after all enum types have been accounted for
            foreach (var enumType in cmg.EnumTypes)
            {
                enumType.SetName(CodeNamer.Instance.GetTypeName(enumType.Name.FixedValue));
                foreach (var v in enumType.Values)
                {
                    v.Name = CodeNamer.Instance.GetEnumMemberName(v.Name);
                }
            }

            // Ensure all enumerated type values have the simplest possible unique names
            // -- The code assumes that all public type names are unique within the client and that the values
            //    of an enumerated type are unique within that type. To safely promote the enumerated value name
            //    to the top-level, it must not conflict with other existing types. If it does, prepending the
            //    value name with the (assumed to be unique) enumerated type name will make it unique.

            // First, collect all type names (since these cannot change)
            var topLevelNames = new HashSet <string>();

            cmg.ModelTypes
            .ForEach(mt => topLevelNames.Add(mt.Name));

            // Then, note each enumerated type with one or more conflicting values and collect the values from
            // those enumerated types without conflicts.  do this on a sorted list to ensure consistent naming
            cmg.EnumTypes.Cast <EnumTypeSwift>().OrderBy(etg => etg.Name.Value)
            .ForEach(em =>
            {
                if (em.Values.Where(v => topLevelNames.Contains(v.Name) || CodeNamerSwift.Instance.UserDefinedNames.Contains(v.Name)).Count() > 0)
                {
                    em.HasUniqueNames = false;
                }
                else
                {
                    em.HasUniqueNames = true;
                    topLevelNames.UnionWith(em.Values.Select(ev => ev.Name).ToList());
                }
            });

            // add documentation comment if there aren't any
            cmg.EnumTypes.Cast <EnumTypeSwift>()
            .ForEach(em =>
            {
                if (em.Name.Equals("enum"))
                {
                    em.Name.FixedValue = em.ClassName;
                }

                if (string.IsNullOrEmpty(em.Documentation))
                {
                    em.Documentation = string.Format("{0} enumerates the values for {1}.", em.Name, em.Name.FixedValue.ToPhrase());
                }
            });
        }