From b5ec669f88dbf095879ab57264fd3b2c53ac9afd Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Wed, 15 Nov 2017 16:26:20 -0500 Subject: [PATCH] [class-parse] Fix Java parameter loader for generics involved methods. When there is a method that takes one or more parameters that are generic instances whose type definition contains more than one type parameters (e.g. `java.util.Map`), they resulted in java.util.Map whereas API XML contains java.util.Map (notice the extra space between generic arguments) and method type matching failed. We should not change parameter definitions format (it is clearly declared to NOT contain spaces within generic arguments), so expand that at loader. --- .../JavaParameterNamesLoader.cs | 2 +- .../Tests/ParameterDescription.txt | 4 ++ .../ParameterFixupFromDescriptionText.xml | 43 +++++++++++++++++++ .../Tests/ParameterFixupTests.cs | 9 ++++ ...amarin.Android.Tools.Bytecode-Tests.csproj | 23 +++++----- .../java/com/xamarin/NestedInterface.java | 11 +++++ 6 files changed, 81 insertions(+), 11 deletions(-) create mode 100644 src/Xamarin.Android.Tools.Bytecode/Tests/ParameterFixupFromDescriptionText.xml create mode 100644 src/Xamarin.Android.Tools.Bytecode/Tests/java/com/xamarin/NestedInterface.java diff --git a/src/Xamarin.Android.Tools.Bytecode/JavaParameterNamesLoader.cs b/src/Xamarin.Android.Tools.Bytecode/JavaParameterNamesLoader.cs index 5194352cf..9f659a07a 100644 --- a/src/Xamarin.Android.Tools.Bytecode/JavaParameterNamesLoader.cs +++ b/src/Xamarin.Android.Tools.Bytecode/JavaParameterNamesLoader.cs @@ -97,7 +97,7 @@ List LoadParameterFixupDescription (string path) Name = name, Parameters = parameters.Replace (", ", "\0").Split ('\0') .Select (s => s.Split (' ')) - .Select (a => new Parameter { Type = string.Join (" ", a.Take (a.Length - 1)), Name = a.Last () }).ToList () + .Select (a => new Parameter { Type = string.Join (" ", a.Take (a.Length - 1)).Replace (",", ", "), Name = a.Last () }).ToList () }); } else { type = line.Substring (line.IndexOf (' ', 2) + 1); diff --git a/src/Xamarin.Android.Tools.Bytecode/Tests/ParameterDescription.txt b/src/Xamarin.Android.Tools.Bytecode/Tests/ParameterDescription.txt index 9c0e8c3cd..db04a6149 100644 --- a/src/Xamarin.Android.Tools.Bytecode/Tests/ParameterDescription.txt +++ b/src/Xamarin.Android.Tools.Bytecode/Tests/ParameterDescription.txt @@ -4,3 +4,7 @@ package java.util ; Anything after semicolon is comment. class Collection add(E e) #ctor() + +package com.xamarin + interface NestedInterface.DnsSdTxtRecordListener + onDnsSdTxtRecordAvailable(java.lang.String fullDomainName, java.util.Map txtRecordMap, java.lang.String srcDevice) diff --git a/src/Xamarin.Android.Tools.Bytecode/Tests/ParameterFixupFromDescriptionText.xml b/src/Xamarin.Android.Tools.Bytecode/Tests/ParameterFixupFromDescriptionText.xml new file mode 100644 index 000000000..dd18f3294 --- /dev/null +++ b/src/Xamarin.Android.Tools.Bytecode/Tests/ParameterFixupFromDescriptionText.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + diff --git a/src/Xamarin.Android.Tools.Bytecode/Tests/ParameterFixupTests.cs b/src/Xamarin.Android.Tools.Bytecode/Tests/ParameterFixupTests.cs index 4faac0120..2c2191d72 100644 --- a/src/Xamarin.Android.Tools.Bytecode/Tests/ParameterFixupTests.cs +++ b/src/Xamarin.Android.Tools.Bytecode/Tests/ParameterFixupTests.cs @@ -102,6 +102,15 @@ public void XmlDeclaration_FixedUpFromParameterDescription () if (File.Exists (tempFile)) File.Delete (tempFile); } + + try { + tempFile = LoadToTempFile ("ParameterDescription.txt"); + + AssertXmlDeclaration (new string [] { "NestedInterface$DnsSdTxtRecordListener.class" }, "ParameterFixupFromDescriptionText.xml", tempFile); + } finally { + if (File.Exists (tempFile)) + File.Delete (tempFile); + } } } } diff --git a/src/Xamarin.Android.Tools.Bytecode/Tests/Xamarin.Android.Tools.Bytecode-Tests.csproj b/src/Xamarin.Android.Tools.Bytecode/Tests/Xamarin.Android.Tools.Bytecode-Tests.csproj index 0cd24b389..ec7794584 100644 --- a/src/Xamarin.Android.Tools.Bytecode/Tests/Xamarin.Android.Tools.Bytecode-Tests.csproj +++ b/src/Xamarin.Android.Tools.Bytecode/Tests/Xamarin.Android.Tools.Bytecode-Tests.csproj @@ -57,13 +57,9 @@ - - + + + @@ -74,8 +70,8 @@ - - + + @@ -141,6 +137,9 @@ IJavaInterface.class + + NestedInterface$DnsSdTxtRecordListener.class + NonGenericGlobalType.class @@ -164,7 +163,11 @@ ParameterDescription.txt - + + + ParameterFixupFromDescriptionText.xml + + diff --git a/src/Xamarin.Android.Tools.Bytecode/Tests/java/com/xamarin/NestedInterface.java b/src/Xamarin.Android.Tools.Bytecode/Tests/java/com/xamarin/NestedInterface.java new file mode 100644 index 000000000..ecd8cdc4a --- /dev/null +++ b/src/Xamarin.Android.Tools.Bytecode/Tests/java/com/xamarin/NestedInterface.java @@ -0,0 +1,11 @@ +package com.xamarin; + +import java.util.Map; + +public class NestedInterface +{ + public interface DnsSdTxtRecordListener + { + void onDnsSdTxtRecordAvailable(String p1, Map p2, String p3); + } +}