Skip to content

Commit 9ee9225

Browse files
committed
[generator] Clean up generated whitespace.
1 parent 007b35b commit 9ee9225

File tree

121 files changed

+924
-970
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+924
-970
lines changed

src/Xamarin.SourceWriter/CodeWriter.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,34 @@ public void Write (string value)
3333

3434
public void WriteLine ()
3535
{
36-
WriteIndent ();
3736
stream.WriteLine ();
3837
need_indent = true;
3938
}
4039

4140
public void WriteLine (string value)
4241
{
43-
WriteIndent ();
42+
if (value?.Length > 0)
43+
WriteIndent ();
44+
4445
stream.WriteLine (value);
4546
need_indent = true;
4647
}
4748

4849
public void WriteLine (string format, params object[] args)
4950
{
50-
WriteIndent ();
51+
if (format?.Length > 0)
52+
WriteIndent ();
53+
5154
stream.WriteLine (format, args);
5255
need_indent = true;
5356
}
5457

58+
public void WriteLineNoIndent (string value)
59+
{
60+
stream.WriteLine (value);
61+
need_indent = true;
62+
}
63+
5564
public void Indent (int count = 1) => indent += count;
5665
public void Unindent (int count = 1) => indent -= count;
5766

src/Xamarin.SourceWriter/Models/CommentWriter.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ public CommentWriter (string value)
1616

1717
public virtual void Write (CodeWriter writer)
1818
{
19-
writer.WriteLine (Value);
19+
if (Value.StartsWith ("#pragma"))
20+
writer.WriteLineNoIndent (Value);
21+
else
22+
writer.WriteLine (Value);
2023
}
2124
}
2225
}

src/Xamarin.SourceWriter/Models/PropertyWriter.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,18 +156,43 @@ protected virtual void WriteBody (CodeWriter writer)
156156

157157
protected virtual void WriteAutomaticPropertyBody (CodeWriter writer)
158158
{
159-
writer.Write ("{ ");
159+
var need_unindent = false;
160+
161+
writer.Write ("{");
160162

161163
if (HasGet) {
164+
if (GetterComments.Count > 0 || GetterAttributes.Count > 0) {
165+
writer.WriteLine ();
166+
writer.Indent ();
167+
need_unindent = true;
168+
}
169+
162170
WriteGetterComments (writer);
163171
WriteGetterAttributes (writer);
164172
writer.Write ("get; ");
173+
174+
if (need_unindent) {
175+
writer.WriteLine ();
176+
writer.Unindent ();
177+
need_unindent = false;
178+
}
165179
}
166180

167181
if (HasSet) {
182+
if (SetterComments.Count > 0 || SetterAttributes.Count > 0) {
183+
writer.WriteLine ();
184+
writer.Indent ();
185+
need_unindent = true;
186+
}
187+
168188
WriteSetterComments (writer);
169189
WriteSetterAttributes (writer);
170190
writer.Write ("set; ");
191+
192+
if (need_unindent) {
193+
writer.WriteLine ();
194+
writer.Unindent ();
195+
}
171196
}
172197

173198
writer.WriteLine ("}");

src/Xamarin.SourceWriter/Models/TypeWriter.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,9 @@ public virtual void WriteMembers (CodeWriter writer)
158158

159159
WriteConstructors (writer);
160160

161-
writer.WriteLine ();
162161
WriteEvents (writer);
163-
writer.WriteLine ();
164162
WriteDelegates (writer);
165-
writer.WriteLine ();
166163
WriteProperties (writer);
167-
writer.WriteLine ();
168164
WriteMethods (writer);
169165
}
170166

tests/Xamarin.SourceWriter-Tests/ClassWriterTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ public void Basics ()
3434
var expected =
3535
@"public partial class MyClass : System.Object {
3636
public bool my_field;
37-
37+
3838
// Test comment
39-
39+
4040
public void MyMethod (bool test)
4141
{
4242
}
43-
43+
4444
}
4545
";
4646

tests/Xamarin.SourceWriter-Tests/InterfaceWriterTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void Basics ()
3131
var expected =
3232
@"public partial interface IMyInterface : IDisposable {
3333
void MyMethod (bool test);
34-
34+
3535
}
3636
";
3737

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[Register ("com/xamarin/android/Parent", DoNotGenerateAcw=true)]
22
[global::System.Obsolete ("Use the 'Com.Xamarin.Android.IParent' type. This class will be removed in a future release.")]
33
public abstract class Parent : Java.Lang.Object {
4-
54
internal Parent ()
65
{
76
}
@@ -28,6 +27,7 @@ public abstract class Parent : Java.Lang.Object {
2827
return JNIEnv.GetString (__v.Handle, JniHandleOwnership.TransferLocalRef);
2928
}
3029
}
30+
3131
// Metadata.xml XPath method reference: path="/api/package[@name='com.xamarin.android']/interface[@name='Parent']/method[@name='comparing' and count(parameter)=0]"
3232
[Obsolete (@"Use 'Com.Xamarin.Android.IParent.Comparing'. This class will be removed in a future release.")]
3333
[Register ("comparing", "()I", "")]
@@ -54,8 +54,8 @@ public abstract class Parent : Java.Lang.Object {
5454
}
5555
}
5656

57-
5857
static readonly JniPeerMembers _members = new JniPeerMembers ("com/xamarin/android/Parent", typeof (Parent));
58+
5959
}
6060

6161
// Metadata.xml XPath interface reference: path="/api/package[@name='com.xamarin.android']/interface[@name='Parent']"
@@ -101,7 +101,6 @@ public partial interface IParent : IJavaObject, IJavaPeerable {
101101

102102
[global::Android.Runtime.Register ("com/xamarin/android/Parent", DoNotGenerateAcw=true)]
103103
internal partial class IParentInvoker : global::Java.Lang.Object, IParent {
104-
105104
static readonly JniPeerMembers _members = new JniPeerMembers ("com/xamarin/android/Parent", typeof (IParentInvoker));
106105

107106
static IntPtr java_class_ref {
@@ -130,8 +129,7 @@ internal partial class IParentInvoker : global::Java.Lang.Object, IParent {
130129
static IntPtr Validate (IntPtr handle)
131130
{
132131
if (!JNIEnv.IsInstanceOf (handle, java_class_ref))
133-
throw new InvalidCastException (string.Format ("Unable to convert instance of type '{0}' to type '{1}'.",
134-
JNIEnv.GetClassNameFromInstance (handle), "com.xamarin.android.Parent"));
132+
throw new InvalidCastException (string.Format ("Unable to convert instance of type '{0}' to type '{1}'.", JNIEnv.GetClassNameFromInstance (handle), "com.xamarin.android.Parent"));
135133
return handle;
136134
}
137135

@@ -151,4 +149,3 @@ internal partial class IParentInvoker : global::Java.Lang.Object, IParent {
151149
}
152150

153151
}
154-

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
// Metadata.xml XPath class reference: path="/api/package[@name='java.code']/class[@name='MyClass']"
22
[global::Android.Runtime.Register ("java/code/MyClass", DoNotGenerateAcw=true)]
3-
public partial class MyClass {
4-
3+
public partial class MyClass {
54
static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/MyClass", typeof (MyClass));
5+
66
internal static IntPtr class_ref {
7-
get {
8-
return _members.JniPeerType.PeerReference.Handle;
9-
}
7+
get { return _members.JniPeerType.PeerReference.Handle; }
108
}
119

12-
protected MyClass (IntPtr javaReference, JniHandleOwnership transfer) : base (javaReference, transfer) {}
10+
protected MyClass (IntPtr javaReference, JniHandleOwnership transfer) : base (javaReference, transfer)
11+
{
12+
}
1313

1414
// Metadata.xml XPath constructor reference: path="/api/package[@name='java.code']/class[@name='MyClass']/constructor[@name='MyClass' and count(parameter)=0]"
1515
[Register (".ctor", "()V", "")]
16-
unsafe MyClass ()
17-
: base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer)
16+
unsafe MyClass () : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer)
1817
{
1918
const string __id = "()V";
2019

@@ -31,8 +30,7 @@ public partial class MyClass {
3130

3231
// Metadata.xml XPath constructor reference: path="/api/package[@name='java.code']/class[@name='MyClass']/constructor[@name='MyClass' and count(parameter)=1 and parameter[1][@type='java.lang.String']]"
3332
[Register (".ctor", "(Ljava/lang/String;)V", "")]
34-
unsafe MyClass (string p0)
35-
: base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer)
33+
unsafe MyClass (string p0) : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer)
3634
{
3735
const string __id = "(Ljava/lang/String;)V";
3836

@@ -224,9 +222,12 @@ public partial class MyClass {
224222

225223
public abstract int AbstractCount {
226224
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_AbstractCount' and count(parameter)=0]"
227-
[Register ("get_AbstractCount", "()I", "Getget_AbstractCountHandler")] get;
225+
[Register ("get_AbstractCount", "()I", "Getget_AbstractCountHandler")]
226+
get;
227+
228228
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_AbstractCount' and count(parameter)=1 and parameter[1][@type='int']]"
229-
[Register ("set_AbstractCount", "(I)V", "Getset_AbstractCount_IHandler")] set;
229+
[Register ("set_AbstractCount", "(I)V", "Getset_AbstractCount_IHandler")]
230+
set;
230231
}
231232

232233
static Delegate cb_GetCountForKey_Ljava_lang_String_;

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,40 @@
22
[Register ("java/code/IMyInterface", "", "java.code.IMyInterfaceInvoker")]
33
public partial interface IMyInterface : IJavaObject, IJavaPeerable {
44
private static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/IMyInterface", typeof (IMyInterface), isInterface: true);
5-
5+
66
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='DoDeclaration' and count(parameter)=0]"
77
[Register ("DoDeclaration", "()V", "GetDoDeclarationHandler:java.code.IMyInterfaceInvoker, MyAssembly")]
88
void DoDeclaration ();
9-
9+
1010
private static Delegate cb_DoDefault;
11-
#pragma warning disable 0169
11+
#pragma warning disable 0169
1212
private static Delegate GetDoDefaultHandler ()
1313
{
1414
if (cb_DoDefault == null)
1515
cb_DoDefault = JNINativeWrapper.CreateDelegate ((_JniMarshal_PP_V) n_DoDefault);
1616
return cb_DoDefault;
1717
}
18+
1819
private static void n_DoDefault (IntPtr jnienv, IntPtr native__this)
1920
{
2021
var __this = global::Java.Lang.Object.GetObject<java.code.IMyInterface> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
2122
__this.DoDefault ();
2223
}
23-
#pragma warning restore 0169
24+
#pragma warning restore 0169
25+
2426
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='DoDefault' and count(parameter)=0]"
2527
[Register ("DoDefault", "()V", "GetDoDefaultHandler:java.code.IMyInterface, MyAssembly")]
2628
virtual unsafe void DoDefault ()
2729
{
2830
const string __id = "DoDefault.()V";
2931
try {
30-
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, null);
32+
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, null);
3133
} finally {
3234
}
3335
}
34-
36+
3537
}
38+
3639
[global::Android.Runtime.Register ("java/code/IMyInterface", DoNotGenerateAcw=true)]
3740
internal partial class IMyInterfaceInvoker : global::Java.Lang.Object, IMyInterface {
3841
static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/IMyInterface", typeof (IMyInterfaceInvoker));
@@ -63,8 +66,7 @@ internal partial class IMyInterfaceInvoker : global::Java.Lang.Object, IMyInterf
6366
static IntPtr Validate (IntPtr handle)
6467
{
6568
if (!JNIEnv.IsInstanceOf (handle, java_class_ref))
66-
throw new InvalidCastException (string.Format ("Unable to convert instance of type '{0}' to type '{1}'.",
67-
JNIEnv.GetClassNameFromInstance (handle), "java.code.IMyInterface"));
69+
throw new InvalidCastException (string.Format ("Unable to convert instance of type '{0}' to type '{1}'.", JNIEnv.GetClassNameFromInstance (handle), "java.code.IMyInterface"));
6870
return handle;
6971
}
7072

@@ -108,4 +110,3 @@ internal partial class IMyInterfaceInvoker : global::Java.Lang.Object, IMyInterf
108110
}
109111

110112
}
111-

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

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[Register ("java/code/IMyInterface", DoNotGenerateAcw=true)]
22
public abstract class MyInterface : Java.Lang.Object {
3-
43
internal MyInterface ()
54
{
65
}
6+
77
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='StaticMethod' and count(parameter)=0]"
88
[Register ("StaticMethod", "()V", "")]
99
public static unsafe void StaticMethod ()
@@ -15,42 +15,50 @@ public abstract class MyInterface : Java.Lang.Object {
1515
}
1616
}
1717

18-
1918
static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/IMyInterface", typeof (MyInterface));
19+
2020
}
2121

2222
[Register ("java/code/IMyInterface", DoNotGenerateAcw=true)]
2323
[global::System.Obsolete ("Use the 'MyInterface' type. This type will be removed in a future release.", error: true)]
2424
public abstract class MyInterfaceConsts : MyInterface {
25-
2625
private MyInterfaceConsts ()
2726
{
2827
}
28+
2929
}
3030

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-
3534
int Count {
3635
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='get_Count' and count(parameter)=0]"
37-
[Register ("get_Count", "()I", "Getget_CountHandler:java.code.IMyInterfaceInvoker, ")] get;
36+
[Register ("get_Count", "()I", "Getget_CountHandler:java.code.IMyInterfaceInvoker, ")]
37+
get;
38+
3839
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='set_Count' and count(parameter)=1 and parameter[1][@type='int']]"
39-
[Register ("set_Count", "(I)V", "Getset_Count_IHandler:java.code.IMyInterfaceInvoker, ")] set;
40+
[Register ("set_Count", "(I)V", "Getset_Count_IHandler:java.code.IMyInterfaceInvoker, ")]
41+
set;
4042
}
4143

4244
string Key {
4345
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='get_Key' and count(parameter)=0]"
44-
[Register ("get_Key", "()Ljava/lang/String;", "Getget_KeyHandler:java.code.IMyInterfaceInvoker, ")] get;
46+
[Register ("get_Key", "()Ljava/lang/String;", "Getget_KeyHandler:java.code.IMyInterfaceInvoker, ")]
47+
get;
48+
4549
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='set_Key' and count(parameter)=1 and parameter[1][@type='java.lang.String']]"
46-
[Register ("set_Key", "(Ljava/lang/String;)V", "Getset_Key_Ljava_lang_String_Handler:java.code.IMyInterfaceInvoker, ")] set;
50+
[Register ("set_Key", "(Ljava/lang/String;)V", "Getset_Key_Ljava_lang_String_Handler:java.code.IMyInterfaceInvoker, ")]
51+
set;
4752
}
4853

4954
int AbstractCount {
5055
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='get_AbstractCount' and count(parameter)=0]"
51-
[Register ("get_AbstractCount", "()I", "Getget_AbstractCountHandler:java.code.IMyInterfaceInvoker, ")] get;
56+
[Register ("get_AbstractCount", "()I", "Getget_AbstractCountHandler:java.code.IMyInterfaceInvoker, ")]
57+
get;
58+
5259
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='set_AbstractCount' and count(parameter)=1 and parameter[1][@type='int']]"
53-
[Register ("set_AbstractCount", "(I)V", "Getset_AbstractCount_IHandler:java.code.IMyInterfaceInvoker, ")] set;
60+
[Register ("set_AbstractCount", "(I)V", "Getset_AbstractCount_IHandler:java.code.IMyInterfaceInvoker, ")]
61+
set;
5462
}
5563

5664
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='GetCountForKey' and count(parameter)=1 and parameter[1][@type='java.lang.String']]"
@@ -69,7 +77,6 @@ public partial interface IMyInterface : IJavaObject, IJavaPeerable {
6977

7078
[global::Android.Runtime.Register ("java/code/IMyInterface", DoNotGenerateAcw=true)]
7179
internal partial class IMyInterfaceInvoker : global::Java.Lang.Object, IMyInterface {
72-
7380
static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/IMyInterface", typeof (IMyInterfaceInvoker));
7481

7582
static IntPtr java_class_ref {
@@ -98,8 +105,7 @@ internal partial class IMyInterfaceInvoker : global::Java.Lang.Object, IMyInterf
98105
static IntPtr Validate (IntPtr handle)
99106
{
100107
if (!JNIEnv.IsInstanceOf (handle, java_class_ref))
101-
throw new InvalidCastException (string.Format ("Unable to convert instance of type '{0}' to type '{1}'.",
102-
JNIEnv.GetClassNameFromInstance (handle), "java.code.IMyInterface"));
108+
throw new InvalidCastException (string.Format ("Unable to convert instance of type '{0}' to type '{1}'.", JNIEnv.GetClassNameFromInstance (handle), "java.code.IMyInterface"));
103109
return handle;
104110
}
105111

@@ -348,4 +354,3 @@ internal partial class IMyInterfaceInvoker : global::Java.Lang.Object, IMyInterf
348354
}
349355

350356
}
351-

0 commit comments

Comments
 (0)