protected override Expression VisitPropertyDefinitionExpression(PropertyDefinitionExpression property)
        {
            var self = Expression.Parameter(this.theCopy.Type, "self");

            var propertyOnTheCopy = Expression.Property(this.theCopy, property.PropertyName);
            var propertyOnSelf = (Expression)Expression.Property(self, property.PropertyName);

            var propertyType = propertyOnTheCopy.Type;

            if (propertyType.GetFickleListElementType() != null)
            {
                propertyOnSelf = FickleExpression.New(propertyType, "initWithArray", new
                {
                    oldArray = propertyOnSelf,
                    copyItems = true
                });
            }
            else if (propertyType is FickleType && !propertyType.IsValueType)
            {
                propertyOnSelf = Expression.Convert(FickleExpression.Call(propertyOnSelf, typeof(object), "copyWithZone", this.zone), propertyType);
            }
            else if (propertyType == typeof(string))
            {
                propertyOnSelf = FickleExpression.Call(propertyOnSelf, typeof(string), "copy", null);
            }

            var assignExpression = Expression.Assign(propertyOnTheCopy, propertyOnSelf);

            this.statements.Add(assignExpression.ToStatement());

            return property;
        }
Exemplo n.º 2
0
        protected override Expression VisitPropertyDefinitionExpression(PropertyDefinitionExpression property)
        {
            if (string.Equals(property.PropertyName, propertyName, StringComparison.InvariantCultureIgnoreCase))
            {
                return new PropertyDefinitionExpression(property.PropertyName, this.newPropertyType);
            }

            return base.VisitPropertyDefinitionExpression(property);
        }
        protected override Expression VisitTypeDefinitionExpression(TypeDefinitionExpression expression)
        {
            var includeExpressions = new List<IncludeExpression>();
            var optionsProperty = new PropertyDefinitionExpression("options", FickleType.Define("NSDictionary"), true);

            var body = FickleExpression.GroupedWide
            (
                optionsProperty,
                FickleExpression.Grouped
                (
                    this.CreateInitWithOptionsMethod(),
                    this.Visit(expression.Body)
                )
            );

            var referencedTypes = ReferencedTypesCollector.CollectReferencedTypes(body);
            referencedTypes.Sort((x, y) => String.Compare(x.Name, y.Name, StringComparison.InvariantCultureIgnoreCase));

            var lookup = new HashSet<Type>(referencedTypes.Where(TypeSystem.IsPrimitiveType));

            if (lookup.Contains(typeof(Guid)) || lookup.Contains(typeof(Guid?)))
            {
                includeExpressions.Add(FickleExpression.Include("PKUUID.h"));
            }

            if (lookup.Contains(typeof(TimeSpan)) || lookup.Contains(typeof(TimeSpan?)))
            {
                includeExpressions.Add(FickleExpression.Include("PKTimeSpan.h"));
            }

            includeExpressions.Add(FickleExpression.Include("PKDictionarySerializable.h"));
            includeExpressions.Add(FickleExpression.Include("PKWebServiceClient.h"));

            var referencedUserTypes = referencedTypes
                .Where(c => (c is FickleType && ((FickleType)c).ServiceClass != null) || c is FickleType && ((FickleType)c).ServiceEnum != null)
                .Sorted((x, y) => x.Name.Length == y.Name.Length ? String.CompareOrdinal(x.Name, y.Name) : x.Name.Length - y.Name.Length);

            includeExpressions.AddRange(referencedUserTypes.Select(c => FickleExpression.Include(c.Name + ".h")));

            var comment = new CommentExpression("This file is AUTO GENERATED");
            var header = new Expression[] { comment, includeExpressions.Sorted(IncludeExpression.Compare).ToStatementisedGroupedExpression() }.ToStatementisedGroupedExpression(GroupedExpressionsExpressionStyle.Wide);

            var interfaceTypes = new List<Type>();

            if (expression.InterfaceTypes != null)
            {
                interfaceTypes.AddRange(expression.InterfaceTypes);
            }

            interfaceTypes.Add(FickleType.Define("PKWebServiceClientDelegate"));

            return new TypeDefinitionExpression(expression.Type, header, body, true, expression.Attributes, interfaceTypes.ToReadOnlyCollection());
        }
Exemplo n.º 4
0
        protected override Expression VisitPropertyDefinitionExpression(PropertyDefinitionExpression property)
        {
            var name = property.PropertyName.ToCamelCase();

            var propertyDefinition = new PropertyDefinitionExpression(name, property.PropertyType, true, property.Modifiers);

            if (name.StartsWith("new"))
            {
                var attributedPropertyGetter = new MethodDefinitionExpression(name, new Expression[0], property.PropertyType, Expression.Empty(), true, "(objc_method_family(none))", null);

                return new Expression[] { propertyDefinition, attributedPropertyGetter }.ToStatementisedGroupedExpression();
            }
            else
            {
                return propertyDefinition;
            }
        }
Exemplo n.º 5
0
        protected override Expression VisitPropertyDefinitionExpression(PropertyDefinitionExpression property)
        {
            var name = property.PropertyName.Uncapitalize();

            fieldDefinitionsForProperties.Add(new FieldDefinitionExpression(name, property.PropertyType, AccessModifiers.Protected));

            var thisProperty = FickleExpression.Variable(property.PropertyType, "this." + name);

            var getterBody = FickleExpression.Block
            (
                new Expression[] { FickleExpression.Return(thisProperty) }
            );

            var setterParam = FickleExpression.Parameter(property.PropertyType, name);

            var setterBody = FickleExpression.Block
            (
                new Expression[] { Expression.Assign(thisProperty, setterParam) }
            );

            var propertyGetter = new MethodDefinitionExpression("get" + property.PropertyName, new List<Expression>(), AccessModifiers.Public, property.PropertyType, getterBody, false);
            var propertySetter = new MethodDefinitionExpression("set" + property.PropertyName, new List<Expression> { setterParam }, AccessModifiers.Public, typeof(void), setterBody, false);

            return new Expression[] { propertyGetter, propertySetter }.ToStatementisedGroupedExpression();
        }
        protected override Expression VisitTypeDefinitionExpression(TypeDefinitionExpression expression)
        {
            var includeExpressions = new List<IncludeExpression>();
            var importExpressions = new List<Expression>();

            var optionsProperty = new PropertyDefinitionExpression("options", FickleType.Define("NSDictionary"), true);
            var responseFilterProperty = new PropertyDefinitionExpression("responseFilter", FickleType.Define("FKGatewayResponseFilter", isInterface:true), true, new[] { "weak" });

            var body = FickleExpression.GroupedWide
            (
                optionsProperty,
                responseFilterProperty,
                new GroupedExpressionsExpression(methods.Select(c => c.ChangePredeclaration(true)))
            );

            var referencedTypes = ReferencedTypesCollector.CollectReferencedTypes(body);
            referencedTypes.Sort((x, y) => String.Compare(x.Name, y.Name, StringComparison.InvariantCultureIgnoreCase));

            var lookup = new HashSet<Type>(referencedTypes.Where(TypeSystem.IsPrimitiveType));

            if (!this.CodeGenerationContext.Options.ImportDependenciesAsFramework)
            {
                if (lookup.Contains(typeof(Guid)) || lookup.Contains(typeof(Guid?)))
                {
                    includeExpressions.Add(FickleExpression.Include("PKUUID.h"));
                }

                if (lookup.Contains(typeof(TimeSpan)) || lookup.Contains(typeof(TimeSpan?)))
                {
                    includeExpressions.Add(FickleExpression.Include("PKTimeSpan.h"));
                }

                includeExpressions.Add(FickleExpression.Include("PKWebServiceClient.h"));
                includeExpressions.Add(FickleExpression.Include("PKDictionarySerializable.h"));
            }
            else
            {
                importExpressions.Add(new CodeLiteralExpression(c => c.WriteLine("@import PlatformKit;")));
            }

            includeExpressions.Add(FickleExpression.Include("FKGatewayResponseFilter.h"));

            var referencedUserTypes = referencedTypes
                .Where(c => (c is FickleType && ((FickleType)c).ServiceClass != null) || c is FickleType && ((FickleType)c).ServiceEnum != null)
                .Sorted((x, y) => x.Name.Length == y.Name.Length ? String.CompareOrdinal(x.Name, y.Name) : x.Name.Length - y.Name.Length);

            includeExpressions.AddRange(referencedUserTypes.Select(c => FickleExpression.Include(c.Name + ".h")));

            var comment = new CommentExpression("This file is AUTO GENERATED");

            var header = new Expression[]
            {
                comment,
                importExpressions.Count == 0 ? null : importExpressions.ToStatementisedGroupedExpression(),
                includeExpressions.Sorted(IncludeExpression.Compare).ToStatementisedGroupedExpression()
            }.ToStatementisedGroupedExpression(GroupedExpressionsExpressionStyle.Wide);

            var interfaceTypes = new List<Type>();

            if (expression.InterfaceTypes != null)
            {
                interfaceTypes.AddRange(expression.InterfaceTypes);
            }

            interfaceTypes.Add(FickleType.Define("PKWebServiceClientDelegate"));

            return new TypeDefinitionExpression(expression.Type, header, body, true, expression.Attributes, interfaceTypes.ToReadOnlyCollection());
        }
        protected override Expression VisitPropertyDefinitionExpression(PropertyDefinitionExpression property)
        {
            var self = Expression.Variable(this.type, "self");
            var retval = FickleExpression.Variable("NSDictionary", "retval");
            var propertyExpression = FickleExpression.Property(self, property.PropertyType, property.PropertyName);

            var expression = GetSerializeExpression(property.PropertyType, propertyExpression, context.Options, false, c => FickleExpression.Call(retval, "setObject", new
            {
                obj = Expression.Convert(c, typeof(object)),
                forKey = Expression.Constant(property.PropertyName)
            }).ToStatement());

            this.propertySetterExpressions.Add(new [] { FickleExpression.Comment(property.PropertyName), expression }.ToGroupedExpression(GroupedExpressionsExpressionStyle.Wide));

            return property;
        }
Exemplo n.º 8
0
        protected override Expression VisitPropertyDefinitionExpression(PropertyDefinitionExpression property)
        {
            var name = this.normalize(property.PropertyName);
            var prefix = reservedKeywords.Contains(name) ? replacementPrefix : "";

            if (name != property.PropertyName || prefix != "")
            {
                return new PropertyDefinitionExpression(prefix + name, property.PropertyType, property.IsPredeclatation);
            }
            else
            {
                return base.VisitPropertyDefinitionExpression(property);
            }
        }
Exemplo n.º 9
0
 protected virtual Expression VisitPropertyDefinitionExpression(PropertyDefinitionExpression property)
 {
     return property;
 }
Exemplo n.º 10
0
        protected override Expression VisitPropertyDefinitionExpression(PropertyDefinitionExpression property)
        {
            if (!property.IsPredeclatation)
            {
                return property;
            }

            this.Write(@"@property (readwrite) ");
            this.Write(property.PropertyType);
            this.Write(' ');
            this.Write(property.PropertyName);
            this.WriteLine(';');

            return property;
        }
        protected override Expression VisitPropertyDefinitionExpression(PropertyDefinitionExpression property)
        {
            var dictionaryType = new FickleType("NSDictionary");
            var currentValueFromDictionary = Expression.Parameter(typeof(object), "currentValueFromDictionary");
            var objectForKeyCall = Expression.Call(Expression.Parameter(dictionaryType, "properties"), new FickleMethodInfo(dictionaryType, typeof(object), "objectForKey", new ParameterInfo[] { new FickleParameterInfo(typeof(string), "key") }), Expression.Constant(property.PropertyName));
            var propertyExpression = Expression.Property(Expression.Parameter(this.type, "self"), new FicklePropertyInfo(this.type, property.PropertyType, property.PropertyName));

            var expressions = new List<Expression>
            {
                FickleExpression.Comment(property.PropertyName),
                Expression.Assign(currentValueFromDictionary, objectForKeyCall).ToStatement(),
                GetDeserializeExpressionProcessValueDeserializer(property.PropertyType, currentValueFromDictionary, c => Expression.Assign(propertyExpression, c).ToStatement())
            };

            this.propertyGetterExpressions.Add(expressions.ToStatementisedGroupedExpression(GroupedExpressionsExpressionStyle.Wide));

            return property;
        }
Exemplo n.º 12
0
        protected override Expression VisitPropertyDefinitionExpression(PropertyDefinitionExpression property)
        {
            this.Write(AccessModifiersToString(AccessModifiers.Public));
            this.Write(property.PropertyType);
            this.Write(' ');
            this.Write(property.PropertyName);
            this.WriteLine(" { get; set; }");

            return property;
        }
Exemplo n.º 13
0
        protected override Expression VisitPropertyDefinitionExpression(PropertyDefinitionExpression property)
        {
            if (!property.IsPredeclaration)
            {
                return property;
            }

            var modifiers = property.Modifiers;

            if (modifiers.Count > 0)
            {
                this.Write(@"@property (readwrite, ");

                var i = 0;

                foreach (var value in modifiers)
                {
                    this.Write(value);

                    if (i != modifiers.Count - 1)
                    {
                        this.Write(", ");
                    }

                    i++;
                }

                this.Write(") ");
            }
            else
            {
                this.Write(@"@property (readwrite) ");
            }

            this.Write(property.PropertyType);
            this.Write(' ');
            this.Write(property.PropertyName);
            this.WriteLine(';');

            return property;
        }