-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement defaulted parameters handling, introduced filtering for non…
… existance paramameters in incjectable implementations (#12)
- Loading branch information
Showing
9 changed files
with
117 additions
and
59 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
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 |
---|---|---|
@@ -1,7 +1,4 @@ | ||
|
||
import ceylon.language.meta.model { | ||
Type | ||
} | ||
import ceylon.language.meta.declaration { | ||
Declaration | ||
} | ||
|
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
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
32 changes: 32 additions & 0 deletions
32
source/herd/depin/engine/injectable/ConstructorInjectable.ceylon
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,32 @@ | ||
import ceylon.language.meta.declaration { | ||
NestableDeclaration, | ||
CallableConstructorDeclaration, | ||
FunctionOrValueDeclaration | ||
} | ||
import herd.depin.api { | ||
Injectable, | ||
Creator | ||
} | ||
shared class ConstructorInjectable(CallableConstructorDeclaration declaration) extends Injectable(declaration){ | ||
shared actual Anything inject(Creator injector) { | ||
value parameters = declaration.parameterDeclarations | ||
.map((FunctionOrValueDeclaration element) => element->injector.create(element)) | ||
.filter((FunctionOrValueDeclaration elementKey -> Anything elementItem) => !elementKey.defaulted || elementItem exists) | ||
.collect((FunctionOrValueDeclaration elementKey -> Anything elementItem) => elementItem); | ||
if(declaration.container.container is NestableDeclaration){ | ||
assert(is Object container = injector.create(declaration.container)); | ||
try{ | ||
return declaration.memberInvoke(container,[], parameters); | ||
}catch(Exception x){ | ||
throw Error.member(x,container,parameters); | ||
} | ||
} | ||
try{ | ||
return declaration.invoke([],*parameters); | ||
}catch(Exception x){ | ||
throw Error(x,parameters); | ||
} | ||
} | ||
|
||
|
||
} |
31 changes: 31 additions & 0 deletions
31
source/herd/depin/engine/injectable/FunctionInjectable.ceylon
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,31 @@ | ||
import ceylon.language.meta.declaration { | ||
NestableDeclaration, | ||
FunctionOrValueDeclaration, | ||
FunctionDeclaration | ||
} | ||
import herd.depin.api { | ||
Injectable, | ||
Creator | ||
} | ||
shared class FunctionInjectable(FunctionDeclaration declaration) extends Injectable(declaration){ | ||
shared actual Anything inject(Creator injector) { | ||
value parameters = declaration.parameterDeclarations | ||
.map((FunctionOrValueDeclaration element) => element->injector.create(element)) | ||
.filter((FunctionOrValueDeclaration elementKey -> Anything elementItem) => !elementKey.defaulted || elementItem exists) | ||
.collect((FunctionOrValueDeclaration elementKey -> Anything elementItem) => elementItem); | ||
if(is NestableDeclaration containerDeclaration=declaration.container){ | ||
assert(exists container = injector.create(containerDeclaration)); | ||
try{ | ||
return declaration.memberInvoke(container,[],parameters); | ||
}catch(Exception x){ | ||
throw Error.member(x,container,parameters); | ||
} | ||
}else{ | ||
try{ | ||
return declaration.invoke([],*parameters); | ||
}catch(Exception x){ | ||
throw Error(x,parameters); | ||
} | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
source/herd/depin/engine/injectable/ValueInjectable.ceylon
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,29 @@ | ||
import ceylon.language.meta.declaration { | ||
NestableDeclaration, | ||
ValueDeclaration | ||
} | ||
import herd.depin.api { | ||
Injectable, | ||
Creator | ||
} | ||
shared class ValueInjectable(ValueDeclaration declaration) extends Injectable(declaration){ | ||
shared actual Anything inject(Creator injector) { | ||
if(is NestableDeclaration containerDeclaration=declaration.container){ | ||
assert(exists container = injector.create(containerDeclaration)); | ||
try{ | ||
return declaration.memberGet(container); | ||
}catch(Exception x){ | ||
throw Error.member(x,container); | ||
} | ||
}else{ | ||
try{ | ||
return declaration.get(); | ||
}catch(Exception x){ | ||
throw Error(x); | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
} |
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 @@ | ||
package herd.depin.engine.injectable; |