You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Java.Base, generator] Bind all of package java.lang (#966)
Context: bc5bcf4
Bind all classes and interfaces in the `java.lang` package.
Alter Java array binding, so that instead of `IList<T>`, we get
"direct" Java arrays, e.g.
namespace Java.Lang {
partial class Character {
// Previous/Xamarin.Android-like
public static int CodePointAt (IList<char>? a, int index);
// New/Desktop
public static int CodePointAt (JavaCharArray? a, int index);
}
}
Rationale: it *allows* for more efficient JVM :: .NET array copying,
by making copies explicit (to the dev), not implicit. We can
add an implicit conversion from e.g. `IEnumerable<char>` to
`JavaCharArray` in the future, if deemed useful.
This also impacts method return types, properties, and fields.
Bind the `java.lang.module` package in the namespace
`Java.Lang.Modules`. This is to avoid a type/namespace conflict
with `java.lang.Module`, bound as `Java.Lang.Module`.
Continue updating `generator` to remove "Android-isms".
Update `Java.Base.csproj` to ignore [warning CS0108][0]:
Java.Lang.Reflect.IAnnotatedArrayType.cs(15,45):
warning CS0108: 'IAnnotatedArrayType.AnnotatedOwnerType' hides inherited member
'IAnnotatedType.AnnotatedOwnerType'. Use the new keyword if hiding was intended.
The problem here is that we have:
public partial interface IAnnotatedType {
// Contains default interface method
virtual unsafe IAnnotatedType? AnnotatedOwnerType => …;
}
public partial interface IAnnotatedArrayType : IAnnotatedType {
// Contains *no* method body; re-abstracted
IAnnotatedType? AnnotatedOwnerType {get;}
}
TODO: figure out how to properly fix this. `managedOverride`
metadata (5a0e37e) doesn't seem useful to "re-abstract" a default
interface member.
Update `Java.Base.targets` to use `generator --global`. This is so
that `java.lang.System` can be bound as `Java.Lang.System` without
causing various C# compilation errors due to type lookup.
(Compare to Xamarin.Android's `Java.Lang.JavaSystem`, which got a
`Java*` prefix to avoid these compilation errors.)
Update `JavaInteropCodeGeneratorTests.CreateOptions()` so that C#
features such as default interface methods and nested interface types
are enabled within the unit tests.
TODO:
* When `generator --codegen-target=JavaInterop1` is used, all the
language features should also be enabled by default.
* Certain Java Annotation-related types aren't bound in
JavaInterop1, vs. XAJavaInterop1. Revisit this.
* "Revisit" use of `JNIEnv.ToLocalJniHandle()` in Xamarin.Android
bindings, and it's outright removal in JavaInterop1 bindings.
@jonpryor *thinks* the `JNIENv.ToLocalJniHandle(v)` was introduced
"in case" `v` would be collected by the GC "during" a JNI call.
Use of `GC.KeepAlive()` (1f21f38, da73d6a), would be a better
solution, but also requires auditing `generator` output.
* Bind the rest of `java.base.jmod` (bc5bcf4).
[0]: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0108
<!-- Bind `Object.finalize()` as `Object.JavaFinalize()` -->
9
+
<attrpath="/api/package[@name='java.lang']//method[@name='finalize' and count(parameter)=0]"name="managedName">JavaFinalize</attr>
10
+
<!-- warning CS0672: Member 'Enum.JavaFinalize()' overrides obsolete member 'Object.JavaFinalize()'. Add the Obsolete attribute to 'Enum.JavaFinalize()'. -->
11
+
<attrpath="/api/package[@name='java.lang']/class[@name='Enum']/method[@name='finalize' and count(parameter)=0]"name="deprecated">deprecated</attr>
12
+
13
+
<!-- AbstractStringBuilder is package-private; fixity fix -->
Copy file name to clipboardExpand all lines: tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteClass.txt
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,7 @@ public partial class MyClass {
24
24
}
25
25
26
26
// Metadata.xml XPath constructor reference: path="/api/package[@name='java.code']/class[@name='MyClass']/constructor[@name='MyClass' and count(parameter)=1 and parameter[1][@type='java.lang.String']]"
27
-
unsafe MyClass (string p0) : base (ref *InvalidJniObjectReference, JniObjectReferenceOptions.None)
27
+
unsafe MyClass (string? p0) : base (ref *InvalidJniObjectReference, JniObjectReferenceOptions.None)
28
28
{
29
29
const string __id = "(Ljava/lang/String;)V";
30
30
@@ -65,7 +65,7 @@ public partial class MyClass {
65
65
}
66
66
}
67
67
68
-
public virtual unsafe string Key {
68
+
public virtual unsafe string? Key {
69
69
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_Key' and count(parameter)=0]"
@@ -120,7 +120,7 @@ public partial class MyClass {
120
120
}
121
121
122
122
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='GetCountForKey' and count(parameter)=1 and parameter[1][@type='java.lang.String']]"
123
-
public virtual unsafe int GetCountForKey (string key)
123
+
public virtual unsafe int GetCountForKey (string? key)
0 commit comments