public NameResoltionCache(BindingDatabase database, CompilationUnit unit, IList <TypeName> parcelableNames) { this.database = database; this.unit = unit; parcelable_names = parcelableNames; cache ["IBinder"] = "Android.OS.IBinder"; cache ["CharSequence"] = "Java.Lang.ICharSequence"; cache ["List"] = "Android.Runtime.JavaList"; cache ["Map"] = "Android.Runtime.JavaDictionary"; }
// This overload is primarily for unit tests. public Result Run(string input, out string output, AssemblyDefinition[] references = null, ParcelableHandling parcelableHandling = ParcelableHandling.Ignore) { var result = new Result(); var database = new BindingDatabase(references ?? Array.Empty <AssemblyDefinition> ()); var lang = new LanguageData(new AidlGrammar() { LanguageFlags = LanguageFlags.Default | LanguageFlags.CreateAst }); var parser = new Parser(lang); var pt = parser.Parse(input); if (pt.HasErrors()) { foreach (var l in pt.ParserMessages) { result.LogMessages.Add("input.aidl", l); } output = null; return(result); } var unit = (CompilationUnit)pt.Root.AstNode; var parcelables = new List <TypeName> (); foreach (Parcelable t in unit.Types.Where(t => t is Parcelable)) { parcelables.Add(unit.Package == null ? t.Name : new TypeName(unit.Package.Identifiers.Concat(t.Name.Identifiers).ToArray())); } var sw = new StringWriter(); var opts = new ConverterOptions { ParcelableHandling = parcelableHandling }; new CSharpCodeGenerator(sw, database).GenerateCode(unit, parcelables, opts); output = sw.ToString(); return(result); }
public Result Run(ConverterOptions opts, Func<string,AssemblyDefinition> resolveAssembly, Func<string,string,string> outputFilenameSelector) { var result = new Result (); var database = new BindingDatabase (opts.References, resolveAssembly); var lang = new LanguageData (new AidlGrammar () { LanguageFlags = LanguageFlags.Default | LanguageFlags.CreateAst }); var parser = new Parser (lang); output_path = opts.OutputDirectory; output_ns = opts.OutputNS; foreach (var file in opts.InputFiles) { var pt = parser.Parse (File.ReadAllText (file), file); if (pt.HasErrors ()) foreach (var l in pt.ParserMessages) result.LogMessages.Add (file, l); else units.Add (file, (CompilationUnit) pt.Root.AstNode); } if (result.LogMessages.Any (e => e.Value.Level == Irony.ErrorLevel.Error)) return result; if (output_path != null && !Directory.Exists (output_path)) Directory.CreateDirectory (output_path); output_path = output_path ?? "./"; var parcelables = new List<TypeName> (); foreach (var u in units.Values) foreach (Parcelable t in u.Types.Where (t => t is Parcelable)) parcelables.Add (u.Package == null ? t.Name : new TypeName (u.Package.Identifiers.Concat (t.Name.Identifiers).ToArray ())); foreach (var pair in units) { string file = outputFilenameSelector (output_path, pair.Key); var sw = new StringWriter (); new CSharpCodeGenerator (sw, database).GenerateCode (pair.Value, parcelables, opts); string csharp = sw.ToString (); if (pair.Value.Package != null && output_ns != null) csharp = csharp.Replace (pair.Value.Package.ToString (), output_ns); using (var fw = File.CreateText (file)) fw.Write (csharp); FileWritten (file, csharp); } return result; }
public Result Run(ConverterOptions opts, Func <string, AssemblyDefinition> resolveAssembly, Func <string, string, string> outputFilenameSelector) { var result = new Result(); var database = new BindingDatabase(opts.References, resolveAssembly); var lang = new LanguageData(new AidlGrammar() { LanguageFlags = LanguageFlags.Default | LanguageFlags.CreateAst }); var parser = new Parser(lang); output_path = opts.OutputDirectory; output_ns = opts.OutputNS; foreach (var file in opts.InputFiles) { var pt = parser.Parse(File.ReadAllText(file), file); if (pt.HasErrors()) { foreach (var l in pt.ParserMessages) { result.LogMessages.Add(file, l); } } else { units.Add(file, (CompilationUnit)pt.Root.AstNode); } } if (result.LogMessages.Any(e => e.Value.Level == Irony.ErrorLevel.Error)) { return(result); } if (output_path != null && !Directory.Exists(output_path)) { Directory.CreateDirectory(output_path); } output_path = output_path ?? "./"; var parcelables = new List <TypeName> (); foreach (var u in units.Values) { foreach (Parcelable t in u.Types.Where(t => t is Parcelable)) { parcelables.Add(u.Package == null ? t.Name : new TypeName(u.Package.Identifiers.Concat(t.Name.Identifiers).ToArray())); } } foreach (var pair in units) { string file = outputFilenameSelector(output_path, pair.Key); var sw = new StringWriter(); new CSharpCodeGenerator(sw, database).GenerateCode(pair.Value, parcelables, opts); string csharp = sw.ToString(); if (pair.Value.Package != null && output_ns != null) { csharp = csharp.Replace(pair.Value.Package.ToString(), output_ns); } using (var fw = File.CreateText(file)) fw.Write(csharp); FileWritten(file, csharp); } return(result); }
public CSharpCodeGenerator(TextWriter writer, BindingDatabase database) { w = writer; this.database = database; }
public NameResoltionCache(BindingDatabase database, CompilationUnit unit, IList<TypeName> parcelableNames) { this.database = database; this.unit = unit; parcelable_names = parcelableNames; cache ["IBinder"] = "Android.OS.IBinder"; cache ["CharSequence"] = "Java.Lang.ICharSequence"; cache ["List"] = "Android.Runtime.JavaList"; cache ["Map"] = "Android.Runtime.JavaDictionary"; }
public CSharpCodeGenerator(TextWriter writer, BindingDatabase database) { w = writer; this.database = database; }