Ejemplo n.º 1
0
 private string ProcessFileTemplate(string args)
 {
     Int32 eolMode = (Int32)MainForm.Settings.EOLMode;
     String lineBreak = LineEndDetector.GetNewLineMarker(eolMode);
     ClassModel cmodel;
     List<String> imports = new List<string>();
     string extends = "";
     string implements = "";
     string access = "";
     string inheritedMethods = "";
     string paramString = "";
     string superConstructor = "";
     string classMetadata = "";
     int index;
     // resolve imports
     if (lastFileOptions.interfaces != null && lastFileOptions.interfaces.Count > 0)
     {
         bool isHaxe2 = PluginBase.CurrentSDK != null && PluginBase.CurrentSDK.Name.ToLower().Contains("haxe 2");
         implements = " implements ";
         string[] _implements;
         index = 0;
         foreach (string item in lastFileOptions.interfaces)
         {
             if (item.Split('.').Length > 1) imports.Add(item);
             _implements = item.Split('.');
             implements += (index > 0 ? (isHaxe2 ? ", implements " : ", ") : "") + _implements[_implements.Length - 1];
             if (lastFileOptions.createInheritedMethods)
             {
                 processOnSwitch = lastFileFromTemplate; 
                 // let ASCompletion generate the implementations when file is opened
             }
             index++;
         }
     }
     if (lastFileOptions.superClass != "")
     {
         String super = lastFileOptions.superClass;
         if (lastFileOptions.superClass.Split('.').Length > 1) imports.Add(super);
         string[] _extends = super.Split('.');
         extends = " extends " + _extends[_extends.Length - 1];
         processContext = ASContext.GetLanguageContext(lastFileOptions.Language);
         if (lastFileOptions.createConstructor && processContext != null && constructorArgs == null)
         {
             cmodel = processContext.GetModel(super.LastIndexOf('.') < 0 ? "" : super.Substring(0, super.LastIndexOf('.')), _extends[_extends.Length - 1], "");
             if (!cmodel.IsVoid())
             {
                 foreach (MemberModel member in cmodel.Members)
                 {
                     if (member.Name == cmodel.Constructor)
                     {
                         paramString = member.ParametersString();
                         AddImports(imports, member, cmodel);
                         superConstructor = "super(";
                         index = 0;
                         if (member.Parameters != null)
                         foreach (MemberModel param in member.Parameters)
                         {
                             if (param.Name.StartsWith('.')) break;
                             var pname = TemplateUtils.GetParamName(param);
                             superConstructor += (index > 0 ? ", " : "") + pname;
                             index++;
                         }
                         superConstructor += ");\n" + (lastFileOptions.Language == "as3" ? "\t\t\t" : "\t\t");
                         break;
                     }
                 }
             }
         }
         processContext = null;
     }
     if (constructorArgs != null)
     {
         paramString = constructorArgs;
         foreach (String type in constructorArgTypes)
         {
             if (!imports.Contains(type))
             {
                 imports.Add(type);
             }
         }
     }
     if (lastFileOptions.Language == "as3")
     {
         access = lastFileOptions.isPublic ? "public " : "internal ";
         access += lastFileOptions.isDynamic ? "dynamic " : "";
         access += lastFileOptions.isFinal ? "final " : "";
     }
     else if (lastFileOptions.Language == "haxe")
     {
         access = lastFileOptions.isPublic ? "public " : "private ";
         access += lastFileOptions.isDynamic ? "dynamic " : "";
         if (lastFileOptions.isFinal) classMetadata += "@:final\n";
     }
     else
     {
         access = lastFileOptions.isDynamic ? "dynamic " : "";
     }
     string importsSrc = "";
     string prevImport = null;
     imports.Sort();
     foreach (string import in imports)
     {
         if (prevImport != import)
         {
             prevImport = import;
             if (import.LastIndexOf('.') == -1) continue;
             if (import.Substring(0, import.LastIndexOf('.')) == lastFileOptions.Package) continue;
             importsSrc += (lastFileOptions.Language == "as3" ? "\t" : "") + "import " + import + ";" + lineBreak;
         }
     }
     if (importsSrc.Length > 0)
     {
         importsSrc += (lastFileOptions.Language == "as3" ? "\t" : "") + lineBreak;
     }
     args = args.Replace("$(Import)", importsSrc);
     args = args.Replace("$(Extends)", extends);
     args = args.Replace("$(Implements)", implements);
     args = args.Replace("$(Access)", access);
     args = args.Replace("$(InheritedMethods)", inheritedMethods);
     args = args.Replace("$(ConstructorArguments)", paramString);
     args = args.Replace("$(Super)", superConstructor);
     args = args.Replace("$(ClassMetadata)", classMetadata);
     return args;
 }