protected override Expression VisitTypeDefinitionExpression(TypeDefinitionExpression expression) { try { currentTypeDefinition = expression; var body = this.Visit(expression.Body); var include = FickleExpression.Include("Foundation/Foundation.h"); var comment = new CommentExpression("This file is AUTO GENERATED"); var header = new Expression[] { comment, include }.ToStatementisedGroupedExpression(GroupedExpressionsExpressionStyle.Wide); return(FickleExpression.GroupedWide ( new TypeDefinitionExpression(expression.Type, header, body, false, expression.Attributes, expression.InterfaceTypes), this.CreateTryParseMethod(), this.CreateToStringMethod() )); } finally { currentTypeDefinition = null; } }
protected virtual void GenerateMasterHeader(ServiceModel serviceModel) { using (var writer = this.GetTextWriterForFile(this.Options.ServiceModelInfo.Name + ".h")) { var headerWriter = new ObjectiveCodeGenerator(writer); var includeExpressions = serviceModel.Classes .Select(c => FickleExpression.Include(c.Name + ".h")) .Concat(serviceModel.Enums.Select(c => FickleExpression.Include(c.Name + ".h"))) .Concat(serviceModel.Gateways.Select(c => FickleExpression.Include(c.Name + ".h"))); var comment = new CommentExpression("This file is AUTO GENERATED"); var commentGroup = new[] { comment }.ToStatementisedGroupedExpression(); var headerGroup = includeExpressions.ToStatementisedGroupedExpression(); var headerExpressions = new List <Expression> { commentGroup, headerGroup }; headerWriter.Visit(headerExpressions.ToGroupedExpression(GroupedExpressionsExpressionStyle.Wide)); } }
protected override Expression VisitTypeDefinitionExpression(TypeDefinitionExpression expression) { var includeExpressions = new List <Expression> { FickleExpression.Include(expression.Type.Name + ".h") }; var comment = new CommentExpression("This file is AUTO GENERATED"); var referencedTypes = ReferencedTypesCollector.CollectReferencedTypes(expression); referencedTypes.Sort((x, y) => String.Compare(x.Name, y.Name, StringComparison.InvariantCultureIgnoreCase)); foreach (var referencedType in referencedTypes.Where(ObjectiveBinderHelpers.TypeIsServiceClass)) { includeExpressions.Add(FickleExpression.Include(referencedType.Name + ".h")); } var headerGroup = includeExpressions.ToStatementisedGroupedExpression(); var header = new Expression[] { comment, headerGroup }.ToStatementisedGroupedExpression(GroupedExpressionsExpressionStyle.Wide); var methods = new List <Expression> { this.CreateInitMethod(expression), this.CreateAllPropertiesAsDictionaryMethod(expression), this.CreateScalarPropertiesAsFormEncodedStringMethod(expression), this.CreateCopyWithZoneMethod(expression), }; var body = methods.ToStatementisedGroupedExpression(GroupedExpressionsExpressionStyle.Wide); return(new TypeDefinitionExpression(expression.Type, header, body, false, expression.Attributes, expression.InterfaceTypes)); }
protected override Expression VisitTypeDefinitionExpression(TypeDefinitionExpression expression) { currentTypeDefinition = expression; currentType = expression.Type; var referencedTypes = ReferencedTypesCollector.CollectReferencedTypes(expression); referencedTypes.Sort((x, y) => string.Compare(x.Name, y.Name, StringComparison.InvariantCultureIgnoreCase)); var includeExpressions = new List <IncludeExpression>(); var lookup = new HashSet <Type>(referencedTypes.Where(TypeSystem.IsPrimitiveType)); if (lookup.Contains(typeof(Guid)) || lookup.Contains(typeof(Guid?))) { includeExpressions.Add(FickleExpression.Include("java.util.UUID")); } if (lookup.Contains(typeof(TimeSpan)) || lookup.Contains(typeof(TimeSpan?))) { includeExpressions.Add(FickleExpression.Include("java.util.Date")); } var comment = new CommentExpression("This file is AUTO GENERATED"); var namespaceExpression = new NamespaceExpression(codeGenerationContext.Options.Namespace); var members = new List <Expression>() { this.Visit(expression.Body) }; if (((FickleType)currentTypeDefinition.Type).ServiceClass.Properties.Count > 0) { includeExpressions.Add(FickleExpression.Include("android.util.JsonReader")); includeExpressions.Add(FickleExpression.Include("android.util.JsonToken")); includeExpressions.Add(FickleExpression.Include("com.jaigo.androiddevkit.*")); includeExpressions.Add(FickleExpression.Include("com.jaigo.androiddevkit.utils.*")); includeExpressions.Add(FickleExpression.Include("java.lang.Exception")); includeExpressions.Add(FickleExpression.Include("java.io.InputStream")); includeExpressions.Add(FickleExpression.Include("java.io.InputStreamReader")); includeExpressions.Add(FickleExpression.Include("java.util.ArrayList")); members.Add(CreateDeserializeStreamMethod()); members.Add(CreateDeserializeReaderMethod()); members.Add(CreateDeserializeElementMethod()); members.Add(CreateSerializeMethod()); } if (CurrentTypeIsResponseType()) { members.Add(CreateCreateErrorResponseMethod()); } var headerGroup = includeExpressions.ToStatementisedGroupedExpression(); var header = new Expression[] { comment, namespaceExpression, headerGroup }.ToStatementisedGroupedExpression(GroupedExpressionsExpressionStyle.Wide); var body = fieldDefinitionsForProperties.Concat(members).ToStatementisedGroupedExpression(GroupedExpressionsExpressionStyle.Wide); return(new TypeDefinitionExpression(expression.Type, header, body, false, expression.Attributes, expression.InterfaceTypes)); }
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)); }
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; } }
protected override Expression VisitTypeDefinitionExpression(TypeDefinitionExpression expression) { var comment = new CommentExpression("This file is AUTO GENERATED"); var includeExpressions = new List <IncludeExpression> { FickleExpression.Include("System"), FickleExpression.Include("System.Collections.Generic") }; foreach (var include in this.codeGenerationContext.Options.Includes) { includeExpressions.Add(FickleExpression.Include(include)); } var headerGroup = includeExpressions.ToStatementisedGroupedExpression(); var header = new Expression[] { comment, headerGroup }.ToStatementisedGroupedExpression(GroupedExpressionsExpressionStyle.Wide); var typeDefinitionExpression = new TypeDefinitionExpression(expression.Type, null, expression.Body, false, expression.Attributes, expression.InterfaceTypes); return(new NamespaceExpression(this.codeGenerationContext.Options.Namespace, header, typeDefinitionExpression)); }
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.Threading.Tasks") }; foreach (var include in this.CodeGenerationContext.Options.Includes) { includeExpressions.Add(FickleExpression.Include(include)); } var comment = new CommentExpression("This file is AUTO GENERATED"); var hostname = new FieldDefinitionExpression(HostnameFieldName, typeof(string), AccessModifiers.Public | AccessModifiers.Static | AccessModifiers.ReadOnly); var client = new FieldDefinitionExpression(FickleApiClientFieldName, this.fickleApiClientType, AccessModifiers.Private | AccessModifiers.ReadOnly); var body = GroupedExpressionsExpression.FlatConcat ( GroupedExpressionsExpressionStyle.Wide, hostname, client, this.CreateStaticConstructor(), 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)); }
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 VisitTypeDefinitionExpression(TypeDefinitionExpression expression) { var includeExpressions = new List <IncludeExpression>(); var importExpressions = new List <Expression>(); var referencedTypes = ReferencedTypesCollector.CollectReferencedTypes(expression); 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("PKDictionarySerializable.h")); includeExpressions.Add(FickleExpression.Include("PKFormEncodingSerializable.h")); } else { importExpressions.Add(new CodeLiteralExpression(c => c.WriteLine("@import PlatformKit;"))); } if (ObjectiveBinderHelpers.TypeIsServiceClass(expression.Type.BaseType)) { includeExpressions.Add(FickleExpression.Include(expression.Type.BaseType.Name + ".h")); } includeExpressions.AddRange(referencedTypes.Where(c => c.IsEnum).Select(c => FickleExpression.Include(c.Name + ".h"))); includeExpressions.Sort(IncludeExpression.Compare); var comment = new CommentExpression("This file is AUTO GENERATED"); var headerExpressions = new List <Expression>() { new[] { comment }.ToStatementisedGroupedExpression(), importExpressions.Count == 0 ? null : importExpressions.ToStatementisedGroupedExpression(), includeExpressions.ToStatementisedGroupedExpression() }; var referencedTypeExpressions = referencedTypes .Where(ObjectiveBinderHelpers.TypeIsServiceClass) .Where(c => c != expression.Type.BaseType) .OrderBy(x => x.Name.Length) .ThenBy(x => x.Name) .Select(c => (Expression) new ReferencedTypeExpression(c)).ToList(); if (referencedTypeExpressions.Count > 0) { headerExpressions.Add(referencedTypeExpressions.ToStatementisedGroupedExpression()); } var header = headerExpressions.ToStatementisedGroupedExpression(GroupedExpressionsExpressionStyle.Wide); var propertyBody = this.Visit(expression.Body); var interfaceTypes = new List <Type> { FickleType.Define("NSCopying"), FickleType.Define("PKDictionarySerializable"), FickleType.Define("PKFormEncodingSerializable") }; return(new TypeDefinitionExpression(expression.Type, header, propertyBody, true, expression.Attributes, interfaceTypes.ToReadOnlyCollection())); }
protected override Expression VisitTypeDefinitionExpression(TypeDefinitionExpression expression) { this.currentType = expression.Type; this.currentTypeDefinitionExpression = expression; this.currentReturnTypes = new HashSet <Type>(ReturnTypesCollector.CollectReturnTypes(expression)); var includeExpressions = new List <IncludeExpression> { FickleExpression.Include(expression.Type.Name + ".h"), FickleExpression.Include("PKWebServiceClient.h"), FickleExpression.Include("NSArray+PKExtensions.h"), FickleExpression.Include(this.CodeGenerationContext.Options.ResponseStatusTypeName + ".h") }; var comment = new CommentExpression("This file is AUTO GENERATED"); var expressions = new List <Expression> { CreateCreateClientMethod(), CreateInitMethod(), CreateInitWithOptionsMethod() }; var rawParameterTypes = ParameterTypesCollector .Collect(expression, c => c.Attributes["Method"].EqualsIgnoreCase("post") && c.Attributes.ContainsKey("Content")) .Select(c => new Tuple <Type, string>(c.Item1.GetFickleListElementType() ?? c.Item1, c.Item2)) .Select(c => new Tuple <Type, string>(c.Item1.GetUnwrappedNullableType(), c.Item2)) .Distinct(); foreach (var value in rawParameterTypes .Select(c => new { Type = c.Item1, Name = this.GetNormalizeRequestMethodName(c.Item1, c.Item2), Format = c.Item2 }) .GroupBy(c => c.Name) .Select(c => c.First())) { var type = value.Type; var format = value.Format; expressions.Add(this.CreateNormalizeRequestObjectMethod(type, format)); } expressions.Add(this.Visit(expression.Body)); if (methodCount > 0) { expressions.Add(this.CreateCreateErrorResponseWithErrorCodeMethod()); expressions.Add(this.CreateParseResultMethod()); } expressions.Add(this.CreateSerializeRequestMethod()); var body = GroupedExpressionsExpression.FlatConcat ( GroupedExpressionsExpressionStyle.Wide, expressions.ToArray() ); var singleValueResponseTypes = currentReturnTypes.Where(c => c.GetUnwrappedNullableType().IsPrimitive).Select(c => FickleType.Define(ObjectiveBinderHelpers.GetValueResponseWrapperTypeName(c))).ToList(); var referencedTypes = ReferencedTypesCollector.CollectReferencedTypes(body).Concat(singleValueResponseTypes).Distinct().ToList(); referencedTypes.Sort((x, y) => string.Compare(x.Name, y.Name, StringComparison.InvariantCultureIgnoreCase)); foreach (var referencedType in referencedTypes.Where(c => (c as FickleType)?.ServiceClass != null)) { includeExpressions.Add(FickleExpression.Include(referencedType.Name + ".h")); } var headerGroup = includeExpressions.Sorted(IncludeExpression.Compare).ToGroupedExpression(); var header = new Expression[] { comment, headerGroup }.ToGroupedExpression(GroupedExpressionsExpressionStyle.Wide); this.currentType = null; return(new TypeDefinitionExpression(expression.Type, header, body, false, expression.Attributes)); }