Exemplo n.º 1
0
        protected override Expression VisitTypeDefinitionExpression(TypeDefinitionExpression expression)
        {
            try
            {
                currentTypeDefinition = expression;
                currentType = expression.Type;

                enumValueField = new FieldDefinitionExpression("value", typeof(int), AccessModifiers.Private | AccessModifiers.Constant);

                var includeExpressions = new List<Expression>()
                {
                    FickleExpression.Include("android.util.JsonReader"),
                    FickleExpression.Include("com.jaigo.androiddevkit.DefaultJsonBuilder"),
                    FickleExpression.Include("java.util.ArrayList")
                };

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

                if (!codeGenerationContext.Options.SerializeEnumsAsStrings)
                {
                    includeExpressions.Add(FickleExpression.Include("com.jaigo.androiddevkit.utils.ConvertUtils"));
                }

                var includeStatements = includeExpressions.ToStatementisedGroupedExpression();

                var comment = new CommentExpression("This file is AUTO GENERATED");
                var namespaceExpression = new NamespaceExpression(codeGenerationContext.Options.Namespace);
                var header = new Expression[] { comment, namespaceExpression, includeStatements }.ToStatementisedGroupedExpression(GroupedExpressionsExpressionStyle.Wide);

                var bodyExpressions = new List<Expression>()
                {
                    expression.Body,
                    enumValueField,
                    CreateConstructor(),
                    CreateDeserializeMethod(),
                    CreateDeserializeArrayMethod(),
                    CreateSerializeMethod(),
                    JavaBinderHelpers.CreateSerializeArrayMethod(currentType)
                };

                var body = new GroupedExpressionsExpression(bodyExpressions);

                return new TypeDefinitionExpression(expression.Type, header, body, false, expression.Attributes, expression.InterfaceTypes);
            }
            finally
            {
                currentTypeDefinition = null;
            }
        }
Exemplo n.º 2
0
        protected override Expression VisitTypeDefinitionExpression(TypeDefinitionExpression expression)
        {
            currentTypeDefinitionExpression = expression;
            currentReturnTypes = new HashSet<Type>(ReturnTypesCollector.CollectReturnTypes(expression));

            var includeExpressions = new List<IncludeExpression>
            {
                FickleExpression.Include("java.util.ArrayList"),
                FickleExpression.Include("com.jaigo.androiddevkit.DefaultJsonBuilder"),
                FickleExpression.Include("com.jaigo.androiddevkit.RequestCallback"),
                FickleExpression.Include("com.jaigo.androiddevkit.utils.ConvertUtils"),
                FickleExpression.Include("com.jaigo.androiddevkit.WebServiceClient")
            };

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

            var client = new FieldDefinitionExpression("webServiceClient", webServiceClientType, AccessModifiers.Private | AccessModifiers.Constant);

            var body = GroupedExpressionsExpression.FlatConcat
            (
                GroupedExpressionsExpressionStyle.Wide,
                client,
                CreateDefaultConstructor(),
                CreateParameterisedConstructor(),
                this.Visit(expression.Body)
            );

            var singleValueResponseTypes = currentReturnTypes.Where(c => c.GetUnwrappedNullableType().IsPrimitive).Select(c => FickleType.Define(JavaBinderHelpers.GetValueResponseWrapperTypeName(c))).ToList();

            var referencedTypes = ReferencedTypesCollector.CollectReferencedTypes(body).Concat(singleValueResponseTypes).Distinct().ToList();
            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(FickleListType)))
            {
                includeExpressions.Add(FickleExpression.Include("java.util.ArrayList"));
            }

            if (lookup.Contains(typeof(Guid)) || lookup.Contains(typeof(Guid?)))
            {
                includeExpressions.Add(FickleExpression.Include("java.util.UUID"));
            }

            if (lookup.Contains(typeof(DateTime)) || lookup.Contains(typeof(DateTime?)))
            {
                includeExpressions.Add(FickleExpression.Include("java.util.Date"));
            }

            var headerGroup = includeExpressions.Sorted(IncludeExpression.Compare).ToGroupedExpression();
            var namespaceExpression = new NamespaceExpression(CodeGenerationContext.Options.Namespace);

            var header = new Expression[] { comment, namespaceExpression, headerGroup }.ToGroupedExpression(GroupedExpressionsExpressionStyle.Wide);

            return new TypeDefinitionExpression(expression.Type, header, body, false, expression.Attributes, expression.InterfaceTypes);
        }
Exemplo n.º 3
0
        protected override Expression VisitTypeDefinitionExpression(TypeDefinitionExpression expression)
        {
            currentTypeDefinitionExpression = expression;

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

            var client = new FieldDefinitionExpression("webServiceClient", webServiceClientType, AccessModifiers.Private | AccessModifiers.Constant);

            var body = GroupedExpressionsExpression.FlatConcat
            (
                GroupedExpressionsExpressionStyle.Wide,
                client,
                CreateDefaultConstructor(),
                CreateParameterisedConstructor(),
                this.Visit(expression.Body)
            );

            var header = new Expression[] { comment }.ToGroupedExpression(GroupedExpressionsExpressionStyle.Wide);

            return new TypeDefinitionExpression(expression.Type, header, body, false, expression.Attributes, expression.InterfaceTypes);
        }
        protected override Expression VisitTypeDefinitionExpression(TypeDefinitionExpression expression)
        {
            this.currentTypeDefinitionExpression = expression;

            var includeExpressions = new List<IncludeExpression>
            {
                FickleExpression.Include("System"),
                FickleExpression.Include("System.Collections.Generic"),
                FickleExpression.Include("System.Net.Http"),
                FickleExpression.Include("System.Threading.Tasks"),
                FickleExpression.Include("System.IO"),
                FickleExpression.Include("System.Net")
            };

            foreach (var include in this.CodeGenerationContext.Options.Includes)
            {
                includeExpressions.Add(FickleExpression.Include(include));
            }

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

            var client = new FieldDefinitionExpression(HttpClientFieldName, this.httpClientType, AccessModifiers.Private | AccessModifiers.ReadOnly);
            var serializer = new FieldDefinitionExpression(HttpStreamSerializerFieldName, this.httpStreamSerializerType, AccessModifiers.Private | AccessModifiers.ReadOnly);

            var body = GroupedExpressionsExpression.FlatConcat
            (
                GroupedExpressionsExpressionStyle.Wide,
                client,
                serializer,
                this.CreateParameterisedConstructor(),
                this.Visit(expression.Body)
            );

            var headerGroup = includeExpressions.Sorted(IncludeExpression.Compare).ToGroupedExpression();

            var header = new Expression[] { comment, headerGroup }.ToGroupedExpression(GroupedExpressionsExpressionStyle.Wide);

            var typeDefinitionExpression = new TypeDefinitionExpression(expression.Type, null, body, false, expression.Attributes, expression.InterfaceTypes);

            return new NamespaceExpression(this.CodeGenerationContext.Options.Namespace, header, typeDefinitionExpression);
        }
Exemplo n.º 5
0
 protected virtual Expression VisitFieldDefinitionExpression(FieldDefinitionExpression field)
 {
     return field;
 }
Exemplo n.º 6
0
        protected override Expression VisitFieldDefinitionExpression(FieldDefinitionExpression field)
        {
            this.Write(field.PropertyType);
            this.Write(' ');
            this.Write(field.PropertyName);
            this.Write(';');

            return field;
        }
Exemplo n.º 7
0
        protected override Expression VisitFieldDefinitionExpression(FieldDefinitionExpression field)
        {
            this.Write(AccessModifiersToString(field.AccessModifiers));
            this.Write(field.PropertyType);
            this.Write(' ');
            this.Write(field.PropertyName);
            this.Write(';');

            return field;
        }