[ElmSharp] Cleanup code of ElmSharp (#384)
authorWonYoung Choi <wy80.choi@samsung.com>
Tue, 14 Aug 2018 01:31:10 +0000 (10:31 +0900)
committerGitHub <noreply@github.com>
Tue, 14 Aug 2018 01:31:10 +0000 (10:31 +0900)
* [ElmSharp] Cleanup code of ElmSharp

Clean-up code to fix issues detected by codacy.

22 files changed:
src/ElmSharp/ElmSharp/AccessibleObject.cs
src/ElmSharp/ElmSharp/Background.cs
src/ElmSharp/ElmSharp/Calendar.cs
src/ElmSharp/ElmSharp/Color.cs
src/ElmSharp/ElmSharp/ColorSelector.cs
src/ElmSharp/ElmSharp/Container.cs
src/ElmSharp/ElmSharp/EdjeObject.cs
src/ElmSharp/ElmSharp/FlipSelector.cs
src/ElmSharp/ElmSharp/GenGrid.cs
src/ElmSharp/ElmSharp/GenList.cs
src/ElmSharp/ElmSharp/Hoversel.cs
src/ElmSharp/ElmSharp/Index.cs
src/ElmSharp/ElmSharp/ItemObject.cs
src/ElmSharp/ElmSharp/MultiButtonEntry.cs
src/ElmSharp/ElmSharp/NamedHint.cs
src/ElmSharp/ElmSharp/Naviframe.cs
src/ElmSharp/ElmSharp/Toolbar.cs
src/ElmSharp/ElmSharp/Transit.cs
src/ElmSharp/Interop/Interop.Ecore.cs
src/ElmSharp/Interop/Interop.Elementary.Bg.cs
src/ElmSharp/Interop/Interop.Elementary.Image.cs
src/ElmSharp/Interop/Interop.Libdl.cs

index 4114094..1415f0c 100755 (executable)
@@ -199,7 +199,7 @@ namespace ElmSharp.Accessible
         /// </summary>
         /// <param name="parent">Parent EvasObject class.</param>
         /// <since_tizen> preview </since_tizen>
-        public AccessibleObject(EvasObject parent) : base(parent)
+        protected AccessibleObject(EvasObject parent) : base(parent)
         {
         }
 
@@ -207,7 +207,7 @@ namespace ElmSharp.Accessible
         /// Creates and initializes a new instance of the AccessibleObject class.
         /// </summary>
         /// <since_tizen> preview </since_tizen>
-        public AccessibleObject() : base()
+        protected AccessibleObject()
         {
         }
 
index 6b140fa..2089fb0 100755 (executable)
@@ -105,7 +105,7 @@ namespace ElmSharp
             }
             else
             {
-                throw new Exception("This method just makes sense if an image file was set.");
+                throw new InvalidOperationException("This method just makes sense if an image file was set.");
             }
         }
 
index aca9f57..12f5f0b 100755 (executable)
@@ -271,8 +271,7 @@ namespace ElmSharp
         {
             get
             {
-                var tm = new Interop.Libc.SystemTime();
-                Interop.Elementary.elm_calendar_displayed_time_get(RealHandle, out tm);
+                Interop.Elementary.elm_calendar_displayed_time_get(RealHandle, out Interop.Libc.SystemTime tm);
                 // TODO
                 // If the defect is fixed, it will be removed.
                 var daysInMonth = DateTime.DaysInMonth(tm.tm_year + 1900, tm.tm_mon + 1);
index 3749974..279e15d 100644 (file)
@@ -184,12 +184,6 @@ namespace ElmSharp
         /// <since_tizen> preview </since_tizen>
         public static bool operator ==(Color a, Color b)
         {
-            if (ReferenceEquals(a, b))
-                return true;
-
-            if ((object)a == null || (object)b == null)
-                return false;
-
             return EqualsInner(a, b);
         }
 
@@ -232,20 +226,20 @@ namespace ElmSharp
         /// <since_tizen> preview </since_tizen>
         public static Color FromHex(string hex)
         {
-            hex = hex.Replace("#", "");
-            switch (hex.Length)
+            string ret = hex.Replace("#", "");
+            switch (ret.Length)
             {
                 case 3: //#rgb => ffrrggbb
-                    hex = string.Format("ff{0}{1}{2}{3}{4}{5}", hex[0], hex[0], hex[1], hex[1], hex[2], hex[2]);
+                    ret = string.Format("ff{0}{1}{2}{3}{4}{5}", ret[0], ret[0], ret[1], ret[1], ret[2], ret[2]);
                     break;
                 case 4: //#argb => aarrggbb
-                    hex = string.Format("{0}{1}{2}{3}{4}{5}{6}{7}", hex[0], hex[0], hex[1], hex[1], hex[2], hex[2], hex[3], hex[3]);
+                    ret = string.Format("{0}{1}{2}{3}{4}{5}{6}{7}", ret[0], ret[0], ret[1], ret[1], ret[2], ret[2], ret[3], ret[3]);
                     break;
                 case 6: //#rrggbb => ffrrggbb
-                    hex = string.Format("ff{0}", hex);
+                    ret = string.Format("ff{0}", ret);
                     break;
             }
-            return FromUint(Convert.ToUInt32(hex.Replace("#", ""), 16));
+            return FromUint(Convert.ToUInt32(ret.Replace("#", ""), 16));
         }
 
         /// <summary>
index db4a2f3..eb7210e 100755 (executable)
@@ -128,7 +128,6 @@ namespace ElmSharp
             {
                 return Color.Default.A;
             }
-
             set
             {
                 Console.WriteLine("ColorSelector instance doesn't support to set Opacity.");
index 764310f..2d1971c 100755 (executable)
@@ -36,7 +36,7 @@ namespace ElmSharp
         /// <param name="parent">The parent is a given object, which will be attached by the Container
         /// as a child. It's <see cref="EvasObject"/> type.</param>
         /// <since_tizen> preview </since_tizen>
-        public Container(EvasObject parent) : base(parent)
+        protected Container(EvasObject parent) : base(parent)
         {
         }
 
@@ -44,7 +44,7 @@ namespace ElmSharp
         /// Creates and initializes a new instance of the Container class.
         /// </summary>
         /// <since_tizen> preview </since_tizen>
-        protected Container() : base()
+        protected Container()
         {
         }
 
index fbbafa1..2a771aa 100644 (file)
@@ -202,7 +202,7 @@ namespace ElmSharp
             }
         }
 
-        class SignalData
+        class SignalData : IEquatable<SignalData>
         {
             public string Emission { get; set; }
             public string Source { get; set; }
@@ -216,22 +216,17 @@ namespace ElmSharp
                 Action = action;
             }
 
-            /// <summary>
-            /// Indicates whether this instance and a specified object are equal.
-            /// </summary>
-            /// <param name="obj">The object to compare with the current instance.</param>
-            /// <returns>
-            /// true if the object and this instance are of the same type and represent the same value.
-            /// otherwise, false.
-            /// </returns>
-            public override bool Equals(object obj)
+            public override bool Equals(object other)
             {
-                SignalData s = obj as SignalData;
-                if (s == null)
+                return Equals(other as SignalData);
+            }
+
+            public bool Equals(SignalData other) {
+                if (other == null)
                 {
                     return false;
                 }
-                return (Emission == s.Emission) && (Source == s.Source) && (Action == s.Action);
+                return (Emission == other.Emission) && (Source == other.Source) && (Action == other.Action);
             }
 
             public override int GetHashCode()
index 2173e4b..760798e 100755 (executable)
@@ -158,7 +158,7 @@ namespace ElmSharp
         /// <since_tizen> preview </since_tizen>
         public void Remove(FlipSelectorItem item)
         {
-            if (item as FlipSelectorItem != null)
+            if (item != null)
                 item.Delete();
         }
 
index 9aa60c9..34074ca 100644 (file)
@@ -36,7 +36,7 @@ namespace ElmSharp
         internal static GenGridItemEventArgs CreateFromSmartEvent(IntPtr data, IntPtr obj, IntPtr info)
         {
             GenGridItem item = ItemObject.GetItemByHandle(info) as GenGridItem;
-            return new GenGridItemEventArgs() { Item = item };
+            return new GenGridItemEventArgs { Item = item };
         }
     }
 
index 446a6b2..1cf6506 100755 (executable)
@@ -90,7 +90,7 @@ namespace ElmSharp
         internal static GenListItemEventArgs CreateFromSmartEvent(IntPtr data, IntPtr obj, IntPtr info)
         {
             GenListItem item = ItemObject.GetItemByHandle(info) as GenListItem;
-            return new GenListItemEventArgs() { Item = item };
+            return new GenListItemEventArgs { Item = item };
         }
     }
 
@@ -168,7 +168,7 @@ namespace ElmSharp
         /// Creates and initializes a new instance of the GenList class.
         /// </summary>
         /// <since_tizen> preview </since_tizen>
-        protected GenList() : base()
+        protected GenList()
         {
         }
 
index 86b81f2..54ae7f4 100755 (executable)
@@ -33,7 +33,7 @@ namespace ElmSharp
         internal static HoverselItemEventArgs CreateFromSmartEvent(IntPtr data, IntPtr obj, IntPtr info)
         {
             HoverselItem item = ItemObject.GetItemByHandle(info) as HoverselItem;
-            return new HoverselItemEventArgs() { Item = item };
+            return new HoverselItemEventArgs { Item = item };
         }
     }
 
index 5b54757..cbe78c4 100755 (executable)
@@ -268,16 +268,5 @@ namespace ElmSharp
             SelectedItem?.SendSelected();
             Changed?.Invoke(this, e);
         }
-
-        void AddInternal(IndexItem item)
-        {
-            _children.Add(item);
-            item.Deleted += Item_Deleted;
-        }
-
-        void Item_Deleted(object sender, EventArgs e)
-        {
-            _children.Remove((IndexItem)sender);
-        }
     }
 }
\ No newline at end of file
index ea16c8d..b97f521 100644 (file)
@@ -352,7 +352,7 @@ namespace ElmSharp
             return s_globalId++;
         }
 
-        class SignalData
+        class SignalData : IEquatable<SignalData>
         {
             public string Emission { get; set; }
             public string Source { get; set; }
@@ -365,22 +365,17 @@ namespace ElmSharp
                 Func = func;
             }
 
-            /// <summary>
-            /// Indicates whether this instance and a specified object are equal.
-            /// </summary>
-            /// <param name="obj">The object to compare with the current instance.</param>
-            /// <returns>
-            /// true if the object and this instance are of the same type and represent the same value,
-            /// otherwise false.
-            /// </returns>
-            public override bool Equals(object obj)
+            public override bool Equals(object other)
             {
-                SignalData s = obj as SignalData;
-                if (s == null)
+                return Equals(other as SignalData);
+            }
+
+            public bool Equals(SignalData other) {
+                if (other == null)
                 {
                     return false;
                 }
-                return (Emission == s.Emission) && (Source == s.Source) && (Func == s.Func);
+                return (Emission == other.Emission) && (Source == other.Source) && (Func == other.Func);
             }
 
             public override int GetHashCode()
@@ -396,11 +391,7 @@ namespace ElmSharp
         {
             IntPtr _trackHandle = IntPtr.Zero;
 
-            /// <summary>
-            /// Creates and initializes a new instance of the ItemEvasObject class.
-            /// </summary>
-            /// <param name="parent">IntPtr</param>
-            public ItemEvasObject(IntPtr parent) : base()
+            public ItemEvasObject(IntPtr parent)
             {
                 _trackHandle = Interop.Elementary.elm_object_item_track(parent);
                 if (_trackHandle != IntPtr.Zero)
@@ -409,11 +400,6 @@ namespace ElmSharp
                 }
             }
 
-            /// <summary>
-            /// Creates a widget handle.
-            /// </summary>
-            /// <param name="parent">Parent EvasObject.</param>
-            /// <returns>Handle IntPtr.</returns>
             protected override IntPtr CreateHandle(EvasObject parent)
             {
                 return _trackHandle;
index 571f3f8..11b19d5 100755 (executable)
@@ -375,7 +375,7 @@ namespace ElmSharp
             // "item,deleted" event will be called after removing the item from ItemObject has been done.
             // ItemObject will no longer have the item instance that is deleted after this.
             // So, ItemDelete event with the removed item should be triggered here.
-            ItemDeleted?.Invoke(this, new MultiButtonEntryItemEventArgs() { Item = removed });
+            ItemDeleted?.Invoke(this, new MultiButtonEntryItemEventArgs { Item = removed });
         }
 
         void OnItemAdded(object sender, MultiButtonEntryItemEventArgs e)
@@ -434,7 +434,7 @@ namespace ElmSharp
         internal static MultiButtonEntryItemEventArgs CreateFromSmartEvent(IntPtr data, IntPtr obj, IntPtr info)
         {
             MultiButtonEntryItem item = ItemObject.GetItemByHandle(info) as MultiButtonEntryItem;
-            return new MultiButtonEntryItemEventArgs() { Item = item };
+            return new MultiButtonEntryItemEventArgs { Item = item };
         }
 
         internal static MultiButtonEntryItemEventArgs CreateAndAddFromSmartEvent(IntPtr data, IntPtr obj, IntPtr info)
@@ -444,7 +444,7 @@ namespace ElmSharp
             // ItemObject does NOT have an item that contains handle matched to "info" at this time.
             // So, item should be created and added internally here.
             MultiButtonEntryItem item = new MultiButtonEntryItem(info);
-            return new MultiButtonEntryItemEventArgs() { Item = item };
+            return new MultiButtonEntryItemEventArgs { Item = item };
         }
     }
 }
\ No newline at end of file
index 5468810..64a8d16 100644 (file)
@@ -26,12 +26,12 @@ namespace ElmSharp
         /// This value can be used for <see cref="EvasObject.WeightX"/> and <see cref="EvasObject.WeightY"/>.
         /// </summary>
         /// <since_tizen> preview </since_tizen>
-        public static double Expand = 1.0;
+        public static readonly double Expand = 1.0;
 
         /// <summary>
         /// This value can be used for <see cref="EvasObject.AlignmentX"/> and <see cref="EvasObject.AlignmentY"/>.
         /// </summary>
         /// <since_tizen> preview </since_tizen>
-        public static double Fill = -1.0;
+        public static readonly double Fill = -1.0;
     }
 }
index 89abd68..579a28d 100755 (executable)
@@ -278,7 +278,7 @@ namespace ElmSharp
             if (item == null)
                 return;
             _itemStack.Remove(item);
-            Popped?.Invoke(this, new NaviframeEventArgs() { Content = item.Content });
+            Popped?.Invoke(this, new NaviframeEventArgs { Content = item.Content });
         }
     }
 }
index 5ab0827..4c8eb08 100755 (executable)
@@ -123,7 +123,7 @@ namespace ElmSharp
         internal static ToolbarItemEventArgs CreateFromSmartEvent(IntPtr data, IntPtr obj, IntPtr info)
         {
             ToolbarItem item = ItemObject.GetItemByHandle(info) as ToolbarItem;
-            return new ToolbarItemEventArgs() { Item = item };
+            return new ToolbarItemEventArgs { Item = item };
         }
     }
 
index afcaa3b..dedadb4 100755 (executable)
@@ -375,7 +375,7 @@ namespace ElmSharp
         void AddObject(EvasObject obj)
         {
             if (_checker.Contains(obj))
-                throw new Exception("Cannot add the duplicate object.");
+                throw new InvalidOperationException("Cannot add the duplicate object.");
 
             _checker.Add(obj);
             Interop.Elementary.elm_transit_object_add(_handle, obj);
@@ -400,7 +400,7 @@ namespace ElmSharp
         void AddChainedTransit(Transit transit)
         {
             if (_checker.Contains(transit))
-                throw new Exception("Cannot add the duplicate transit.");
+                throw new InvalidOperationException("Cannot add the duplicate transit.");
 
             _checker.Add(transit);
             Interop.Elementary.elm_transit_chain_transit_add(_handle, transit._handle);
index e1d9111..baff068 100644 (file)
@@ -36,7 +36,6 @@ internal static partial class Interop
             CubicBezier
         }
 
-        internal delegate void EcoreCallback(IntPtr data);
         internal delegate bool EcoreTaskCallback(IntPtr data);
         internal delegate bool EcoreEventCallback(IntPtr data, int type, IntPtr evt);
         internal delegate bool EcoreTimelineCallback(IntPtr data, double pos);
index 2f6f732..d9a28c4 100644 (file)
@@ -52,8 +52,7 @@ internal static partial class Interop
 
         internal static string BackgroundFileGet(IntPtr obj)
         {
-            IntPtr file = IntPtr.Zero;
-            elm_bg_file_get(obj, out file, IntPtr.Zero);
+            elm_bg_file_get(obj, out IntPtr file, IntPtr.Zero);
             return Marshal.PtrToStringAnsi(file);
         }
     }
index 860e9fd..a3bb17e 100644 (file)
@@ -25,7 +25,7 @@ internal static partial class Interop
         internal static extern IntPtr elm_image_add(IntPtr obj);
 
         [DllImport(Libraries.Elementary)]
-        internal static extern void elm_image_async_open_set(IntPtr obj, bool async);
+        internal static extern void elm_image_async_open_set(IntPtr obj, bool @async);
 
         [DllImport(Libraries.Elementary)]
         internal static extern IntPtr elm_image_object_get(IntPtr obj);
index 4f233f8..df4889e 100644 (file)
@@ -52,7 +52,7 @@ internal static partial class Interop
             var errPtr = dlerror();
             if (errPtr != IntPtr.Zero)
             {
-                throw new Exception("dlsym : " + Marshal.PtrToStringAnsi(errPtr));
+                throw new InvalidOperationException("dlsym : " + Marshal.PtrToStringAnsi(errPtr));
             }
             return res;
         }