private static MethodDefinition DeclareMethod(AssemblyDefinition assembly, JavaClass jc, JavaMethod jm) { string name = IdentifierHelper.GetDotNetFullName(jm.GetName(jc)); MethodAttributes attributes = jm.GetAttributes(); ModuleDefinition module = assembly.MainModule; string returnTypeName = jm.GetReturnType(jc); TypeReference returnType = module.GetDescriptorType(returnTypeName); if (name == ".ctor" || name == ".cctor") { attributes |= MethodAttributes.SpecialName | MethodAttributes.RTSpecialName; attributes &= ~MethodAttributes.Virtual; } MethodDefinition result = new MethodDefinition(name, attributes, returnType); string[] parameterTypes = jm.GetParameterTypes(jc); string[] parameterNames = jm.GetParameterNames(jc); for (int i = 0; i < parameterTypes.Length; i++) { result.Parameters.Add(new ParameterDefinition(parameterNames[i], ParameterAttributes.None, module.GetDescriptorType(parameterTypes[i]))); } return(result); }
private static TypeDefinition ConvertClass(JavaClass jc) { string className = $"{jc.GetPackageName()}{jc.GetName()}"; string dotnetNamespace = IdentifierHelper.GetDotNetNamespace(className); string dotnetClass = IdentifierHelper.GetDotNetClassName(className); TypeDefinition result = new TypeDefinition(dotnetNamespace, dotnetClass, jc.GetAttributes()); return(result); }
/// <summary> /// Gets the type reference from a module from a java type names. /// </summary> /// <param name="module">The module.</param> /// <param name="javaTypeName">Name of the java type.</param> /// <returns>The type reference.</returns> public static TypeReference GetJavaType(this ModuleDefinition module, string javaTypeName) { Guard.NotNull(ref module, nameof(module)); Guard.NotNull(ref javaTypeName, nameof(javaTypeName)); if (javaTypeName[0] == '[') { return(module.GetDescriptorType(javaTypeName)); } string dotnetNamespace = IdentifierHelper.GetDotNetNamespace(javaTypeName); string dotnetClass = IdentifierHelper.GetDotNetClassName(javaTypeName); return(module.GetType(dotnetNamespace, dotnetClass)); }