Skip to content

Commit 4f47ec8

Browse files
authored
[generator] Make DIM invoking plumbing private (#581)
Context: #509 We have never used explicit `private` modifiers on class members due to the [Mono Coding Guidelines][0], as `private` is the default. However, when working with Default Interface Methods on interfaces members, the default is `public`. This results in our plumbing members like `_members` and `static Delegate cb_DoSomething;` being exposed as part of the interface's public API. This commit makes private interface members explicitly `private`. [0]: https://www.mono-project.com/community/contributing/coding-guidelines/
1 parent 2a0f863 commit 4f47ec8

File tree

12 files changed

+40
-38
lines changed

12 files changed

+40
-38
lines changed

tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteInterfaceDefaultMethod.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
// Metadata.xml XPath interface reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']"
22
[Register ("java/code/IMyInterface", "", "java.code.IMyInterfaceInvoker")]
33
public partial interface IMyInterface : IJavaObject, IJavaPeerable {
4-
static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/IMyInterface", typeof (IMyInterface), isInterface: true);
4+
private static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/IMyInterface", typeof (IMyInterface), isInterface: true);
55

6-
static Delegate cb_DoSomething;
6+
private static Delegate cb_DoSomething;
77
#pragma warning disable 0169
8-
static Delegate GetDoSomethingHandler ()
8+
private static Delegate GetDoSomethingHandler ()
99
{
1010
if (cb_DoSomething == null)
1111
cb_DoSomething = JNINativeWrapper.CreateDelegate ((Action<IntPtr, IntPtr>) n_DoSomething);
1212
return cb_DoSomething;
1313
}
1414

15-
static void n_DoSomething (IntPtr jnienv, IntPtr native__this)
15+
private static void n_DoSomething (IntPtr jnienv, IntPtr native__this)
1616
{
1717
java.code.IMyInterface __this = global::Java.Lang.Object.GetObject<java.code.IMyInterface> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
1818
__this.DoSomething ();

tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteInterfaceDefaultProperty.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
// Metadata.xml XPath interface reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']"
22
[Register ("java/code/IMyInterface", "", "java.code.IMyInterfaceInvoker")]
33
public partial interface IMyInterface : IJavaObject, IJavaPeerable {
4-
static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/IMyInterface", typeof (IMyInterface), isInterface: true);
4+
private static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/IMyInterface", typeof (IMyInterface), isInterface: true);
55

6-
static Delegate cb_get_Value;
6+
private static Delegate cb_get_Value;
77
#pragma warning disable 0169
8-
static Delegate Getget_ValueHandler ()
8+
private static Delegate Getget_ValueHandler ()
99
{
1010
if (cb_get_Value == null)
1111
cb_get_Value = JNINativeWrapper.CreateDelegate ((Func<IntPtr, IntPtr, int>) n_get_Value);
1212
return cb_get_Value;
1313
}
1414

15-
static int n_get_Value (IntPtr jnienv, IntPtr native__this)
15+
private static int n_get_Value (IntPtr jnienv, IntPtr native__this)
1616
{
1717
java.code.IMyInterface __this = global::Java.Lang.Object.GetObject<java.code.IMyInterface> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
1818
return __this.Value;
1919
}
2020
#pragma warning restore 0169
2121

22-
static Delegate cb_set_Value_I;
22+
private static Delegate cb_set_Value_I;
2323
#pragma warning disable 0169
24-
static Delegate Getset_Value_IHandler ()
24+
private static Delegate Getset_Value_IHandler ()
2525
{
2626
if (cb_set_Value_I == null)
2727
cb_set_Value_I = JNINativeWrapper.CreateDelegate ((Action<IntPtr, IntPtr, int>) n_set_Value_I);
2828
return cb_set_Value_I;
2929
}
3030

31-
static void n_set_Value_I (IntPtr jnienv, IntPtr native__this, int value)
31+
private static void n_set_Value_I (IntPtr jnienv, IntPtr native__this, int value)
3232
{
3333
java.code.IMyInterface __this = global::Java.Lang.Object.GetObject<java.code.IMyInterface> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
3434
__this.Value = value;

tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteInterfaceDefaultPropertyGetterOnly.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
// Metadata.xml XPath interface reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']"
22
[Register ("java/code/IMyInterface", "", "java.code.IMyInterfaceInvoker")]
33
public partial interface IMyInterface : IJavaObject, IJavaPeerable {
4-
static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/IMyInterface", typeof (IMyInterface), isInterface: true);
4+
private static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/IMyInterface", typeof (IMyInterface), isInterface: true);
55

6-
static Delegate cb_get_Value;
6+
private static Delegate cb_get_Value;
77
#pragma warning disable 0169
8-
static Delegate Getget_ValueHandler ()
8+
private static Delegate Getget_ValueHandler ()
99
{
1010
if (cb_get_Value == null)
1111
cb_get_Value = JNINativeWrapper.CreateDelegate ((Func<IntPtr, IntPtr, int>) n_get_Value);
1212
return cb_get_Value;
1313
}
1414

15-
static int n_get_Value (IntPtr jnienv, IntPtr native__this)
15+
private static int n_get_Value (IntPtr jnienv, IntPtr native__this)
1616
{
1717
java.code.IMyInterface __this = global::Java.Lang.Object.GetObject<java.code.IMyInterface> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
1818
return __this.Value;

tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteStaticInterfaceMethod.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public abstract class MyInterfaceConsts : MyInterface {
3131
// Metadata.xml XPath interface reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']"
3232
[Register ("java/code/IMyInterface", "", "java.code.IMyInterfaceInvoker")]
3333
public partial interface IMyInterface : IJavaObject, IJavaPeerable {
34-
static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/IMyInterface", typeof (IMyInterface), isInterface: true);
34+
private static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/IMyInterface", typeof (IMyInterface), isInterface: true);
3535

3636
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='DoSomething' and count(parameter)=0]"
3737
[Register ("DoSomething", "()V", "")]

tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteStaticInterfaceProperty.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Metadata.xml XPath interface reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']"
22
[Register ("java/code/IMyInterface", "", "java.code.IMyInterfaceInvoker")]
33
public partial interface IMyInterface : IJavaObject, IJavaPeerable {
4-
static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/IMyInterface", typeof (IMyInterface), isInterface: true);
4+
private static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/IMyInterface", typeof (IMyInterface), isInterface: true);
55

66
static unsafe int Value {
77
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='get_Value' and count(parameter)=0]"

tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteInterfaceDefaultMethod.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
// Metadata.xml XPath interface reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']"
22
[Register ("java/code/IMyInterface", "", "java.code.IMyInterfaceInvoker")]
33
public partial interface IMyInterface : IJavaObject, IJavaPeerable {
4-
static readonly JniPeerMembers _members = new XAPeerMembers ("java/code/IMyInterface", typeof (IMyInterface), isInterface: true);
4+
private static readonly JniPeerMembers _members = new XAPeerMembers ("java/code/IMyInterface", typeof (IMyInterface), isInterface: true);
55

6-
static Delegate cb_DoSomething;
6+
private static Delegate cb_DoSomething;
77
#pragma warning disable 0169
8-
static Delegate GetDoSomethingHandler ()
8+
private static Delegate GetDoSomethingHandler ()
99
{
1010
if (cb_DoSomething == null)
1111
cb_DoSomething = JNINativeWrapper.CreateDelegate ((Action<IntPtr, IntPtr>) n_DoSomething);
1212
return cb_DoSomething;
1313
}
1414

15-
static void n_DoSomething (IntPtr jnienv, IntPtr native__this)
15+
private static void n_DoSomething (IntPtr jnienv, IntPtr native__this)
1616
{
1717
java.code.IMyInterface __this = global::Java.Lang.Object.GetObject<java.code.IMyInterface> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
1818
__this.DoSomething ();

tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteInterfaceDefaultProperty.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
// Metadata.xml XPath interface reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']"
22
[Register ("java/code/IMyInterface", "", "java.code.IMyInterfaceInvoker")]
33
public partial interface IMyInterface : IJavaObject, IJavaPeerable {
4-
static readonly JniPeerMembers _members = new XAPeerMembers ("java/code/IMyInterface", typeof (IMyInterface), isInterface: true);
4+
private static readonly JniPeerMembers _members = new XAPeerMembers ("java/code/IMyInterface", typeof (IMyInterface), isInterface: true);
55

6-
static Delegate cb_get_Value;
6+
private static Delegate cb_get_Value;
77
#pragma warning disable 0169
8-
static Delegate Getget_ValueHandler ()
8+
private static Delegate Getget_ValueHandler ()
99
{
1010
if (cb_get_Value == null)
1111
cb_get_Value = JNINativeWrapper.CreateDelegate ((Func<IntPtr, IntPtr, int>) n_get_Value);
1212
return cb_get_Value;
1313
}
1414

15-
static int n_get_Value (IntPtr jnienv, IntPtr native__this)
15+
private static int n_get_Value (IntPtr jnienv, IntPtr native__this)
1616
{
1717
java.code.IMyInterface __this = global::Java.Lang.Object.GetObject<java.code.IMyInterface> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
1818
return __this.Value;
1919
}
2020
#pragma warning restore 0169
2121

22-
static Delegate cb_set_Value_I;
22+
private static Delegate cb_set_Value_I;
2323
#pragma warning disable 0169
24-
static Delegate Getset_Value_IHandler ()
24+
private static Delegate Getset_Value_IHandler ()
2525
{
2626
if (cb_set_Value_I == null)
2727
cb_set_Value_I = JNINativeWrapper.CreateDelegate ((Action<IntPtr, IntPtr, int>) n_set_Value_I);
2828
return cb_set_Value_I;
2929
}
3030

31-
static void n_set_Value_I (IntPtr jnienv, IntPtr native__this, int value)
31+
private static void n_set_Value_I (IntPtr jnienv, IntPtr native__this, int value)
3232
{
3333
java.code.IMyInterface __this = global::Java.Lang.Object.GetObject<java.code.IMyInterface> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
3434
__this.Value = value;

tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteInterfaceDefaultPropertyGetterOnly.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
// Metadata.xml XPath interface reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']"
22
[Register ("java/code/IMyInterface", "", "java.code.IMyInterfaceInvoker")]
33
public partial interface IMyInterface : IJavaObject, IJavaPeerable {
4-
static readonly JniPeerMembers _members = new XAPeerMembers ("java/code/IMyInterface", typeof (IMyInterface), isInterface: true);
4+
private static readonly JniPeerMembers _members = new XAPeerMembers ("java/code/IMyInterface", typeof (IMyInterface), isInterface: true);
55

6-
static Delegate cb_get_Value;
6+
private static Delegate cb_get_Value;
77
#pragma warning disable 0169
8-
static Delegate Getget_ValueHandler ()
8+
private static Delegate Getget_ValueHandler ()
99
{
1010
if (cb_get_Value == null)
1111
cb_get_Value = JNINativeWrapper.CreateDelegate ((Func<IntPtr, IntPtr, int>) n_get_Value);
1212
return cb_get_Value;
1313
}
1414

15-
static int n_get_Value (IntPtr jnienv, IntPtr native__this)
15+
private static int n_get_Value (IntPtr jnienv, IntPtr native__this)
1616
{
1717
java.code.IMyInterface __this = global::Java.Lang.Object.GetObject<java.code.IMyInterface> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
1818
return __this.Value;

tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteStaticInterfaceMethod.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public abstract class MyInterfaceConsts : MyInterface {
3131
// Metadata.xml XPath interface reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']"
3232
[Register ("java/code/IMyInterface", "", "java.code.IMyInterfaceInvoker")]
3333
public partial interface IMyInterface : IJavaObject, IJavaPeerable {
34-
static readonly JniPeerMembers _members = new XAPeerMembers ("java/code/IMyInterface", typeof (IMyInterface), isInterface: true);
34+
private static readonly JniPeerMembers _members = new XAPeerMembers ("java/code/IMyInterface", typeof (IMyInterface), isInterface: true);
3535

3636
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='DoSomething' and count(parameter)=0]"
3737
[Register ("DoSomething", "()V", "")]

tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteStaticInterfaceProperty.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Metadata.xml XPath interface reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']"
22
[Register ("java/code/IMyInterface", "", "java.code.IMyInterfaceInvoker")]
33
public partial interface IMyInterface : IJavaObject, IJavaPeerable {
4-
static readonly JniPeerMembers _members = new XAPeerMembers ("java/code/IMyInterface", typeof (IMyInterface), isInterface: true);
4+
private static readonly JniPeerMembers _members = new XAPeerMembers ("java/code/IMyInterface", typeof (IMyInterface), isInterface: true);
55

66
static unsafe int Value {
77
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='get_Value' and count(parameter)=0]"

0 commit comments

Comments
 (0)