public static JavaInterfaceModel ParseInterface(JavaPackage package, XElement element) { var nested_name = element.XGetAttribute("name"); var visibility = element.XGetAttribute("visibility"); var deprecated = element.XGetAttribute("deprecated"); var is_static = element.XGetAttribute("static") == "true"; var jni_signature = element.XGetAttribute("jni-signature"); var model = new JavaInterfaceModel(package, nested_name, visibility, deprecated, is_static, jni_signature); if (element.XGetAttribute("merge.SourceFile") is string source && source.HasValue()) { model.PropertyBag.Add("merge.SourceFile", source); } if (element.XGetAttribute("deprecated-since") is string dep && dep.HasValue()) { model.PropertyBag.Add("deprecated-since", dep); } if (element.Element("typeParameters") is XElement tp) { ParseTypeParameters(model.TypeParameters, tp); } foreach (var child in element.Elements()) { switch (child.Name.LocalName) { case "field": model.Fields.Add(ParseField(model, child)); break; case "implements": model.Implements.Add(ParseImplements(child)); break; case "method": if (child.XGetAttribute("synthetic") != "true") { model.Methods.Add(ParseMethod(model, child)); } break; } } return(model); }
public static void GeneralPerformanceReport(string reportFilePath, JavaInterfaceModel model) { var config = new TemplateServiceConfiguration { ReferenceResolver = new MyIReferenceResolver() }; config.Namespaces = new HashSet <string>(); //config.Namespaces.Add("System"); //config.Namespaces.Add("System.Runtime"); //config.Namespaces.Add("System.Collections"); ; //config.Namespaces.Add("System.Collections.Generic"); //config.Namespaces.Add("System.Linq"); var service = RazorEngineService.Create(config); var templateContent = File.ReadAllText(@"D:\DemoAggregate\DoNetToJava\Template\JavaInterface.java"); var writer = new StringWriter(); service.RunCompile(templateContent, "TemplateKey", writer, null, model); var content = writer.ToString(); File.WriteAllText(reportFilePath, content); }
public static JavaInterfaceModel?ParseInterface(TypeDefinition type, JavaTypeCollection collection) { // TODO: type paramters? var obs_attr = GetObsoleteAttribute(type.CustomAttributes); var reg_attr = GetRegisterAttribute(type.CustomAttributes); if (reg_attr is null) { return(null); } var encoded_fullname = ((string)reg_attr.ConstructorArguments [0].Value); var(package, nested_name) = DecodeRegisterJavaFullName(encoded_fullname); var model = new JavaInterfaceModel( javaPackage: GetOrCreatePackage(collection, package, type.Namespace), javaNestedName: nested_name, javaVisibility: type.IsPublic || type.IsNestedPublic ? "public" : "protected internal", javaDeprecated: obs_attr != null ? "deprecated" : "not-deprecated", javaStatic: false, jniSignature: FormatJniSignature(package, nested_name) ); ParseImplementedInterfaces(type, model); foreach (var method in type.Methods) { if (ParseMethod(method, model) is JavaMethodModel m) { model.Methods.Add(m); } } return(model); }