From be577bd3c34de6ca8b66696e2ed67f34c51513e0 Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Tue, 22 Jan 2019 11:33:18 +0100 Subject: [PATCH] Errors refact --- src/hex/collection/ArrayMap.hx | 2 +- src/hex/collection/HashMap.hx | 2 +- src/hex/collection/Locator.hx | 6 ++- src/hex/core/HashCodeFactory.hx | 2 +- src/hex/error/Error.hx | 46 +++++++++++++++++++ src/hex/error/IllegalArgumentException.hx | 14 ------ src/hex/error/IllegalStateException.hx | 14 ------ src/hex/error/NoSuchElementException.hx | 14 ------ src/hex/error/NullPointerException.hx | 14 ------ src/hex/error/PrivateConstructorException.hx | 14 ------ .../error/UnsupportedOperationException.hx | 14 ------ src/hex/error/VirtualMethodException.hx | 14 ------ src/hex/event/TriggerBuilder.hx | 2 +- src/hex/util/ArrayUtil.hx | 2 +- src/hex/util/ClassUtil.hx | 9 +--- src/hex/util/MacroUtil.hx | 3 +- 16 files changed, 59 insertions(+), 113 deletions(-) create mode 100644 src/hex/error/Error.hx delete mode 100644 src/hex/error/IllegalArgumentException.hx delete mode 100644 src/hex/error/IllegalStateException.hx delete mode 100644 src/hex/error/NoSuchElementException.hx delete mode 100644 src/hex/error/NullPointerException.hx delete mode 100644 src/hex/error/PrivateConstructorException.hx delete mode 100644 src/hex/error/UnsupportedOperationException.hx delete mode 100644 src/hex/error/VirtualMethodException.hx diff --git a/src/hex/collection/ArrayMap.hx b/src/hex/collection/ArrayMap.hx index 9cfe3f7..feefec3 100644 --- a/src/hex/collection/ArrayMap.hx +++ b/src/hex/collection/ArrayMap.hx @@ -1,8 +1,8 @@ package hex.collection; import hex.collection.IHashMap; -import hex.error.NullPointerException; import hex.util.ArrayUtil; +using hex.error.Error; /** * ... diff --git a/src/hex/collection/HashMap.hx b/src/hex/collection/HashMap.hx index 429c178..130df79 100644 --- a/src/hex/collection/HashMap.hx +++ b/src/hex/collection/HashMap.hx @@ -1,7 +1,7 @@ package hex.collection; import hex.core.HashCodeFactory; -import hex.error.NullPointerException; +using hex.error.Error; /** * ... diff --git a/src/hex/collection/Locator.hx b/src/hex/collection/Locator.hx index b07c638..e5ba6e2 100644 --- a/src/hex/collection/Locator.hx +++ b/src/hex/collection/Locator.hx @@ -1,5 +1,7 @@ package hex.collection; +using hex.error.Error; + /** * ... * @author Francis Bourre @@ -43,7 +45,7 @@ class Locator } else { - throw new hex.error.NoSuchElementException( "Can't find item with '" + key + "' key" ); + throw new NoSuchElementException( "Can't find item with '" + key + "' key" ); } } @@ -61,7 +63,7 @@ class Locator { if ( this._map.containsKey( key ) ) { - throw new hex.error.IllegalArgumentException( "item is already registered with '" + key + "' key" ); + throw new IllegalArgumentException( "item is already registered with '" + key + "' key" ); } else { diff --git a/src/hex/core/HashCodeFactory.hx b/src/hex/core/HashCodeFactory.hx index 17db311..4c9ea4f 100644 --- a/src/hex/core/HashCodeFactory.hx +++ b/src/hex/core/HashCodeFactory.hx @@ -1,6 +1,6 @@ package hex.core; -import hex.error.PrivateConstructorException; +using hex.error.Error; /** * ... diff --git a/src/hex/error/Error.hx b/src/hex/error/Error.hx new file mode 100644 index 0000000..523d47b --- /dev/null +++ b/src/hex/error/Error.hx @@ -0,0 +1,46 @@ +package hex.error; + +import haxe.PosInfos; +using tink.CoreApi; + +@IgnoreCover +class IllegalArgumentException extends Error +{ + public function new ( message : String, ?posInfos : PosInfos ) super( code, message, pos ); +} + +@IgnoreCover +class IllegalStateException extends Error +{ + public function new ( message : String, ?posInfos : PosInfos ) super( code, message, pos ); +} + +@IgnoreCover +class NoSuchElementException extends Error +{ + public function new ( message : String, ?posInfos : PosInfos ) super( code, message, pos ); +} + +@IgnoreCover +class NullPointerException extends Error +{ + public function new ( message : String, ?posInfos : PosInfos ) super( code, message, pos ); +} + +@IgnoreCover +class PrivateConstructorException extends Error +{ + public function new ( ?message : String = "This class can't be instantiated.", ?posInfos : PosInfos ) super( code, message, pos ); +} + +@IgnoreCover +class UnsupportedOperationException extends Error +{ + public function new ( message : String, ?posInfos : PosInfos ) super( code, message, pos ); +} + +@IgnoreCover +class VirtualMethodException extends Error +{ + public function new ( ?message : String = 'this method must be overridden', ?posInfos : PosInfos ) super( code, message, pos ); +} \ No newline at end of file diff --git a/src/hex/error/IllegalArgumentException.hx b/src/hex/error/IllegalArgumentException.hx deleted file mode 100644 index 65d8c64..0000000 --- a/src/hex/error/IllegalArgumentException.hx +++ /dev/null @@ -1,14 +0,0 @@ -package hex.error; - -import haxe.PosInfos; -using tink.CoreApi; - -/** - * ... - * @author Francis Bourre - */ -@IgnoreCover -class IllegalArgumentException extends Error -{ - public function new ( message : String, ?posInfos : PosInfos ) super( code, message, pos ); -} \ No newline at end of file diff --git a/src/hex/error/IllegalStateException.hx b/src/hex/error/IllegalStateException.hx deleted file mode 100644 index e6d7f4e..0000000 --- a/src/hex/error/IllegalStateException.hx +++ /dev/null @@ -1,14 +0,0 @@ -package hex.error; - -import haxe.PosInfos; -using tink.CoreApi; - -/** - * ... - * @author Francis Bourre - */ -@IgnoreCover -class IllegalStateException extends Error -{ - public function new ( message : String, ?posInfos : PosInfos ) super( code, message, pos ); -} \ No newline at end of file diff --git a/src/hex/error/NoSuchElementException.hx b/src/hex/error/NoSuchElementException.hx deleted file mode 100644 index d13d105..0000000 --- a/src/hex/error/NoSuchElementException.hx +++ /dev/null @@ -1,14 +0,0 @@ -package hex.error; - -import haxe.PosInfos; -using tink.CoreApi; - -/** - * ... - * @author Francis Bourre - */ -@IgnoreCover -class NoSuchElementException extends Error -{ - public function new ( message : String, ?posInfos : PosInfos ) super( code, message, pos ); -} \ No newline at end of file diff --git a/src/hex/error/NullPointerException.hx b/src/hex/error/NullPointerException.hx deleted file mode 100644 index 4ea39b5..0000000 --- a/src/hex/error/NullPointerException.hx +++ /dev/null @@ -1,14 +0,0 @@ -package hex.error; - -import haxe.PosInfos; -using tink.CoreApi; - -/** - * ... - * @author Francis Bourre - */ -@IgnoreCover -class NullPointerException extends Error -{ - public function new ( message : String, ?posInfos : PosInfos ) super( code, message, pos ); -} \ No newline at end of file diff --git a/src/hex/error/PrivateConstructorException.hx b/src/hex/error/PrivateConstructorException.hx deleted file mode 100644 index 6d4f71c..0000000 --- a/src/hex/error/PrivateConstructorException.hx +++ /dev/null @@ -1,14 +0,0 @@ -package hex.error; - -import haxe.PosInfos; -using tink.CoreApi; - -/** - * ... - * @author Francis Bourre - */ -@IgnoreCover -class PrivateConstructorException extends Error -{ - public function new ( ?message : String = "This class can't be instantiated.", ?posInfos : PosInfos ) super( code, message, pos ); -} \ No newline at end of file diff --git a/src/hex/error/UnsupportedOperationException.hx b/src/hex/error/UnsupportedOperationException.hx deleted file mode 100644 index 947ddbf..0000000 --- a/src/hex/error/UnsupportedOperationException.hx +++ /dev/null @@ -1,14 +0,0 @@ -package hex.error; - -import haxe.PosInfos; -using tink.CoreApi; - -/** - * ... - * @author Francis Bourre - */ -@IgnoreCover -class UnsupportedOperationException extends Error -{ - public function new ( message : String, ?posInfos : PosInfos ) super( code, message, pos ); -} diff --git a/src/hex/error/VirtualMethodException.hx b/src/hex/error/VirtualMethodException.hx deleted file mode 100644 index de86a23..0000000 --- a/src/hex/error/VirtualMethodException.hx +++ /dev/null @@ -1,14 +0,0 @@ -package hex.error; - -import haxe.PosInfos; -using tink.CoreApi; - -/** - * ... - * @author Francis Bourre - */ -@IgnoreCover -class VirtualMethodException extends Error -{ - public function new ( ?message : String = 'this method must be overridden', ?posInfos : PosInfos ) super( code, message, pos ); -} \ No newline at end of file diff --git a/src/hex/event/TriggerBuilder.hx b/src/hex/event/TriggerBuilder.hx index 88db34a..b7c4323 100644 --- a/src/hex/event/TriggerBuilder.hx +++ b/src/hex/event/TriggerBuilder.hx @@ -9,13 +9,13 @@ import haxe.macro.Type.ClassType; import haxe.macro.Type.Ref; import haxe.macro.Type.TypeParameter; import haxe.macro.TypeTools; -import hex.error.PrivateConstructorException; import hex.event.ITrigger; import hex.util.MacroUtil; using haxe.macro.Context; using haxe.macro.Tools; using tink.MacroApi; +using hex.error.Error; /** * ... diff --git a/src/hex/util/ArrayUtil.hx b/src/hex/util/ArrayUtil.hx index 725eb0c..8f18952 100644 --- a/src/hex/util/ArrayUtil.hx +++ b/src/hex/util/ArrayUtil.hx @@ -1,6 +1,6 @@ package hex.util; -import hex.error.PrivateConstructorException; +using hex.error.Error; /** * ... diff --git a/src/hex/util/ClassUtil.hx b/src/hex/util/ClassUtil.hx index 61f4971..fc62c54 100644 --- a/src/hex/util/ClassUtil.hx +++ b/src/hex/util/ClassUtil.hx @@ -1,7 +1,6 @@ package hex.util; -import hex.error.IllegalArgumentException; -import hex.error.PrivateConstructorException; +using hex.error.Error; /** * ... @@ -9,11 +8,7 @@ import hex.error.PrivateConstructorException; */ class ClassUtil { - /** @private */ - function new() - { - throw new PrivateConstructorException(); - } + /** @private */ function new() throw new PrivateConstructorException(); static public function getInheritanceChain( clazz : Class ) : Array> { diff --git a/src/hex/util/MacroUtil.hx b/src/hex/util/MacroUtil.hx index 0bef299..f41f871 100644 --- a/src/hex/util/MacroUtil.hx +++ b/src/hex/util/MacroUtil.hx @@ -8,6 +8,7 @@ import haxe.macro.Expr.TypePath; import haxe.macro.ExprTools; import haxe.macro.Type.ClassType; import haxe.macro.TypeTools; +using hex.error.Error; using Lambda; @@ -17,7 +18,7 @@ using Lambda; */ class MacroUtil { - /** @private */ function new() throw new hex.error.PrivateConstructorException(); + /** @private */ function new() throw new PrivateConstructorException(); macro public static function classImplementsInterface( classRef : haxe.macro.Expr.ExprOf, interfaceRef : haxe.macro.Expr.ExprOf ) : Expr {