Skip to content

Commit befdbc0

Browse files
jpobstjonpryor
authored andcommitted
[generator] Don't [Register] a Connector for static properties (#488)
Default interface member static properties do not need to mention a *connector-method* within the `[Register]` custom attribute. Connector-methods are only for method *overrides*, and static methods cannot be overridden. Additionally, the connector method-related "glue" code isn't emitted, so the connector-method value doesn't exist. Update default interface member static property generation to mirror that of [class static member generation][0] and emit the empty string (`string.Empty`) as the conector method for static properties. [0]: https://github.com/xamarin/java.interop/blob/fe13b1655d8a979f281cf923c97c9e0bf58dc614/tools/generator/Java.Interop.Tools.Generator.CodeGeneration/CodeGenerator.cs#L1376-L1377
1 parent 1fecdda commit befdbc0

File tree

11 files changed

+26
-26
lines changed

11 files changed

+26
-26
lines changed

tools/generator/Java.Interop.Tools.Generator.CodeGeneration/CodeGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,15 +1489,15 @@ public void WriteProperty (Property property, GenBase gen, string indent, bool w
14891489
writer.WriteLine ("{0}{1}{2} unsafe {3} {4} {{", indent, visibility, virtual_override, opt.GetOutputName (property.Getter.ReturnType), decl_name);
14901490
if (gen.IsGeneratable)
14911491
writer.WriteLine ("{0}\t// Metadata.xml XPath method reference: path=\"{1}/method[@name='{2}'{3}]\"", indent, gen.MetadataXPathReference, property.Getter.JavaName, property.Getter.Parameters.GetMethodXPathPredicate ());
1492-
writer.WriteLine ("{0}\t[Register (\"{1}\", \"{2}\", \"{3}\"{4})]", indent, property.Getter.JavaName, property.Getter.JniSignature, property.Getter.GetConnectorNameFull (opt), property.Getter.AdditionalAttributeString ());
1492+
writer.WriteLine ("{0}\t[Register (\"{1}\", \"{2}\", \"{3}\"{4})]", indent, property.Getter.JavaName, property.Getter.JniSignature, property.Getter.IsVirtual ? property.Getter.GetConnectorNameFull (opt) : string.Empty, property.Getter.AdditionalAttributeString ());
14931493
writer.WriteLine ("{0}\tget {{", indent);
14941494
WriteMethodBody (property.Getter, indent + "\t\t", gen);
14951495
writer.WriteLine ("{0}\t}}", indent);
14961496
if (property.Setter != null) {
14971497
if (gen.IsGeneratable)
14981498
writer.WriteLine ("{0}\t// Metadata.xml XPath method reference: path=\"{1}/method[@name='{2}'{3}]\"", indent, gen.MetadataXPathReference, property.Setter.JavaName, property.Setter.Parameters.GetMethodXPathPredicate ());
14991499
WriteMethodCustomAttributes (property.Setter, indent);
1500-
writer.WriteLine ("{0}\t[Register (\"{1}\", \"{2}\", \"{3}\"{4})]", indent, property.Setter.JavaName, property.Setter.JniSignature, property.Setter.GetConnectorNameFull (opt), property.Setter.AdditionalAttributeString ());
1500+
writer.WriteLine ("{0}\t[Register (\"{1}\", \"{2}\", \"{3}\"{4})]", indent, property.Setter.JavaName, property.Setter.JniSignature, property.Setter.IsVirtual ? property.Setter.GetConnectorNameFull (opt) : string.Empty, property.Setter.AdditionalAttributeString ());
15011501
writer.WriteLine ("{0}\tset {{", indent);
15021502
string pname = property.Setter.Parameters [0].Name;
15031503
property.Setter.Parameters [0].Name = "value";

tools/generator/Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteClass.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public partial class MyClass {
168168

169169
public static unsafe int StaticCount {
170170
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_StaticCount' and count(parameter)=0]"
171-
[Register ("get_StaticCount", "()I", "Getget_StaticCountHandler")]
171+
[Register ("get_StaticCount", "()I", "")]
172172
get {
173173
const string __id = "get_StaticCount.()I";
174174
try {
@@ -178,7 +178,7 @@ public partial class MyClass {
178178
}
179179
}
180180
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_StaticCount' and count(parameter)=1 and parameter[1][@type='int']]"
181-
[Register ("set_StaticCount", "(I)V", "Getset_StaticCount_IHandler")]
181+
[Register ("set_StaticCount", "(I)V", "")]
182182
set {
183183
const string __id = "set_StaticCount.(I)V";
184184
try {

tools/generator/Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteClassProperties.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public virtual unsafe string Key {
115115

116116
public static unsafe int StaticCount {
117117
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_StaticCount' and count(parameter)=0]"
118-
[Register ("get_StaticCount", "()I", "Getget_StaticCountHandler")]
118+
[Register ("get_StaticCount", "()I", "")]
119119
get {
120120
const string __id = "get_StaticCount.()I";
121121
try {
@@ -125,7 +125,7 @@ public static unsafe int StaticCount {
125125
}
126126
}
127127
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_StaticCount' and count(parameter)=1 and parameter[1][@type='int']]"
128-
[Register ("set_StaticCount", "(I)V", "Getset_StaticCount_IHandler")]
128+
[Register ("set_StaticCount", "(I)V", "")]
129129
set {
130130
const string __id = "set_StaticCount.(I)V";
131131
try {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ public partial interface IMyInterface : IJavaObject, IJavaPeerable {
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]"
8-
[Register ("get_Value", "()I", "Getget_ValueHandler")]
8+
[Register ("get_Value", "()I", "")]
99
get {
1010
const string __id = "get_Value.()I";
1111
try {
@@ -15,7 +15,7 @@ public partial interface IMyInterface : IJavaObject, IJavaPeerable {
1515
}
1616
}
1717
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='set_Value' and count(parameter)=1 and parameter[1][@type='int']]"
18-
[Register ("set_Value", "(I)V", "Getset_Value_IHandler")]
18+
[Register ("set_Value", "(I)V", "")]
1919
set {
2020
const string __id = "set_Value.(I)V";
2121
try {

tools/generator/Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteClass.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public partial class MyClass {
168168

169169
public static unsafe int StaticCount {
170170
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_StaticCount' and count(parameter)=0]"
171-
[Register ("get_StaticCount", "()I", "Getget_StaticCountHandler")]
171+
[Register ("get_StaticCount", "()I", "")]
172172
get {
173173
const string __id = "get_StaticCount.()I";
174174
try {
@@ -178,7 +178,7 @@ public partial class MyClass {
178178
}
179179
}
180180
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_StaticCount' and count(parameter)=1 and parameter[1][@type='int']]"
181-
[Register ("set_StaticCount", "(I)V", "Getset_StaticCount_IHandler")]
181+
[Register ("set_StaticCount", "(I)V", "")]
182182
set {
183183
const string __id = "set_StaticCount.(I)V";
184184
try {

tools/generator/Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteClassProperties.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public virtual unsafe string Key {
115115

116116
public static unsafe int StaticCount {
117117
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_StaticCount' and count(parameter)=0]"
118-
[Register ("get_StaticCount", "()I", "Getget_StaticCountHandler")]
118+
[Register ("get_StaticCount", "()I", "")]
119119
get {
120120
const string __id = "get_StaticCount.()I";
121121
try {
@@ -125,7 +125,7 @@ public static unsafe int StaticCount {
125125
}
126126
}
127127
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_StaticCount' and count(parameter)=1 and parameter[1][@type='int']]"
128-
[Register ("set_StaticCount", "(I)V", "Getset_StaticCount_IHandler")]
128+
[Register ("set_StaticCount", "(I)V", "")]
129129
set {
130130
const string __id = "set_StaticCount.(I)V";
131131
try {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ public partial interface IMyInterface : IJavaObject, IJavaPeerable {
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]"
8-
[Register ("get_Value", "()I", "Getget_ValueHandler")]
8+
[Register ("get_Value", "()I", "")]
99
get {
1010
const string __id = "get_Value.()I";
1111
try {
@@ -15,7 +15,7 @@ public partial interface IMyInterface : IJavaObject, IJavaPeerable {
1515
}
1616
}
1717
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='set_Value' and count(parameter)=1 and parameter[1][@type='int']]"
18-
[Register ("set_Value", "(I)V", "Getset_Value_IHandler")]
18+
[Register ("set_Value", "(I)V", "")]
1919
set {
2020
const string __id = "set_Value.(I)V";
2121
try {

tools/generator/Tests/Unit-Tests/CodeGeneratorExpectedResults/XamarinAndroid/WriteClass.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public partial class MyClass {
212212
static IntPtr id_set_StaticCount_I;
213213
public static unsafe int StaticCount {
214214
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_StaticCount' and count(parameter)=0]"
215-
[Register ("get_StaticCount", "()I", "Getget_StaticCountHandler")]
215+
[Register ("get_StaticCount", "()I", "")]
216216
get {
217217
if (id_get_StaticCount == IntPtr.Zero)
218218
id_get_StaticCount = JNIEnv.GetStaticMethodID (class_ref, "get_StaticCount", "()I");
@@ -222,7 +222,7 @@ public partial class MyClass {
222222
}
223223
}
224224
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_StaticCount' and count(parameter)=1 and parameter[1][@type='int']]"
225-
[Register ("set_StaticCount", "(I)V", "Getset_StaticCount_IHandler")]
225+
[Register ("set_StaticCount", "(I)V", "")]
226226
set {
227227
if (id_set_StaticCount_I == IntPtr.Zero)
228228
id_set_StaticCount_I = JNIEnv.GetStaticMethodID (class_ref, "set_StaticCount", "(I)V");

tools/generator/Tests/Unit-Tests/CodeGeneratorExpectedResults/XamarinAndroid/WriteClassProperties.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ static IntPtr id_get_StaticCount;
139139
static IntPtr id_set_StaticCount_I;
140140
public static unsafe int StaticCount {
141141
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_StaticCount' and count(parameter)=0]"
142-
[Register ("get_StaticCount", "()I", "Getget_StaticCountHandler")]
142+
[Register ("get_StaticCount", "()I", "")]
143143
get {
144144
if (id_get_StaticCount == IntPtr.Zero)
145145
id_get_StaticCount = JNIEnv.GetStaticMethodID (class_ref, "get_StaticCount", "()I");
@@ -149,7 +149,7 @@ public static unsafe int StaticCount {
149149
}
150150
}
151151
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_StaticCount' and count(parameter)=1 and parameter[1][@type='int']]"
152-
[Register ("set_StaticCount", "(I)V", "Getset_StaticCount_IHandler")]
152+
[Register ("set_StaticCount", "(I)V", "")]
153153
set {
154154
if (id_set_StaticCount_I == IntPtr.Zero)
155155
id_set_StaticCount_I = JNIEnv.GetStaticMethodID (class_ref, "set_StaticCount", "(I)V");

tools/generator/Tests/expected.ji/StaticProperties/Xamarin.Test.SomeObject.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected SomeObject (IntPtr javaReference, JniHandleOwnership transfer) : base
3232

3333
public static unsafe int SomeInteger {
3434
// Metadata.xml XPath method reference: path="/api/package[@name='xamarin.test']/class[@name='SomeObject']/method[@name='getSomeInteger' and count(parameter)=0]"
35-
[Register ("getSomeInteger", "()I", "GetGetSomeIntegerHandler")]
35+
[Register ("getSomeInteger", "()I", "")]
3636
get {
3737
const string __id = "getSomeInteger.()I";
3838
try {
@@ -42,7 +42,7 @@ public static unsafe int SomeInteger {
4242
}
4343
}
4444
// Metadata.xml XPath method reference: path="/api/package[@name='xamarin.test']/class[@name='SomeObject']/method[@name='setSomeInteger' and count(parameter)=1 and parameter[1][@type='int']]"
45-
[Register ("setSomeInteger", "(I)V", "GetSetSomeInteger_IHandler")]
45+
[Register ("setSomeInteger", "(I)V", "")]
4646
set {
4747
const string __id = "setSomeInteger.(I)V";
4848
try {
@@ -56,7 +56,7 @@ public static unsafe int SomeInteger {
5656

5757
public static unsafe string SomeString {
5858
// Metadata.xml XPath method reference: path="/api/package[@name='xamarin.test']/class[@name='SomeObject']/method[@name='getSomeString' and count(parameter)=0]"
59-
[Register ("getSomeString", "()Ljava/lang/String;", "GetGetSomeStringHandler")]
59+
[Register ("getSomeString", "()Ljava/lang/String;", "")]
6060
get {
6161
const string __id = "getSomeString.()Ljava/lang/String;";
6262
try {
@@ -66,7 +66,7 @@ public static unsafe string SomeString {
6666
}
6767
}
6868
// Metadata.xml XPath method reference: path="/api/package[@name='xamarin.test']/class[@name='SomeObject']/method[@name='setSomeString' and count(parameter)=1 and parameter[1][@type='java.lang.String']]"
69-
[Register ("setSomeString", "(Ljava/lang/String;)V", "GetSetSomeString_Ljava_lang_String_Handler")]
69+
[Register ("setSomeString", "(Ljava/lang/String;)V", "")]
7070
set {
7171
const string __id = "setSomeString.(Ljava/lang/String;)V";
7272
IntPtr native_value = JNIEnv.NewString (value);

0 commit comments

Comments
 (0)