Skip to content

[generator] Revert change to use auto-properties in EventArgs classes. #736

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
Oct 13, 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
Original file line number Diff line number Diff line change
Expand Up @@ -123,24 +123,37 @@ internal partial class AnimatorListenerInvoker : global::Java.Lang.Object, Anima

// event args for java.code.AnimatorListener.OnAnimationEnd
public partial class AnimationEndEventArgs : global::System.EventArgs {
bool handled;

public bool Handled {
get { return handled; }
set { handled = value; }
}

public AnimationEndEventArgs (bool handled, int param1)
{
this.Handled = handled;
this.Param1 = param1;
this.handled = handled;
this.param1 = param1;
}

int param1;

public int Param1 {
get { return param1; }
}

public AnimationEndEventArgs (bool handled, int param1, int param2)
{
this.Handled = handled;
this.Param1 = param1;
this.Param2 = param2;
this.handled = handled;
this.param1 = param1;
this.param2 = param2;
}

public bool Handled { get; set; }
int param2;

public int Param1 { get; private set; }

public int Param2 { get; private set; }
public int Param2 {
get { return param2; }
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,42 @@ public unsafe void OnEvent (global::Com.Google.Android.Exoplayer.Drm.IExoMediaDr
public partial class ExoMediaDrmOnEventEventArgs : global::System.EventArgs {
public ExoMediaDrmOnEventEventArgs (global::Com.Google.Android.Exoplayer.Drm.IExoMediaDrm p0, byte[] p1, int p2, int p3, byte[] p4)
{
this.P0 = p0;
this.P1 = p1;
this.P2 = p2;
this.P3 = p3;
this.P4 = p4;
this.p0 = p0;
this.p1 = p1;
this.p2 = p2;
this.p3 = p3;
this.p4 = p4;
}

public global::Com.Google.Android.Exoplayer.Drm.IExoMediaDrm P0 { get; private set; }
global::Com.Google.Android.Exoplayer.Drm.IExoMediaDrm p0;

public byte[] P1 { get; private set; }
public global::Com.Google.Android.Exoplayer.Drm.IExoMediaDrm P0 {
get { return p0; }
}

byte[] p1;

public byte[] P1 {
get { return p1; }
}

int p2;

public int P2 { get; private set; }
public int P2 {
get { return p2; }
}

int p3;

public int P3 { get; private set; }
public int P3 {
get { return p3; }
}

public byte[] P4 { get; private set; }
byte[] p4;

public byte[] P4 {
get { return p4; }
}

}

Expand Down
53 changes: 38 additions & 15 deletions tools/generator/SourceWriters/InterfaceEventArgsClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,12 @@ public InterfaceEventArgsClass (InterfaceGen iface, Method method)
IsPublic = true;
IsPartial = true;

UsePriorityOrder = true;

Comments.Add ($"// event args for {iface.JavaName}.{method.JavaName}");

// Add: public bool Handled { get; set; }
if (method.IsEventHandlerWithHandledProperty)
Properties.Add (new PropertyWriter {
Name = "Handled",
PropertyType = TypeReferenceWriter.Bool,
IsPublic = true,
HasGet = true,
HasSet = true,
IsAutoProperty = true
});
Properties.Add (new HandledProperty ());
}

public void AddMembersFromMethod (InterfaceGen iface, Method method, CodeGenerationOptions opt)
Expand All @@ -47,15 +41,15 @@ void AddConstructor (InterfaceGen iface, Method method, CodeGenerationOptions op

if (method.IsEventHandlerWithHandledProperty) {
ctor.Parameters.Add (new MethodParameterWriter ("handled", TypeReferenceWriter.Bool));
ctor.Body.Add ("this.Handled = handled;");
ctor.Body.Add ("this.handled = handled;");
}

foreach (var p in method.Parameters) {
if (p.IsSender)
continue;

ctor.Parameters.Add (new MethodParameterWriter (p.Name, new TypeReferenceWriter (opt.GetTypeReferenceName (p))));
ctor.Body.Add ($"this.{p.PropertyName} = {opt.GetSafeIdentifier (p.Name)};");
ctor.Body.Add ($"this.{opt.GetSafeIdentifier (p.Name)} = {opt.GetSafeIdentifier (p.Name)};");
}

Constructors.Add (ctor);
Expand All @@ -71,18 +65,47 @@ void AddProperties (Method method, CodeGenerationOptions opt)
if (Properties.Any (prop => prop.Name == p.PropertyName))
continue;

Fields.Add (new FieldWriter {
Name = opt.GetSafeIdentifier (p.Name),
Type = new TypeReferenceWriter (opt.GetTypeReferenceName (p))
});

var prop = new PropertyWriter {
Name = p.PropertyName,
PropertyType = new TypeReferenceWriter (opt.GetTypeReferenceName (p)),
IsPublic = true,
HasGet = true,
HasSet = true,
IsAutoProperty = true,
AutoSetterVisibility = Visibility.Private
HasGet = true
};

prop.GetBody.Add ($"return {opt.GetSafeIdentifier (p.Name)};");

Properties.Add (prop);
}
}
}

public class HandledProperty : PropertyWriter
{
public HandledProperty ()
{
Name = "Handled";
PropertyType = TypeReferenceWriter.Bool;

IsPublic = true;

HasGet = true;
GetBody.Add ("return handled;");

HasSet = true;
SetBody.Add ("handled = value;");
}

public override void Write (CodeWriter writer)
{
writer.WriteLine ("bool handled;");
writer.WriteLine ();

base.Write (writer);
}
}
}