Skip to content

Commit 60e4e7d

Browse files
committed
Parse parameters.
1 parent 96d183c commit 60e4e7d

18 files changed

+59
-72
lines changed

src/Xamarin.SourceWriter/Models/MethodParameterWriter.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class MethodParameterWriter
99
public TypeReferenceWriter Type { get; set; }
1010
public List<AttributeWriter> Attributes { get; } = new List<AttributeWriter> ();
1111
public string Name { get; set; }
12+
public bool IsExtension { get; set; }
1213

1314
public MethodParameterWriter (string name, TypeReferenceWriter type)
1415
{
@@ -20,6 +21,9 @@ public virtual void WriteParameter (CodeWriter writer)
2021
{
2122
WriteAttributes (writer);
2223

24+
if (IsExtension)
25+
writer.Write ("this ");
26+
2327
Type.WriteTypeReference (writer);
2428
writer.Write (Name);
2529
}

src/Xamarin.SourceWriter/Models/MethodWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Xamarin.SourceWriter
66
{
77
public class MethodWriter : ISourceWriter
88
{
9-
private Visibility visibility;
9+
Visibility visibility;
1010

1111
public string Name { get; set; }
1212
public List<MethodParameterWriter> Parameters { get; } = new List<MethodParameterWriter> ();

src/Xamarin.SourceWriter/Models/TypeReferenceWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class TypeReferenceWriter
99
public string Namespace { get; set; }
1010
public string Name { get; set; }
1111
public bool Nullable { get; set; }
12-
12+
1313
// These purposely create new instances, as they are not immutable.
1414
// For example you may intend to make an instance null, but if there
1515
// was only one, you would make them all null.

tools/generator/SourceWriters/BoundClass.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,6 @@ void AddProperties (ClassGen klass, CodeGenerationOptions opt)
321321
if (prop.Setter != null)
322322
prop.Setter.IsVirtual = set_virt;
323323
}
324-
325324
}
326325

327326
void AddProperty (ClassGen klass, Property property, CodeGenerationOptions opt)

tools/generator/SourceWriters/BoundConstructor.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public BoundConstructor (ClassGen klass, Ctor constructor, bool useBase, CodeGen
4242

4343
BaseCall = $"{(useBase ? "base" : "this")} (IntPtr.Zero, JniHandleOwnership.DoNotTransfer)";
4444
context_this = context.ContextType.GetObjectHandleProperty ("this");
45+
46+
this.AddMethodParameters (constructor.Parameters, opt);
4547
}
4648

4749
protected override void WriteBody (CodeWriter writer)
@@ -100,11 +102,6 @@ void WriteParamterListCallArgs (CodeWriter writer, ParameterList parameters, boo
100102
writer.WriteLine ("__args [{0}] = new {1} ({2});", i, JValue, p.GetCall (opt));
101103
}
102104
}
103-
104-
protected override void WriteParameters (CodeWriter writer)
105-
{
106-
writer.Write (constructor.GetSignature (opt));
107-
}
108105
}
109106

110107
public class StringOverloadConstructor : BoundConstructor
@@ -113,11 +110,9 @@ public StringOverloadConstructor (ClassGen klass, Ctor constructor, bool useBase
113110
base (klass, constructor, useBase, opt, context)
114111
{
115112
Comments.Clear ();
116-
}
113+
Parameters.Clear ();
117114

118-
protected override void WriteParameters (CodeWriter writer)
119-
{
120-
writer.Write (constructor.GetSignature (opt).Replace ("Java.Lang.ICharSequence", "string").Replace ("global::string", "string"));
115+
this.AddMethodParametersStringOverloads (constructor.Parameters, opt);
121116
}
122117
}
123118
}

tools/generator/SourceWriters/BoundInterfaceMethodDeclaration.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ public BoundInterfaceMethodDeclaration (Method method, string adapter, CodeGener
3434
Attributes.Add (new RegisterAttr (method.JavaName, method.JniSignature, method.ConnectorName + ":" + method.GetAdapterName (opt, adapter), additionalProperties: method.AdditionalAttributeString ()));
3535

3636
SourceWriterExtensions.AddMethodCustomAttributes (Attributes, method);
37-
}
38-
39-
protected override void WriteParameters (CodeWriter writer)
40-
{
41-
writer.Write (method.GetSignature (opt));
37+
this.AddMethodParameters (method.Parameters, opt);
4238
}
4339
}
4440
}

tools/generator/SourceWriters/BoundMethod.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public BoundMethod (GenBase type, Method method, CodeGenerationOptions opt, bool
6060
Attributes.Add (new RegisterAttr (method.JavaName, method.JniSignature, method.IsVirtual ? method.GetConnectorNameFull (opt) : string.Empty, additionalProperties: method.AdditionalAttributeString ()));
6161

6262
SourceWriterExtensions.AddMethodCustomAttributes (Attributes, method);
63+
this.AddMethodParameters (method.Parameters, opt);
6364
}
6465

6566
public override void Write (CodeWriter writer)
@@ -76,10 +77,5 @@ protected override void WriteBody (CodeWriter writer)
7677
SourceWriterExtensions.WriteMethodBody (writer, method, opt);
7778
method.IsVirtual = old_virtual;
7879
}
79-
80-
protected override void WriteParameters (CodeWriter writer)
81-
{
82-
writer.Write (method.GetSignature (opt));
83-
}
8480
}
8581
}

tools/generator/SourceWriters/BoundMethodAbstractDeclaration.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public BoundMethodAbstractDeclaration (GenBase gen, Method method, CodeGeneratio
4545
Attributes.Add (new RegisterAttr (method.JavaName, method.JniSignature, method.ConnectorName, additionalProperties: method.AdditionalAttributeString ()));
4646

4747
SourceWriterExtensions.AddMethodCustomAttributes (Attributes, method);
48+
this.AddMethodParameters (method.Parameters, opt);
4849
}
4950

5051
public override void Write (CodeWriter writer)
@@ -54,10 +55,5 @@ public override void Write (CodeWriter writer)
5455

5556
base.Write (writer);
5657
}
57-
58-
protected override void WriteParameters (CodeWriter writer)
59-
{
60-
writer.Write (method.GetSignature (opt));
61-
}
6258
}
6359
}

tools/generator/SourceWriters/BoundMethodExtensionStringOverload.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,14 @@ public BoundMethodExtensionStringOverload (Method method, CodeGenerationOptions
2828

2929
if (method.Deprecated != null)
3030
Attributes.Add (new ObsoleteAttr (method.Deprecated.Replace ("\"", "\"\"").Trim ()));
31+
32+
Parameters.Add (new MethodParameterWriter ("self", new TypeReferenceWriter (selfType)) { IsExtension = true });
33+
this.AddMethodParametersStringOverloads (method.Parameters, opt);
3134
}
3235

3336
protected override void WriteBody (CodeWriter writer)
3437
{
3538
SourceWriterExtensions.WriteMethodStringOverloadBody (writer, method, opt, true);
3639
}
37-
38-
protected override void WriteParameters (CodeWriter writer)
39-
{
40-
writer.Write ($"this {self_type} self{(method.Parameters.Count > 0 ? ", " : "")}");
41-
writer.Write (method.GetSignature (opt).Replace ("Java.Lang.ICharSequence", "string").Replace ("global::string", "string"));
42-
}
4340
}
4441
}

tools/generator/SourceWriters/BoundMethodStringOverload.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,13 @@ public BoundMethodStringOverload (Method method, CodeGenerationOptions opt)
2626

2727
if (method.Deprecated != null)
2828
Attributes.Add (new ObsoleteAttr (method.Deprecated.Replace ("\"", "\"\"").Trim ()));
29+
30+
this.AddMethodParametersStringOverloads (method.Parameters, opt);
2931
}
3032

3133
protected override void WriteBody (CodeWriter writer)
3234
{
3335
SourceWriterExtensions.WriteMethodStringOverloadBody (writer, method, opt, false);
3436
}
35-
36-
protected override void WriteParameters (CodeWriter writer)
37-
{
38-
writer.Write (method.GetSignature (opt).Replace ("Java.Lang.ICharSequence", "string").Replace ("global::string", "string"));
39-
}
4037
}
4138
}

0 commit comments

Comments
 (0)