/// <summary> /// Convert the given interface method if it has explicit implementations. /// </summary> private void ConvertInterfaceMethod(TypeDefinition iType, MethodDefinition iMethod, Dictionary<TypeDefinition, List<TypeDefinition>> interfaceToImplementingTypes) { var implementations = GetImplementations(iMethod, interfaceToImplementingTypes); var iMethodIsJavaWithGenericParams = iMethod.IsJavaMethodWithGenericParams(); var iMethodContainsGenericParams = iMethod.ContainsGenericParameter; if (!iMethodIsJavaWithGenericParams && !iMethodContainsGenericParams && (!implementations.Any(x => x.Item2.IsExplicitImplementation()))) { // There are no explicit implementation. // No need to convert return; } // Rename method string newName; bool createExplicitStubs = true; var oldName = iMethod.Name; var attr = iMethod.GetDexOrJavaImportAttribute(); if (attr != null) { string className; string memberName; string descriptor; attr.GetDexOrJavaImportNames(iMethod, out memberName, out descriptor, out className); newName = memberName; } else if ((attr = iMethod.GetDexNameAttribute()) != null) { newName = (string) (attr.ConstructorArguments[0].Value); createExplicitStubs = false; } else { var module = reachableContext.Compiler.Module; var xiType = XBuilder.AsTypeReference(module, iType); newName = methodNames.GetUniqueName(NameConverter.GetConvertedName(xiType) + "_" + iMethod.Name); oldName = newName; } Rename(iMethod, newName); // Update implementations foreach (var typeAndImpl in implementations) { var type = typeAndImpl.Item1; var impl = typeAndImpl.Item2; if (impl.IsExplicitImplementation()) { // Convert to implicit impl.IsPublic = true; // Rename Rename(impl, newName); // Update names of overrides foreach (var @override in impl.Overrides) { @override.Name = newName; } } else if (!(impl.HasDexImportAttribute() || impl.HasJavaImportAttribute())) { // Add stub redirecting explicit implementation to implicit implementation if (createExplicitStubs/* && !type.IsInterface TODO: check what to do with interfaces*/) { CreateExplicitStub(type, impl, newName, oldName, iMethod, iMethodIsJavaWithGenericParams /*|| iMethodContainsGenericParams*/); } } } }