diff --git a/.gitignore b/.gitignore index 7429fd2..5b4e7c3 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ hexCore.iml +bin +.haxelib \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 6f4e535..0d2883d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,7 +32,15 @@ before_install: - sudo apt-get install -qq libgtk2.0-0:i386 install: + - haxelib newrepo +#hexLog + - git clone --recursive -b $DEPENDENCIES_BRANCH https://github.com/DoclerLabs/hexLog.git ./hexlog + - haxelib dev hexlog ./hexlog +#hexUnit - git clone --recursive -b $DEPENDENCIES_BRANCH https://github.com/DoclerLabs/hexUnit.git ./hexunit + - haxelib dev hexunit ./hexunit + - haxelib dev hexcore . + - haxelib path hexcore - export DISPLAY=:99.0; - export AUDIODEV=null; - haxe flash/install.hxml diff --git a/build-each.hxml b/build-each.hxml index 883452f..ecd4306 100644 --- a/build-each.hxml +++ b/build-each.hxml @@ -1,5 +1,8 @@ -main MainCoreTest --cp src +-lib hexcore +-lib hexunit +-lib hexlog + -cp test --cp hexunit/src + -D debug=true \ No newline at end of file diff --git a/haxelib.json b/haxelib.json index 7d48edb..6e84b50 100644 --- a/haxelib.json +++ b/haxelib.json @@ -6,10 +6,10 @@ "description": "Independent core elements for building OOP projects and frameworks", "contributors": ["doclerlabs"], "releasenote": "First release. Still alpha testing", - "version": "0.1.0", + "version": "git", "url": "https://github.com/DoclerLabs/hexCore", "dependencies": { - + "hexlog": "git:https://github.com/DoclerLabs/hexLog.git" } } \ No newline at end of file diff --git a/src/hex/collection/HashMap.hx b/src/hex/collection/HashMap.hx index 9020e4e..d8a299e 100644 --- a/src/hex/collection/HashMap.hx +++ b/src/hex/collection/HashMap.hx @@ -176,7 +176,7 @@ class HashMap implements IHashMap { s = '_B' + o; } - else if ( Std.is( o, Float ) || Std.is( o, Int ) ) + else if ( Std.is( o, Float ) ) { s = '_N' + o; } diff --git a/src/hex/collection/Locator.hx b/src/hex/collection/Locator.hx index daa1fc6..1773335 100644 --- a/src/hex/collection/Locator.hx +++ b/src/hex/collection/Locator.hx @@ -4,7 +4,7 @@ import hex.error.IllegalArgumentException; import hex.error.NoSuchElementException; import hex.event.ITrigger; import hex.event.ITriggerOwner; -import hex.log.Stringifier; +import hex.util.Stringifier; /** * ... diff --git a/src/hex/collection/LocatorMessage.hx b/src/hex/collection/LocatorMessage.hx index 3742a40..c93fa05 100644 --- a/src/hex/collection/LocatorMessage.hx +++ b/src/hex/collection/LocatorMessage.hx @@ -1,5 +1,6 @@ package hex.collection; +import hex.error.PrivateConstructorException; import hex.event.MessageType; /** @@ -8,11 +9,12 @@ import hex.event.MessageType; */ class LocatorMessage { - inline static public var REGISTER = new MessageType( "onRegister" ); - inline static public var UNREGISTER = new MessageType( "onUnregister" ); - + /** @private */ function new() { - + throw new PrivateConstructorException(); } + + inline static public var REGISTER = new MessageType( "onRegister" ); + inline static public var UNREGISTER = new MessageType( "onUnregister" ); } \ No newline at end of file diff --git a/src/hex/control/AsyncHandler.hx b/src/hex/control/AsyncHandler.hx deleted file mode 100644 index 31d673a..0000000 --- a/src/hex/control/AsyncHandler.hx +++ /dev/null @@ -1,47 +0,0 @@ -package hex.control; - -import hex.error.IllegalStateException; - -/** - * ... - * @author Francis Bourre - */ -class AsyncHandler implements ICompletable -{ - var _completeResponder : ArrayVoid>; - var _failResponder : ArrayVoid>; - - public function new() - { - this._completeResponder = []; - this._failResponder = []; - } - - public function onComplete( callback : ResultType->Void ) : ICompletable - { - this._completeResponder.push( callback ); - return this; - } - - public function onFail( callback : String->Void ) : ICompletable - { - this._failResponder.push( callback ); - return this; - } - - public function complete( result : ResultType ) : Void - { - for ( responder in this._completeResponder ) - { - responder( result ); - } - } - - public function fail( errorMessage : String ) : Void - { - for ( responder in this._failResponder ) - { - responder( errorMessage ); - } - } -} diff --git a/src/hex/control/AsyncHandlerUtil.hx b/src/hex/control/AsyncHandlerUtil.hx deleted file mode 100644 index 8bc0a3a..0000000 --- a/src/hex/control/AsyncHandlerUtil.hx +++ /dev/null @@ -1,116 +0,0 @@ -package hex.control; - -import haxe.Constraints.Function; -import haxe.ds.StringMap; -import haxe.macro.Context; -import haxe.macro.Expr; -import hex.error.PrivateConstructorException; - -/** - * ... - * @author Francis Bourre - */ -class AsyncHandlerUtil -{ - /** @private */ - function new() - { - throw new PrivateConstructorException(); - } - - static function arrowDecompose( f: Expr ) : { left: Expr, right: Expr } - { - var l: Expr = null; - var r: Expr = null; - - switch( f.expr ) - { - case EBinop( OpArrow, e1, e2 ): - { - l = e1; - r = e2; - } - - default: r = f; - } - - return { left: l, right: r }; - } - - static function _getLeftName( e : Expr ) - { - return AsyncHandlerUtil._getLeftNames( e )[ 0 ]; - } - - static function _getLeftNames( L : Expr, min : Int = 1 ) - { - var names : Array = - if ( L != null ) - { - switch( L.expr ) - { - case EConst( CIdent( s ) ): [ s ]; - - case EArrayDecl( els ): - els.map( function( e ) - return switch( e.expr ) - { - case EConst( CIdent( s ) ): s; - default: '_'; - }); - - case _: []; - } - } - else []; - - var t = ''; - while ( names.length < min ) names.push( t += '_' ); - return names; - } - - static function _getUniqueLocalVarNames( count, locals ) : Array - { - var r = new Array(); - var tmap = new StringMap(); - - while ( r.length < count ) - { - var t = '__tmp_' + Std.random( 0xffffff ); - if ( !locals.exists( t ) && !tmap.exists( t ) ) - { - r.push( t ); - tmap.set( t, 1 ); - } - } - return r; - } - - macro public static function on( h : ExprOf>, f : Expr ) : ExprOf> - { - var ad = AsyncHandlerUtil.arrowDecompose( f ); - var leftName = AsyncHandlerUtil._getLeftName( ad.left ); - var fExp = ad.right; - - var locals = AsyncHandlerUtil._getUniqueLocalVarNames( 1, Context.getLocalTVars() ); - var fName = locals.pop(); - - var mm = macro { function $fName( $leftName ) { return $fExp; } }; - return macro - { - $h.onComplete( $mm ); - } - } - - macro public static function triggers( h : ExprOf>, newHandler : ExprOf> ) : ExprOf> - { - var arg = AsyncHandlerUtil._getUniqueLocalVarNames( 1, Context.getLocalTVars() ).pop(); - - return macro - { - var $arg = ( $newHandler ); - $h.onComplete( $i{arg}.complete ); - $i{arg}; - } - } -} \ No newline at end of file diff --git a/src/hex/control/Callback.hx b/src/hex/control/Callback.hx new file mode 100644 index 0000000..f6641be --- /dev/null +++ b/src/hex/control/Callback.hx @@ -0,0 +1,26 @@ +package hex.control; + +/** + * ... + * @author back2dos + */ +abstract Callback( T->Void ) from ( T->Void ) +{ + inline function new(f) + this = f; + + @:from static function fromNiladic( f : Void->Void ) : Callback //inlining this seems to cause recursive implicit casts + return new Callback( function ( r ) f() ); + + public inline function invoke( data : T ) : Void //TODO: consider swallowing null here + ( this )( data ); + + @:to inline function toFunction() + return this; + + @:from static function fromMany( callbacks : Array> ) : Callback + return + function ( v : A ) + for ( callback in callbacks ) + callback.invoke( v ); +} \ No newline at end of file diff --git a/src/hex/control/async/AsyncCallback.hx b/src/hex/control/async/AsyncCallback.hx new file mode 100644 index 0000000..71501ce --- /dev/null +++ b/src/hex/control/async/AsyncCallback.hx @@ -0,0 +1,233 @@ +package hex.control.async; + +import haxe.ds.StringMap; +import haxe.macro.Context; +import haxe.macro.Expr; +import hex.error.Exception; +import hex.error.IllegalStateException; +import hex.error.PrivateConstructorException; + +/** + * ... + * @author Francis Bourre + */ +class AsyncCallback implements IAsyncCallback +{ + static var _map : Map, Bool> = new Map(); + + var _completeResponder : Array>; + var _failResponder : ArrayVoid>; + var _result : AsyncResult; + + public function new() + { + this._completeResponder = []; + this._failResponder = []; + this._result = Result.WAITING; + + AsyncCallback._map.set( this, true ); + } + + public static function get( callback : Callback> ) : AsyncCallback + { + var handler = new AsyncCallback(); + callback.invoke( handler._complete ); + return handler; + } + + macro public function whenComplete( ethis : Expr, clazz : Expr ) : ExprOf> + { + return AsyncCallbackUtil.whenComplete( ethis, clazz ); + } + + public function onComplete( onComplete : Callback ) : AsyncCallback + { + switch( this._result ) + { + case Result.WAITING: + this._completeResponder.push( onComplete ); + + case Result.DONE( result ): + onComplete.invoke( result ); + + case _: + } + + return this; + } + + public function onFail( onFail : Exception->Void ) : AsyncCallback + { + switch( this._result ) + { + case Result.WAITING: + this._failResponder.push( onFail ); + + case Result.FAILED( error ): + onFail( error ); + + case _: + } + + return this; + } + + function _complete( result : AsyncResult ) : Void + { + switch( result ) + { + case Result.DONE( result ): + this._doComplete( result ); + + case Result.FAILED( error ): + this._doFail( error ); + + case _: + } + } + + function _doComplete( result : ResultType ) : Void + { + if ( AsyncCallback._map.exists( this ) ) + { + this._result = result; + for ( responder in this._completeResponder ) + { + responder.invoke( result ); + } + + this._dispose(); + } + else + { + throw new IllegalStateException( 'AsyncCallback is disposed' ); + } + } + + function _doFail( error : Exception ) : Void + { + if ( AsyncCallback._map.exists( this ) ) + { + this._result = error; + for ( responder in this._failResponder ) + { + responder( error ); + } + + this._dispose(); + } + else + { + throw new IllegalStateException( 'AsyncCallback is disposed' ); + } + } + + function _dispose() : Void + { + AsyncCallback._map.remove( this ); + this._completeResponder = null; + this._failResponder = null; + } +} + +enum Result +{ + WAITING; + DONE( result : T ); + FAILED( e : Exception ); +} + +private class AsyncCallbackUtil +{ + /** @private */ + function new() + { + throw new PrivateConstructorException(); + } + + #if macro + static function arrowDecompose( f: Expr ) : { left: Expr, right: Expr } + { + var l: Expr = null; + var r: Expr = null; + + switch( f.expr ) + { + case EBinop( OpArrow, e1, e2 ): + { + l = e1; + r = e2; + } + + default: r = f; + } + + return { left: l, right: r }; + } + + static function _getLeftName( e : Expr ) + { + return AsyncCallbackUtil._getLeftNames( e )[ 0 ]; + } + + static function _getLeftNames( L : Expr, min : Int = 1 ) + { + var names : Array = + if ( L != null ) + { + switch( L.expr ) + { + case EConst( CIdent( s ) ): [ s ]; + + case EArrayDecl( els ): + els.map( function( e ) + return switch( e.expr ) + { + case EConst( CIdent( s ) ): s; + default: '_'; + }); + + case _: []; + } + } + else []; + + var t = ''; + while ( names.length < min ) names.push( t += '_' ); + return names; + } + + static function _getUniqueLocalVarNames( count, locals ) : Array + { + var r = new Array(); + var tmap = new StringMap(); + + while ( r.length < count ) + { + var t = '__tmp_' + Std.random( 0xffffff ); + if ( !locals.exists( t ) && !tmap.exists( t ) ) + { + r.push( t ); + tmap.set( t, 1 ); + } + } + return r; + } + + public static function whenComplete( h : ExprOf>, f : Expr ) : ExprOf> + { + var ad = AsyncCallbackUtil.arrowDecompose( f ); + var leftName = AsyncCallbackUtil._getLeftName( ad.left ); + var fExp = ad.right; + + var locals = AsyncCallbackUtil._getUniqueLocalVarNames( 1, Context.getLocalTVars() ); + var fName = locals.pop(); + + var mm = macro { function $fName( $leftName ) { return $fExp; } }; + return macro + { + $h.onComplete( $mm ); + } + } + #end +} \ No newline at end of file diff --git a/src/hex/control/async/AsyncResult.hx b/src/hex/control/async/AsyncResult.hx new file mode 100644 index 0000000..b3fc4c8 --- /dev/null +++ b/src/hex/control/async/AsyncResult.hx @@ -0,0 +1,25 @@ +package hex.control.async; + +import hex.control.async.AsyncCallback; + +/** + * ... + * @author Francis Bourre + */ +abstract AsyncResult( Result ) from ( Result ) +{ + inline function new( r ) + { + this = r; + } + + @:from public static inline function completed( result : ResultType ) : AsyncResult + { + return new AsyncResult( Result.DONE( result ) ); + } + + @:from public static inline function failed( error : hex.error.Exception ) : AsyncResult + { + return new AsyncResult( Result.FAILED( error) ); + } +} \ No newline at end of file diff --git a/src/hex/control/async/Handler.hx b/src/hex/control/async/Handler.hx new file mode 100644 index 0000000..cef2f87 --- /dev/null +++ b/src/hex/control/async/Handler.hx @@ -0,0 +1,7 @@ +package hex.control.async; + +/** + * @author Francis Bourre + */ + +typedef Handler = AsyncResult->Void; \ No newline at end of file diff --git a/src/hex/control/async/IAsyncCallback.hx b/src/hex/control/async/IAsyncCallback.hx new file mode 100644 index 0000000..31b4758 --- /dev/null +++ b/src/hex/control/async/IAsyncCallback.hx @@ -0,0 +1,13 @@ +package hex.control.async; + +import hex.error.Exception; + +/** + * @author Francis Bourre + */ + +interface IAsyncCallback +{ + function onComplete( onComplete : Callback ) : IAsyncCallback; + function onFail( onFail : Exception->Void ) : IAsyncCallback; +} \ No newline at end of file diff --git a/src/hex/control/async/Nothing.hx b/src/hex/control/async/Nothing.hx new file mode 100644 index 0000000..f8511be --- /dev/null +++ b/src/hex/control/async/Nothing.hx @@ -0,0 +1,9 @@ +package hex.control.async; + +/** + * @author Francis Bourre + */ +enum Nothing +{ + Nothing; +} \ No newline at end of file diff --git a/src/hex/control/forward/ForwarderBuilder.hx b/src/hex/control/forward/ForwarderBuilder.hx index d9ca513..4ddf380 100644 --- a/src/hex/control/forward/ForwarderBuilder.hx +++ b/src/hex/control/forward/ForwarderBuilder.hx @@ -1,5 +1,6 @@ package hex.control.forward; +#if macro import haxe.macro.Context; import haxe.macro.Expr; import hex.error.PrivateConstructorException; @@ -106,4 +107,5 @@ class ForwarderBuilder } return a; } -} \ No newline at end of file +} +#end \ No newline at end of file diff --git a/src/hex/control/payload/ExecutionPayload.hx b/src/hex/control/payload/ExecutionPayload.hx index 6cbfb90..77628cf 100644 --- a/src/hex/control/payload/ExecutionPayload.hx +++ b/src/hex/control/payload/ExecutionPayload.hx @@ -1,6 +1,5 @@ package hex.control.payload; -import hex.error.IllegalArgumentException; import hex.error.NullPointerException; /** @@ -31,11 +30,6 @@ class ExecutionPayload { this._type = Type.getClass( this._data ); } - - if ( !Std.is( this._data, this._type ) ) - { - throw new IllegalArgumentException( "ExecutionPayload data '" + this._data + "' should be an instance of type '" + this._type + "'" ); - } this._name = name; } @@ -66,19 +60,14 @@ class ExecutionPayload public function withName( name : String ) : ExecutionPayload { - this._name = name != null ? name : ""; + this._name = name; return this; } public function withClassName( className : String ) : ExecutionPayload { this._type = Type.resolveClass( className.split( '<' )[ 0 ] ); - if ( this._type == null ) - { - throw new IllegalArgumentException( "type '" + className + "' not found" ); - } - - this._className = className; + this._className = className.split( " " ).join( '' ); return this; } } diff --git a/src/hex/data/GUID.hx b/src/hex/data/GUID.hx index 3817e5e..863e327 100644 --- a/src/hex/data/GUID.hx +++ b/src/hex/data/GUID.hx @@ -1,11 +1,19 @@ package hex.data; +import hex.error.PrivateConstructorException; + /** * ... * @author Krisztian Fekete */ class GUID { + /** @private */ + function new() + { + throw new PrivateConstructorException(); + } + inline public static function randomIntegerWithinRange( min : Int, max : Int ) : Int { return Math.floor( Math.random() * ( 1 + max - min ) + min ); diff --git a/src/hex/domain/DefaultDomain.hx b/src/hex/domain/DefaultDomain.hx index 3420abb..ccfc2aa 100644 --- a/src/hex/domain/DefaultDomain.hx +++ b/src/hex/domain/DefaultDomain.hx @@ -1,12 +1,10 @@ package hex.domain; -import hex.domain.Domain; - /** * ... * @author Francis Bourre */ -class DefaultDomain extends Domain +class DefaultDomain { - public static var DOMAIN : DefaultDomain = DomainUtil.getDomain( "DefaultDomain", DefaultDomain ); + public static var DOMAIN = Domain.getDomain( "DefaultDomain" ); } diff --git a/src/hex/domain/Domain.hx b/src/hex/domain/Domain.hx index ffa5c52..3905825 100644 --- a/src/hex/domain/Domain.hx +++ b/src/hex/domain/Domain.hx @@ -1,54 +1,134 @@ package hex.domain; -import hex.log.Stringifier; -import hex.error.NullPointerException; import hex.error.IllegalArgumentException; +import hex.error.NullPointerException; +import hex.util.Stringifier; /** * ... * @author Francis Bourre */ +@:final class Domain { - var _domainName : String; - static var _domainNames = new Map(); + var _name : String; + var _parent : Domain; + + static var _domains = new Map(); - public function new( domainName : String ) + function new( domainName : String ) { if ( domainName == null ) { throw new NullPointerException( "Domain's name can't be null" ); } - else if ( Domain._domainNames.exists( domainName ) ) + else if ( Domain._domains.exists( domainName ) ) { throw new IllegalArgumentException( "Domain has already been registered with name '" + domainName + "'" ); } else { - Domain._domainNames.set( domainName, this ); - this._domainName = domainName; + Domain._domains.set( domainName, this ); + this._name = domainName; } } public function getName() : String { - return this._domainName; + return this._name; } - public static function getDomain( domainName : String ) : Domain + public function getParent() : Domain + { + return this._parent; + } + + static public function getDomain( domainName : String ) : Domain { - if ( !Domain._domainNames.exists( domainName ) ) - { - return null; - } + var domain = null; + + if ( Domain._domains.exists( domainName ) ) + { + domain = Domain._domains.get( domainName ); + } else { - return Domain._domainNames.get( domainName ); + domain = new Domain( domainName ); + Domain._domains.set( domainName, domain ); + Domain._reparent(); } + + return domain; } public function toString() : String { return Stringifier.stringify( this ) + " with name '" + this.getName() + "'"; } + + static function _reparent() : Void + { + var domains = Domain._domains; + + for ( key in domains.keys() ) + { + var domain = domains.get( key ); + if ( key != null && key != '' ) + { + var i = key.lastIndexOf( '.' ); + if ( i > 0 ) + { + key = key.substring( 0, i ); + var parent = Domain._getDomain( key ); + if ( parent == null ) + { + parent = TopLevelDomain.DOMAIN; + } + domain._parent = parent; + } + else + { + domain._parent = TopLevelDomain.DOMAIN; + } + } + } + } + + static public function _getDomain( name : String ) : Domain + { + var domains = Domain._domains; + + var domain = domains.get( name ); + if ( domain != null ) + { + return domain; + } + + var substr = name; + while ( ( substr = Domain._getSubName( substr ) ) != null ) + { + domain = domains.get( substr ); + if ( domain != null ) + { + return domain; + } + } + + return TopLevelDomain.DOMAIN; + } + + /** + * + * @param name + * @return + */ + static function _getSubName( name : String ) : String + { + if ( name == null || name == '' ) + { + return null; + } + var i = name.lastIndexOf( '.' ); + return i > 0 ? name.substring( 0, i ) : ''; + } } diff --git a/src/hex/domain/DomainDispatcher.hx b/src/hex/domain/DomainDispatcher.hx index 0e0cd9e..07f48cc 100644 --- a/src/hex/domain/DomainDispatcher.hx +++ b/src/hex/domain/DomainDispatcher.hx @@ -101,12 +101,12 @@ class DomainDispatcher implements IDomainDispatcher( messageType : MessageType, scope : Dynamic, callback : T, domain : Domain ) : Bool { return this.getDomainDispatcher( domain ).addHandler( messageType, scope, callback ); } - public function removeHandler( messageType : MessageType, scope : Dynamic, callback : Dynamic, domain : Domain ) : Bool + public function removeHandler( messageType : MessageType, scope : Dynamic, callback : T, domain : Domain ) : Bool { return this.getDomainDispatcher( domain ).removeHandler( messageType, scope, callback ); } diff --git a/src/hex/domain/DomainExpert.hx b/src/hex/domain/DomainExpert.hx index 9e380a6..a038ea0 100644 --- a/src/hex/domain/DomainExpert.hx +++ b/src/hex/domain/DomainExpert.hx @@ -1,7 +1,6 @@ package hex.domain; import hex.core.HashCodeFactory; -import hex.domain.Domain; import hex.error.IllegalStateException; import hex.module.IModule; @@ -53,7 +52,7 @@ class DomainExpert } else { - var domain = DomainUtil.getDomain( key, Domain ); + var domain = Domain.getDomain( key ); this._removedModules.set( key, false ); this._subscribedModules.set( module, domain ); return domain; diff --git a/src/hex/domain/DomainUtil.hx b/src/hex/domain/DomainUtil.hx deleted file mode 100644 index a7f1f77..0000000 --- a/src/hex/domain/DomainUtil.hx +++ /dev/null @@ -1,35 +0,0 @@ -package hex.domain; - -import hex.error.IllegalArgumentException; -import hex.util.ClassUtil; - -/** - * ... - * @author Francis Bourre - */ -class DomainUtil -{ - static var _domain = new Map(); - - function new() - { - - } - - static public function getDomain( domainName : String, type : Class ) : DomainType - { - var domain : DomainType = null; - - if ( DomainUtil._domain.exists( domainName ) ) - { - domain = DomainUtil._domain.get( domainName ); - } - else - { - domain = Type.createInstance( type, [ domainName ] ); - DomainUtil._domain.set( domainName, domain ); - } - - return domain; - } -} \ No newline at end of file diff --git a/src/hex/domain/IDomainDispatcher.hx b/src/hex/domain/IDomainDispatcher.hx index f874384..c2c880f 100644 --- a/src/hex/domain/IDomainDispatcher.hx +++ b/src/hex/domain/IDomainDispatcher.hx @@ -32,9 +32,9 @@ interface IDomainDispatcher function removeListener( listener : ListenerType, ?domain : Domain ) : Bool; - function addHandler( messageType : MessageType, scope : Dynamic, callback : Dynamic, domain : Domain ) : Bool; + function addHandler( messageType : MessageType, scope : Dynamic, callback : T, domain : Domain ) : Bool; - function removeHandler( messageType : MessageType, scope : Dynamic, callback : Dynamic, domain : Domain ) : Bool; + function removeHandler( messageType : MessageType, scope : Dynamic, callback : T, domain : Domain ) : Bool; function dispatch( messageType : MessageType, ?domain : Domain, ?data : Array ) : Void; diff --git a/src/hex/domain/NoDomain.hx b/src/hex/domain/NoDomain.hx index 4933ce7..eaa5871 100644 --- a/src/hex/domain/NoDomain.hx +++ b/src/hex/domain/NoDomain.hx @@ -1,12 +1,10 @@ package hex.domain; -import hex.domain.Domain; - /** * ... * @author Francis Bourre */ -class NoDomain extends Domain +class NoDomain { - public static var DOMAIN : NoDomain = DomainUtil.getDomain( "NoDomain", NoDomain ); + public static var DOMAIN = Domain.getDomain( "NoDomain" ); } diff --git a/src/hex/domain/TopLevelDomain.hx b/src/hex/domain/TopLevelDomain.hx index 31201fc..acfba61 100644 --- a/src/hex/domain/TopLevelDomain.hx +++ b/src/hex/domain/TopLevelDomain.hx @@ -4,7 +4,7 @@ package hex.domain; * ... * @author Francis Bourre */ -class TopLevelDomain extends Domain +class TopLevelDomain { - public static var DOMAIN : TopLevelDomain = DomainUtil.getDomain( "TopLevelDomain", TopLevelDomain ); + public static var DOMAIN = Domain.getDomain( "TopLevelDomain" ); } \ No newline at end of file diff --git a/src/hex/error/Exception.hx b/src/hex/error/Exception.hx index a2cab18..e5f8975 100644 --- a/src/hex/error/Exception.hx +++ b/src/hex/error/Exception.hx @@ -1,8 +1,11 @@ package hex.error; -import hex.log.Logger; -import hex.log.Stringifier; import haxe.PosInfos; +import hex.util.Stringifier; + +#if (!macro && debug) +import hex.log.HexLog.*; +#end /** * ... @@ -20,8 +23,10 @@ class Exception this.posInfos = posInfos; this.name = Stringifier.stringify( this ); - #if debug - Logger.error( this.toString() ); + #if (!macro && debug) + error(this.toString()); + #elseif (macro && debug) + trace(this.toString()); #end } diff --git a/src/hex/error/IllegalArgumentException.hx b/src/hex/error/IllegalArgumentException.hx index 0922dc8..9aedf8d 100644 --- a/src/hex/error/IllegalArgumentException.hx +++ b/src/hex/error/IllegalArgumentException.hx @@ -6,6 +6,7 @@ import haxe.PosInfos; * ... * @author Francis Bourre */ +@IgnoreCover class IllegalArgumentException extends Exception { public function new ( message : String, ?posInfos : PosInfos ) diff --git a/src/hex/error/IllegalStateException.hx b/src/hex/error/IllegalStateException.hx index a8caffc..052e38e 100644 --- a/src/hex/error/IllegalStateException.hx +++ b/src/hex/error/IllegalStateException.hx @@ -6,6 +6,7 @@ import haxe.PosInfos; * ... * @author Francis Bourre */ +@IgnoreCover class IllegalStateException extends Exception { public function new ( message : String, ?posInfos : PosInfos ) diff --git a/src/hex/error/NoSuchElementException.hx b/src/hex/error/NoSuchElementException.hx index e7f30c7..ab8aaa4 100644 --- a/src/hex/error/NoSuchElementException.hx +++ b/src/hex/error/NoSuchElementException.hx @@ -6,6 +6,7 @@ import haxe.PosInfos; * ... * @author Francis Bourre */ +@IgnoreCover class NoSuchElementException extends Exception { public function new ( message : String, ?posInfos : PosInfos ) diff --git a/src/hex/error/NullPointerException.hx b/src/hex/error/NullPointerException.hx index aeba096..c63ba4e 100644 --- a/src/hex/error/NullPointerException.hx +++ b/src/hex/error/NullPointerException.hx @@ -6,6 +6,7 @@ import haxe.PosInfos; * ... * @author Francis Bourre */ +@IgnoreCover class NullPointerException extends Exception { public function new ( message : String, ?posInfos : PosInfos ) diff --git a/src/hex/error/PrivateConstructorException.hx b/src/hex/error/PrivateConstructorException.hx index 7552b2c..ee517de 100644 --- a/src/hex/error/PrivateConstructorException.hx +++ b/src/hex/error/PrivateConstructorException.hx @@ -6,6 +6,7 @@ import haxe.PosInfos; * ... * @author Francis Bourre */ +@IgnoreCover class PrivateConstructorException extends Exception { public function new ( ?message : String = "This class can't be instantiated.", ?posInfos : PosInfos ) diff --git a/src/hex/error/UnsupportedOperationException.hx b/src/hex/error/UnsupportedOperationException.hx index 499595a..bda02ae 100644 --- a/src/hex/error/UnsupportedOperationException.hx +++ b/src/hex/error/UnsupportedOperationException.hx @@ -6,6 +6,7 @@ import haxe.PosInfos; * ... * @author Francis Bourre */ +@IgnoreCover class UnsupportedOperationException extends Exception { public function new ( message : String, ?posInfos : PosInfos ) diff --git a/src/hex/error/VirtualMethodException.hx b/src/hex/error/VirtualMethodException.hx index 0946cf2..b5f2152 100644 --- a/src/hex/error/VirtualMethodException.hx +++ b/src/hex/error/VirtualMethodException.hx @@ -6,6 +6,7 @@ import haxe.PosInfos; * ... * @author Francis Bourre */ +@IgnoreCover class VirtualMethodException extends Exception { public function new ( ?message : String = 'this method must be overridden', ?posInfos : PosInfos ) diff --git a/src/hex/event/BasicEvent.hx b/src/hex/event/BasicEvent.hx index 7b35a15..a2d7437 100644 --- a/src/hex/event/BasicEvent.hx +++ b/src/hex/event/BasicEvent.hx @@ -1,6 +1,6 @@ package hex.event; -import hex.log.Stringifier; +import hex.util.Stringifier; /** * ... diff --git a/src/hex/event/CompositeDispatcher.hx b/src/hex/event/CompositeDispatcher.hx index bf4c7dd..05e7653 100644 --- a/src/hex/event/CompositeDispatcher.hx +++ b/src/hex/event/CompositeDispatcher.hx @@ -1,7 +1,7 @@ package hex.event; import hex.error.UnsupportedOperationException; -import hex.log.Stringifier; +import hex.util.Stringifier; /** * ... diff --git a/src/hex/event/Dispatcher.hx b/src/hex/event/Dispatcher.hx index 54a964f..e072c97 100644 --- a/src/hex/event/Dispatcher.hx +++ b/src/hex/event/Dispatcher.hx @@ -2,7 +2,7 @@ package hex.event; import hex.error.IllegalArgumentException; import hex.error.UnsupportedOperationException; -import hex.log.Stringifier; +import hex.util.Stringifier; /** * ... @@ -23,64 +23,71 @@ class Dispatcher implements IDispatcher public function dispatch( messageType : MessageType, ?data : Array ) : Void { - this._seal( true ); - - var parameters : Array = null; - - var iterator = this._listeners.keys(); - while ( iterator.hasNext() ) - { - var listener : ListenerType = iterator.next(); - var m : Map = this._listeners.get( listener ); + if ( !this._isSealed ) + { + this._seal( true ); - if ( Lambda.count( m ) > 0 ) - { - if ( m.exists( messageType ) ) + var parameters : Array = null; + + var iterator = this._listeners.keys(); + while ( iterator.hasNext() ) + { + var listener : ListenerType = iterator.next(); + var m : Map = this._listeners.get( listener ); + + if ( Lambda.count( m ) > 0 ) { - var handler : CallbackHandler = m.get( messageType ); - handler.call( data ); + if ( m.exists( messageType ) ) + { + var handler : CallbackHandler = m.get( messageType ); + handler.call( data ); + } } - } - else - { - var messageName : String = messageType; - var callback = Reflect.field( listener, messageName ); - if ( callback != null && messageName != 'handleMessage' ) - { - Reflect.callMethod ( listener, callback, data ); - } - else - { - callback = Reflect.field( listener, 'handleMessage' ); - - if ( callback != null ) + else + { + var messageName : String = messageType; + var callback = Reflect.field( listener, messageName ); + if ( callback != null && messageName != 'handleMessage' ) { - if ( parameters == null ) + Reflect.callMethod ( listener, callback, data ); + } + else + { + callback = Reflect.field( listener, 'handleMessage' ); + + if ( callback != null ) { - parameters = [messageType]; - if ( data != null ) + if ( parameters == null ) { - parameters = parameters.concat( data ); - } - } - - Reflect.callMethod ( listener, callback, parameters ); - - } else - { - var msg : String = Stringifier.stringify( this ) + ".dispatch failed. " + - " You must implement '" + messageType + "' or 'handleMessage' method in '" + - Stringifier.stringify( listener ) + "' instance."; - throw( new UnsupportedOperationException( msg ) ); + parameters = [messageType]; + if ( data != null ) + { + parameters = parameters.concat( data ); + } + } + + Reflect.callMethod ( listener, callback, parameters ); + + } else + { + var msg : String = Stringifier.stringify( this ) + ".dispatch failed. " + + " You must implement '" + messageType + "' or 'handleMessage' method in '" + + Stringifier.stringify( listener ) + "' instance."; + throw( new UnsupportedOperationException( msg ) ); + } } - } - } - } - - this._seal( false ); + } + } + + this._seal( false ); + } + else + { + this._cachedMethodCalls.push( this.dispatch.bind( messageType, data ) ); + } } - public function addHandler( messageType : MessageType, scope : Dynamic, callback : Dynamic ) : Bool + public function addHandler( messageType : MessageType, scope : Dynamic, callback : T ) : Bool { if ( !this._isSealed ) { @@ -123,7 +130,7 @@ class Dispatcher implements IDispatcher } } - public function removeHandler( messageType : MessageType, scope : Dynamic, callback : Dynamic ) : Bool + public function removeHandler( messageType : MessageType, scope : Dynamic, callback : T ) : Bool { if ( !this._isSealed ) { diff --git a/src/hex/event/IDispatcher.hx b/src/hex/event/IDispatcher.hx index ceb3ec4..01dc296 100644 --- a/src/hex/event/IDispatcher.hx +++ b/src/hex/event/IDispatcher.hx @@ -6,8 +6,8 @@ package hex.event; interface IDispatcher { function dispatch( messageType : MessageType, ?data : Array ) : Void; - function addHandler( messageType : MessageType, scope : Dynamic, callback : Dynamic ) : Bool; - function removeHandler( messageType : MessageType, scope : Dynamic, callback : Dynamic ) : Bool; + function addHandler( messageType : MessageType, scope : Dynamic, callback : T ) : Bool; + function removeHandler( messageType : MessageType, scope : Dynamic, callback : T ) : Bool; function addListener( listener : ListenerType ) : Bool; function removeListener( listener : ListenerType ) : Bool; function removeAllListeners() : Void; diff --git a/src/hex/event/TriggerBuilder.hx b/src/hex/event/TriggerBuilder.hx index d88301e..3b861ac 100644 --- a/src/hex/event/TriggerBuilder.hx +++ b/src/hex/event/TriggerBuilder.hx @@ -14,6 +14,7 @@ import hex.event.ITrigger; import hex.util.MacroUtil; using haxe.macro.Context; +using haxe.macro.Tools; /** * ... @@ -189,14 +190,39 @@ class TriggerBuilder static function _buildClassVOFromTFunction( triggerDefinition : { args: Array, ret: ComplexType, triggerParamType : Null } ) : ClassVO { - var className = '__Trigger_Class__' + (TriggerBuilder._ID++); - var dispatcherClass : TypeDefinition = null; + var getPack = function( className : String ) : { pack: Array, className: String } + { + var pack = className.split( "." ); + var className = pack[ pack.length -1 ]; + pack.splice( pack.length - 1, 1 ); - dispatcherClass = TriggerBuilder._getClassSkeleton( className, triggerDefinition.triggerParamType ); + return { pack: pack, className: className }; + } var l = triggerDefinition.args.length; - var args = [ for ( i in 0...l ) { name: 'arg' + i, type: triggerDefinition.args[ i ], opt: false } ]; + var args = []; + for ( i in 0...l ) + { + var t = triggerDefinition.args[ i ]; + switch( t ) + { + case TPath( p ): + var ttype = t.toType().toString().split('<')[0]; + var tPack = getPack( ttype ); + //do the dirty job of setting the right pack for each argument if the developer forgets to set it. + p.pack = tPack.pack; + + case _: + } + args.push( { name: 'arg' + i, type: t, opt: false } ); + } + var className = '__Trigger_Class__' + (TriggerBuilder._ID++); + var dispatcherClass : TypeDefinition = null; + + //build class + dispatcherClass = TriggerBuilder._getClassSkeleton( className, triggerDefinition.triggerParamType ); + var newField : Field = { meta: null, diff --git a/src/hex/log/DomainLogger.hx b/src/hex/log/DomainLogger.hx deleted file mode 100644 index bbeab32..0000000 --- a/src/hex/log/DomainLogger.hx +++ /dev/null @@ -1,62 +0,0 @@ -package hex.log; - -import haxe.PosInfos; -import hex.domain.Domain; -import hex.error.NullPointerException; -import hex.log.Logger; - -/** - * ... - * @author Francis Bourre - */ -class DomainLogger implements ILogger -{ - var _domain : Domain; - var _logger : Logger; - - public function new( domain : Domain ) - { - if ( domain == null ) - { - throw new NullPointerException( "Domain should be specified for contructor call" ); - } - - this._domain = domain; - this._logger = Logger.getInstance(); - } - - public function clear() : Void - { - this._logger.clear(); - } - - public function debug( o : Dynamic, ?posInfos : PosInfos ) : Void - { - this._logger.log( o, LogLevel.DEBUG, this._domain, posInfos ); - } - - public function info( o : Dynamic, ?posInfos : PosInfos ) : Void - { - this._logger.log( o, LogLevel.INFO, this._domain, posInfos ); - } - - public function warn( o : Dynamic, ?posInfos : PosInfos ) : Void - { - this._logger.log( o, LogLevel.WARN, this._domain, posInfos ); - } - - public function error( o : Dynamic, ?posInfos : PosInfos ) : Void - { - this._logger.log( o, LogLevel.ERROR, this._domain, posInfos ); - } - - public function fatal( o : Dynamic, ?posInfos : PosInfos ) : Void - { - this._logger.log( o, LogLevel.FATAL, this._domain, posInfos ); - } - - public function getDomain() : Domain - { - return this._domain; - } -} \ No newline at end of file diff --git a/src/hex/log/ILogListener.hx b/src/hex/log/ILogListener.hx deleted file mode 100644 index 13e99cd..0000000 --- a/src/hex/log/ILogListener.hx +++ /dev/null @@ -1,16 +0,0 @@ -package hex.log; - -/** - * ... - * @author Francis Bourre - */ -interface ILogListener -{ - function onClear() : Void; - - /** - * Triggered when a Log event is dispatched by the Logging API. - * @see Logger - */ - function onLog( message : LoggerMessage ) : Void; -} \ No newline at end of file diff --git a/src/hex/log/ILogger.hx b/src/hex/log/ILogger.hx deleted file mode 100644 index f3d7f8c..0000000 --- a/src/hex/log/ILogger.hx +++ /dev/null @@ -1,24 +0,0 @@ -package hex.log; - -import haxe.PosInfos; -import hex.domain.Domain; - -/** - * @author Francis Bourre - */ -interface ILogger -{ - function clear() : Void; - - function debug( o : Dynamic, ?posInfos : PosInfos ) : Void; - - function info( o : Dynamic, ?posInfos : PosInfos ) : Void; - - function warn( o : Dynamic, ?posInfos : PosInfos ) : Void; - - function error( o : Dynamic, ?posInfos : PosInfos ) : Void; - - function fatal( o : Dynamic, ?posInfos : PosInfos ) : Void; - - function getDomain() : Domain; -} \ No newline at end of file diff --git a/src/hex/log/LogLevel.hx b/src/hex/log/LogLevel.hx deleted file mode 100644 index 450a8f9..0000000 --- a/src/hex/log/LogLevel.hx +++ /dev/null @@ -1,98 +0,0 @@ -package hex.log; - -/** - * ... - * @author Francis Bourre - */ -class LogLevel -{ - static var _ALL = new LogLevel( 0 ); - static var _DEBUG = new LogLevel( 10000 ); - static var _INFO = new LogLevel( 20000 ); - static var _WARN = new LogLevel( 30000 ); - static var _ERROR = new LogLevel( 40000 ); - static var _FATAL = new LogLevel( 50000 ); - static var _OFF = new LogLevel( 60000 ); - - @:isVar public static var LEVELS( get, null ) : Array; - static function get_LEVELS() : Array - { - return [ LogLevel._ALL, LogLevel._DEBUG, LogLevel._INFO, LogLevel._WARN, LogLevel._ERROR, LogLevel._FATAL, LogLevel._OFF ]; - } - - @:isVar public static var ALL( get, null ) : LogLevel; - inline static function get_ALL() : LogLevel - { - return LogLevel._ALL; - } - - @:isVar public static var DEBUG( get, null ) : LogLevel; - inline static function get_DEBUG() : LogLevel - { - return LogLevel._DEBUG; - } - - @:isVar public static var INFO( get, null ) : LogLevel; - inline static function get_INFO() : LogLevel - { - return LogLevel._INFO; - } - - @:isVar public static var WARN( get, null ) : LogLevel; - inline static function get_WARN() : LogLevel - { - return LogLevel._WARN; - } - - @:isVar public static var ERROR( get, null ) : LogLevel; - inline static function get_ERROR() : LogLevel - { - return LogLevel._ERROR; - } - - @:isVar public static var FATAL( get, null ) : LogLevel; - inline static function get_FATAL() : LogLevel - { - return LogLevel._FATAL; - } - - @:isVar public static var OFF( get, null ) : LogLevel; - inline static function get_OFF() : LogLevel - { - return LogLevel._OFF; - } - - @:isVar public var value( get, null ) : Int; - function get_value() : Int - { - return this.value; - } - - public function new( value : Int ) - { - this.value = value; - } - - public function toString() : String - { - switch( this.value ) - { - case 0 : - return "ALL"; - case 10000 : - return "DEBUG"; - case 20000 : - return "INFO"; - case 30000 : - return "WARN"; - case 40000 : - return "ERROR"; - case 50000 : - return "FATAL"; - case 60000 : - return "OFF"; - } - - return ""; - } -} \ No newline at end of file diff --git a/src/hex/log/Logger.hx b/src/hex/log/Logger.hx deleted file mode 100644 index 006a612..0000000 --- a/src/hex/log/Logger.hx +++ /dev/null @@ -1,114 +0,0 @@ -package hex.log; - -import haxe.PosInfos; -import hex.domain.Domain; -import hex.domain.DomainDispatcher; -import hex.domain.NoDomain; - -/** - * ... - * @author Francis Bourre - */ -class Logger -{ - static var _Instance : Logger = null; - - var _dispatcher : DomainDispatcher; - var _level : LogLevel; - - public function new() - { - this.setLevel( LogLevel.ALL ); - this._dispatcher = new DomainDispatcher(); - } - - public static function getInstance() : Logger - { - if ( Logger._Instance == null ) - { - Logger._Instance = new Logger(); - } - - return Logger._Instance; - } - - public function setLevel( level : LogLevel ) : Void - { - this._level = level; - } - - public function getLevel() : LogLevel - { - return this._level; - } - - public function clear() : Void - { - this._dispatcher.dispatch( LoggerMessage.CLEAR ); - } - - public function log( o : Dynamic, level : LogLevel, ?domain : Domain, ?posInfos : PosInfos ) : Void - { - if ( this._level.value <= level.value ) - { - this._dispatcher.dispatch( LoggerMessage.LOG, domain, [ new LoggerMessage( o, level, domain == null ? NoDomain.DOMAIN : domain, posInfos ) ] ); - } - } - - public function addListener( listener : ILogListener, ?domain : Domain ) : Bool - { - this._dispatcher.addHandler( LoggerMessage.LOG, listener, listener.onLog, domain ); - return this._dispatcher.addHandler( LoggerMessage.CLEAR, listener, listener.onClear, domain ); - } - - public function removeListener( listener : ILogListener, ?domain : Domain ) : Bool - { - this._dispatcher.removeHandler( LoggerMessage.LOG, listener, listener.onLog, domain ); - return this._dispatcher.removeHandler( LoggerMessage.CLEAR, listener, listener.onClear, domain ); - } - - public function isRegistered( listener : ILogListener, ?domain : Domain ) : Bool - { - return this._dispatcher.isRegistered( listener, LoggerMessage.LOG, domain ); - } - - public function removeAllListeners() : Void - { - this._dispatcher.removeAllListeners(); - } - - public function toString() : String - { - return Stringifier.stringify( this ); - } - - public static function debug( o : Dynamic, ?domain : Domain, ?posInfos : PosInfos ) : Void - { - Logger.getInstance().log( o, LogLevel.DEBUG, domain, posInfos ); - } - - public static function info( o : Dynamic, ?domain : Domain, ?posInfos : PosInfos ) : Void - { - Logger.getInstance().log( o, LogLevel.INFO, domain, posInfos ); - } - - public static function warn( o : Dynamic, ?domain : Domain, ?posInfos : PosInfos ) : Void - { - Logger.getInstance().log( o, LogLevel.WARN, domain, posInfos ); - } - - public static function error( o : Dynamic, ?domain : Domain, ?posInfos : PosInfos ) : Void - { - Logger.getInstance().log( o, LogLevel.ERROR, domain, posInfos ); - } - - public static function fatal( o : Dynamic, ?domain : Domain, ?posInfos : PosInfos ) : Void - { - Logger.getInstance().log( o, LogLevel.FATAL, domain, posInfos ); - } - - public static function clear_all( ?domain : Domain ) : Void - { - Logger.getInstance().clear(); - } -} diff --git a/src/hex/log/LoggerMessage.hx b/src/hex/log/LoggerMessage.hx deleted file mode 100644 index f17221a..0000000 --- a/src/hex/log/LoggerMessage.hx +++ /dev/null @@ -1,28 +0,0 @@ -package hex.log; - -import haxe.PosInfos; -import hex.domain.Domain; -import hex.event.MessageType; - -/** - * ... - * @author Francis Bourre - */ -class LoggerMessage -{ - inline public static var LOG = new MessageType( "onLog" ); - inline public static var CLEAR = new MessageType( "onClear" ); - - public var message : Dynamic; - public var level : LogLevel; - public var domain : Domain; - public var posInfos : PosInfos; - - public function new( message : Dynamic, level : LogLevel, ?domain : Domain, ?posInfos : PosInfos ) - { - this.message = message; - this.level = level; - this.domain = domain; - this.posInfos = posInfos; - } -} \ No newline at end of file diff --git a/src/hex/log/Stringifier.hx b/src/hex/log/Stringifier.hx deleted file mode 100644 index adc173b..0000000 --- a/src/hex/log/Stringifier.hx +++ /dev/null @@ -1,70 +0,0 @@ -package hex.log; - -import haxe.PosInfos; -import hex.error.PrivateConstructorException; - -/** - * ... - * @author Francis Bourre - */ -class Stringifier -{ - /** @private */ - function new() - { - throw new PrivateConstructorException(); - } - - //-------------------------------------------------------------------- - // Private properties - //-------------------------------------------------------------------- - - static var _STRATEGY : IStringifierStrategy; - - //-------------------------------------------------------------------- - // Public API - //-------------------------------------------------------------------- - - /** - * Sets the concrete stringifier to use for process. - * - * @param o Stringifier concrete implementation - * - * @see BasicStringifier - */ - public static function setStringifier( o : IStringifierStrategy ) : Void - { - Stringifier._STRATEGY = o; - } - - /** - * Returns the current used stringifier. - */ - public static function getStringifier() : IStringifierStrategy - { - return Stringifier._STRATEGY; - } - - /** - * Process stringify processing. - * - * @param target Object to stringify - */ - public static function stringify( target : Dynamic ) : String - { - if ( Stringifier._STRATEGY == null ) - { - Stringifier._STRATEGY = new BasicStringifierStrategy(); - } - - return Stringifier._STRATEGY.stringify( target ); - } - - /** - * Returns the current code postion informations. - */ - public static function getPosInfos( ?posInfos : PosInfos ) : PosInfos - { - return posInfos; - } -} diff --git a/src/hex/log/layout/JavaScriptConsoleLayout.hx b/src/hex/log/layout/JavaScriptConsoleLayout.hx deleted file mode 100644 index c1feb06..0000000 --- a/src/hex/log/layout/JavaScriptConsoleLayout.hx +++ /dev/null @@ -1,56 +0,0 @@ -package hex.log.layout; - -#if js -import haxe.PosInfos; -import hex.log.ILogListener; -import hex.log.LoggerMessage; -import js.Browser; - -/** - * ... - * @author Francis Bourre - */ -class JavaScriptConsoleLayout implements ILogListener -{ - public function new() - { - - } - - public function onLog( message : LoggerMessage ) : Void - { - var posInfos : PosInfos = message.posInfos; - var info : String = posInfos != null ? " at " + posInfos.className + "::" + posInfos.methodName + " line " + posInfos.lineNumber + " in file " + posInfos.fileName : ""; - var m : haxe.extern.Rest->Void; - - if ( message.level.value == LogLevel.DEBUG.value ) - { - m = Browser.console.debug; - } - else if ( message.level.value == LogLevel.INFO.value ) - { - m = Browser.console.info; - } - else if ( message.level.value == LogLevel.WARN.value ) - { - m = Browser.console.warn; - } - else if ( message.level.value == LogLevel.FATAL.value || message.level.value == LogLevel.ERROR.value) - { - m = Browser.console.error; - - } - else - { - m = Browser.console.log; - } - - m( message.message, "[" + message.domain.getName() + "]" + info ); - } - - public function onClear() : Void - { - Browser.console.clear(); - } -} -#end \ No newline at end of file diff --git a/src/hex/log/layout/LogLayoutHTMLView.hx b/src/hex/log/layout/LogLayoutHTMLView.hx deleted file mode 100644 index 1f76cbc..0000000 --- a/src/hex/log/layout/LogLayoutHTMLView.hx +++ /dev/null @@ -1,431 +0,0 @@ -package hex.log.layout; - -#if js -import hex.domain.Domain; -import hex.log.layout.LogProxyLayout; -import js.html.DOMRect; -import js.html.Element; -import js.html.Event; -import js.html.HTMLDocument; -import js.html.InputElement; -import js.html.KeyboardEvent; -import js.html.SelectElement; -import js.html.TouchEvent; - -/** - * ... - * @author Francis Bourre - */ -class LogLayoutHTMLView -{ - static var TAP_THRESHOLD : UInt = 250; - - var _console : Element; - var _proxy : LogProxyLayout; - - var _toggleStartPosition : Array = [ 0, 0 ]; - var _transformPosition : Array = [ 0, 0 ]; - var _changePosition : Array = [ 0, 0 ]; - var _toggleButtonRect : DOMRect; - var _toggleBtnCenter : Array; - - var _swipeHorizontalVO : SwipeHorizontalVO = new SwipeHorizontalVO(); - - var _debugWrapperSelector : String; - - var _debugConsole : Element; - var _list : Element; - var _wrapper : Element; - var _toggleButton : Element; - var _leftArrowButton : Element; - var _rightArrowButton : Element; - - var _searchInput : InputElement; - var _domainInput : InputElement; - var _levelSelector : SelectElement; - - var _tapStartTime : Float; - var _levels : Map = new Map(); - - var _searchLength : Int = 0; - var _searchIndex : Int = 0; - - public var consoleWrapperTaget : String = ".debug-console-list-wrapper"; - - public function new( proxy : LogProxyLayout, wrapperSelector:String = "body" ) - { - this._proxy = proxy; - this._debugWrapperSelector = wrapperSelector; - this._init(); - } - - function _init() : Void - { - _buildView(); - _buildBehavior(); - } - - inline function _buildView():Void - { - var document : HTMLDocument = js.Browser.window.document; - var container:Element = document.querySelector(this._debugWrapperSelector); - - var debugWrapper = document.createDivElement(); - debugWrapper.style.position = "fixed"; - debugWrapper.innerHTML = ConsoleStyle.template; - container.appendChild(debugWrapper); - - var debugStyle = document.createStyleElement(); - debugStyle.innerHTML = ConsoleStyle.style; - container.appendChild(debugStyle); - - this._debugConsole = document.querySelector('.debug-console'); - this._list = document.querySelector('.debug-console-list'); - this._wrapper = document.querySelector('.debug-console-list-wrapper'); - this._toggleButton = document.querySelector('.debug-console-toggle'); - this._leftArrowButton = document.querySelector('.debug-console-control-caret--left'); - this._rightArrowButton = document.querySelector('.debug-console-control-caret--right'); - - this._searchInput = cast document.querySelector('.debug-console-control-item--search input'); - this._domainInput = cast document.querySelector('.debug-console-control-item--domain input'); - this._levelSelector = cast document.querySelector('.debug-console-control-item--level select'); - - for ( level in LogLevel.LEVELS ) - { - var option = document.createOptionElement(); - option.innerHTML = level.toString(); - option.value = level.toString(); - this._levels.set( level.toString(), level ); - this._levelSelector.appendChild( option ); - } - - this._toggleButtonRect = this._toggleButton.getBoundingClientRect(); - this._toggleBtnCenter = [ this._toggleButtonRect.width / 2, this._toggleButtonRect.height / 2]; - } - - inline function _buildBehavior():Void - { - this._leftArrowButton.addEventListener( 'click', this._onPreviousSearchButtonClick ); - this._rightArrowButton.addEventListener( 'click', this._onNextSearchButtonClick ); - this._toggleButton.addEventListener( 'click', this._toggleDebugConsole ); - this._toggleButton.addEventListener( 'touchstart', this._onToggleButtonTouchStart ); - this._toggleButton.addEventListener( 'touchmove', this._onToggleButtonTouchMove ); - this._toggleButton.addEventListener( 'touchend', this._onToggleButtonTouchEnd ); - - this._wrapper.addEventListener( 'touchstart', this._onWrapperTouchStart ); - this._wrapper.addEventListener( 'touchmove', this._onWrapperTouchMove ); - this._wrapper.addEventListener( 'touchend', this._onWrapperTouchEnd ); - - this._searchInput.addEventListener( "input", this._onSearchStart ); - this._searchInput.addEventListener("keypress", this._onSearchKeyPress); - this._domainInput.addEventListener( "input", this._onSetDomain ); - - this._levelSelector.addEventListener( "change", this._onChangeLevel ); - } - - function _onSearchStart( e : Event ) : Void - { - this._searchIndex = 0; - this._searchLength = 0; - if (this._searchInput.value.length < 2) return; - - this._searchLength = this._proxy.searchFor( this._searchInput.value, '', '' ); - if ( this._searchLength > 0 ) - { - js.Browser.window.document.getElementById( "searchedWord" + this._searchIndex ).scrollIntoView(); - } - } - - function _onSearchKeyPress( e : KeyboardEvent ) : Void - { - if (e.shiftKey && e.keyCode == KeyboardEvent.DOM_VK_RETURN) - { - this._onPreviousSearchButtonClick(e); - } else if(e.keyCode == KeyboardEvent.DOM_VK_RETURN) - { - this._onNextSearchButtonClick(e); - } - } - - function _onSetDomain( e : Event ) : Void - { - if (this._levelSelector.value.length < 2) return; - this._proxy.filter( this._levels.get( this._levelSelector.value ), Domain.getDomain( this._domainInput.value ) ); - } - - function _onChangeLevel( e : Event ) : Void - { - this._proxy.filter( this._levels.get( this._levelSelector.value ), Domain.getDomain( this._domainInput.value ) ); - } - - function _onToggleButtonTouchStart( e : TouchEvent ) : Void - { - e.preventDefault(); - this._toggleStartPosition = [ e.touches[ 0 ].pageX, e.touches[ 0 ].pageY ]; - this._changePosition = this._transformPosition; - - this._tapStartTime = ( Date.now() ).getTime(); - } - - function _onToggleButtonTouchMove( e : TouchEvent ) : Void - { - e.stopPropagation(); - e.preventDefault(); - - var touchList = e.touches[ 0 ]; - - this._changePosition = - [ - this._transformPosition[ 0 ] + touchList.pageX - this._toggleStartPosition[ 0 ], - this._transformPosition[ 1 ] + touchList.pageY - this._toggleStartPosition[ 1 ] - ]; - - this._toggleButton.style.transform = 'translate(' + _changePosition[ 0 ] + 'px, ' + _changePosition[ 1 ] + 'px)'; - } - - function _onToggleButtonTouchEnd( e : TouchEvent ) : Void - { - this._transformPosition[ 0 ] = this._changePosition[ 0 ]; - this._transformPosition[ 1 ] = this._changePosition[ 1 ]; - - if ( ( Date.now() ).getTime() - this._tapStartTime < LogLayoutHTMLView.TAP_THRESHOLD ) - { - this._toggleDebugConsole(); - } - } - - function _onWrapperTouchStart( e : TouchEvent ) : Void - { - var t = e.touches.item(0); - _swipeHorizontalVO.startX = t.screenX; - _swipeHorizontalVO.startY = t.screenY; - } - - function _onWrapperTouchMove( e : TouchEvent ) : Void - { - var t = e.touches.item(0); - _swipeHorizontalVO.endX = t.screenX; - _swipeHorizontalVO.endY = t.screenY; - } - - function _onWrapperTouchEnd( e : TouchEvent ) : Void - { - if ((((this._swipeHorizontalVO.endX - SwipeHorizontalVO.MIN_X > this._swipeHorizontalVO.startX) || (this._swipeHorizontalVO.endX + SwipeHorizontalVO.MIN_X < this._swipeHorizontalVO.startX)) && ((this._swipeHorizontalVO.endY < this._swipeHorizontalVO.startY + SwipeHorizontalVO.MAX_Y) && (this._swipeHorizontalVO.startY > this._swipeHorizontalVO.endY - SwipeHorizontalVO.MAX_Y) && (this._swipeHorizontalVO.endX > 0)))) { - if (_swipeHorizontalVO.endX > _swipeHorizontalVO.startX) - { - this._onNextSearchButtonClick(e); - } - else - { - this._onPreviousSearchButtonClick(e); - } - } - - this._swipeHorizontalVO.startX = this._swipeHorizontalVO.startY = this._swipeHorizontalVO.endX = this._swipeHorizontalVO.endY = 0; - } - - function _toggleDebugConsole() : Void - { - this._debugConsole.classList.toggle( 'hidden' ); - } - - function _onPreviousSearchButtonClick( e : Event ) : Void - { - e.stopPropagation(); - e.preventDefault(); - - if ( this._searchLength > 0 ) - { - this._removeSelectedClass(); - this._searchIndex = this._searchIndex > 0 ? this._searchIndex -1 : this._searchLength -1; - this._refreshSelectedItem(); - } - } - - function _onNextSearchButtonClick( e : Event ) : Void - { - e.stopPropagation(); - e.preventDefault(); - - if ( this._searchLength > 0 ) - { - this._removeSelectedClass(); - this._searchIndex = this._searchIndex < this._searchLength -1 ? this._searchIndex +1 : 0; - this._refreshSelectedItem(); - } - } - - function _removeSelectedClass() : Void - { - var item = js.Browser.window.document.getElementById( "searchedWord" + this._searchIndex ); - item.parentElement.parentElement.classList.remove("selected"); - } - - function _refreshSelectedItem():Void - { - var item = js.Browser.window.document.getElementById( "searchedWord" + this._searchIndex ); - item.scrollIntoView(); - item.parentElement.parentElement.classList.add("selected"); - } -} - -class SwipeHorizontalVO -{ - public static var MIN_X : Int = 30; //min x swipe for horizontal swipe - public static var MAX_X : Int = 30; //max x difference for vertical swipe - public static var MIN_Y : Int = 50; //min y swipe for vertical swipe - public static var MAX_Y : Int = 60; //max y difference for horizontal swipe - - public var startX : Int = 0; - public var startY : Int = 0; - public var endX : Int = 0; - public var endY : Int = 0; - - public function new() {} -} - -class ConsoleStyle -{ - public static var template = ' - - -'; - public static var style = ' -html, -body, -.debug-console { - margin: 0; - height: 100%; - width: 100%; -} - -.debug-console-toggle { - position: fixed; - z-index: 1001; - left: 10px; - top: 10px; -} - -.debug-console { - position: fixed; - z-index: 1000; - top: 0; - right: 0; - bottom: 0; - left: 0; - background: rgba(0, 0, 0, 0.8); -} - -.debug-console.hidden { - display: none; -} - -.debug-console, -.debug-console-list-wrapper, -.debug-console-control { - box-sizing: border-box; -} - -.debug-console-list-wrapper, -.debug-console-control { - position: absolute; - left: 0; - right: 0; -} - -.debug-console-list-wrapper { - top: 0; - height: calc(100% - 24px); - -webkit-overflow-scrolling: touch; - overflow-x: hidden; - overflow-y: scroll; -} - -.debug-console-list { - padding: 0; - margin: 10px; - list-style: none; -} - -.debug-console-list li { - margin: 0 0 2px 0; - color: lime; -} - -.debug-console-control { - bottom: 0; - height: 30px; - letter-spacing: -0.3125em; - padding: 5px 0% 5px 5px; -} - -.debug-console-control-item, -.debug-console-control-item--search .debug-console-control-item-input, -.debug-console-control-caret { - display: inline-block; - vertical-align: top; - letter-spacing: normal; - word-spacing: normal; - box-sizing: border-box; -} - -.debug-console-control-item { - padding-right: 1%; -} - -.debug-console-control-item-input { - box-sizing: border-box; - height: 20px; - line-height: 20px; - width: 100%; -} - -.debug-console-control-item--search { - letter-spacing: -0.3125em; -} - -.debug-console-control-caret--left { - width: 24px; - margin-right: 4px; -} -.debug-console-control-caret--right { - width: 24px; - margin-left: 4px; -} - -.debug-console-control-item--search { - width: 50%; - padding: 0 8px 0 0; -} - -.debug-console-control-item--search .debug-console-control-item-input { - width: calc(100% - 56px); -} - -.debug-console-control-item--domain, -.debug-console-control-item--level { - width: 25%; -} - -.highlight-word { background-color:#FFFF00; } - -.selected { background-color:#999900 } -'; -} -#end \ No newline at end of file diff --git a/src/hex/log/layout/LogProxyLayout.hx b/src/hex/log/layout/LogProxyLayout.hx deleted file mode 100644 index f9f0ffa..0000000 --- a/src/hex/log/layout/LogProxyLayout.hx +++ /dev/null @@ -1,133 +0,0 @@ -package hex.log.layout; - -import hex.domain.Domain; -import hex.domain.DomainUtil; -import hex.log.ILogListener; -import hex.log.LogLevel; -import hex.log.LoggerMessage; -import hex.model.ModelDispatcher; - -/** - * ... - * @author Francis Bourre - */ -class LogProxyLayout implements ILogListener -{ - private var _leftSearchSeparator : String; - private var _rightSearchSeparator : String; - - var _dispatcher : LogProxyLayoutDispatcher; - var _messages : Array; - var _filteredLevel : LogLevel; - var _filteredDomain : Domain; - - var _searchedWord : String = ""; - - public function new() - { - this._dispatcher = new LogProxyLayoutDispatcher(); - this._messages = []; - - this._filteredLevel = LogLevel.ALL; - this._filteredDomain = AllDomain.DOMAIN; - - Logger.getInstance().addListener( this ); - } - - public function onClear() : Void - { - this._dispatcher.onClear(); - } - - public function onLog( message : LoggerMessage ) : Void - { - //Create message - this._messages.push( message ); - - //Dispatch message - if ( ( this._filteredDomain == AllDomain.DOMAIN || this._filteredDomain == message.domain) && - ( this._filteredLevel == LogLevel.ALL || this._filteredLevel == message.level ) ) - { - this._dispatcher.onLog( message ); - } - } - - public function addListener( listener : ILogListener ) : Bool - { - return this._dispatcher.addListener( listener ); - } - - public function removeListener( listener : ILogListener) : Bool - { - return this._dispatcher.removeListener( listener ); - } - - public function filter( ?level : LogLevel, ?domain : Domain ) : Void - { - this._filteredLevel = level == null ? LogLevel.ALL : level; - this._filteredDomain = domain == null ? AllDomain.DOMAIN : domain; - this._dispatcher.onClear(); - this._render(); - } - - public function searchFor( word : String = "", leftSearchSeparator : String, rightSearchSeparator : String ) : Int - { - this._searchedWord = word; - this._leftSearchSeparator = leftSearchSeparator; - this._rightSearchSeparator = rightSearchSeparator; - this._dispatcher.onClear(); - - return this._render(); - } - - function _render() : Int - { - var searchLength : Int = 0; - - for ( message in this._messages ) - { - if ( ( this._filteredDomain == AllDomain.DOMAIN || this._filteredDomain == message.domain) && - ( this._filteredLevel == LogLevel.ALL || this._filteredLevel == message.level ) ) - { - var messageContent : String = "" + message.message; - if ( this._searchedWord.length > 0 && messageContent.indexOf( this._searchedWord ) != -1 ) - { - messageContent = ( messageContent.split( this._searchedWord ) ) - .join( this._getLeftSeparator( searchLength, this._leftSearchSeparator ) + this._searchedWord + this._rightSearchSeparator ); - searchLength++; - } - this._dispatcher.onLog( new LoggerMessage( messageContent, message.level, message.domain, message.posInfos ) ); - } - } - - return searchLength; - } - - function _getLeftSeparator( index : Int, separator : String ) : String - { - return separator.split( ">" ).join( " id='searchedWord" + index ) + "'>"; - } -} - -class AllDomain extends Domain -{ - public static var DOMAIN : AllDomain = DomainUtil.getDomain( "AllDomain", AllDomain ); -} - -class LogProxyLayoutDispatcher extends ModelDispatcher implements ILogListener -{ - public function new() - { - super(); - } - - public function onClear() : Void - { - - } - - public function onLog( message : LoggerMessage ) : Void - { - - } -} \ No newline at end of file diff --git a/src/hex/log/layout/SimpleBrowserLayout.hx b/src/hex/log/layout/SimpleBrowserLayout.hx deleted file mode 100644 index 816828b..0000000 --- a/src/hex/log/layout/SimpleBrowserLayout.hx +++ /dev/null @@ -1,171 +0,0 @@ -package hex.log.layout; - -#if js -import haxe.PosInfos; -import hex.domain.Domain; -import hex.error.NullPointerException; -import hex.log.LogLevel; -import hex.log.LoggerMessage; -import js.Browser; -import js.html.Element; -import js.html.SpanElement; - -/** - * ... - * @author Francis Bourre - */ -class SimpleBrowserLayout implements ILogListener -{ - var _console : Element; - var _levelStyle : Map; - - var _levelDisplay : Bool = true; - var _domainDisplay : Bool = true; - var _timeDisplay : Bool = true; - - public function new( targetID : String = "console", leveldisplay : Bool = true, domainDisplay : Bool = true, timeDisplay : Bool = true ) - { - this._setConsole( targetID ); - this.setDomainDisplay( domainDisplay ); - this.setLevelDisplay( leveldisplay ); - this.setDisplayTime( timeDisplay ); - - this._createLevelStyle(); - } - - public function setLevelDisplay( b : Bool ) : Void - { - this._levelDisplay = b; - } - - public function setDomainDisplay( b : Bool ) : Void - { - this._domainDisplay = b; - } - - public function setDisplayTime( b : Bool ) : Void - { - this._timeDisplay = b; - } - - function _createLevelStyle() - { - this._levelStyle = new Map(); - - this._levelStyle.set( LogLevel.DEBUG, "lightgrey" ); - this._levelStyle.set( LogLevel.INFO, "green" ); - this._levelStyle.set( LogLevel.WARN, "yellow" ); - this._levelStyle.set( LogLevel.ERROR, "orange" ); - this._levelStyle.set( LogLevel.FATAL, "red" ); - } - - function _setConsole( targetId : String ) : Void - { - this._console = Browser.document.querySelector( targetId ); - - if ( this._console == null ) - { - throw new NullPointerException( "Div named '" + targetId + "' was not found in '" + Stringifier.stringify( this ) + "'" ); - } - - this._console.style.whiteSpace = "pre"; - this._console.style.fontFamily = "Lucida Console"; - this._console.style.fontSize = "11px"; - } - - public function onLog( loggerMessage : LoggerMessage ) : Void - { - var message : Dynamic = loggerMessage.message; - var level : LogLevel = loggerMessage.level; - var domain : Domain = loggerMessage.domain; - var posInfos : PosInfos = loggerMessage.posInfos; - - var leftBracket = this._createElement( "[", this._getStyle( level ) ); - var rightBracket = this._createElement( "]", this._getStyle( level ) ); - var time = this._createElement( this._getTime(), this._getStyle( level ) ); - var levelName = this._createElement( level.toString(), this._getStyle( level ) + "+bold" ); - var domainName : String = ( domain != null && domain.getName() != null ) ? "@" + domain.getName() : ""; - var domain = this._createElement( domainName, this._getStyle( level ) ); - var message = this._createElement( "\t\t" + message, this._getStyle( level ) ); - var info = this._createElement( posInfos != null ? " at " + posInfos.className + "::" + posInfos.methodName + " line " + posInfos.lineNumber + " in file " + posInfos.fileName : "", this._getStyle( level ) ); - - this._log( this._getEncapsulateElements( [ leftBracket, levelName, domain, rightBracket, message, info] ) ); - } - - public function onClear() : Void - { - this._console.innerHTML = ""; - } - - function _getTime() : String - { - return "" + Date.now().getTime(); - } - - function _getStyle( level : LogLevel ) : String - { - return this._levelStyle.get( level ); - } - - function _log( element : Element ) : Void - { - element.style.marginLeft = "10px"; - element.appendChild( Browser.document.createTextNode("\n") ); - this._console.appendChild( element ); - this._console.scrollTop = this._console.scrollHeight; - } - - function _createElement( message : String, ?color : String ) : Element - { - var span : SpanElement = Browser.document.createSpanElement(); - span.innerHTML = message; - if ( color != null ) this._setAttributes( span, color ); - return span; - } - - function _getEncapsulateElements( elementList : Array ) : Element - { - var container : SpanElement = Browser.document.createSpanElement(); - - for ( element in elementList ) - { - container.appendChild( element ); - } - - return container; - } - - function _setAttributes( element : Element, color : String ) : Void - { - var colorAttributes : Array = color.split( "+" ); - for ( attr in colorAttributes ) - { - this._setAttribute( element, attr ); - } - } - - function _setAttribute( element:Element, attr:String ) : Void - { - switch( attr ) - { - case "bold": - element.style.fontWeight = "bold"; - - case "red": - element.style.color = "#e62323"; - - case "orange": - element.style.color = "#FF8000"; - - case "yellow": - element.style.color = "#ffcf18"; - - case "lightgrey": - element.style.color = "#d9d9d9"; - - case "green": - element.style.color = "#27fe11"; - } - } -} -#end \ No newline at end of file diff --git a/src/hex/log/layout/TraceLayout.hx b/src/hex/log/layout/TraceLayout.hx deleted file mode 100644 index 572ff65..0000000 --- a/src/hex/log/layout/TraceLayout.hx +++ /dev/null @@ -1,33 +0,0 @@ -package hex.log.layout; - -import haxe.Log; -import haxe.PosInfos; -import hex.log.ILogListener; -import hex.log.LoggerMessage; - -/** - * ... - * @author Francis Bourre - */ -class TraceLayout implements ILogListener -{ - public function new() - { - - } - - public function onLog( message : LoggerMessage ) : Void - { - var posInfos : PosInfos = message.posInfos; - var info : String = posInfos != null ? " at " + posInfos.className + "::" + posInfos.methodName + " line " + posInfos.lineNumber + " in file " + posInfos.fileName : ""; - - Log.trace( ">>> " + message.level + ":" + message.message + " [" + message.domain.getName() + "]" + info, posInfos ); - } - - public function onClear() : Void - { - #if (flash || js) - Log.clear(); - #end - } -} diff --git a/src/hex/model/ModelDispatcherAutoBuildMacro.hx b/src/hex/model/ModelDispatcherAutoBuildMacro.hx index db98fd0..d852ee9 100644 --- a/src/hex/model/ModelDispatcherAutoBuildMacro.hx +++ b/src/hex/model/ModelDispatcherAutoBuildMacro.hx @@ -1,5 +1,6 @@ package hex.model; +#if macro import haxe.macro.Context; import haxe.macro.Expr.Field; @@ -40,4 +41,5 @@ class ModelDispatcherAutoBuildMacro return fields; } -} \ No newline at end of file +} +#end \ No newline at end of file diff --git a/src/hex/module/IModule.hx b/src/hex/module/IModule.hx index eac2d6c..b139de3 100644 --- a/src/hex/module/IModule.hx +++ b/src/hex/module/IModule.hx @@ -21,9 +21,9 @@ interface IModule extends IContextOwner function dispatchPublicMessage( messageType : MessageType, ?data : Array ) : Void; - function addHandler( messageType : MessageType, scope : Dynamic, callback : Dynamic ) : Void; + function addHandler( messageType : MessageType, scope : Dynamic, callback : T ) : Void; - function removeHandler( messageType : MessageType, scope : Dynamic, callback : Dynamic ) : Void; + function removeHandler( messageType : MessageType, scope : Dynamic, callback : T ) : Void; function getDomain() : Domain; diff --git a/src/hex/module/ModuleMessage.hx b/src/hex/module/ModuleMessage.hx index 4581bc4..f61e738 100644 --- a/src/hex/module/ModuleMessage.hx +++ b/src/hex/module/ModuleMessage.hx @@ -1,5 +1,6 @@ package hex.module; +import hex.error.PrivateConstructorException; import hex.event.MessageType; /** @@ -11,8 +12,9 @@ class ModuleMessage inline public static var INITIALIZED = new MessageType( "onModuleInitialisation" ); inline public static var RELEASED = new MessageType( "onModuleRelease" ); + /** @private */ function new() { - + throw new PrivateConstructorException(); } } \ No newline at end of file diff --git a/src/hex/structures/PointFactory.hx b/src/hex/structures/PointFactory.hx index 0229746..a9fbe8e 100644 --- a/src/hex/structures/PointFactory.hx +++ b/src/hex/structures/PointFactory.hx @@ -1,14 +1,17 @@ package hex.structures; +import hex.error.PrivateConstructorException; + /** * ... * @author Francis Bourre */ class PointFactory { + /** @private */ function new() { - + throw new PrivateConstructorException(); } inline static public function build( x : Int = 0, y : Int = 0 ) : Point diff --git a/src/hex/log/BasicStringifierStrategy.hx b/src/hex/util/BasicStringifierStrategy.hx similarity index 96% rename from src/hex/log/BasicStringifierStrategy.hx rename to src/hex/util/BasicStringifierStrategy.hx index 8cf3945..9b9ee10 100644 --- a/src/hex/log/BasicStringifierStrategy.hx +++ b/src/hex/util/BasicStringifierStrategy.hx @@ -1,4 +1,4 @@ -package hex.log; +package hex.util; /** * ... diff --git a/src/hex/log/IStringifierStrategy.hx b/src/hex/util/IStringifierStrategy.hx similarity index 91% rename from src/hex/log/IStringifierStrategy.hx rename to src/hex/util/IStringifierStrategy.hx index 9d08c68..34f6c38 100644 --- a/src/hex/log/IStringifierStrategy.hx +++ b/src/hex/util/IStringifierStrategy.hx @@ -1,4 +1,4 @@ -package hex.log; +package hex.util; /** * ... diff --git a/src/hex/util/MacroUtil.hx b/src/hex/util/MacroUtil.hx index 137b005..9ade916 100644 --- a/src/hex/util/MacroUtil.hx +++ b/src/hex/util/MacroUtil.hx @@ -6,6 +6,7 @@ import haxe.macro.Expr.TypeParam; import haxe.macro.Expr.TypePath; import haxe.macro.Type.ClassType; import haxe.macro.TypeTools; +import hex.error.PrivateConstructorException; /** * ... @@ -13,10 +14,11 @@ import haxe.macro.TypeTools; */ class MacroUtil { - function new() - { - - } + /** @private */ + function new() + { + throw new PrivateConstructorException(); + } macro public static function classImplementsInterface( classRef : haxe.macro.Expr.ExprOf, interfaceRef : haxe.macro.Expr.ExprOf ) : Expr { diff --git a/src/hex/util/PerformanceUtil.hx b/src/hex/util/PerformanceUtil.hx deleted file mode 100644 index f3f7560..0000000 --- a/src/hex/util/PerformanceUtil.hx +++ /dev/null @@ -1,72 +0,0 @@ -package hex.util; - -/** - * ... - * @author duke - */ -class PerformanceUtil -{ - static var timers = new Map(); - - /** - * Start speed test. - * @param name Name of test. - */ - public static function startTimer( name : String = "test" ) : Void - { - PerformanceUtil.timers[ name ] = new PerformanceVO( Date.now().getTime(), getMemory() ); - trace( "*** TEST STARTED: " + name + " ***" ); - } - - /** - * Stop speed test. It outputs the result - * @param name The name of started test. - */ - public static function stopTimer( name : String = "test") : Void - { - if ( PerformanceUtil.timers[ name ] != null ) - { - trace( "*** TEST FINISHED: " + name + " time: " + - ( Date.now().getTime() - PerformanceUtil.timers[ name ].startTime ) + " ms memory: " + - ( Math.round( ( PerformanceUtil.getMemory() - PerformanceUtil.timers[ name ].memory ) / 1024 * 100) / 100 ) + " KB ***" ); - - PerformanceUtil.timers.remove( name ); - } - else - { - trace( "*** NO TEST FOUND: " + name + " ***" ); - } - } - - static function getMemory( ):Float - { - #if flash - return flash.system.System.totalMemory; - #elseif js - if ( Reflect.hasField(js.Browser.window, "performance" ) ) - { - var perf:Dynamic = Reflect.field(js.Browser.window, "performance" ); - return Reflect.hasField(perf, "memory") ? Reflect.field(Reflect.field( perf, "memory"), "totalJSHeapSize") : null; //usedJSHeapSize - } - else - { - return 0; - } - #else - return 0; - #end - } - -} - -private class PerformanceVO -{ - public var memory : Float; - public var startTime : Float; - - public function new( startTime : Float, memory : Float ) - { - this.startTime = startTime; - this.memory = memory; - } -} \ No newline at end of file diff --git a/src/hex/util/Stringifier.hx b/src/hex/util/Stringifier.hx new file mode 100644 index 0000000..f01e605 --- /dev/null +++ b/src/hex/util/Stringifier.hx @@ -0,0 +1,53 @@ +package hex.util; + +import hex.error.PrivateConstructorException; + +/** + * ... + * @author Francis Bourre + */ +class Stringifier +{ + /** @private */ + function new() + { + throw new PrivateConstructorException(); + } + + static var _STRATEGY : IStringifierStrategy; + + /** + * Sets the concrete stringifier to be used. + * + * @param stringifier Stringifier concrete implementation + * + * @see hex.log.BasicStringifierStrategy + */ + public static function setStringifier( stringifier : IStringifierStrategy ) : Void + { + Stringifier._STRATEGY = stringifier; + } + + /** + * Returns the current stringifier used. + */ + public static function getStringifier() : IStringifierStrategy + { + return Stringifier._STRATEGY; + } + + /** + * Process stringify processing. + * + * @param target Object to stringified + */ + public static function stringify( target : T ) : String + { + if ( Stringifier._STRATEGY == null ) + { + Stringifier._STRATEGY = new BasicStringifierStrategy(); + } + + return Stringifier._STRATEGY.stringify( target ); + } +} diff --git a/test/hex/HexCoreSuite.hx b/test/hex/HexCoreSuite.hx index 8587c0a..d1d3363 100644 --- a/test/hex/HexCoreSuite.hx +++ b/test/hex/HexCoreSuite.hx @@ -7,7 +7,9 @@ import hex.data.CoreDataSuite; import hex.di.CoreDiSuite; import hex.domain.CoreDomainSuite; import hex.event.CoreEventSuite; +import hex.error.CoreErrorSuite; import hex.model.CoreModelSuite; +import hex.module.CoreModuleSuite; import hex.service.CoreServiceSuite; import hex.structures.CoreStructuresSuite; import hex.util.CoreUtilSuite; @@ -19,5 +21,20 @@ import hex.util.CoreUtilSuite; class HexCoreSuite { @Suite( "HexCore" ) - public var list : Array> = [ CoreCollectionSuite, CoreControlSuite, CoreCoreSuite, CoreDataSuite, CoreDiSuite, CoreDomainSuite, CoreEventSuite, CoreModelSuite, CoreServiceSuite, CoreStructuresSuite, CoreUtilSuite ]; + public var list : Array> = + [ + CoreCollectionSuite, + CoreControlSuite, + CoreCoreSuite, + CoreDataSuite, + CoreDiSuite, + CoreDomainSuite, + CoreEventSuite, + CoreErrorSuite, + CoreModelSuite, + CoreModuleSuite, + CoreServiceSuite, + CoreStructuresSuite, + CoreUtilSuite + ]; } diff --git a/test/hex/collection/LocatorMessageTest.hx b/test/hex/collection/LocatorMessageTest.hx index a9b9822..de30dfd 100644 --- a/test/hex/collection/LocatorMessageTest.hx +++ b/test/hex/collection/LocatorMessageTest.hx @@ -1,6 +1,5 @@ package hex.collection; -import hex.event.MessageType; import hex.unittest.assertion.Assert; /** @@ -9,6 +8,12 @@ import hex.unittest.assertion.Assert; */ class LocatorMessageTest { + @Test( "test constructor is private" ) + public function testPrivateConstructor() : Void + { + Assert.constructorIsPrivate( LocatorMessage ); + } + @Test( "test 'REGISTER' property" ) public function testRegisterProperty() : Void { diff --git a/test/hex/collection/LocatorTest.hx b/test/hex/collection/LocatorTest.hx index c99e550..fc9f26d 100644 --- a/test/hex/collection/LocatorTest.hx +++ b/test/hex/collection/LocatorTest.hx @@ -230,13 +230,27 @@ class LocatorTest locator.register( 'test', true ); Assert.equals( 1, listener.callbackCallCount ); Assert.equals( 'test', listener.callbackKey ); - Assert.equals( true, listener.callbackValue ); + Assert.isTrue( listener.callbackValue ); listener.reset(); locator.unregister( 'test' ); Assert.equals( 1, listener.callbackCallCount ); Assert.equals( 'test', listener.callbackKey ); Assert.isFalse( listener.callbackValue ); + + locator.removeListener( listener ); + + listener.reset(); + locator.register( 'test', true ); + Assert.equals( 0, listener.callbackCallCount ); + Assert.isNull( listener.callbackKey ); + Assert.isFalse( listener.callbackValue ); + + listener.reset(); + locator.unregister( 'test' ); + Assert.equals( 0, listener.callbackCallCount ); + Assert.isNull( listener.callbackKey ); + Assert.isFalse( listener.callbackValue ); } } diff --git a/test/hex/control/AsyncCallbackTest.hx b/test/hex/control/AsyncCallbackTest.hx new file mode 100644 index 0000000..ade49c1 --- /dev/null +++ b/test/hex/control/AsyncCallbackTest.hx @@ -0,0 +1,259 @@ +package hex.control; + +import hex.control.async.AsyncCallback; +import hex.control.async.Handler; +import hex.control.async.IAsyncCallback; +import hex.control.async.Nothing; +import hex.error.Exception; +import hex.error.IllegalArgumentException; +import hex.error.IllegalStateException; +import hex.unittest.assertion.Assert; + +using hex.util.ArrayUtil; + +/** + * ... + * @author Francis Bourre + */ +class AsyncCallbackTest +{ + @Test( 'Test with argument result' ) + public function testWithArgumentResult() : Void + { + var result : String; + var error : Exception; + + //test completion + _loadString( false ).onComplete( function(r) {result = r;} ).onFail( function(e) {error = e;} ); + + Assert.equals( 'test', result ); + Assert.isNull( error ); + + //test failure + result = null; + error = null; + _loadString( true ).onComplete( function(r) { result = r; } ).onFail( function(e) { error = e; } ); + + Assert.isInstanceOf( error, Exception ); + Assert.equals( 'message', error.message ); + Assert.isNull( result ); + } + + @Test( 'Test without argument result' ) + public function testWithoutArgumentResult() : Void + { + var result : String; + var error : Exception; + + //test completion + _load( false ).onComplete( function() {result = 'test';} ).onFail( function(e) {error = e;} ); + + Assert.equals( 'test', result ); + Assert.isNull( error ); + + //test failure + result = null; + error = null; + _load( true ).onComplete( function() { result = 'test'; } ).onFail( function(e) { error = e; } ); + + Assert.isInstanceOf( error, Exception ); + Assert.equals( 'message', error.message ); + Assert.isNull( result ); + } + + @Test( 'Test completion twice' ) + public function testCompletionTwice() : Void + { + var error : IllegalStateException = null; + + try + { + AsyncCallback.get + ( + function ( handler : Handler ) + { + handler( Nothing ); + handler( Nothing ); + } + ); + } + catch ( e : IllegalStateException ) + { + error = e; + } + + Assert.isInstanceOf( error, IllegalStateException ); + } + + @Test( 'Test failure twice' ) + public function testFailureTwice() : Void + { + var error : IllegalStateException = null; + + try + { + AsyncCallback.get + ( + function ( handler : Handler ) + { + handler( new Exception( 'message' ) ); + handler( new Exception( 'message' ) ); + } + ); + } + catch ( e : IllegalStateException ) + { + error = e; + } + + Assert.isInstanceOf( error, IllegalStateException ); + } + + @Test( 'Test completion and failure at the same time' ) + public function testCompletionAndFailureAtTheSameTime() : Void + { + var error : IllegalStateException = null; + + try + { + AsyncCallback.get + ( + function ( handler : Handler ) + { + handler( Nothing ); + handler( new Exception( 'message' ) ); + } + ); + } + catch ( e : IllegalStateException ) + { + error = e; + } + + Assert.isInstanceOf( error, IllegalStateException ); + } + + @Test( "test simple lambda chaining" ) + public function testSimpleLambdaChaining() + { + var r0 = 0; + var r1 = 0; + + var async = AsyncCallback.get + ( + function ( handler : Handler ) + { + handler( 4 ); + } + ); + + async + .whenComplete( i => r0 = 3 + i ) + .whenComplete( j => r1 = r0 * 2 ); + + Assert.equals( 7, r0, "result0 should be 3 + 4" ); + Assert.equals( 14, r1, "result1 should be 7 * 2" ); + } + + @Test( "test try catch" ) + public function testTryCatch() + { + var error : Exception = null; + var r0 = 0.0; + + + var async = AsyncCallback.get + ( + function ( handler : Handler ) + { + try + { + var a = []; + handler( a[2] ); + } + catch ( e : Dynamic ) + { + handler( new IllegalArgumentException( 'message' ) ); + } + } + ); + + async + .whenComplete( i => r0 = 3 + i ) + .onFail( function(e) { error = e; } ); + + Assert.isInstanceOf( error, IllegalArgumentException ); + Assert.equals( 'message', error.message ); + Assert.equals( 0.0, r0 ); + } + + @Test( "test chaining with ArrayUtil" ) + public function testChainingWithArrayUtil() + { + var collection = [ for ( i in 0...10 ) { id: i, name: "user_" + i, isMember: i % 2 == 0 } ]; + + var async = AsyncCallback.get + ( + function ( handler : Handler> ) + { + handler( collection ); + } + ); + + async + .whenComplete( a => a.forEach( e => e.name += "Test" ) ) + .whenComplete( a => collection = a.filters( e => e.isMember ) ) + .whenComplete( a => a.forEach( e => if ( e.id > 5 ) collection.remove( e ) ) ); + + Assert.deepEquals( + [ + { id:0, name: "user_0Test", isMember: true }, + { id:2, name: "user_2Test", isMember: true }, + { id:4, name: "user_4Test", isMember: true } + ] + , collection, "collection content should be the same" ); + } + + static function _load( failure : Bool ) : IAsyncCallback + { + return AsyncCallback.get + ( + function ( handler : Handler ) + { + if ( !failure ) + { + handler( Nothing ); + } + else + { + handler( new Exception( 'message' ) ); + } + } + ); + } + + static function _loadString( failure : Bool ) : IAsyncCallback + { + return AsyncCallback.get + ( + function ( handler : Handler ) + { + if ( !failure ) + { + handler( 'test' ); + } + else + { + handler( new Exception( 'message' ) ); + } + } + ); + } +} + +typedef User = +{ + var id : Int; + var name : String; + var isMember : Bool; +} \ No newline at end of file diff --git a/test/hex/control/AsyncHandlerTest.hx b/test/hex/control/AsyncHandlerTest.hx deleted file mode 100644 index 9acdf12..0000000 --- a/test/hex/control/AsyncHandlerTest.hx +++ /dev/null @@ -1,98 +0,0 @@ -package hex.control; - -import hex.error.IllegalStateException; -import hex.unittest.assertion.Assert; - -/** - * ... - * @author Francis Bourre - */ -class AsyncHandlerTest -{ - var result0 : String; - var result1 : String; - var error0 : String; - var error1 : String; - - @Before - function _init() : Void - { - result0 = ""; - result1 = ""; - error0 = ""; - error1 = ""; - } - - @Test( "test callbacks" ) - public function testCallbacks() - { - var responder = new AsyncHandler(); - - responder - .onComplete( function( s : String) { result0 = s; } ) - .onComplete( function( s : String) { result1 = s; } ) - .onFail( function( e : String) { error0 = e; } ) - .onFail( function( e : String) { error1 = e; } ); - - responder.complete( "hello" ); - - Assert.equals( "hello", result0, "result0 should be passed" ); - Assert.equals( "hello", result1, "result1 should be passed" ); - Assert.equals( "", error0, "error0 should not be setted" ); - Assert.equals( "", error1, "error1 should not be setted" ); - - this._init(); - responder.complete( "hello2" ); - - Assert.equals( "hello2", result0, "result0 should be passed" ); - Assert.equals( "hello2", result1, "result1 should be passed" ); - Assert.equals( "", error0, "error0 should not be setted" ); - Assert.equals( "", error1, "error1 should not be setted" ); - - this._init(); - responder.fail( "error" ); - - Assert.equals( "", result0, "result0 should not be setted" ); - Assert.equals( "", result1, "result1 should not be setted" ); - Assert.equals( "error", error0, "error0 should be passed" ); - Assert.equals( "error", error1, "error1 should be passed" ); - - this._init(); - responder.fail( "error2" ); - - Assert.equals( "", result0, "result0 should not be setted" ); - Assert.equals( "", result1, "result1 should not be setted" ); - Assert.equals( "error2", error0, "error0 should be passed" ); - Assert.equals( "error2", error1, "error1 should be passed" ); - - this._init(); - responder.complete( "hello" ); - - Assert.equals( "hello", result0, "result0 should be passed" ); - Assert.equals( "hello", result1, "result1 should be passed" ); - Assert.equals( "", error0, "error0 should not be setted" ); - Assert.equals( "", error1, "error1 should not be setted" ); - } - - @Test( "test callbacks" ) - public function testCallbackChaining() - { - var responder = new AsyncHandler(); - var anotheResponder = new AsyncHandler(); - - var intResult = 0; - - responder - .onComplete( function( i : Int ) { anotheResponder.onComplete( function( s : String ) { result0 = ">" + s; } ); anotheResponder.complete( ">" + i ); } ) - .onComplete( function( i : Int ) { intResult = i; } ) - .onFail( function( e : String) { error0 = e; } ) - .onFail( function( e : String) { error1 = e; } ); - - responder.complete( 3 ); - - Assert.equals( ">>3", result0, "result0 should be passed" ); - Assert.equals( 3, intResult, "result1 should be passed" ); - Assert.equals( "", error0, "error0 should not be setted" ); - Assert.equals( "", error1, "error1 should not be setted" ); - } -} \ No newline at end of file diff --git a/test/hex/control/AsyncHandlerUtilTest.hx b/test/hex/control/AsyncHandlerUtilTest.hx deleted file mode 100644 index 77c97aa..0000000 --- a/test/hex/control/AsyncHandlerUtilTest.hx +++ /dev/null @@ -1,126 +0,0 @@ -package hex.control; - -#if (!neko || haxe_ver >= "3.3") -import haxe.Timer; -import hex.unittest.assertion.Assert; -import hex.unittest.runner.MethodRunner; - -using hex.util.ArrayUtil; -using hex.control.AsyncHandlerUtil; - -/** - * ... - * @author Francis Bourre - */ -class AsyncHandlerUtilTest -{ - var result : Int; - - @Test( "test simple lambda" ) - public function testSimpleLambda() - { - var result = 0; - - var handler = new AsyncHandler(); - handler.on( i => result = i + 3 ); - handler.complete( 4 ); - - Assert.equals( 7, result, "result should be sum of arg and 3" ); - } - - @Test( "test simple lambda chaining" ) - public function testSimpleLambdaChaining() - { - var result0 = 0; - var result1 = 0; - - var handler = new AsyncHandler(); - - handler - .on( i => result0 = i + 3 ) - .on( j => result1 = result0 * 2 ); - - handler.complete( 4 ); - - Assert.equals( 7, result0, "result0 should be 3 + 4" ); - Assert.equals( 14, result1, "result1 should be 7 * 2" ); - } - - @Async( "test lambda chaining" ) - public function testChainingLambdas() - { - this.result = 0; - - var handler = new AsyncHandler(); - - handler - .on( i => this.result = i + 3 ) - .on( j => this.result *= 2 ) - .triggers ( new AsyncHandler() - .on( l => this.result *= 20 ) - .on( l => this.result -= 1 ) - ) - .triggers ( new TimeoutIntHandler() ) - .on( l => this.result -= 3 - ) - .onComplete( MethodRunner.asyncHandler( this._onChainingEnd ) ); - - - handler.complete( 4 ); - } - - private function _onChainingEnd( i : Int ) : Void - { - Assert.equals( 276, this.result, "result should be ((4 + 3) *20) -1 -3" ); - } - - @Test( "test chaining with ArrayUtil" ) - public function testChainingWithArrayUtil() - { - var collection = [ for ( i in 0...10 ) { id: i, name: "user_"+i, isMember: i%2==0 } ]; - - var handler = new AsyncHandler>(); - - handler - .on( a => a.forEach( e => e.name += "Test" ) ) - .on( a => collection = a.filters( e => e.isMember ) ) - .on( a => a.forEach( e => if ( e.id > 5 ) collection.remove( e ) ) ); - - - handler.complete( collection ); - - Assert.deepEquals( - [ - { id:0, name: "user_0Test", isMember: true }, - { id:2, name: "user_2Test", isMember: true }, - { id:4, name: "user_4Test", isMember: true } - ] - , collection, "collection content should be the same" ); - } -} - -private class TimeoutIntHandler extends AsyncHandler -{ - public function new() - { - super(); - } - - override public function complete( i : Int ) : Void - { - Timer.delay( this._do.bind( i ), 100 ); - } - - private function _do( i : Int ) : Void - { - super.complete( i ); - } -} - -typedef User = -{ - var id : Int; - var name : String; - var isMember : Bool; -} -#end diff --git a/test/hex/control/CoreControlSuite.hx b/test/hex/control/CoreControlSuite.hx index b4ac619..814fee3 100644 --- a/test/hex/control/CoreControlSuite.hx +++ b/test/hex/control/CoreControlSuite.hx @@ -9,9 +9,5 @@ import hex.control.payload.CorePayloadSuite; class CoreControlSuite { @Suite( "Control" ) - #if !neko - public var list : Array> = [ AsyncHandlerTest, AsyncHandlerUtilTest, AsyncResponderTest, CorePayloadSuite ]; - #else - public var list : Array> = [ AsyncHandlerTest, AsyncResponderTest, CorePayloadSuite ]; - #end + public var list : Array> = [ AsyncCallbackTest, AsyncResponderTest, CorePayloadSuite ]; } \ No newline at end of file diff --git a/test/hex/control/payload/ExecutionPayloadTest.hx b/test/hex/control/payload/ExecutionPayloadTest.hx index c21f1c8..2c5e3ce 100644 --- a/test/hex/control/payload/ExecutionPayloadTest.hx +++ b/test/hex/control/payload/ExecutionPayloadTest.hx @@ -45,21 +45,6 @@ class ExecutionPayloadTest } #end - @Test( "Test constructor throws IllegalArgumentException" ) - public function testConstructorThrowsIllegalArgumentException() : Void - { - Assert.constructorCallThrows( IllegalArgumentException, ExecutionPayload, [ this._data, String ], "constructor should throw IllegalArgumentException" ); - } - - /*@Test( "Test overwriting type property" ) - public function testOverwritingType() : Void - { - this._executionPayload.withClass( IMockType ); - Assert.notEquals( IMockData, this._executionPayload.getType(), "type should not be the same" ); - Assert.equals( IMockType, this._executionPayload.getType(), "type should be the same" ); - Assert.equals( "hex.control.payload.IMockType", this._executionPayload.getClassName(), "class name should be the same" ); - }*/ - @Test( "Test overwriting name property" ) public function testOverwritingName() : Void { diff --git a/test/hex/control/payload/PayloadUtilTest.hx b/test/hex/control/payload/PayloadUtilTest.hx index 4f054ae..e623786 100644 --- a/test/hex/control/payload/PayloadUtilTest.hx +++ b/test/hex/control/payload/PayloadUtilTest.hx @@ -13,6 +13,12 @@ import hex.unittest.assertion.Assert; */ class PayloadUtilTest { + @Test( "test constructor is private" ) + public function testPrivateConstructor() : Void + { + Assert.constructorIsPrivate( PayloadUtil ); + } + @Test( "Test mapping" ) public function testMapping() : Void { @@ -52,6 +58,46 @@ class PayloadUtilTest injector.unmappedPayloads, "'CommandExecutor.mapPayload' should unmap right values" ); } + + @Test( "Test mapping with class name" ) + public function testMappingWithClassName() : Void + { + var injector = new MockDependencyInjectorForMapping(); + + var mockImplementation = new MockImplementation( "mockImplementation" ); + var anotherMockImplementation = new MockImplementation( "anotherMockImplementation" ); + + var mockPayload = new ExecutionPayload( mockImplementation, IMockType, "mockPayload" ).withClassName( 'MockImplementation' ); + var stringPayload = new ExecutionPayload( "test", String, "stringPayload" ); + var anotherMockPayload = new ExecutionPayload( anotherMockImplementation, IMockType, "anotherMockPayload" ).withClassName( 'MockImplementation' ); + + var payloads : Array = [ mockPayload, stringPayload, anotherMockPayload ]; + PayloadUtil.mapPayload( payloads, injector ); + + Assert.deepEquals( [[mockImplementation, 'MockImplementation', "mockPayload"], ["test", String, "stringPayload"], [anotherMockImplementation, 'MockImplementation', "anotherMockPayload"] ], + injector.mappedPayloads, + "'CommandExecutor.mapPayload' should map right values" ); + } + + @Test( "Test unmapping with class name" ) + public function testUnmappingWithClassName() : Void + { + var injector = new MockDependencyInjectorForMapping(); + + var mockImplementation = new MockImplementation( "mockImplementation" ); + var anotherMockImplementation = new MockImplementation( "anotherMockImplementation" ); + + var mockPayload = new ExecutionPayload( mockImplementation, IMockType, "mockPayload" ).withClassName( 'MockImplementation' ); + var stringPayload = new ExecutionPayload( "test", String, "stringPayload" ); + var anotherMockPayload = new ExecutionPayload( anotherMockImplementation, IMockType, "anotherMockPayload" ).withClassName( 'MockImplementation' ); + + var payloads : Array = [ mockPayload, stringPayload, anotherMockPayload ]; + PayloadUtil.unmapPayload( payloads, injector ); + + Assert.deepEquals( [['MockImplementation', "mockPayload"], [String, "stringPayload"], ['MockImplementation', "anotherMockPayload"] ], + injector.unmappedPayloads, + "'CommandExecutor.mapPayload' should unmap right values" ); + } } private class MockDependencyInjectorForMapping extends MockDependencyInjector diff --git a/test/hex/core/HashCodeFactoryTest.hx b/test/hex/core/HashCodeFactoryTest.hx index 1323510..5f1ce14 100644 --- a/test/hex/core/HashCodeFactoryTest.hx +++ b/test/hex/core/HashCodeFactoryTest.hx @@ -5,6 +5,12 @@ import hex.unittest.assertion.Assert; class HashCodeFactoryTest { + @Test( "test constructor is private" ) + public function testPrivateConstructor() : Void + { + Assert.constructorIsPrivate( HashCodeFactory ); + } + @Test( "Test constructor can't be called" ) public function testConstructorNullException() : Void { @@ -34,6 +40,13 @@ class HashCodeFactoryTest var anotherKey : Int = HashCodeFactory.getKey( o ); Assert.equals( key, anotherKey, "Two 'HashCodeFactory.getKEY' calls on the same target should return the same value" ); } + + @Test( "Test 'getNextName'" ) + public function testGetNextName() : Void + { + var previewKey : Int = HashCodeFactory.previewNextKey(); + Assert.equals( "" + previewKey, HashCodeFactory.getNextName(), "'HashCodeFactory.getNextName' and 'HashCodeFactory.previewNextKey' should return the same String value" ); + } } private class MockObject diff --git a/test/hex/data/GUIDTest.hx b/test/hex/data/GUIDTest.hx index 6248c9d..2c8b2cb 100644 --- a/test/hex/data/GUIDTest.hx +++ b/test/hex/data/GUIDTest.hx @@ -8,6 +8,12 @@ import hex.unittest.assertion.Assert; */ class GUIDTest { + @Test( "test constructor is private" ) + public function testPrivateConstructor() : Void + { + Assert.constructorIsPrivate( GUID ); + } + @Test( "Test randomIntegerWithinRange function" ) public function testRandomIntegerWithinRange() : Void { diff --git a/test/hex/domain/CoreDomainSuite.hx b/test/hex/domain/CoreDomainSuite.hx index 501e4a4..d8ea755 100644 --- a/test/hex/domain/CoreDomainSuite.hx +++ b/test/hex/domain/CoreDomainSuite.hx @@ -7,5 +7,11 @@ package hex.domain; class CoreDomainSuite { @Suite( "Domain" ) - public var list : Array> = [ DefaultDomainTest, DomainTest, DomainUtilTest, NoDomainTest, TopLevelDomainTest ]; + public var list : Array> = + [ + DefaultDomainTest, + DomainTest, + NoDomainTest, + TopLevelDomainTest + ]; } \ No newline at end of file diff --git a/test/hex/domain/DefaultDomainTest.hx b/test/hex/domain/DefaultDomainTest.hx index 36eb420..07d0433 100644 --- a/test/hex/domain/DefaultDomainTest.hx +++ b/test/hex/domain/DefaultDomainTest.hx @@ -17,6 +17,6 @@ class DefaultDomainTest @Test( "Test if DefaultDomain.DOMAIN is an instance of DefaultDomain" ) public function testDefaultDomainStaticVariableType() : Void { - Assert.isInstanceOf( DefaultDomain.DOMAIN, DefaultDomain, "domain should be an instance of 'DefaultDomain'" ); + Assert.isInstanceOf( DefaultDomain.DOMAIN, Domain, "domain should be an instance of 'DefaultDomain'" ); } } diff --git a/test/hex/domain/DomainTest.hx b/test/hex/domain/DomainTest.hx index 8f1101b..0f4e706 100644 --- a/test/hex/domain/DomainTest.hx +++ b/test/hex/domain/DomainTest.hx @@ -1,8 +1,8 @@ package hex.domain; import hex.domain.Domain; -import hex.error.NullPointerException; import hex.error.IllegalArgumentException; +import hex.error.NullPointerException; import hex.unittest.assertion.Assert; /** @@ -14,7 +14,7 @@ class DomainTest @Test( "Test 'name' property passed to constructor" ) public function testConstructor() : Void { - var domain = new Domain( "testConstructor" ); + var domain = Type.createInstance( Domain, [ "testConstructor" ] ); Assert.equals( "testConstructor", domain.getName(), "'name' property should be the same passed to constructor" ); } @@ -29,33 +29,76 @@ class DomainTest @Test( "Test using twice the same 'name' value" ) public function testConstructorWithNameValues() : Void { - var domain = new Domain( "testConstructorWithNameValues" ); + var domain = Type.createInstance( Domain, [ "testConstructorWithNameValues" ] ); Assert.constructorCallThrows( IllegalArgumentException, Domain, ["testConstructorWithNameValues"], "" ); } @Test( "Test getName function" ) public function testGetName() : Void { - var domain = new Domain( "testGetName" ); - Assert.equals( "testGetName", domain.getName(), "'getName' method should return correct domain's name" ); + var domainName = Type.getClassName( Type.getClass( this ) ) + "_testGetName"; + var domain = Domain.getDomain( domainName ); + + Assert.equals( domainName, domain.getName(), "`getName` method should return correct domain's name" ); + } + + @Test( "Test `getParent` function" ) + public function testGetParent() : Void + { + var domainName = 'parent.' + Type.getClassName( Type.getClass( this ) ) + '_testGetParent'; + var domain = Domain.getDomain( domainName ); + + Assert.equals( TopLevelDomain.DOMAIN, domain.getParent(), "`getParent` method should return root parent" ); + + var childDomain = Domain.getDomain( domainName + '.child' ); + Assert.notEquals( domain, childDomain, "domains should not be the same" ); + Assert.equals( domain, childDomain.getParent(), "`getParent` method should return parent" ); + + var parentDomain = Domain.getDomain( 'parent' ); + Assert.notEquals( parentDomain, domain, "domains should not be the same" ); + Assert.notEquals( parentDomain, childDomain, "domains should not be the same" ); + Assert.equals( parentDomain, domain.getParent(), "`getParent` method should return root parent" ); } @Test( "Test getDomain function" ) public function testGetDomain() : Void { - var newDomain = new Domain( "testGetDomain" ); + var newDomain = Type.createInstance( Domain, [ "testGetDomain" ] ); var domain = Domain.getDomain( "testGetDomain" ); Assert.equals( newDomain, domain, "getDomain method should return the same instance if it already exists" ); domain = Domain.getDomain( "nonExistingDomain" ); - Assert.equals( null, domain, "'getDomain' method should return null if the requested domain doesn't exist" ); + Assert.isInstanceOf( domain, Domain, "'getDomain' method should return new instance if it doesn't exist" ); + Assert.equals( "nonExistingDomain", domain.getName(), "'getDomain' method should return new instance if it doesn't exist" ); } @Test( "Test toString function" ) public function testToString() : Void { - var domain = new Domain( "testToString" ); + var domain = Type.createInstance( Domain, [ "testToString" ] ); var expectedString = "hex.domain.Domain with name 'testToString'"; Assert.equals( expectedString, domain.toString(), "toString method should return expected string value" ); } + + @Test( "Test `getDomain` method" ) + public function testDomainCreation() : Void + { + var domainName = Type.getClassName( Type.getClass( this ) ) + "_testDomainCreation"; + + var domain = Domain.getDomain( domainName ); + Assert.isNotNull( domain, "`getDomain` function should create a domain if doesn't exist" ); + Assert.isInstanceOf( domain, Domain, "`getDomain` should return a domain instance of the requested type" ); + Assert.equals( domainName, domain.getName(), "domain's name should be the same that was requested" ); + } + + @Test( "Test `getDomain` twice" ) + public function testGetDomainTwice() : Void + { + var domainName = Type.getClassName( Type.getClass( this ) ) + "_testGetDomainTwice"; + + var domain = Domain.getDomain( domainName ); + var anotherDomainWithTheSameName = Domain.getDomain( domainName ); + + Assert.equals( domain, anotherDomainWithTheSameName, "getDomain should return the same domain" ); + } } diff --git a/test/hex/domain/DomainUtilTest.hx b/test/hex/domain/DomainUtilTest.hx deleted file mode 100644 index abca3ed..0000000 --- a/test/hex/domain/DomainUtilTest.hx +++ /dev/null @@ -1,32 +0,0 @@ -package hex.domain; - -import hex.unittest.assertion.Assert; - -/** - * ... - * @author Tamas Kinsztler - */ -class DomainUtilTest -{ - @Test( "Test 'getDomain' method" ) - public function testDomainCreation() : Void - { - var domainName = Type.getClassName( Type.getClass( this ) ) + "_testDomainCreation"; - - var domain = DomainUtil.getDomain( domainName, Domain ); - Assert.isNotNull( domain, "getDomain function should create a domain if doesn't exist" ); - Assert.isInstanceOf( domain, Domain, "getDomain should return a domain instance of the requested type" ); - Assert.equals( domainName, domain.getName(), "domain's name should be the same that was requested" ); - } - - @Test( "Test 'getDomain' twice" ) - public function testGetDomainTwice() : Void - { - var domainName = Type.getClassName( Type.getClass( this ) ) + "_testGetDomainTwice"; - - var domain = DomainUtil.getDomain( domainName, DefaultDomain ); - var anotherDomainWithTheSameName = Domain.getDomain( domainName ); - - Assert.equals( domain, anotherDomainWithTheSameName, "getDomain should return the same domain" ); - } -} diff --git a/test/hex/domain/NoDomainTest.hx b/test/hex/domain/NoDomainTest.hx index d9e4d7c..e5f9315 100644 --- a/test/hex/domain/NoDomainTest.hx +++ b/test/hex/domain/NoDomainTest.hx @@ -17,6 +17,6 @@ class NoDomainTest @Test( "Test if NoDomain.DOMAIN is an instance of NoDomain" ) public function testNoDomainStaticVariableType() : Void { - Assert.isInstanceOf( NoDomain.DOMAIN, NoDomain, "domain should be an instance of 'NoDomain'" ); + Assert.isInstanceOf( NoDomain.DOMAIN, Domain, "domain should be an instance of 'NoDomain'" ); } } diff --git a/test/hex/domain/TopLevelDomainTest.hx b/test/hex/domain/TopLevelDomainTest.hx index 2105c81..c55ea4a 100644 --- a/test/hex/domain/TopLevelDomainTest.hx +++ b/test/hex/domain/TopLevelDomainTest.hx @@ -17,6 +17,6 @@ class TopLevelDomainTest @Test( "Test if TopLevelDomain.DOMAIN is an instance of TopLevelDomain" ) public function testTopLevelDomainStaticVariableType() : Void { - Assert.isInstanceOf( TopLevelDomain.DOMAIN, TopLevelDomain, "domain should be an instance of 'TopLevelDomain'" ); + Assert.isInstanceOf( TopLevelDomain.DOMAIN, Domain, "domain should be an instance of 'TopLevelDomain'" ); } } diff --git a/test/hex/error/CoreErrorSuite.hx b/test/hex/error/CoreErrorSuite.hx new file mode 100644 index 0000000..370916c --- /dev/null +++ b/test/hex/error/CoreErrorSuite.hx @@ -0,0 +1,14 @@ +package hex.error; + +/** + * ... + * @author Francis Bourre + */ +class CoreErrorSuite +{ + @Suite( "Error" ) + public var list : Array> = + [ + ExceptionTest + ]; +} \ No newline at end of file diff --git a/test/hex/error/ExceptionTest.hx b/test/hex/error/ExceptionTest.hx new file mode 100644 index 0000000..6bfdab3 --- /dev/null +++ b/test/hex/error/ExceptionTest.hx @@ -0,0 +1,20 @@ +package hex.error; + +import hex.unittest.assertion.Assert; + +/** + * ... + * @author Francis Bourre + */ +class ExceptionTest +{ + @Test( "Test 'name' property passed to constructor" ) + public function testConstructor() : Void + { + var e = new Exception( "message" ); + Assert.equals( "message", e.message ); + Assert.isNotNull( "message", e.name ); + Assert.isNotNull( "message", e.posInfos ); + Assert.isNotNull( "message", e.toString() ); + } +} \ No newline at end of file diff --git a/test/hex/event/GenericConnection.hx b/test/hex/event/GenericConnection.hx index bb61240..4d166ed 100644 --- a/test/hex/event/GenericConnection.hx +++ b/test/hex/event/GenericConnection.hx @@ -6,6 +6,5 @@ package hex.event; */ interface GenericConnection { - @:astSource function onChangeValue( value : U ) : Void; } \ No newline at end of file diff --git a/test/hex/event/MockColor.hx b/test/hex/event/MockColor.hx new file mode 100644 index 0000000..5522155 --- /dev/null +++ b/test/hex/event/MockColor.hx @@ -0,0 +1,11 @@ +package hex.event; + +/** + * @author Francis Bourre + */ +enum MockColor +{ + Red; + Green; + Blue; +} \ No newline at end of file diff --git a/test/hex/event/MockTypedef.hx b/test/hex/event/MockTypedef.hx new file mode 100644 index 0000000..c33ea4d --- /dev/null +++ b/test/hex/event/MockTypedef.hx @@ -0,0 +1,9 @@ +package hex.event; + +/** + * @author Francis Bourre + */ +typedef MockTypedef = +{ + var name : String; +} \ No newline at end of file diff --git a/test/hex/event/TriggerTest.hx b/test/hex/event/TriggerTest.hx index 130e0e4..ad16570 100644 --- a/test/hex/event/TriggerTest.hx +++ b/test/hex/event/TriggerTest.hx @@ -1,5 +1,7 @@ package hex.event; +import hex.event.MockTypedef; +import hex.data.IParser; import hex.structures.Size; import hex.unittest.assertion.Assert; @@ -20,9 +22,19 @@ class TriggerTest model.intOutput.connect( intMockDriver ); model.stringOutput.connect( stringMockDriver ); model.genericOutput.connect( genericMockDriver ); + var callbackResult; model.callbacks.connect( function ( s : String, i : Int ) callbackResult = { s: s, i: i } ); + var colorResult = MockColor.Red; + model.colorCallbacks.connect( function ( color : MockColor ) colorResult = color ); + + var parserResult = ''; + model.triggerParser.connect( function ( parser : IParser ) parserResult = parser.parse( 'test' ) ); + + var parserResult2; + model.triggerParser2.connect( function ( parser : IParser ) parserResult2 = parser.parse( 'test' ) ); + model.changeAllValues( 3, "test", this ); Assert.equals( 1, intMockDriver.callbackCallCount ); Assert.equals( 1, stringMockDriver.callbackCallCount ); @@ -32,6 +44,9 @@ class TriggerTest Assert.equals( this, genericMockDriver.callbackParam ); Assert.equals( "test", callbackResult.s ); Assert.equals( 3, callbackResult.i ); + Assert.equals( MockColor.Blue, colorResult ); + Assert.equals('test was parsed', parserResult ); + Assert.equals('test', parserResult2.name ); model.stringOutput.disconnectAll(); model.genericOutput.disconnectAll(); @@ -58,6 +73,13 @@ private class MockModel implements ITriggerOwner public var genericOutput( default, never ) : ITrigger>; public var callbacks( default, never ) : ITriggerInt->Void>; + + public var colorCallbacks( default, never ) : ITriggerVoid>; + + public var triggerParser( default, never ) : ITrigger->Void>; + + public var triggerParser2( default, never ) : ITrigger->Void>; + public function new(){} @@ -67,9 +89,30 @@ private class MockModel implements ITriggerOwner this.stringOutput.onChangeStringValue( s ); this.genericOutput.onChangeValue( o ); this.callbacks.trigger( s, i ); + this.colorCallbacks.trigger( MockColor.Blue ); + this.triggerParser.trigger( new MockParser() ); + this.triggerParser2.trigger( new MockParser2() ); } } +private class MockParser implements IParser +{ + public function new() {} + public function parse( serializedContent : Dynamic, target : Dynamic = null ) : String + { + return serializedContent + " was parsed"; + } +} + +private class MockParser2 implements IParser +{ + public function new() {} + public function parse( serializedContent : Dynamic, target : Dynamic = null ) : MockTypedef + { + return {name:serializedContent}; + } +} + private class IntMockDriver implements IIntConnection { public var callbackCallCount : Int = 0; diff --git a/test/hex/module/CoreModuleSuite.hx b/test/hex/module/CoreModuleSuite.hx new file mode 100644 index 0000000..24ffc85 --- /dev/null +++ b/test/hex/module/CoreModuleSuite.hx @@ -0,0 +1,11 @@ +package hex.module; + +/** + * ... + * @author Francis Bourre + */ +class CoreModuleSuite +{ + @Suite( "Module" ) + public var list : Array> = [ ModuleMessageTest ]; +} \ No newline at end of file diff --git a/test/hex/module/ModuleMessageTest.hx b/test/hex/module/ModuleMessageTest.hx new file mode 100644 index 0000000..33567ba --- /dev/null +++ b/test/hex/module/ModuleMessageTest.hx @@ -0,0 +1,30 @@ +package hex.module; + +import hex.unittest.assertion.Assert; + +/** + * ... + * @author Francis Bourre + */ +class ModuleMessageTest +{ + @Test( "test constructor is private" ) + public function testPrivateConstructor() : Void + { + Assert.constructorIsPrivate( ModuleMessage ); + } + + @Test( "test 'INITIALIZED' property" ) + public function testInitializedProperty() : Void + { + var message = ModuleMessage.INITIALIZED; + Assert.equals( "onModuleInitialisation", message ); + } + + @Test( "test 'RELEASED' property" ) + public function testReleasedProperty() : Void + { + var message = ModuleMessage.RELEASED; + Assert.equals( "onModuleRelease", message ); + } +} \ No newline at end of file diff --git a/test/hex/structures/CoreStructuresSuite.hx b/test/hex/structures/CoreStructuresSuite.hx index 74ab04a..43265ef 100644 --- a/test/hex/structures/CoreStructuresSuite.hx +++ b/test/hex/structures/CoreStructuresSuite.hx @@ -7,5 +7,11 @@ package hex.structures; class CoreStructuresSuite { @Suite( "Structures" ) - public var list : Array> = [ PointTest, PointFTest, SizeTest ]; + public var list : Array> = + [ + PointTest, + PointFTest, + PointFactoryTest, + SizeTest + ]; } \ No newline at end of file diff --git a/test/hex/structures/PointFactoryTest.hx b/test/hex/structures/PointFactoryTest.hx new file mode 100644 index 0000000..2c4c5a7 --- /dev/null +++ b/test/hex/structures/PointFactoryTest.hx @@ -0,0 +1,24 @@ +package hex.structures; + +import hex.unittest.assertion.Assert; + +/** + * ... + * @author Francis Bourre + */ +class PointFactoryTest +{ + @Test( "test constructor is private" ) + public function testPrivateConstructor() : Void + { + Assert.constructorIsPrivate( PointFactory ); + } + + @Test( "test `build` method" ) + public function testBuildMethod() : Void + { + var p = PointFactory.build( 3, 5 ); + Assert.equals( 3, p.x ); + Assert.equals( 5, p.y ); + } +} \ No newline at end of file diff --git a/test/hex/util/ClassUtilTest.hx b/test/hex/util/ClassUtilTest.hx index 98b9a11..e42bbed 100644 --- a/test/hex/util/ClassUtilTest.hx +++ b/test/hex/util/ClassUtilTest.hx @@ -11,6 +11,12 @@ class ClassUtilTest { public static inline var STATIC_REF : String = "static_ref"; + @Test( "test constructor is private" ) + public function testPrivateConstructor() : Void + { + Assert.constructorIsPrivate( ClassUtil ); + } + @Test( "Test getClassReference" ) public function testGetClassReference() : Void { diff --git a/test/hex/util/CoreUtilSuite.hx b/test/hex/util/CoreUtilSuite.hx index b6df3c3..600bbf1 100644 --- a/test/hex/util/CoreUtilSuite.hx +++ b/test/hex/util/CoreUtilSuite.hx @@ -7,5 +7,5 @@ package hex.util; class CoreUtilSuite { @Suite( "Util" ) - public var list : Array> = [ ClassUtilTest ]; + public var list : Array> = [ ClassUtilTest, StringifierTest ]; } \ No newline at end of file diff --git a/test/hex/util/StringifierTest.hx b/test/hex/util/StringifierTest.hx new file mode 100644 index 0000000..464673d --- /dev/null +++ b/test/hex/util/StringifierTest.hx @@ -0,0 +1,38 @@ +package hex.util; + +import hex.unittest.assertion.Assert; + +/** + * ... + * @author Francis Bourre + */ +class StringifierTest +{ + @Test( "test constructor is private" ) + public function testPrivateConstructor() : Void + { + Assert.constructorIsPrivate( Stringifier ); + } + + @Test( "test accessors" ) + public function testAccessors() : Void + { + Stringifier.stringify( 'test' ); + Assert.isNotNull( Stringifier.getStringifier() ); + Assert.isInstanceOf( Stringifier.getStringifier(), BasicStringifierStrategy ); + + var stringifier = new MockStringifierStrategy(); + Stringifier.setStringifier( stringifier ); + Assert.equals( stringifier, Stringifier.getStringifier() ); + } +} + +private class MockStringifierStrategy implements IStringifierStrategy +{ + public function new() { } + + public function stringify( target : Dynamic ) : String + { + return 'test'; + } +} \ No newline at end of file