Skip to content

Commit

Permalink
Merge pull request #36 from DoclerLabs/develop
Browse files Browse the repository at this point in the history
prepare 0.35.0
  • Loading branch information
aliokan authored Feb 19, 2018
2 parents 2fa1883 + c869743 commit cee5490
Show file tree
Hide file tree
Showing 16 changed files with 440 additions and 129 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ install:
- git clone --recursive -b $DEPENDENCIES_BRANCH https://github.com/DoclerLabs/hexInject.git ./hexinject
- haxelib dev hexinject ./hexinject
#tink_macro
- haxelib install tink_macro 0.15.0
- haxelib install tink_macro 0.16.1
#hexDSL
- haxelib dev hexdsl .
- export DISPLAY=:99.0;
Expand All @@ -69,4 +69,4 @@ notifications:
recipients:
- [email protected]
- [email protected]
- [email protected]
- [email protected]
3 changes: 1 addition & 2 deletions haxelib.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"url": "https://github.com/DoclerLabs/hexDSL",
"dependencies":
{
"hexinject": "git:https://github.com/DoclerLabs/hexInject.git",
"tink_macro": "0.15.0"
"hexinject": "git:https://github.com/DoclerLabs/hexInject.git"
}
}
3 changes: 2 additions & 1 deletion src/hex/compiletime/basic/BasicCompileTimeSettings.hx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class BasicCompileTimeSettings
ContextTypeList.MAPPING_DEFINITION => hex.compiletime.factory.MappingDefinitionFactory.build,
ContextTypeList.ALIAS => hex.compiletime.factory.AliasFactory.build,
ContextTypeList.CONTEXT => hex.compiletime.factory.ContextFactory.build,
ContextTypeList.CONTEXT_ARGUMENT => hex.compiletime.factory.ContextArgumentFactory.build
ContextTypeList.CONTEXT_ARGUMENT => hex.compiletime.factory.ContextArgumentFactory.build,
ContextTypeList.CLOSURE => hex.compiletime.factory.ClosureFactory.build
];
}
#end
120 changes: 7 additions & 113 deletions src/hex/compiletime/basic/CompileTimeContextFactory.hx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package hex.compiletime.basic;

#if macro
import haxe.macro.Context;
import haxe.macro.Expr;
import haxe.macro.Type.ClassType;
import hex.collection.ILocator;
Expand Down Expand Up @@ -31,7 +30,7 @@ class CompileTimeContextFactory
{
var _injectorContainerInterface : ClassType;
var _moduleInterface : ClassType;
var _dependencyInterface : ClassType;


var _isInitialized : Bool;
var _expressions : Array<Expr>;
Expand All @@ -47,14 +46,14 @@ class CompileTimeContextFactory
var _propertyVOLocator : Locator<String, Array<PropertyVO>>;
var _methodCallVOLocator : Locator<String, MethodCallVO>;
var _typeLocator : Locator<String, String>;
var _dependencyChecker : MappingDependencyChecker;

public function new( expressions : Array<Expr> )
{
this._expressions = expressions;
this._isInitialized = false;
this._injectorContainerInterface = MacroUtil.getClassType( Type.getClassName( hex.di.IInjectorContainer ) );
this._moduleInterface = MacroUtil.getClassType( Type.getClassName( hex.module.IContextModule ) );
this._dependencyInterface = MacroUtil.getClassType( Type.getClassName( hex.di.mapping.IDependencyOwner ) );
}

public function init( applicationContext : IApplicationContext ) : Void
Expand All @@ -75,7 +74,7 @@ class CompileTimeContextFactory
this._mappedTypes = [];
this._injectedInto = [];
this._factoryMap = hex.compiletime.basic.BasicCompileTimeSettings.factoryMap;

this._dependencyChecker = new MappingDependencyChecker( this._coreFactory, this._typeLocator );
this._coreFactory.addListener( this );
}
}
Expand Down Expand Up @@ -103,6 +102,7 @@ class CompileTimeContextFactory

public function dispose() : Void
{
this._dependencyChecker = null;
this._coreFactory.removeListener( this );
this._coreFactory.clear();
this._constructorVOLocator.release();
Expand Down Expand Up @@ -270,7 +270,7 @@ class CompileTimeContextFactory

var result = buildMethod( this._getFactoryVO( constructorVO ) );

this._checkDependencies( constructorVO );
this._dependencyChecker.checkDependencies( constructorVO );

if ( id != null )
{
Expand All @@ -291,106 +291,17 @@ class CompileTimeContextFactory
this._coreFactory.register( id, result );
}

function _getMappingDefinition( e )
{
switch( e.expr )
{
case EObjectDecl( fields ):

return fields.fold (
function (f, o)
{
switch( f.field )
{
case 'fromType': Reflect.setField( o, f.field, haxe.macro.ExprTools.getValue( f.expr ) );
case 'withName': Reflect.setField( o, f.field, haxe.macro.ExprTools.getValue( f.expr ) );
case _:
}
return o;
}, {} );

case _:
}

return null;
}

function _getMappingDefinitions( e : Expr ) : Array<hex.di.mapping.MappingDefinition>
{
var a = [];
switch( e.expr )
{
case EVars( vars ) :
if ( vars[ 0 ].type != null )
{
if ( haxe.macro.ComplexTypeTools.toString( vars[ 0 ].type ) == 'Array<hex.di.mapping.MappingDefinition>' )
{
switch( vars[ 0 ].expr.expr )
{
case EArrayDecl( values ):
for ( value in values )
{
switch( value.expr )
{
case EObjectDecl( fields ):
var mapping = _getMappingDefinition( value );
if ( mapping != null ) a.push( mapping );

case EConst(CIdent(ident)):
a = a.concat( _getMappingDefinitions( this._coreFactory.locate( ident ) ) );

case wtf:
trace( 'wtf', wtf );
}
}

case _:
}

}
else if ( haxe.macro.ComplexTypeTools.toString( vars[ 0 ].type ) == 'hex.di.mapping.MappingDefinition' )
{
var mapping = _getMappingDefinition( vars[ 0 ].expr );
if ( mapping != null ) a.push( mapping );
}
}

case _:
}

return cast a;
}

function _checkDependencies( constructorVO : ConstructorVO ) : Void
{
if ( MacroUtil.implementsInterface( this._getClassType( constructorVO.className ), _dependencyInterface ) )
{
var mappings = constructorVO.arguments
.filter( function ( arg ) return arg.ref != null )
.map( function ( arg ) return this._coreFactory.locate( arg.ref ) )
.filter( function ( arg ) return arg != null )
.flatMap( _getMappingDefinitions )
.array();

if ( !hex.di.mapping.MappingChecker.matchForClassName( constructorVO.className, mappings ) )
{
var missingMappings = hex.di.mapping.MappingChecker.getMissingMapping( constructorVO.className, mappings );
Context.fatalError( "Missing mappings:" + missingMappings, constructorVO.filePosition );
}
}
}

function _tryToRegisterModule( constructorVO : ConstructorVO ) : Void
{
if ( MacroUtil.implementsInterface( this._getClassType( constructorVO.className ), _moduleInterface ) )
if ( MacroUtil.implementsInterface( MacroUtil.getClassType( constructorVO.className, null, false ), _moduleInterface ) )
{
this._moduleLocator.register( constructorVO.ID, constructorVO.ID );
}
}

function _parseInjectInto( constructorVO : ConstructorVO ) : Void
{
if ( constructorVO.injectInto && MacroUtil.implementsInterface( this._getClassType( constructorVO.className ), _injectorContainerInterface ) )
if ( constructorVO.injectInto && MacroUtil.implementsInterface( MacroUtil.getClassType( constructorVO.className, null, false ), _injectorContainerInterface ) )
{
//TODO throws an error if interface is not implemented
this._injectedInto.push(
Expand Down Expand Up @@ -434,22 +345,5 @@ class CompileTimeContextFactory
{
return { constructorVO : constructorVO, contextFactory : this };
}

//helper
inline function _getClassType( className : String ) : haxe.macro.Type.ClassType
{
try
{
return switch Context.getType( className )
{
case TInst( t, _ ): t.get();
default: null;
}
}
catch ( e : Dynamic )
{
return null;
}
}
}
#end
Loading

0 comments on commit cee5490

Please sign in to comment.