Commit 37cff25
authored
[Java.Base, generator] Bind all of package java.io (#968)
Context: bc5bcf4
Bind all classes and interfaces in the `java.io` package.
Binding the [`java.io.StringBufferInputStream.buffer`][0] field
exposed a `generator` bug: property setters for `String` fields would
not compile, producing:
partial class StringBufferInputStream {
protected string? Buffer {
get { ... }
set {
const string __id = "buffer.Ljava/lang/String;";
var native_value = global::Java.Interop.JniEnvironment.Strings.NewString (value);
try {
_members.InstanceFields.SetValue (__id, this, native_value?.PeerReference ?? default);
} finally {
global::Java.Interop.JniObjectReference.Dispose (ref native_value);
GC.KeepAlive (value);
}
}
}
}
Specifically, `native_value?.PeerReference` is not valid, and
unnecessary. This was due to a bug in `BoundFieldAsProperty.cs`,
as `String` field marshaling hit the "Object" marshaling path, which
was not warranted in this case, as `String` is treated specially.
Fix this bug.
Binding [`java.io.ObjectOutputStream.PutField.write(ObjectOutput)`][1]
presented a larger binding problem: it's an `abstract` method on an
`abstract` class, *but* the `PutFieldInvoker.Write()` method was
`[Obsolete]` when `PutField.Write()` was not!
public abstract partial class /* ObjectOutputStream. */ PutField {
public abstract void Write (Java.IO.IObjectOutput? p0);
}
internal partial class /* ObjectOutputStream. */ PutFieldInvoker : PutField {
[Obsolete (@"deprecated")]
public override void Write (Java.IO.IObjectOutput? p0) => ...
}
This state of affairs triggers a CS0809 warning, which is an error in
Release configuration builds:
##[error]src/Java.Base/obj/Release-net6.0/mcw/Java.IO.ObjectOutputStream.cs(311,32)
Error CS0809: Obsolete member 'ObjectOutputStream.PutFieldInvoker.Write(IObjectOutput?)'
overrides non-obsolete member 'ObjectOutputStream.PutField.Write(IObjectOutput?)'
Turns Out™ that `BoundMethodAbstractDeclaration.cs` never "forwarded"
deprecated attributes? Meaning that `abstract` methods would *never*
be `[Obsolete]`, even if their Java peer was `@deprecated`?
Update `BoundMethodAbstractDeclaration` so that if the Java method is
deprecated, the bound `abstract` method is `[Obsolete]`. This fixes
the CS0809, as now `PutField.Write()` and `PutFieldInvoker.Write()`
are consistent with each other.
TODO: should this change be done for *all* codegen targets?
Finally, in order to make it easier to view and review the
current `Java.Base.dll` API -- without requiring that it be built
locally -- add a `_GenerateRefApi` target to `Java.Base.targets`
which uses the `Microsoft.DotNet.GenAPI` NuGet package to generate
"reference assembly source" for `Java.Base.dll`. This is stored in
`src\Java.Base-ref.cs`.
[0]: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/StringBufferInputStream.html#buffer
[1]: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/ObjectOutputStream.PutField.html#write(java.io.ObjectOutput)1 parent a65d6fb commit 37cff25
File tree
8 files changed
+5370
-2
lines changed- src
- Java.Base
- Java.IO
- Transforms
- tools/generator/SourceWriters
8 files changed
+5370
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
7 | 11 | | |
8 | 12 | | |
9 | 13 | | |
| |||
75 | 79 | | |
76 | 80 | | |
77 | 81 | | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
78 | 95 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
155 | | - | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
156 | 161 | | |
157 | 162 | | |
158 | 163 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
55 | 60 | | |
56 | 61 | | |
57 | 62 | | |
| |||
0 commit comments