Skip to content

Commit e8be497

Browse files
committed
[Java.Interop] Type & Member Remapping Support
Context: #867 Type fallback: done. InTune support: done? * Rename instance methods done * Rename static methods done * "Move" instance methods to static methods done * Replacement type: done
1 parent d3f0c5c commit e8be497

21 files changed

+1519
-279
lines changed

src/Java.Interop/Java.Interop.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
<OutputPath>$(ToolOutputFullPath)</OutputPath>
2727
<DocumentationFile>$(ToolOutputFullPath)Java.Interop.xml</DocumentationFile>
2828
<JNIEnvGenPath>$(BuildToolOutputFullPath)</JNIEnvGenPath>
29-
<LangVersion>8.0</LangVersion>
29+
<LangVersion Condition=" '$(JIBuildingForNetCoreApp)' == 'True' ">9.0</LangVersion>
30+
<LangVersion Condition=" '$(LangVersion)' == '' ">8.0</LangVersion>
3031
<Nullable>enable</Nullable>
3132
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
3233
<MSBuildWarningsAsMessages>NU1702</MSBuildWarningsAsMessages>

src/Java.Interop/Java.Interop/JavaArray.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ bool IList.IsFixedSize {
231231

232232
object? IList.this [int index] {
233233
get {return this [index];}
234-
#pragma warning disable 8601
234+
#pragma warning disable 8600,8601
235235
set {this [index] = (T) value;}
236-
#pragma warning restore 8601
236+
#pragma warning restore 8600,8601
237237
}
238238

239239
void ICollection.CopyTo (Array array, int index)

src/Java.Interop/Java.Interop/JniMethodInfo.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ public sealed class JniMethodInfo
1010

1111
public bool IsStatic {get; private set;}
1212

13+
#if NET
14+
internal JniType? StaticRedirect;
15+
internal int? ParameterCount;
16+
#endif //NET
17+
1318
internal bool IsValid {
1419
get {return ID != IntPtr.Zero;}
1520
}

src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods.cs

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,59 @@ internal JniInstanceMethods GetConstructorsForType (Type declaringType)
8484
public JniMethodInfo GetMethodInfo (string encodedMember)
8585
{
8686
lock (InstanceMethods) {
87-
if (!InstanceMethods.TryGetValue (encodedMember, out var m)) {
88-
string method, signature;
89-
JniPeerMembers.GetNameAndSignature (encodedMember, out method, out signature);
90-
m = JniPeerType.GetInstanceMethod (method, signature);
91-
InstanceMethods.Add (encodedMember, m);
87+
if (InstanceMethods.TryGetValue (encodedMember, out var m)) {
88+
return m;
9289
}
93-
return m;
9490
}
91+
string method, signature;
92+
JniPeerMembers.GetNameAndSignature (encodedMember, out method, out signature);
93+
var info = GetMethodInfo (method, signature);
94+
lock (InstanceMethods) {
95+
if (InstanceMethods.TryGetValue (encodedMember, out var m)) {
96+
return m;
97+
}
98+
InstanceMethods.Add (encodedMember, info);
99+
}
100+
return info;
95101
}
96102

103+
JniMethodInfo GetMethodInfo (string method, string signature)
104+
{
105+
#if NET
106+
var m = (JniMethodInfo?) null;
107+
var newMethod = JniEnvironment.Runtime.TypeManager.GetReplacementMethodInfo (Members.JniPeerTypeName, method, signature);
108+
if (newMethod.HasValue) {
109+
using var t = new JniType (newMethod.Value.JniTargetType ?? JniPeerType.Name);
110+
if (newMethod.Value.TargetJniMethodIsStatic && t.TryGetStaticMethod (
111+
newMethod.Value.TargetJniMethodName ?? method,
112+
newMethod.Value.TargetJniMethodSignature ?? signature,
113+
out m)) {
114+
m.ParameterCount = newMethod.Value.TargetJniMethodParameterCount;
115+
m.StaticRedirect = new JniType (newMethod.Value.JniTargetType ?? JniPeerType.Name);
116+
return m;
117+
}
118+
if (t.TryGetInstanceMethod (
119+
newMethod.Value.TargetJniMethodName ?? method,
120+
newMethod.Value.TargetJniMethodSignature ?? signature,
121+
out m)) {
122+
return m;
123+
}
124+
}
125+
if (JniPeerType.TryGetInstanceMethod (method, signature, out m)) {
126+
return m;
127+
}
128+
var fallbackTypes = JniEnvironment.Runtime.TypeManager.GetFallbackTypes (Members.JniPeerTypeName);
129+
if (fallbackTypes != null) {
130+
foreach (var ft in fallbackTypes) {
131+
using var t = new JniType (ft);
132+
if (t.TryGetInstanceMethod (method, signature, out m)) {
133+
return m;
134+
}
135+
}
136+
}
137+
#endif // NET
138+
return JniPeerType.GetInstanceMethod (method, signature);
139+
}
97140
public unsafe JniObjectReference StartCreateInstance (string constructorSignature, Type declaringType, JniArgumentValue* parameters)
98141
{
99142
if (constructorSignature == null)

0 commit comments

Comments
 (0)