Skip to content

Commit 437238f

Browse files
committed
Fixes for Mono.Android.dll.
1 parent 7e002f3 commit 437238f

26 files changed

+208
-116
lines changed

src/Xamarin.SourceWriter/Models/DelegateWriter.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44

55
namespace Xamarin.SourceWriter
66
{
7-
public class DelegateWriter : ISourceWriter
7+
public class DelegateWriter : ISourceWriter, ITakeParameters
88
{
99
private Visibility visibility;
1010

1111
public string Name { get; set; }
12+
public List<MethodParameterWriter> Parameters { get; } = new List<MethodParameterWriter> ();
1213
public TypeReferenceWriter Type { get; set; }
1314
public List<string> Comments { get; } = new List<string> ();
1415
public List<AttributeWriter> Attributes { get; } = new List<AttributeWriter> ();
@@ -23,7 +24,6 @@ public class DelegateWriter : ISourceWriter
2324
public bool IsProtected { get => visibility == Visibility.Protected; set => visibility = value ? Visibility.Protected : Visibility.Default; }
2425
public int Priority { get; set; }
2526
public bool IsShadow { get; set; }
26-
public string Signature { get; set; }
2727

2828
public void SetVisibility (string visibility)
2929
{
@@ -81,10 +81,29 @@ public virtual void WriteSignature (CodeWriter writer)
8181
if (IsShadow)
8282
writer.Write ("new ");
8383

84+
writer.Write ("delegate ");
85+
8486
WriteType (writer);
8587

8688
writer.Write (Name + " ");
87-
writer.Write ($"({Signature})");
89+
writer.Write ("(");
90+
91+
WriteParameters (writer);
92+
93+
writer.Write (")");
94+
95+
writer.Write (";");
96+
}
97+
98+
protected virtual void WriteParameters (CodeWriter writer)
99+
{
100+
for (var i = 0; i < Parameters.Count; i++) {
101+
var p = Parameters [i];
102+
p.WriteParameter (writer);
103+
104+
if (i < Parameters.Count - 1)
105+
writer.Write (", ");
106+
}
88107
}
89108

90109
protected virtual void WriteType (CodeWriter writer)

src/Xamarin.SourceWriter/Models/FieldWriter.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,27 @@ namespace Xamarin.SourceWriter
66
{
77
public class FieldWriter : ISourceWriter
88
{
9-
private Visibility visibility;
9+
Visibility visibility;
1010

1111
public string Name { get; set; }
1212
public TypeReferenceWriter Type { get; set; }
1313
public List<string> Comments { get; } = new List<string> ();
1414
public List<AttributeWriter> Attributes { get; } = new List<AttributeWriter> ();
15-
public bool IsPublic { get => visibility == Visibility.Public; set => visibility = value ? Visibility.Public : Visibility.Default; }
15+
public bool IsPublic { get => visibility.HasFlag (Visibility.Public); set => visibility = value ? Visibility.Public : Visibility.Default; }
1616
public bool UseExplicitPrivateKeyword { get; set; }
17-
public bool IsInternal { get => visibility == Visibility.Internal; set => visibility = value ? Visibility.Internal : Visibility.Default; }
17+
public bool IsInternal { get => visibility.HasFlag (Visibility.Internal); set => visibility = value ? Visibility.Internal : Visibility.Default; }
1818
public bool IsConst { get; set; }
1919
public string Value { get; set; }
2020
public bool IsStatic { get; set; }
2121
public bool IsReadonly { get; set; }
22-
public bool IsPrivate { get => visibility == Visibility.Private; set => visibility = value ? Visibility.Private : Visibility.Default; }
23-
public bool IsProtected { get => visibility == Visibility.Protected; set => visibility = value ? Visibility.Protected : Visibility.Default; }
22+
public bool IsPrivate { get => visibility.HasFlag (Visibility.Private); set => visibility = value ? Visibility.Private : Visibility.Default; }
23+
public bool IsProtected { get => visibility.HasFlag (Visibility.Protected); set => visibility = value ? Visibility.Protected : Visibility.Default; }
2424
public int Priority { get; set; }
2525
public bool IsShadow { get; set; }
2626

2727
public void SetVisibility (string visibility)
2828
{
29-
switch (visibility?.ToLowerInvariant ()) {
29+
switch (visibility?.ToLowerInvariant ().Trim ()) {
3030
case "public":
3131
IsPublic = true;
3232
break;
@@ -39,6 +39,9 @@ public void SetVisibility (string visibility)
3939
case "private":
4040
IsPrivate = true;
4141
break;
42+
default:
43+
Console.WriteLine ($"Unrecognized field visibility: `{visibility}`");
44+
break;
4245
}
4346
}
4447

@@ -65,6 +68,8 @@ public virtual void WriteSignature (CodeWriter writer)
6568
{
6669
if (IsPublic)
6770
writer.Write ("public ");
71+
else if (IsProtected)
72+
writer.Write ("protected ");
6873
else if (IsInternal)
6974
writer.Write ("internal ");
7075
else if (IsPrivate)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Xamarin.SourceWriter
6+
{
7+
public interface ITakeParameters
8+
{
9+
List<MethodParameterWriter> Parameters { get; }
10+
}
11+
}

src/Xamarin.SourceWriter/Models/MethodWriter.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Xamarin.SourceWriter
66
{
7-
public class MethodWriter : ISourceWriter
7+
public class MethodWriter : ISourceWriter, ITakeParameters
88
{
99
Visibility visibility;
1010

@@ -30,6 +30,7 @@ public class MethodWriter : ISourceWriter
3030
public bool IsDeclaration { get; set; }
3131

3232
public string ExplicitInterfaceImplementation { get; set; }
33+
public bool NewFirst { get; set; } // TODO: Temporary to match unit tests
3334

3435
public void SetVisibility (string visibility)
3536
{
@@ -70,6 +71,9 @@ public virtual void WriteAttributes (CodeWriter writer)
7071

7172
public virtual void WriteSignature (CodeWriter writer)
7273
{
74+
if (IsShadow && NewFirst)
75+
writer.Write ("new ");
76+
7377
if (IsPublic)
7478
writer.Write ("public ");
7579
if (IsInternal)
@@ -79,7 +83,7 @@ public virtual void WriteSignature (CodeWriter writer)
7983
if (IsPrivate)
8084
writer.Write ("private ");
8185

82-
if (IsShadow)
86+
if (IsShadow && !NewFirst)
8387
writer.Write ("new ");
8488

8589
if (IsOverride)

src/Xamarin.SourceWriter/Models/TypeWriter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Xamarin.SourceWriter
88
public abstract class TypeWriter : ISourceWriter
99
{
1010
Visibility visibility;
11-
int current_priority;
11+
int current_priority = 1;
1212

1313
public string Name { get; set; }
1414
public string Inherits { get; set; }
@@ -56,7 +56,7 @@ protected void MemberAdded (object sender, System.Collections.Specialized.Notify
5656

5757
public void SetVisibility (string visibility)
5858
{
59-
switch (visibility?.ToLowerInvariant ()) {
59+
switch (visibility?.ToLowerInvariant ().Trim ()) {
6060
case "public":
6161
IsPublic = true;
6262
break;

tests/generator-Tests/expected.ji/TestInterface/Test.ME.TestInterfaceImplementation.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public abstract partial class TestInterfaceImplementation : global::Java.Lang.Ob
1212

1313
public static class InterfaceConsts {
1414

15+
// The following are fields from: test.me.TestInterface
1516

1617
// Metadata.xml XPath field reference: path="/api/package[@name='test.me']/interface[@name='TestInterface']/field[@name='SPAN_COMPOSING']"
1718
[Register ("SPAN_COMPOSING")]

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1414,9 +1414,13 @@ public void WriteMethod (Method method, string indent, GenBase type, bool genera
14141414

14151415
public void WriteParameterListCallArgs (ParameterList parameters, string indent, bool invoker)
14161416
{
1417+
var lines = new List<string> ();
1418+
SourceWriterExtensions.AddParameterListCallArgs (lines, parameters, opt, invoker);
1419+
14171420
var cw = new CodeWriter (writer, indent);
14181421

1419-
SourceWriterExtensions.WriteParameterListCallArgs (cw, parameters, opt, invoker);
1422+
foreach (var l in lines)
1423+
cw.WriteLine (l);
14201424
}
14211425

14221426
public void WriteProperty (Property property, GenBase gen, string indent, bool with_callbacks = true, bool force_override = false)

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.IO;
34
using generator.SourceWriters;
45
using Mono.Options;
@@ -189,8 +190,13 @@ internal override void WriteMethodIdField (Method method, string indent)
189190

190191
internal override void WriteMethodBody (Method method, string indent, GenBase type)
191192
{
193+
var body = new List<string> ();
194+
SourceWriterExtensions.AddMethodBody (body, method, opt);
195+
192196
var cw = new CodeWriter (writer, indent);
193-
SourceWriterExtensions.WriteMethodBody (cw, method, opt);
197+
198+
foreach (var s in body)
199+
cw.WriteLine (s);
194200

195201
//writer.WriteLine ("{0}const string __id = \"{1}.{2}\";", indent, method.JavaName, method.JniSignature);
196202
//foreach (string prep in method.Parameters.GetCallPrep (opt))

tools/generator/SourceWriters/Attributes/GeneratedEnumAttr.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ public class GeneratedEnumAttr : AttributeWriter
1515

1616
public override void WriteAttribute (CodeWriter writer)
1717
{
18-
writer.WriteLine ($"[{(is_return ? "return:" : string.Empty)}global::Android.Runtime.GeneratedEnum]");
18+
if (is_return)
19+
writer.WriteLine ($"[return:global::Android.Runtime.GeneratedEnum]");
20+
else
21+
writer.Write ($"[global::Android.Runtime.GeneratedEnum] ");
1922
}
2023
}
2124
}

tools/generator/SourceWriters/Attributes/ObsoleteAttr.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public override void WriteAttribute (CodeWriter writer)
3030
attr_name = "global::System." + attr_name;
3131

3232
if (Message is null && !WriteEmptyString && !IsError) {
33-
writer.Write ($"[{attr_name}]");
33+
writer.WriteLine ($"[{attr_name}]");
3434
return;
3535
}
3636

0 commit comments

Comments
 (0)