efl_mono: Use PascalCase in events

Summary:
To deal with events with the same name as some methods (Del, Invalidate,
etc), the suffix Evt was added.

Thus, now we use

obj.ButtonClickedEvt += callback;

Instead of

obj.BUTTON_CLICKED += cal

The argument classes use the same scheme, being called <Evt name>_Args.
Depends on D5991

Reviewers: felipealmeida

Reviewed By: felipealmeida

Subscribers: cedric

Differential Revision: https://phab.enlightenment.org/D5992
This commit is contained in:
Lauro Moura 2018-04-16 12:36:51 -03:00
parent e59e8f0a15
commit 628e5ab950
11 changed files with 71 additions and 58 deletions

View File

@ -39,11 +39,11 @@ inline std::string escape_keyword(std::string const& name)
std::string managed_method_name(std::string const& underscore_name)
{
std::vector<std::string> names = name_helpers::split(underscore_name, '_');
std::vector<std::string> names = utils::split(underscore_name, '_');
name_helpers::reorder_verb(names);
return escape_keyword(name_helpers::pascal_case(names));
return escape_keyword(utils::to_pascal_case(names));
}
}

View File

@ -173,8 +173,7 @@ struct klass
if (!etype.is_engaged())
continue;
std::string evt_name = utils::to_uppercase(e.name);
std::replace(evt_name.begin(), evt_name.end(), ',', '_');
std::string evt_name = name_helpers::managed_event_name(e.name);
std::string arg_type = (*etype).original_type.visit(get_csharp_type_visitor{});
if (!as_generator("///<summary>Event argument wrapper for event " << string << ".</summary>\n"
@ -221,7 +220,7 @@ struct klass
for (auto &&e : cls.events)
{
std::string wrapper_args_type;
std::string evt_name = utils::to_uppercase(e.name);
std::string evt_name = name_helpers::managed_event_name(e.name);
std::replace(evt_name.begin(), evt_name.end(), ',', '_');
efl::eina::optional<grammar::attributes::type_def> etype = e.type;
@ -569,9 +568,7 @@ struct klass
s << n;
s << '_';
}
std::string evt_name = utils::to_uppercase(evt.name);
std::replace(evt_name.begin(), evt_name.end(), ',', '_');
s << klass.cxx_name << '_' << evt_name;
s << klass.cxx_name << '_' << name_helpers::managed_event_name(evt.name);
return s.str();
}
@ -633,8 +630,7 @@ struct klass
// Self events
for (auto&& e : cls.events)
{
std::string upper_name = utils::to_uppercase(e.name);
std::replace(upper_name.begin(), upper_name.end(), ',', '_');
std::string upper_name = name_helpers::managed_event_name(e.name);
std::string upper_c_name = utils::to_uppercase(e.c_name);
std::string event_name = e.name;
std::replace(event_name.begin(), event_name.end(), ',', '_');
@ -720,8 +716,7 @@ struct klass
{
std::string wrapper_evt_name = translate_inherited_event_name(e, klass);
std::string upper_name = utils::to_uppercase(e.name);
std::replace(upper_name.begin(), upper_name.end(), ',', '_');
std::string upper_name = name_helpers::managed_event_name(e.name);
std::string upper_c_name = utils::to_uppercase(e.c_name);
std::stringstream wrapper_args_type;

View File

@ -7,9 +7,14 @@
#include <sstream>
#include <string>
#include <vector>
#include "utils.hh"
namespace eolian_mono {
/* Utility functions for naming things. Compared to the utils.hh, this header has higher level
* functions, dealing with the knowledge of how to convert the items to the C# style we are using, for
* example, while being too short to be implemented as full-fledged generators.
*/
namespace name_helpers {
static const std::vector<std::string> verbs =
@ -103,33 +108,9 @@ void reorder_verb(std::vector<std::string> &names)
}
}
std::vector<std::string> split(std::string const &input, char delim)
std::string managed_event_name(std::string const& name)
{
std::stringstream ss(input);
std::string name;
std::vector<std::string> names;
while (std::getline(ss, name, delim)) {
if (!name.empty())
names.push_back(name);
}
return names;
}
std::string pascal_case(const std::vector<std::string> &names)
{
std::vector<std::string> outv(names.size());
std::stringstream osstream;
std::transform(names.begin(), names.end(), outv.begin(),
[](std::string name) {
name[0] = std::toupper(name[0]);
return name;
});
std::copy(outv.begin(), outv.end(), std::ostream_iterator<std::string>(osstream, ""));
return osstream.str();
return utils::to_pascal_case(utils::split(name, ','), "") + "Evt";
}
} // namespace name_helpers

View File

@ -2,10 +2,12 @@
#define EOLIAN_MONO_UTILS_HPP
#include <string>
#include <sstream>
#include <iterator>
#include <algorithm>
/* Compared to the helpers.hh header, these functions are lower level, not dealing with
* binding-specific structures or knowledge */
/* Compared to the helpers.hh and name_helpers headers, these functions are
* lower level, not dealing with binding-specific structures or knowledge */
namespace eolian_mono { namespace utils {
@ -26,6 +28,41 @@ namespace eolian_mono { namespace utils {
ret[0] = std::toupper(ret[0]);
return ret;
}
std::vector<std::string> split(std::string const &input, char delim)
{
std::stringstream ss(input);
std::string name;
std::vector<std::string> names;
while (std::getline(ss, name, delim))
{
if (!name.empty())
names.push_back(name);
}
return names;
}
std::string to_pascal_case(const std::vector<std::string> &names, std::string const& delim="")
{
std::vector<std::string> outv(names.size());
std::stringstream osstream;
std::transform(names.begin(), names.end(), outv.begin(),
[](std::string name) {
name[0] = std::toupper(name[0]);
return name;
});
std::copy(outv.begin(), outv.end(), std::ostream_iterator<std::string>(osstream, delim.c_str()));
std::string ret = osstream.str();
if (delim != "")
ret.pop_back(); // We could implement an infix_iterator but this pop is enough for now.
return ret;
}
} }
#endif

View File

@ -10,7 +10,7 @@ public class Example
button.SetText(text);
button.SetSize(new eina.Size2D(w, h));
button.CLICKED += callback;
button.ClickedEvt += callback;
return button;
}
@ -56,7 +56,7 @@ public class Example
efl.ui.Slider slider = new efl.ui.SliderConcrete(box);
slider.SetSize(new eina.Size2D(W, H));
slider.CHANGED += (object sender, EventArgs e) => {
slider.ChangedEvt += (object sender, EventArgs e) => {
bar.SetRangeValue(slider.GetRangeValue());
};

View File

@ -23,7 +23,7 @@ public class Example
popup.SetVisible(true);
popup.SetButton(efl.ui.popup_alert.Button.Positive, "Ok");
popup.SetSize(new eina.Size2D(150, 30));
popup.BUTTON_CLICKED += (object sender, efl.ui.BUTTON_CLICKED_Args e) => {
popup.ButtonClickedEvt += (object sender, efl.ui.ButtonClickedEvt_Args e) => {
popup.SetParent(null);
popup.Del();
};
@ -99,7 +99,7 @@ public class Example
kms_box.Pack(kms_input);
kms_box.Pack(kms_button);
kms_button.CLICKED += (object sender, EventArgs e) => {
kms_button.ClickedEvt += (object sender, EventArgs e) => {
try
{
string text = kms_input.GetText();
@ -115,7 +115,7 @@ public class Example
}
};
miles_button.CLICKED += (object sender, EventArgs e) => {
miles_button.ClickedEvt += (object sender, EventArgs e) => {
try
{
string text = miles_input.GetText();

View File

@ -30,7 +30,7 @@ class TestMain
rect.SetSize(size);
rect.SetVisible(true);
canvas.KEY_DOWN += (object sender, efl.input.KEY_DOWN_Args e) => {
canvas.KeyDownEvt += (object sender, efl.input.KeyDownEvt_Args e) => {
color_index = (color_index + 1) % 3;
Console.WriteLine("Key Down");
Console.WriteLine("Got key obj at {0}", e.arg.raw_handle.ToString("X"));

View File

@ -45,7 +45,7 @@ class TestMain
bg.SetVisible(true);
bg.SetKeyFocus(true);
bg.KEY_DOWN += On_KeyDown;
bg.KeyDownEvt += On_KeyDown;
text = new evas.TextConcrete(canvas);
text.SetStyle(evas.Text_Style_Type.OutlineSoftShadow);
@ -87,7 +87,7 @@ class TestMain
}
private void On_KeyDown(object sender, efl.input.KEY_DOWN_Args e)
private void On_KeyDown(object sender, efl.input.KeyDownEvt_Args e)
{
var key = e.arg.GetKey();

View File

@ -46,7 +46,7 @@ class TestEo
bool delEventCalled = false;
{
test.Testing obj = new test.TestingConcrete();
obj.DEL += (object sender, EventArgs e) => { delEventCalled = true; };
obj.DelEvt += (object sender, EventArgs e) => { delEventCalled = true; };
((IDisposable)obj).Dispose();
}

View File

@ -110,9 +110,9 @@ class TestEolianError
// the managed code
efl.Loop loop = new efl.LoopConcrete();
Listener listener = new Listener();
loop.CALLBACK_ADD += listener.callback;
loop.CallbackAddEvt += listener.callback;
Test.AssertRaises<efl.EflException>(() => loop.IDLE += listener.another_callback);
Test.AssertRaises<efl.EflException>(() => loop.IdleEvt += listener.another_callback);
}
}
}

View File

@ -23,12 +23,12 @@ class TestEoEvents
efl.Loop loop = new efl.LoopConcrete();
loop.SetName("loop");
TestEoEvents listener = new TestEoEvents();
loop.CALLBACK_ADD += listener.callback;
loop.CallbackAddEvt += listener.callback;
Test.Assert(!listener.called);
Test.Assert(!listener.correct_sender);
Test.AssertEquals("loop", loop.GetName());
loop.IDLE += listener.another_callback;
loop.IdleEvt += listener.another_callback;
Test.Assert(listener.called);
Test.Assert(listener.correct_sender);
Test.AssertEquals("loop_called", loop.GetName());
@ -39,7 +39,7 @@ class TestEoEvents
test.Testing obj = new test.TestingConcrete();
string received_string = null;
obj.EVT_WITH_STRING += (object sender, test.EVT_WITH_STRING_Args e) => {
obj.EvtWithStringEvt += (object sender, test.EvtWithStringEvt_Args e) => {
received_string = e.arg;
};
@ -53,7 +53,7 @@ class TestEoEvents
test.Testing obj = new test.TestingConcrete();
int received_int= 0;
obj.EVT_WITH_INT += (object sender, test.EVT_WITH_INT_Args e) => {
obj.EvtWithIntEvt += (object sender, test.EvtWithIntEvt_Args e) => {
received_int = e.arg;
};
@ -66,7 +66,7 @@ class TestEoEvents
{
test.Testing obj = new test.TestingConcrete();
uint received_uint = 0;
obj.EVT_WITH_UINT += (object sender, test.EVT_WITH_UINT_Args e) => {
obj.EvtWithUintEvt += (object sender, test.EvtWithUintEvt_Args e) => {
received_uint = e.arg;
};
@ -80,7 +80,7 @@ class TestEoEvents
test.Testing obj = new test.TestingConcrete();
float received_float= 0;
obj.EVT_WITH_FLOAT += (object sender, test.EVT_WITH_FLOAT_Args e) => {
obj.EvtWithFloatEvt += (object sender, test.EvtWithFloatEvt_Args e) => {
received_float = e.arg;
};
@ -94,7 +94,7 @@ class TestEoEvents
test.Testing obj = new test.TestingConcrete();
test.Testing received_obj = null;
obj.EVT_WITH_OBJ += (object sender, test.EVT_WITH_OBJ_Args e) => {
obj.EvtWithObjEvt += (object sender, test.EvtWithObjEvt_Args e) => {
received_obj = e.arg;
};