Skip to content

Commit 3ff6f8f

Browse files
authored
[Java.Base] Fix CS0108 Warnings (#1008)
Context: a65d6fb Context: 22d5687 Context: fadbb82 Commit a65d6fb added [warning CS0108][0] to `$(NoWarn)`, as there was no way to fix this warning on `IAnnotatedArrayType`. With commits 22d5687 and fadbb82, 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)
1 parent fadbb82 commit 3ff6f8f

File tree

3 files changed

+53
-14
lines changed

3 files changed

+53
-14
lines changed

src/Java.Base-ref.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ protected ByteArrayInputStream(ref Java.Interop.JniObjectReference reference, Ja
8181
[System.ComponentModel.EditorBrowsableAttribute(1)]
8282
[System.Diagnostics.DebuggerBrowsableAttribute(0)]
8383
public override Java.Interop.JniPeerMembers JniPeerMembers { get { throw null; } }
84-
protected int Mark { get { throw null; } set { } }
84+
protected int MarkedPosition { get { throw null; } set { } }
8585
protected int Pos { get { throw null; } set { } }
8686
[Java.Interop.JniMethodSignatureAttribute("read", "()I")]
8787
public override int Read() { throw null; }
@@ -511,7 +511,7 @@ public override void Write(Java.Interop.JavaCharArray? cbuf, int off, int len) {
511511
public partial interface ICloseable : Java.Interop.IJavaPeerable, Java.Lang.IAutoCloseable, System.IDisposable
512512
{
513513
[Java.Interop.JniMethodSignatureAttribute("close", "()V")]
514-
new void Close();
514+
void Java.Lang.IAutoCloseable.Close();
515515
}
516516
[Java.Interop.JniTypeSignatureAttribute("java/io/DataInput", GenerateJavaPeer=false)]
517517
public partial interface IDataInput : Java.Interop.IJavaPeerable, System.IDisposable
@@ -693,7 +693,7 @@ public partial interface IObjectInput : Java.Interop.IJavaPeerable, Java.IO.IDat
693693
[Java.Interop.JniMethodSignatureAttribute("available", "()I")]
694694
int Available();
695695
[Java.Interop.JniMethodSignatureAttribute("close", "()V")]
696-
new void Close();
696+
void Java.Lang.IAutoCloseable.Close();
697697
[Java.Interop.JniMethodSignatureAttribute("read", "()I")]
698698
int Read();
699699
[Java.Interop.JniMethodSignatureAttribute("read", "([B)I")]
@@ -770,16 +770,16 @@ public partial interface IObjectInputValidation : Java.Interop.IJavaPeerable, Sy
770770
[Java.Interop.JniTypeSignatureAttribute("java/io/ObjectOutput", GenerateJavaPeer=false)]
771771
public partial interface IObjectOutput : Java.Interop.IJavaPeerable, Java.IO.IDataOutput, Java.Lang.IAutoCloseable, System.IDisposable
772772
{
773-
[Java.Interop.JniMethodSignatureAttribute("close", "()V")]
774-
new void Close();
775773
[Java.Interop.JniMethodSignatureAttribute("flush", "()V")]
776774
void Flush();
777775
[Java.Interop.JniMethodSignatureAttribute("write", "([B)V")]
778-
new void Write(Java.Interop.JavaSByteArray? p0);
776+
void Java.IO.IDataOutput.Write(Java.Interop.JavaSByteArray? p0);
779777
[Java.Interop.JniMethodSignatureAttribute("write", "([BII)V")]
780-
new void Write(Java.Interop.JavaSByteArray? p0, int p1, int p2);
778+
void Java.IO.IDataOutput.Write(Java.Interop.JavaSByteArray? p0, int p1, int p2);
781779
[Java.Interop.JniMethodSignatureAttribute("write", "(I)V")]
782-
new void Write(int p0);
780+
void Java.IO.IDataOutput.Write(int p0);
781+
[Java.Interop.JniMethodSignatureAttribute("close", "()V")]
782+
void Java.Lang.IAutoCloseable.Close();
783783
[Java.Interop.JniMethodSignatureAttribute("writeObject", "(Ljava/lang/Object;)V")]
784784
void WriteObject(Java.Lang.Object? p0);
785785
}
@@ -6621,7 +6621,7 @@ public GenericSignatureFormatError(string? message) { }
66216621
public partial interface IAnnotatedArrayType : Java.Interop.IJavaPeerable, Java.Lang.Reflect.IAnnotatedElement, Java.Lang.Reflect.IAnnotatedType, System.IDisposable
66226622
{
66236623
Java.Lang.Reflect.IAnnotatedType? AnnotatedGenericComponentType { [Java.Interop.JniMethodSignatureAttribute("getAnnotatedGenericComponentType", "()Ljava/lang/reflect/AnnotatedType;")] get; }
6624-
new Java.Lang.Reflect.IAnnotatedType? AnnotatedOwnerType { [Java.Interop.JniMethodSignatureAttribute("getAnnotatedOwnerType", "()Ljava/lang/reflect/AnnotatedType;")] get; }
6624+
Java.Lang.Reflect.IAnnotatedType? Java.Lang.Reflect.IAnnotatedType.AnnotatedOwnerType { [Java.Interop.JniMethodSignatureAttribute("getAnnotatedOwnerType", "()Ljava/lang/reflect/AnnotatedType;")] get; }
66256625
}
66266626
[Java.Interop.JniTypeSignatureAttribute("java/lang/reflect/AnnotatedElement", GenerateJavaPeer=false)]
66276627
public partial interface IAnnotatedElement : Java.Interop.IJavaPeerable, System.IDisposable
@@ -6648,7 +6648,7 @@ public partial interface IAnnotatedElement : Java.Interop.IJavaPeerable, System.
66486648
[Java.Interop.JniTypeSignatureAttribute("java/lang/reflect/AnnotatedParameterizedType", GenerateJavaPeer=false)]
66496649
public partial interface IAnnotatedParameterizedType : Java.Interop.IJavaPeerable, Java.Lang.Reflect.IAnnotatedElement, Java.Lang.Reflect.IAnnotatedType, System.IDisposable
66506650
{
6651-
new Java.Lang.Reflect.IAnnotatedType? AnnotatedOwnerType { [Java.Interop.JniMethodSignatureAttribute("getAnnotatedOwnerType", "()Ljava/lang/reflect/AnnotatedType;")] get; }
6651+
Java.Lang.Reflect.IAnnotatedType? Java.Lang.Reflect.IAnnotatedType.AnnotatedOwnerType { [Java.Interop.JniMethodSignatureAttribute("getAnnotatedOwnerType", "()Ljava/lang/reflect/AnnotatedType;")] get; }
66526652
[Java.Interop.JniMethodSignatureAttribute("getAnnotatedActualTypeArguments", "()[Ljava/lang/reflect/AnnotatedType;")]
66536653
Java.Interop.JavaObjectArray<Java.Lang.Reflect.IAnnotatedType>? GetAnnotatedActualTypeArguments();
66546654
}
@@ -6661,14 +6661,14 @@ public partial interface IAnnotatedType : Java.Interop.IJavaPeerable, Java.Lang.
66616661
[Java.Interop.JniTypeSignatureAttribute("java/lang/reflect/AnnotatedTypeVariable", GenerateJavaPeer=false)]
66626662
public partial interface IAnnotatedTypeVariable : Java.Interop.IJavaPeerable, Java.Lang.Reflect.IAnnotatedElement, Java.Lang.Reflect.IAnnotatedType, System.IDisposable
66636663
{
6664-
new Java.Lang.Reflect.IAnnotatedType? AnnotatedOwnerType { [Java.Interop.JniMethodSignatureAttribute("getAnnotatedOwnerType", "()Ljava/lang/reflect/AnnotatedType;")] get; }
6664+
Java.Lang.Reflect.IAnnotatedType? Java.Lang.Reflect.IAnnotatedType.AnnotatedOwnerType { [Java.Interop.JniMethodSignatureAttribute("getAnnotatedOwnerType", "()Ljava/lang/reflect/AnnotatedType;")] get; }
66656665
[Java.Interop.JniMethodSignatureAttribute("getAnnotatedBounds", "()[Ljava/lang/reflect/AnnotatedType;")]
66666666
Java.Interop.JavaObjectArray<Java.Lang.Reflect.IAnnotatedType>? GetAnnotatedBounds();
66676667
}
66686668
[Java.Interop.JniTypeSignatureAttribute("java/lang/reflect/AnnotatedWildcardType", GenerateJavaPeer=false)]
66696669
public partial interface IAnnotatedWildcardType : Java.Interop.IJavaPeerable, Java.Lang.Reflect.IAnnotatedElement, Java.Lang.Reflect.IAnnotatedType, System.IDisposable
66706670
{
6671-
new Java.Lang.Reflect.IAnnotatedType? AnnotatedOwnerType { [Java.Interop.JniMethodSignatureAttribute("getAnnotatedOwnerType", "()Ljava/lang/reflect/AnnotatedType;")] get; }
6671+
Java.Lang.Reflect.IAnnotatedType? Java.Lang.Reflect.IAnnotatedType.AnnotatedOwnerType { [Java.Interop.JniMethodSignatureAttribute("getAnnotatedOwnerType", "()Ljava/lang/reflect/AnnotatedType;")] get; }
66726672
[Java.Interop.JniMethodSignatureAttribute("getAnnotatedLowerBounds", "()[Ljava/lang/reflect/AnnotatedType;")]
66736673
Java.Interop.JavaObjectArray<Java.Lang.Reflect.IAnnotatedType>? GetAnnotatedLowerBounds();
66746674
[Java.Interop.JniMethodSignatureAttribute("getAnnotatedUpperBounds", "()[Ljava/lang/reflect/AnnotatedType;")]

src/Java.Base/Java.Base.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
<TargetFramework>$(DotNetTargetFramework)</TargetFramework>
55
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
66
<Nullable>enable</Nullable>
7-
<!-- TODO: CS0108 is due to e.g. interfaces re-abstracting default interface methods -->
8-
<NoWarn>$(NoWarn);8764;CS0108</NoWarn>
7+
<NoWarn>$(NoWarn);8764</NoWarn>
98
</PropertyGroup>
109

1110
<Import Project="..\..\TargetFrameworkDependentValues.props" />

src/Java.Base/Transforms/Metadata.xml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,46 @@
1212
<!-- warning CS0672: Member 'Enum.JavaFinalize()' overrides obsolete member 'Object.JavaFinalize()'. Add the Obsolete attribute to 'Enum.JavaFinalize()'. -->
1313
<attr path="/api/package[@name='java.lang']/class[@name='Enum']/method[@name='finalize' and count(parameter)=0]" name="deprecated">deprecated</attr>
1414

15+
<!-- warning CS0108: 'MEMBER' hides inherited member 'MEMBER'. Use the new keyword if hiding was intended. -->
16+
<attr path="/api/package[@name='java.io']/class[
17+
@name='ByteArrayInputStream'
18+
]/field[@name='mark']"
19+
name="managedName">MarkedPosition</attr>
20+
<attr path="/api/package[@name='java.lang.reflect']/interface[
21+
@name='AnnotatedArrayType'
22+
or @name='AnnotatedParameterizedType'
23+
or @name='AnnotatedTypeVariable'
24+
or @name='AnnotatedWildcardType'
25+
]/method[@name='getAnnotatedOwnerType' and count(parameter)=0]"
26+
name="managedOverride">reabstract</attr>
27+
<attr path="/api/package[@name='java.lang.reflect']/interface[
28+
@name='AnnotatedArrayType'
29+
or @name='AnnotatedParameterizedType'
30+
or @name='AnnotatedTypeVariable'
31+
or @name='AnnotatedWildcardType'
32+
]/method[@name='getAnnotatedOwnerType' and count(parameter)=0]"
33+
name="explicitInterface">IAnnotatedType</attr>
34+
<attr path="/api/package[@name='java.io']/interface[
35+
@name='Closeable'
36+
or @name='ObjectInput'
37+
or @name='ObjectOutput'
38+
]/method[@name='close' and count(parameter)=0]"
39+
name="managedOverride">reabstract</attr>
40+
<attr path="/api/package[@name='java.io']/interface[
41+
@name='Closeable'
42+
or @name='ObjectInput'
43+
or @name='ObjectOutput'
44+
]/method[@name='close' and count(parameter)=0]"
45+
name="explicitInterface">Java.Lang.IAutoCloseable</attr>
46+
<attr path="/api/package[@name='java.io']/interface[
47+
@name='ObjectOutput'
48+
]/method[@name='write']"
49+
name="managedOverride">reabstract</attr>
50+
<attr path="/api/package[@name='java.io']/interface[
51+
@name='ObjectOutput'
52+
]/method[@name='write']"
53+
name="explicitInterface">IDataOutput</attr>
54+
1555
<!-- AbstractStringBuilder is package-private; fixity fix -->
1656
<remove-node path="//api/package[@name='java.lang']/class[@name='AbstractStringBuilder']" />
1757

0 commit comments

Comments
 (0)