-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from DoclerLabs/develop
prepare 0.33.0
- Loading branch information
Showing
11 changed files
with
427 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2017 Francis Bourre | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package hex.di; | ||
|
||
/** | ||
* @deprecated | ||
* @author Francis Bourre | ||
*/ | ||
#if !macro | ||
@:remove | ||
@:autoBuild( hex.di.annotation.FastAnnotationReader.readMetadata( hex.di.IInjectable ) ) | ||
#end | ||
interface IInjectable | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package hex.di.annotation; | ||
|
||
import haxe.macro.Context; | ||
import haxe.macro.Expr; | ||
import haxe.macro.Expr.Field; | ||
import hex.annotation.AnnotationReplaceBuilder; | ||
import hex.error.PrivateConstructorException; | ||
import hex.reflect.ClassReflectionData; | ||
|
||
using Lambda; | ||
|
||
/** | ||
* ... | ||
* @author Francis Bourre | ||
*/ | ||
class AnnotationTransformer | ||
{ | ||
#if macro | ||
private static var _map : Map<String, Bool> = new Map(); | ||
|
||
/** @private */ | ||
function new() | ||
{ | ||
throw new PrivateConstructorException(); | ||
} | ||
|
||
macro public static function readMetadata( metadataExpr : Expr ) : Array<Field> | ||
{ | ||
//if it's an interface we don't want to build reflection data | ||
if ( Context.getLocalClass().get().isInterface ) | ||
{ | ||
return Context.getBuildFields(); | ||
} | ||
|
||
return reflect( metadataExpr, Context.getBuildFields() ); | ||
} | ||
|
||
public static function reflect( metadataExpr : Expr, fields : Array<Field> ) : Array<Field> | ||
{ | ||
var localClass = Context.getLocalClass().get(); | ||
var className = localClass.pack.join( "." ) + "." + localClass.name; | ||
var hasBeenBuilt = AnnotationTransformer._map.exists( className ); | ||
|
||
//Reflection data to be used to generate fields | ||
var data : ClassReflectionData; | ||
|
||
var annotationFilter = [ "Inject", "PostConstruct", "Optional", "PreDestroy" ]; | ||
|
||
// use AnnotationReplaceBuilder to to process the metadata but only the ones that we care about | ||
fields | ||
.flatMap( function ( f ) return f.meta ) | ||
.filter( function ( m ) return annotationFilter.indexOf( m.name ) != -1 ) | ||
.map( AnnotationReplaceBuilder.processMetadata ); | ||
|
||
if ( hasBeenBuilt ) | ||
{ | ||
// get the existing data and remove them from the static_classes | ||
var existingData = hex.reflect.ReflectionBuilder._static_classes.find( function(d) return d.name == localClass.module ); | ||
hex.reflect.ReflectionBuilder._static_classes.remove( existingData ); | ||
|
||
// reflect new fields | ||
fields = hex.reflect.ReflectionBuilder.parseMetadata( metadataExpr, fields, annotationFilter, false ); | ||
|
||
// get new fields | ||
data = hex.reflect.ReflectionBuilder._static_classes[ hex.reflect.ReflectionBuilder._static_classes.length - 1 ]; | ||
|
||
//merge everything together | ||
data = mergeReflectionData( existingData, data ); | ||
|
||
//write the merged data back | ||
hex.reflect.ReflectionBuilder._static_classes[ hex.reflect.ReflectionBuilder._static_classes.length - 1 ] = data; | ||
} | ||
else | ||
{ | ||
//parse annotations | ||
fields = hex.reflect.ReflectionBuilder.parseMetadata( metadataExpr, fields, annotationFilter, false ); | ||
|
||
//get/set data result | ||
data = hex.reflect.ReflectionBuilder._static_classes[ hex.reflect.ReflectionBuilder._static_classes.length - 1 ]; | ||
} | ||
|
||
AnnotationTransformer._map.set( className, true ); | ||
|
||
var f = fields.filter( function ( f ) { return f.name == "__ai" || f.name == "__ac" || f.name == "__ap"; } ); | ||
if ( f.length != 0 ) | ||
{ | ||
//remove existing reflection data | ||
for ( removedField in f ) fields.remove( removedField ); | ||
} | ||
|
||
// Generate and append fields | ||
hex.di.annotation.FastInjectionBuilder._generateInjectionProcessorExpr( fields, data ); | ||
return fields; | ||
} | ||
|
||
static private function mergeReflectionData( data1 : ClassReflectionData, data2 : ClassReflectionData ) : ClassReflectionData | ||
{ | ||
return | ||
{ | ||
name: data1.name, | ||
superClassName: data1.superClassName, | ||
constructor: data2.constructor, // using constructor from the new data (nothing to merge here) | ||
properties: data1.properties.concat( data2.properties ), | ||
methods: data1.methods.concat( data2.methods ) | ||
}; | ||
} | ||
|
||
#end | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.