static string Generate(Type type, string applicationJavaClass = null) { var td = SupportDeclarations.GetTypeDefinition(type); var g = new JavaCallableWrapperGenerator(td, null) { ApplicationJavaClass = applicationJavaClass, }; var o = new StringWriter(); g.Generate("__o"); g.Generate(o); return(o.ToString()); }
static string Generate(Type type, string applicationJavaClass = null) { var td = SupportDeclarations.GetTypeDefinition(type); var g = new JavaCallableWrapperGenerator(td, null) { ApplicationJavaClass = applicationJavaClass, }; var o = new StringWriter(); var dir = Path.GetDirectoryName(typeof(JavaCallableWrapperGeneratorTests).Assembly.Location); g.Generate(Path.Combine(dir, "__o")); g.Generate(o); return(o.ToString()); }
static string Generate(Type type, string applicationJavaClass = null, string monoRuntimeInit = null) { var td = SupportDeclarations.GetTypeDefinition(type); var g = new JavaCallableWrapperGenerator(td, log: null, cache: null) { ApplicationJavaClass = applicationJavaClass, GenerateOnCreateOverrides = true, MonoRuntimeInitialization = monoRuntimeInit, }; var o = new StringWriter(); var dir = Path.GetDirectoryName(typeof(JavaCallableWrapperGeneratorTests).Assembly.Location); g.Generate(Path.Combine(dir, "__o")); g.Generate(o); return(o.ToString()); }
static void GenerateJavaCallableWrapper(TypeDefinition type, string outputPath) { var generator = new JavaCallableWrapperGenerator(type, log: Console.WriteLine) { }; generator.Generate(outputPath); }
public static bool CreateJavaSources(TaskLoggingHelper log, IEnumerable <TypeDefinition> javaTypes, string outputPath, string applicationJavaClass, string androidSdkPlatform, bool useSharedRuntime, bool generateOnCreateOverrides, bool hasExportReference) { string monoInit = GetMonoInitSource(androidSdkPlatform, useSharedRuntime); bool ok = true; using (var memoryStream = new MemoryStream()) using (var writer = new StreamWriter(memoryStream)) { foreach (var t in javaTypes) { //Reset for reuse memoryStream.SetLength(0); try { var jti = new JavaCallableWrapperGenerator(t, log.LogWarning) { GenerateOnCreateOverrides = generateOnCreateOverrides, ApplicationJavaClass = applicationJavaClass, MonoRuntimeInitialization = monoInit, }; jti.Generate(writer); writer.Flush(); var path = jti.GetDestinationPath(outputPath); MonoAndroidHelper.CopyIfStreamChanged(memoryStream, path); if (jti.HasExport && !hasExportReference) { Diagnostic.Error(4210, "You need to add a reference to Mono.Android.Export.dll when you use ExportAttribute or ExportFieldAttribute."); } } catch (XamarinAndroidException xae) { ok = false; log.LogError( subcategory: "", errorCode: "XA" + xae.Code, helpKeyword: string.Empty, file: xae.SourceFile, lineNumber: xae.SourceLine, columnNumber: 0, endLineNumber: 0, endColumnNumber: 0, message: xae.MessageWithoutCode, messageArgs: new object [0] ); } catch (Exception ex) { ok = false; Diagnostic.Error(4209, "Failed to create JavaTypeInfo for class: {0} due to {1}", t.FullName, ex); } } } return(ok); }
static void GenerateJavaCallableWrapper(TypeDefinition type, string outputPath, TypeDefinitionCache cache) { if (type.IsInterface) { return; } var generator = new JavaCallableWrapperGenerator(type, log: Console.WriteLine, cache) { }; generator.Generate(outputPath); }
static void GenerateJavaSource(TaskLoggingHelper log, TypeDefinition t, string outputPath, bool useSharedRuntime, bool generateOnCreateOverrides, bool hasExportReference) { try { var jti = new JavaCallableWrapperGenerator (t, log.LogWarning) { UseSharedRuntime = useSharedRuntime, GenerateOnCreateOverrides = generateOnCreateOverrides, }; jti.Generate (outputPath); if (jti.HasExport && !hasExportReference) Diagnostic.Error (4210, "You need to add a reference to Mono.Android.Export.dll when you use ExportAttribute or ExportFieldAttribute."); } catch (Exception ex) { if (ex is XamarinAndroidException) throw; Diagnostic.Error (4209, "Failed to create JavaTypeInfo for class: {0} due to {1}", t.FullName, ex); } }
static void GenerateJavaSource(TaskLoggingHelper log, TypeDefinition t, string outputPath, bool useSharedRuntime, bool generateOnCreateOverrides, bool hasExportReference) { try { var jti = new JavaCallableWrapperGenerator(t, log.LogWarning) { UseSharedRuntime = useSharedRuntime, GenerateOnCreateOverrides = generateOnCreateOverrides, }; jti.Generate(outputPath); if (jti.HasExport && !hasExportReference) { Diagnostic.Error(4210, "You need to add a reference to Mono.Android.Export.dll when you use ExportAttribute or ExportFieldAttribute."); } } catch (Exception ex) { if (ex is XamarinAndroidException) { throw; } Diagnostic.Error(4209, "Failed to create JavaTypeInfo for class: {0} due to {1}", t.FullName, ex); } }
bool CreateJavaSources(IEnumerable <TypeDefinition> javaTypes, TypeDefinitionCache cache) { string outputPath = Path.Combine(OutputDirectory, "src"); string monoInit = GetMonoInitSource(AndroidSdkPlatform); bool hasExportReference = ResolvedAssemblies.Any(assembly => Path.GetFileName(assembly.ItemSpec) == "Mono.Android.Export.dll"); bool generateOnCreateOverrides = int.Parse(AndroidSdkPlatform) <= 10; bool ok = true; foreach (var t in javaTypes) { using (var writer = MemoryStreamPool.Shared.CreateStreamWriter()) { try { var jti = new JavaCallableWrapperGenerator(t, Log.LogWarning, cache) { GenerateOnCreateOverrides = generateOnCreateOverrides, ApplicationJavaClass = ApplicationJavaClass, MonoRuntimeInitialization = monoInit, }; jti.Generate(writer); writer.Flush(); var path = jti.GetDestinationPath(outputPath); MonoAndroidHelper.CopyIfStreamChanged(writer.BaseStream, path); if (jti.HasExport && !hasExportReference) { Diagnostic.Error(4210, Properties.Resources.XA4210); } } catch (XamarinAndroidException xae) { ok = false; Log.LogError( subcategory: "", errorCode: "XA" + xae.Code, helpKeyword: string.Empty, file: xae.SourceFile, lineNumber: xae.SourceLine, columnNumber: 0, endLineNumber: 0, endColumnNumber: 0, message: xae.MessageWithoutCode, messageArgs: new object [0] ); } catch (DirectoryNotFoundException ex) { ok = false; if (OS.IsWindows) { Diagnostic.Error(5301, Properties.Resources.XA5301, t.FullName, ex); } else { Diagnostic.Error(4209, Properties.Resources.XA4209, t.FullName, ex); } } catch (Exception ex) { ok = false; Diagnostic.Error(4209, Properties.Resources.XA4209, t.FullName, ex); } } } return(ok); }