Skip to content

Commit e1ad506

Browse files
atsushienojonpryor
authored andcommitted
[class-parse] Fix Java parameter loader for generics involved methods. (#215)
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<K,V>`), they resulted in java.util.Map<X,Y> whereas API XML contains java.util.Map<X, Y> (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.
1 parent 1bcfcc5 commit e1ad506

File tree

6 files changed

+81
-11
lines changed

6 files changed

+81
-11
lines changed

src/Xamarin.Android.Tools.Bytecode/JavaParameterNamesLoader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ List<Package> LoadParameterFixupDescription (string path)
9797
Name = name,
9898
Parameters = parameters.Replace (", ", "\0").Split ('\0')
9999
.Select (s => s.Split (' '))
100-
.Select (a => new Parameter { Type = string.Join (" ", a.Take (a.Length - 1)), Name = a.Last () }).ToList ()
100+
.Select (a => new Parameter { Type = string.Join (" ", a.Take (a.Length - 1)).Replace (",", ", "), Name = a.Last () }).ToList ()
101101
});
102102
} else {
103103
type = line.Substring (line.IndexOf (' ', 2) + 1);

src/Xamarin.Android.Tools.Bytecode/Tests/ParameterDescription.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ package java.util ; Anything after semicolon is comment.
44
class Collection<E>
55
add(E e)
66
#ctor()
7+
8+
package com.xamarin
9+
interface NestedInterface.DnsSdTxtRecordListener
10+
onDnsSdTxtRecordAvailable(java.lang.String fullDomainName, java.util.Map<java.lang.String,java.lang.String> txtRecordMap, java.lang.String srcDevice)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<api
2+
api-source="class-parse">
3+
<package
4+
name="com.xamarin"
5+
jni-name="com/xamarin">
6+
<interface
7+
abstract="true"
8+
deprecated="not deprecated"
9+
final="false"
10+
name="NestedInterface.DnsSdTxtRecordListener"
11+
jni-signature="Lcom/xamarin/NestedInterface$DnsSdTxtRecordListener;"
12+
static="true"
13+
visibility="public">
14+
<method
15+
abstract="true"
16+
deprecated="not deprecated"
17+
final="false"
18+
name="onDnsSdTxtRecordAvailable"
19+
native="false"
20+
return="void"
21+
jni-return="V"
22+
static="false"
23+
synchronized="false"
24+
visibility="public"
25+
bridge="false"
26+
synthetic="false"
27+
jni-signature="(Ljava/lang/String;Ljava/util/Map;Ljava/lang/String;)V">
28+
<parameter
29+
name="fullDomainName"
30+
type="java.lang.String"
31+
jni-type="Ljava/lang/String;" />
32+
<parameter
33+
name="txtRecordMap"
34+
type="java.util.Map&lt;java.lang.String, java.lang.String&gt;"
35+
jni-type="Ljava/util/Map&lt;Ljava/lang/String;Ljava/lang/String;&gt;;" />
36+
<parameter
37+
name="srcDevice"
38+
type="java.lang.String"
39+
jni-type="Ljava/lang/String;" />
40+
</method>
41+
</interface>
42+
</package>
43+
</api>

src/Xamarin.Android.Tools.Bytecode/Tests/ParameterFixupTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ public void XmlDeclaration_FixedUpFromParameterDescription ()
102102
if (File.Exists (tempFile))
103103
File.Delete (tempFile);
104104
}
105+
106+
try {
107+
tempFile = LoadToTempFile ("ParameterDescription.txt");
108+
109+
AssertXmlDeclaration (new string [] { "NestedInterface$DnsSdTxtRecordListener.class" }, "ParameterFixupFromDescriptionText.xml", tempFile);
110+
} finally {
111+
if (File.Exists (tempFile))
112+
File.Delete (tempFile);
113+
}
105114
}
106115
}
107116
}

src/Xamarin.Android.Tools.Bytecode/Tests/Xamarin.Android.Tools.Bytecode-Tests.csproj

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,9 @@
5757
<Compile Include="ParameterFixupTests.cs" />
5858
</ItemGroup>
5959
<ItemGroup>
60-
<TestJar
61-
Include="java\**\*.java"
62-
Exclude="java\java\util\Collection.java"
63-
/>
64-
<TestJarNoParameters
65-
Include="java\java\util\Collection.java"
66-
/>
60+
<TestJar Include="java\**\*.java" Exclude="java\java\util\Collection.java" />
61+
<TestJarNoParameters Include="java\java\util\Collection.java" />
62+
<TestJar Include="java\com\xamarin\NestedInterface.java" />
6763
</ItemGroup>
6864
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
6965
<PropertyGroup>
@@ -74,8 +70,8 @@
7470
</PropertyGroup>
7571
<Target Name="BuildClasses" Inputs="@(TestJar)" Outputs="@(TestJar-&gt;'$(IntermediateOutputPath)classes\%(RecursiveDir)%(Filename).class')">
7672
<MakeDir Directories="$(IntermediateOutputPath)classes" />
77-
<Exec Command="&quot;$(JavaCPath)&quot; -parameters -source 1.5 -target 1.6 -g -d &quot;$(IntermediateOutputPath)classes&quot; @(TestJar->'%(Identity)', ' ')" />
78-
<Exec Command="&quot;$(JavaCPath)&quot; -source 1.5 -target 1.6 -g -d &quot;$(IntermediateOutputPath)classes&quot; @(TestJarNoParameters->'%(Identity)', ' ')" />
73+
<Exec Command="&quot;$(JavaCPath)&quot; -parameters -source 1.5 -target 1.6 -g -d &quot;$(IntermediateOutputPath)classes&quot; @(TestJar-&gt;'%(Identity)', ' ')" />
74+
<Exec Command="&quot;$(JavaCPath)&quot; -source 1.5 -target 1.6 -g -d &quot;$(IntermediateOutputPath)classes&quot; @(TestJarNoParameters-&gt;'%(Identity)', ' ')" />
7975
</Target>
8076
<ItemGroup>
8177
<ProjectReference Include="..\Xamarin.Android.Tools.Bytecode.csproj">
@@ -141,6 +137,9 @@
141137
<EmbeddedResource Include="$(IntermediateOutputPath)classes\com\xamarin\IJavaInterface.class">
142138
<LogicalName>IJavaInterface.class</LogicalName>
143139
</EmbeddedResource>
140+
<EmbeddedResource Include="$(IntermediateOutputPath)classes\com\xamarin\NestedInterface$DnsSdTxtRecordListener.class">
141+
<LogicalName>NestedInterface$DnsSdTxtRecordListener.class</LogicalName>
142+
</EmbeddedResource>
144143
<EmbeddedResource Include="$(IntermediateOutputPath)classes\NonGenericGlobalType.class">
145144
<LogicalName>NonGenericGlobalType.class</LogicalName>
146145
</EmbeddedResource>
@@ -164,7 +163,11 @@
164163
</EmbeddedResource>
165164
<EmbeddedResource Include="ParameterDescription.txt">
166165
<LogicalName>ParameterDescription.txt</LogicalName>
167-
</EmbeddedResource> </ItemGroup>
166+
</EmbeddedResource>
167+
<EmbeddedResource Include="ParameterFixupFromDescriptionText.xml">
168+
<LogicalName>ParameterFixupFromDescriptionText.xml</LogicalName>
169+
</EmbeddedResource>
170+
</ItemGroup>
168171
<ItemGroup>
169172
<None Include="packages.config" />
170173
</ItemGroup>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.xamarin;
2+
3+
import java.util.Map;
4+
5+
public class NestedInterface
6+
{
7+
public interface DnsSdTxtRecordListener
8+
{
9+
void onDnsSdTxtRecordAvailable(String p1, Map<String, String> p2, String p3);
10+
}
11+
}

0 commit comments

Comments
 (0)