Пример #1
0
        public virtual List <string> ImportType(IType type, string ns)
        {
            List <string> imports        = new List <string>();
            var           sequenceType   = type as SequenceType;
            var           dictionaryType = type as DictionaryType;
            var           primaryType    = type as PrimaryType;
            var           compositeType  = type as CompositeType;

            if (sequenceType != null)
            {
                imports.Add("java.util.List");
                imports.AddRange(ImportType(sequenceType.ElementType, ns));
            }
            else if (dictionaryType != null)
            {
                imports.Add("java.util.Map");
                imports.AddRange(ImportType(dictionaryType.ValueType, ns));
            }
            else if (compositeType != null && ns != null)
            {
                if (type.Name.Contains('<'))
                {
                    imports.AddRange(compositeType.ParseGenericType().SelectMany(t => ImportType(t, ns)));
                }
                else if (compositeType.Extensions.ContainsKey(ExternalExtension) &&
                         (bool)compositeType.Extensions[ExternalExtension])
                {
                    imports.Add(string.Join(
                                    ".",
                                    "com.microsoft.rest",
                                    type.Name));
                }
                else
                {
                    imports.Add(string.Join(
                                    ".",
                                    ns.ToLower(CultureInfo.InvariantCulture),
                                    "models",
                                    type.Name));
                }
            }
            else if (type is EnumType && ns != null)
            {
                imports.Add(string.Join(
                                ".",
                                ns.ToLower(CultureInfo.InvariantCulture),
                                "models",
                                type.Name));
            }
            else if (primaryType != null)
            {
                var importedFrom = JavaCodeNamer.ImportPrimaryType(primaryType);
                if (importedFrom != null)
                {
                    imports.Add(importedFrom);
                }
            }
            return(imports);
        }
Пример #2
0
 public ModelTemplateModel(CompositeType source, ServiceClient serviceClient)
 {
     this.LoadFrom(source);
     ServiceClient = serviceClient;
     if (source.BaseModelType != null)
     {
         _parent = new ModelTemplateModel(source.BaseModelType, serviceClient);
     }
     _namer = new JavaCodeNamer();
 }
Пример #3
0
 public ModelTemplateModel(CompositeType source, ServiceClient serviceClient)
 {
     this.LoadFrom(source);
     ServiceClient = serviceClient;
     if (source.BaseModelType != null)
     {
         _parent = new ModelTemplateModel(source.BaseModelType, serviceClient);
     }
     _namer         = new JavaCodeNamer(serviceClient.Namespace);
     PropertyModels = new List <PropertyModel>();
     Properties.ForEach(p => PropertyModels.Add(new PropertyModel(p, serviceClient.Namespace)));
 }
Пример #4
0
 public ModelTemplateModel(CompositeType source, ServiceClient serviceClient)
 {
     this.LoadFrom(source);
     ServiceClient = serviceClient;
     if(source.BaseModelType != null)
     {
         _parent = new ModelTemplateModel(source.BaseModelType, serviceClient);
     }
     _namer = new JavaCodeNamer(serviceClient.Namespace);
     PropertyModels = new List<PropertyModel>();
     Properties.ForEach(p => PropertyModels.Add(new PropertyModel(p, serviceClient.Namespace)));
 }
Пример #5
0
        /// <summary>
        /// Generates input mapping code block.
        /// </summary>
        /// <returns></returns>
        public virtual string BuildInputMappings()
        {
            var builder = new IndentedStringBuilder();

            foreach (var transformation in InputParameterTransformation)
            {
                var  nullCheck             = BuildNullCheckExpression(transformation);
                bool conditionalAssignment = !string.IsNullOrEmpty(nullCheck) && !transformation.OutputParameter.IsRequired;
                if (conditionalAssignment)
                {
                    builder.AppendLine("{0} {1} = null;",
                                       JavaCodeNamer.WrapPrimitiveType(transformation.OutputParameter.Type).Name,
                                       transformation.OutputParameter.Name);
                    builder.AppendLine("if ({0}) {{", nullCheck).Indent();
                }

                if (transformation.ParameterMappings.Any(m => !string.IsNullOrEmpty(m.OutputParameterProperty)) &&
                    transformation.OutputParameter.Type is CompositeType)
                {
                    builder.AppendLine("{0}{1} = new {2}();",
                                       !conditionalAssignment ? transformation.OutputParameter.Type.Name + " " : "",
                                       transformation.OutputParameter.Name,
                                       transformation.OutputParameter.Type.Name);
                }

                foreach (var mapping in transformation.ParameterMappings)
                {
                    builder.AppendLine("{0}{1}{2};",
                                       !conditionalAssignment && !(transformation.OutputParameter.Type is CompositeType) ?
                                       transformation.OutputParameter.Type.Name + " " : "",
                                       transformation.OutputParameter.Name,
                                       GetMapping(mapping));
                }

                if (conditionalAssignment)
                {
                    builder.Outdent()
                    .AppendLine("}");
                }
            }

            return(builder.ToString());
        }
Пример #6
0
 public MethodTemplateModel(Method source, ServiceClient serviceClient)
 {
     this.LoadFrom(source);
     ParameterTemplateModels = new List <ParameterTemplateModel>();
     source.Parameters.Where(p => p.Location == ParameterLocation.Path).ForEach(p => ParameterTemplateModels.Add(new ParameterTemplateModel(p)));
     source.Parameters.Where(p => p.Location != ParameterLocation.Path).ForEach(p => ParameterTemplateModels.Add(new ParameterTemplateModel(p)));
     ServiceClient = serviceClient;
     if (source.Group != null)
     {
         OperationName   = source.Group.ToPascalCase();
         ClientReference = "this.client";
     }
     else
     {
         OperationName   = serviceClient.Name;
         ClientReference = "this";
     }
     _namer = new JavaCodeNamer();
 }
Пример #7
0
 public JavaCodeGenerator(Settings settings) : base(settings)
 {
     Namer = new JavaCodeNamer(settings.Namespace);
 }
Пример #8
0
 public JavaCodeGenerator(Settings settings) : base(settings)
 {
     Namer = new JavaCodeNamer(settings.Namespace);
 }
Пример #9
0
 public virtual string TypeTokenType(IType type)
 {
     return(JavaCodeNamer.WrapPrimitiveType(type).Name);
 }