From a095562461fcb65f2bc02c78106e4432e11587bd Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Sun, 10 Jul 2022 11:58:17 -0400 Subject: [PATCH] [Java.Base] Fix CS0108 Warnings Context: a65d6fb4d79041c959435c15dc3dcf5331e5d715 Context: 22d5687bc5c572ea0eadbd1a23f02f424af782d1 Context: fadbb82c3b8ab7979c19e9f139bdf2589e47549e Commit a65d6fb4 added [warning CS0108][0] to `$(NoWarn)`, as there was no way to fix this warning on `IAnnotatedArrayType`. With commits 22d5687b and fadbb82c, it is now possible to fix the CS0108 warning on `IAnnotatedArrayType`, among others. Remove CS0108 from `$(NoWarn)`, and use `Metadata.xml` to fix/avoid the constructs which caused the CS0108 warnings. One CS0108 which *isn't* fixed by [reabstraction][1] of Interface Default Members is for the [`java.io.ByteArrayInputStream.mark`][2] field, which has the same name -- and thus hides -- the [`InputStream.mark()` method][3]. This isn't a problem for Java -- context disambiguates between field access and a method invocation -- but in C# the easier solution is to use Metadata to rename `ByteArrayInputStream.mark` to `ByteArrayInputStream.MarkedPosition`, which fixes the CS0108. [0]: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0108 [1]: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-8.0/default-interface-methods#reabstraction [2]: https://developer.android.com/reference/java/io/ByteArrayInputStream#mark [3]: https://developer.android.com/reference/java/io/InputStream#mark(int) --- src/Java.Base-ref.cs | 24 ++++++++-------- src/Java.Base/Java.Base.csproj | 3 +- src/Java.Base/Transforms/Metadata.xml | 40 +++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 14 deletions(-) diff --git a/src/Java.Base-ref.cs b/src/Java.Base-ref.cs index d9c46e290..973dc50b7 100644 --- a/src/Java.Base-ref.cs +++ b/src/Java.Base-ref.cs @@ -81,7 +81,7 @@ protected ByteArrayInputStream(ref Java.Interop.JniObjectReference reference, Ja [System.ComponentModel.EditorBrowsableAttribute(1)] [System.Diagnostics.DebuggerBrowsableAttribute(0)] public override Java.Interop.JniPeerMembers JniPeerMembers { get { throw null; } } - protected int Mark { get { throw null; } set { } } + protected int MarkedPosition { get { throw null; } set { } } protected int Pos { get { throw null; } set { } } [Java.Interop.JniMethodSignatureAttribute("read", "()I")] public override int Read() { throw null; } @@ -511,7 +511,7 @@ public override void Write(Java.Interop.JavaCharArray? cbuf, int off, int len) { public partial interface ICloseable : Java.Interop.IJavaPeerable, Java.Lang.IAutoCloseable, System.IDisposable { [Java.Interop.JniMethodSignatureAttribute("close", "()V")] - new void Close(); + void Java.Lang.IAutoCloseable.Close(); } [Java.Interop.JniTypeSignatureAttribute("java/io/DataInput", GenerateJavaPeer=false)] public partial interface IDataInput : Java.Interop.IJavaPeerable, System.IDisposable @@ -693,7 +693,7 @@ public partial interface IObjectInput : Java.Interop.IJavaPeerable, Java.IO.IDat [Java.Interop.JniMethodSignatureAttribute("available", "()I")] int Available(); [Java.Interop.JniMethodSignatureAttribute("close", "()V")] - new void Close(); + void Java.Lang.IAutoCloseable.Close(); [Java.Interop.JniMethodSignatureAttribute("read", "()I")] int Read(); [Java.Interop.JniMethodSignatureAttribute("read", "([B)I")] @@ -770,16 +770,16 @@ public partial interface IObjectInputValidation : Java.Interop.IJavaPeerable, Sy [Java.Interop.JniTypeSignatureAttribute("java/io/ObjectOutput", GenerateJavaPeer=false)] public partial interface IObjectOutput : Java.Interop.IJavaPeerable, Java.IO.IDataOutput, Java.Lang.IAutoCloseable, System.IDisposable { - [Java.Interop.JniMethodSignatureAttribute("close", "()V")] - new void Close(); [Java.Interop.JniMethodSignatureAttribute("flush", "()V")] void Flush(); [Java.Interop.JniMethodSignatureAttribute("write", "([B)V")] - new void Write(Java.Interop.JavaSByteArray? p0); + void Java.IO.IDataOutput.Write(Java.Interop.JavaSByteArray? p0); [Java.Interop.JniMethodSignatureAttribute("write", "([BII)V")] - new void Write(Java.Interop.JavaSByteArray? p0, int p1, int p2); + void Java.IO.IDataOutput.Write(Java.Interop.JavaSByteArray? p0, int p1, int p2); [Java.Interop.JniMethodSignatureAttribute("write", "(I)V")] - new void Write(int p0); + void Java.IO.IDataOutput.Write(int p0); + [Java.Interop.JniMethodSignatureAttribute("close", "()V")] + void Java.Lang.IAutoCloseable.Close(); [Java.Interop.JniMethodSignatureAttribute("writeObject", "(Ljava/lang/Object;)V")] void WriteObject(Java.Lang.Object? p0); } @@ -6621,7 +6621,7 @@ public GenericSignatureFormatError(string? message) { } public partial interface IAnnotatedArrayType : Java.Interop.IJavaPeerable, Java.Lang.Reflect.IAnnotatedElement, Java.Lang.Reflect.IAnnotatedType, System.IDisposable { Java.Lang.Reflect.IAnnotatedType? AnnotatedGenericComponentType { [Java.Interop.JniMethodSignatureAttribute("getAnnotatedGenericComponentType", "()Ljava/lang/reflect/AnnotatedType;")] get; } - new Java.Lang.Reflect.IAnnotatedType? AnnotatedOwnerType { [Java.Interop.JniMethodSignatureAttribute("getAnnotatedOwnerType", "()Ljava/lang/reflect/AnnotatedType;")] get; } + Java.Lang.Reflect.IAnnotatedType? Java.Lang.Reflect.IAnnotatedType.AnnotatedOwnerType { [Java.Interop.JniMethodSignatureAttribute("getAnnotatedOwnerType", "()Ljava/lang/reflect/AnnotatedType;")] get; } } [Java.Interop.JniTypeSignatureAttribute("java/lang/reflect/AnnotatedElement", GenerateJavaPeer=false)] public partial interface IAnnotatedElement : Java.Interop.IJavaPeerable, System.IDisposable @@ -6648,7 +6648,7 @@ public partial interface IAnnotatedElement : Java.Interop.IJavaPeerable, System. [Java.Interop.JniTypeSignatureAttribute("java/lang/reflect/AnnotatedParameterizedType", GenerateJavaPeer=false)] public partial interface IAnnotatedParameterizedType : Java.Interop.IJavaPeerable, Java.Lang.Reflect.IAnnotatedElement, Java.Lang.Reflect.IAnnotatedType, System.IDisposable { - new Java.Lang.Reflect.IAnnotatedType? AnnotatedOwnerType { [Java.Interop.JniMethodSignatureAttribute("getAnnotatedOwnerType", "()Ljava/lang/reflect/AnnotatedType;")] get; } + Java.Lang.Reflect.IAnnotatedType? Java.Lang.Reflect.IAnnotatedType.AnnotatedOwnerType { [Java.Interop.JniMethodSignatureAttribute("getAnnotatedOwnerType", "()Ljava/lang/reflect/AnnotatedType;")] get; } [Java.Interop.JniMethodSignatureAttribute("getAnnotatedActualTypeArguments", "()[Ljava/lang/reflect/AnnotatedType;")] Java.Interop.JavaObjectArray? GetAnnotatedActualTypeArguments(); } @@ -6661,14 +6661,14 @@ public partial interface IAnnotatedType : Java.Interop.IJavaPeerable, Java.Lang. [Java.Interop.JniTypeSignatureAttribute("java/lang/reflect/AnnotatedTypeVariable", GenerateJavaPeer=false)] public partial interface IAnnotatedTypeVariable : Java.Interop.IJavaPeerable, Java.Lang.Reflect.IAnnotatedElement, Java.Lang.Reflect.IAnnotatedType, System.IDisposable { - new Java.Lang.Reflect.IAnnotatedType? AnnotatedOwnerType { [Java.Interop.JniMethodSignatureAttribute("getAnnotatedOwnerType", "()Ljava/lang/reflect/AnnotatedType;")] get; } + Java.Lang.Reflect.IAnnotatedType? Java.Lang.Reflect.IAnnotatedType.AnnotatedOwnerType { [Java.Interop.JniMethodSignatureAttribute("getAnnotatedOwnerType", "()Ljava/lang/reflect/AnnotatedType;")] get; } [Java.Interop.JniMethodSignatureAttribute("getAnnotatedBounds", "()[Ljava/lang/reflect/AnnotatedType;")] Java.Interop.JavaObjectArray? GetAnnotatedBounds(); } [Java.Interop.JniTypeSignatureAttribute("java/lang/reflect/AnnotatedWildcardType", GenerateJavaPeer=false)] public partial interface IAnnotatedWildcardType : Java.Interop.IJavaPeerable, Java.Lang.Reflect.IAnnotatedElement, Java.Lang.Reflect.IAnnotatedType, System.IDisposable { - new Java.Lang.Reflect.IAnnotatedType? AnnotatedOwnerType { [Java.Interop.JniMethodSignatureAttribute("getAnnotatedOwnerType", "()Ljava/lang/reflect/AnnotatedType;")] get; } + Java.Lang.Reflect.IAnnotatedType? Java.Lang.Reflect.IAnnotatedType.AnnotatedOwnerType { [Java.Interop.JniMethodSignatureAttribute("getAnnotatedOwnerType", "()Ljava/lang/reflect/AnnotatedType;")] get; } [Java.Interop.JniMethodSignatureAttribute("getAnnotatedLowerBounds", "()[Ljava/lang/reflect/AnnotatedType;")] Java.Interop.JavaObjectArray? GetAnnotatedLowerBounds(); [Java.Interop.JniMethodSignatureAttribute("getAnnotatedUpperBounds", "()[Ljava/lang/reflect/AnnotatedType;")] diff --git a/src/Java.Base/Java.Base.csproj b/src/Java.Base/Java.Base.csproj index c8d3cf20b..95534c848 100644 --- a/src/Java.Base/Java.Base.csproj +++ b/src/Java.Base/Java.Base.csproj @@ -4,8 +4,7 @@ $(DotNetTargetFramework) true enable - - $(NoWarn);8764;CS0108 + $(NoWarn);8764 diff --git a/src/Java.Base/Transforms/Metadata.xml b/src/Java.Base/Transforms/Metadata.xml index 21828b346..ced7d892c 100644 --- a/src/Java.Base/Transforms/Metadata.xml +++ b/src/Java.Base/Transforms/Metadata.xml @@ -12,6 +12,46 @@ deprecated + + MarkedPosition + reabstract + IAnnotatedType + reabstract + Java.Lang.IAutoCloseable + reabstract + IDataOutput +