Пример #1
0
        protected virtual Expression VisitGroupedExpressionsExpression(GroupedExpressionsExpression expression)
        {
            var expressions = this.VisitExpressionList(expression.Expressions);

            if (expressions != expression.Expressions)
            {
                return new GroupedExpressionsExpression(expressions, expression.Style);
            }

            return expression;
        }
Пример #2
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;
            }
        }