Skip to content

[generator] Clean up generated whitespace. #692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/Xamarin.SourceWriter/CodeWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,34 @@ public void Write (string value)

public void WriteLine ()
{
WriteIndent ();
stream.WriteLine ();
need_indent = true;
}

public void WriteLine (string value)
{
WriteIndent ();
if (value?.Length > 0)
WriteIndent ();

stream.WriteLine (value);
need_indent = true;
}

public void WriteLine (string format, params object[] args)
{
WriteIndent ();
if (format?.Length > 0)
WriteIndent ();

stream.WriteLine (format, args);
need_indent = true;
}

public void WriteLineNoIndent (string value)
{
stream.WriteLine (value);
need_indent = true;
}

public void Indent (int count = 1) => indent += count;
public void Unindent (int count = 1) => indent -= count;

Expand Down
5 changes: 4 additions & 1 deletion src/Xamarin.SourceWriter/Models/CommentWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ public CommentWriter (string value)

public virtual void Write (CodeWriter writer)
{
writer.WriteLine (Value);
if (Value.StartsWith ("#pragma"))
writer.WriteLineNoIndent (Value);
else
writer.WriteLine (Value);
}
}
}
27 changes: 26 additions & 1 deletion src/Xamarin.SourceWriter/Models/PropertyWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,43 @@ protected virtual void WriteBody (CodeWriter writer)

protected virtual void WriteAutomaticPropertyBody (CodeWriter writer)
{
writer.Write ("{ ");
var need_unindent = false;

writer.Write ("{");

if (HasGet) {
if (GetterComments.Count > 0 || GetterAttributes.Count > 0) {
writer.WriteLine ();
writer.Indent ();
need_unindent = true;
}

WriteGetterComments (writer);
WriteGetterAttributes (writer);
writer.Write ("get; ");

if (need_unindent) {
writer.WriteLine ();
writer.Unindent ();
need_unindent = false;
}
}

if (HasSet) {
if (SetterComments.Count > 0 || SetterAttributes.Count > 0) {
writer.WriteLine ();
writer.Indent ();
need_unindent = true;
}

WriteSetterComments (writer);
WriteSetterAttributes (writer);
writer.Write ("set; ");

if (need_unindent) {
writer.WriteLine ();
writer.Unindent ();
}
}

writer.WriteLine ("}");
Expand Down
4 changes: 0 additions & 4 deletions src/Xamarin.SourceWriter/Models/TypeWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,9 @@ public virtual void WriteMembers (CodeWriter writer)

WriteConstructors (writer);

writer.WriteLine ();
WriteEvents (writer);
writer.WriteLine ();
WriteDelegates (writer);
writer.WriteLine ();
WriteProperties (writer);
writer.WriteLine ();
WriteMethods (writer);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/Xamarin.SourceWriter-Tests/ClassWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ public void Basics ()
var expected =
@"public partial class MyClass : System.Object {
public bool my_field;

// Test comment

public void MyMethod (bool test)
{
}

}
";

Expand Down
2 changes: 1 addition & 1 deletion tests/Xamarin.SourceWriter-Tests/InterfaceWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void Basics ()
var expected =
@"public partial interface IMyInterface : IDisposable {
void MyMethod (bool test);

}
";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[Register ("com/xamarin/android/Parent", DoNotGenerateAcw=true)]
[global::System.Obsolete ("Use the 'Com.Xamarin.Android.IParent' type. This class will be removed in a future release.")]
public abstract class Parent : Java.Lang.Object {

internal Parent ()
{
}
Expand All @@ -28,6 +27,7 @@ public abstract class Parent : Java.Lang.Object {
return JNIEnv.GetString (__v.Handle, JniHandleOwnership.TransferLocalRef);
}
}

// Metadata.xml XPath method reference: path="/api/package[@name='com.xamarin.android']/interface[@name='Parent']/method[@name='comparing' and count(parameter)=0]"
[Obsolete (@"Use 'Com.Xamarin.Android.IParent.Comparing'. This class will be removed in a future release.")]
[Register ("comparing", "()I", "")]
Expand All @@ -54,8 +54,8 @@ public abstract class Parent : Java.Lang.Object {
}
}


static readonly JniPeerMembers _members = new JniPeerMembers ("com/xamarin/android/Parent", typeof (Parent));

}

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

[global::Android.Runtime.Register ("com/xamarin/android/Parent", DoNotGenerateAcw=true)]
internal partial class IParentInvoker : global::Java.Lang.Object, IParent {

static readonly JniPeerMembers _members = new JniPeerMembers ("com/xamarin/android/Parent", typeof (IParentInvoker));

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

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

}

Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
// Metadata.xml XPath class reference: path="/api/package[@name='java.code']/class[@name='MyClass']"
[global::Android.Runtime.Register ("java/code/MyClass", DoNotGenerateAcw=true)]
public partial class MyClass {

public partial class MyClass {
static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/MyClass", typeof (MyClass));

internal static IntPtr class_ref {
get {
return _members.JniPeerType.PeerReference.Handle;
}
get { return _members.JniPeerType.PeerReference.Handle; }
}

protected MyClass (IntPtr javaReference, JniHandleOwnership transfer) : base (javaReference, transfer) {}
protected MyClass (IntPtr javaReference, JniHandleOwnership transfer) : base (javaReference, transfer)
{
}

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

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

// 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']]"
[Register (".ctor", "(Ljava/lang/String;)V", "")]
unsafe MyClass (string p0)
: base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer)
unsafe MyClass (string p0) : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer)
{
const string __id = "(Ljava/lang/String;)V";

Expand Down Expand Up @@ -224,9 +222,12 @@ public partial class MyClass {

public abstract int AbstractCount {
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_AbstractCount' and count(parameter)=0]"
[Register ("get_AbstractCount", "()I", "Getget_AbstractCountHandler")] get;
[Register ("get_AbstractCount", "()I", "Getget_AbstractCountHandler")]
get;

// 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']]"
[Register ("set_AbstractCount", "(I)V", "Getset_AbstractCount_IHandler")] set;
[Register ("set_AbstractCount", "(I)V", "Getset_AbstractCount_IHandler")]
set;
}

static Delegate cb_GetCountForKey_Ljava_lang_String_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,40 @@
[Register ("java/code/IMyInterface", "", "java.code.IMyInterfaceInvoker")]
public partial interface IMyInterface : IJavaObject, IJavaPeerable {
private static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/IMyInterface", typeof (IMyInterface), isInterface: true);

// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='DoDeclaration' and count(parameter)=0]"
[Register ("DoDeclaration", "()V", "GetDoDeclarationHandler:java.code.IMyInterfaceInvoker, MyAssembly")]
void DoDeclaration ();

private static Delegate cb_DoDefault;
#pragma warning disable 0169
#pragma warning disable 0169
private static Delegate GetDoDefaultHandler ()
{
if (cb_DoDefault == null)
cb_DoDefault = JNINativeWrapper.CreateDelegate ((_JniMarshal_PP_V) n_DoDefault);
return cb_DoDefault;
}

private static void n_DoDefault (IntPtr jnienv, IntPtr native__this)
{
var __this = global::Java.Lang.Object.GetObject<java.code.IMyInterface> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
__this.DoDefault ();
}
#pragma warning restore 0169
#pragma warning restore 0169

// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='DoDefault' and count(parameter)=0]"
[Register ("DoDefault", "()V", "GetDoDefaultHandler:java.code.IMyInterface, MyAssembly")]
virtual unsafe void DoDefault ()
{
const string __id = "DoDefault.()V";
try {
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, null);
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, null);
} finally {
}
}

}

[global::Android.Runtime.Register ("java/code/IMyInterface", DoNotGenerateAcw=true)]
internal partial class IMyInterfaceInvoker : global::Java.Lang.Object, IMyInterface {
static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/IMyInterface", typeof (IMyInterfaceInvoker));
Expand Down Expand Up @@ -63,8 +66,7 @@ internal partial class IMyInterfaceInvoker : global::Java.Lang.Object, IMyInterf
static IntPtr Validate (IntPtr handle)
{
if (!JNIEnv.IsInstanceOf (handle, java_class_ref))
throw new InvalidCastException (string.Format ("Unable to convert instance of type '{0}' to type '{1}'.",
JNIEnv.GetClassNameFromInstance (handle), "java.code.IMyInterface"));
throw new InvalidCastException (string.Format ("Unable to convert instance of type '{0}' to type '{1}'.", JNIEnv.GetClassNameFromInstance (handle), "java.code.IMyInterface"));
return handle;
}

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

}

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[Register ("java/code/IMyInterface", DoNotGenerateAcw=true)]
public abstract class MyInterface : Java.Lang.Object {

internal MyInterface ()
{
}

// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='StaticMethod' and count(parameter)=0]"
[Register ("StaticMethod", "()V", "")]
public static unsafe void StaticMethod ()
Expand All @@ -15,42 +15,50 @@ public abstract class MyInterface : Java.Lang.Object {
}
}


static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/IMyInterface", typeof (MyInterface));

}

[Register ("java/code/IMyInterface", DoNotGenerateAcw=true)]
[global::System.Obsolete ("Use the 'MyInterface' type. This type will be removed in a future release.", error: true)]
public abstract class MyInterfaceConsts : MyInterface {

private MyInterfaceConsts ()
{
}

}

// Metadata.xml XPath interface reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']"
[Register ("java/code/IMyInterface", "", "java.code.IMyInterfaceInvoker")]
public partial interface IMyInterface : IJavaObject, IJavaPeerable {

int Count {
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='get_Count' and count(parameter)=0]"
[Register ("get_Count", "()I", "Getget_CountHandler:java.code.IMyInterfaceInvoker, ")] get;
[Register ("get_Count", "()I", "Getget_CountHandler:java.code.IMyInterfaceInvoker, ")]
get;

// 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']]"
[Register ("set_Count", "(I)V", "Getset_Count_IHandler:java.code.IMyInterfaceInvoker, ")] set;
[Register ("set_Count", "(I)V", "Getset_Count_IHandler:java.code.IMyInterfaceInvoker, ")]
set;
}

string Key {
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='get_Key' and count(parameter)=0]"
[Register ("get_Key", "()Ljava/lang/String;", "Getget_KeyHandler:java.code.IMyInterfaceInvoker, ")] get;
[Register ("get_Key", "()Ljava/lang/String;", "Getget_KeyHandler:java.code.IMyInterfaceInvoker, ")]
get;

// 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']]"
[Register ("set_Key", "(Ljava/lang/String;)V", "Getset_Key_Ljava_lang_String_Handler:java.code.IMyInterfaceInvoker, ")] set;
[Register ("set_Key", "(Ljava/lang/String;)V", "Getset_Key_Ljava_lang_String_Handler:java.code.IMyInterfaceInvoker, ")]
set;
}

int AbstractCount {
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='get_AbstractCount' and count(parameter)=0]"
[Register ("get_AbstractCount", "()I", "Getget_AbstractCountHandler:java.code.IMyInterfaceInvoker, ")] get;
[Register ("get_AbstractCount", "()I", "Getget_AbstractCountHandler:java.code.IMyInterfaceInvoker, ")]
get;

// 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']]"
[Register ("set_AbstractCount", "(I)V", "Getset_AbstractCount_IHandler:java.code.IMyInterfaceInvoker, ")] set;
[Register ("set_AbstractCount", "(I)V", "Getset_AbstractCount_IHandler:java.code.IMyInterfaceInvoker, ")]
set;
}

// 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']]"
Expand All @@ -69,7 +77,6 @@ public partial interface IMyInterface : IJavaObject, IJavaPeerable {

[global::Android.Runtime.Register ("java/code/IMyInterface", DoNotGenerateAcw=true)]
internal partial class IMyInterfaceInvoker : global::Java.Lang.Object, IMyInterface {

static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/IMyInterface", typeof (IMyInterfaceInvoker));

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

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

}

Loading