Commit b37ae0c
committed
[Java.Base, generator] Bind all of package java.lang
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.
`java.lang.String` is no longer bound as `System.String`. This might
be a mistake/reconsidered, but the current rationale is that bindings
should "more directly" mirror the underlying Java API. We can
provide method overloads or implicit conversions to make C#
integration "nicer", e.g. we have an implicit conversion from
`System.String` to `Java.Lang.String` for now.
Rename `.toString()` to `.ToJavaString()` -- which returns
`Java.Lang.String` (see previous paragraph) -- and provide
`Java.Lang.Object.ToString()` and `Java.Lang.Throwable.ToString()`
overrides which call `.ToJavaString()`.
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;}
}
I'm not sure how to properly represent 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. Also add an explicit entry for
`java.lang.String` so that unit tests which assume that
`java.lang.String` exists will pass, as the "normal" Xamarin.Android-
style `java.lang.String` :: `string` binding is currently skipped.
Update `tests/generator-Tests/**/*.xml` so that `java.lang.String`
is present within the `api.xml` when they also use `java.lang.String`
as a type "elsewhere" (method parameter/return type, field type).
This is to reduce reliance on the builtin bindings, which
JavaInterop1 bindings try to minimize.
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/cs01081 parent 05bfece commit b37ae0c
File tree
112 files changed
+1186
-352
lines changed- src/Java.Base
- Java.Lang
- Transforms
- tests/generator-Tests
- Integration-Tests
- Unit-Tests
- CodeGeneratorExpectedResults/JavaInterop1
- expected.ji
- Arrays
- CSharpKeywords
- GenericArguments
- NormalProperties
- StaticMethods
- StaticProperties
- Streams
- expected.xaji
- Arrays
- CSharpKeywords
- GenericArguments
- NormalMethods
- NormalProperties
- StaticMethods
- StaticProperties
- Streams
- TestInterface
- java.util.List
- expected
- AccessModifiers
- Adapters
- Android.Graphics.Color
- Arrays
- CSharpKeywords
- Constructors
- Core_ClassParse
- Core_Jar2Xml
- EnumerationFixup
- GenericArguments
- InterfaceMethodsConflict
- NestedTypes
- NonStaticFields
- NormalMethods
- NormalProperties
- ParameterXPath
- StaticFields
- StaticMethods
- StaticProperties
- Streams
- TestInterface
- java.lang.Enum
- java.lang.Object
- java.util.List
- tools/generator
- Java.Interop.Tools.Generator.ObjectModel
- Symbols
- SourceWriters
- Extensions
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
112 files changed
+1186
-352
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
13 | 19 | | |
14 | 20 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
13 | 19 | | |
14 | 20 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
| 5 | + | |
| 6 | + | |
15 | 7 | | |
16 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
17 | 28 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | | - | |
11 | 9 | | |
12 | 10 | | |
13 | 11 | | |
| |||
0 commit comments