-
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.
Merge pull request #15 from Voiteh/issue/12
Issue/12
- Loading branch information
Showing
30 changed files
with
273 additions
and
98 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; |
39 changes: 39 additions & 0 deletions
39
test/test/herd/depin/engine/integration/ClassInjectionTest.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,39 @@ | ||
import ceylon.test { | ||
test | ||
} | ||
|
||
import herd.depin.engine { | ||
Depin | ||
} | ||
|
||
import test.herd.depin.engine.integration.model { | ||
Person, | ||
fixture, | ||
DataSource, | ||
DefaultParametersConstructor, | ||
DefaultedParametersByFunction, | ||
DefaultedParameterFunction | ||
} | ||
shared class ClassInjectionTest() { | ||
|
||
Depin depin=Depin().include{ | ||
inclusions = {`package test.herd.depin.engine.integration.dependencies`}; | ||
}; | ||
|
||
shared test void shouldInjectJohnPerson(){ | ||
assert(depin.inject(`Person`)==fixture.person.john); | ||
} | ||
|
||
shared test void shouldInjectMysqlDataSource(){ | ||
assert(depin.inject(`DataSource`)==fixture.dataSouce.mysqlDataSource); | ||
} | ||
shared test void shouldInjectNonDefaultParameters(){ | ||
assert(depin.inject(`DefaultParametersConstructor`)==fixture.defaultParameter.instance); | ||
} | ||
shared test void shouldInjectDefaultedParameterFromFunction(){ | ||
assert(depin.inject(`DefaultedParametersByFunction`)==fixture.defaultedParameterByFunction.instance); | ||
} | ||
shared test void shouldInjectDefaultedParameterClassFunction(){ | ||
assert(depin.inject(`DefaultedParameterFunction`).fun()==fixture.defaultedParameterFunction.param); | ||
} | ||
} |
28 changes: 0 additions & 28 deletions
28
test/test/herd/depin/engine/integration/ClassSimpleInjections.ceylon
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
test/test/herd/depin/engine/integration/dependencies/defaultParametersDependencies.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,12 @@ | ||
import test.herd.depin.engine.integration.model { | ||
fixture | ||
} | ||
import herd.depin.engine { | ||
dependency | ||
} | ||
shared dependency String nonDefault=fixture.defaultParameter.nonDefault; | ||
|
||
|
||
shared dependency String defaultedByFunction(String defaulted=fixture.defaultedParameterByFunction.param){ | ||
return defaulted; | ||
} |
21 changes: 21 additions & 0 deletions
21
test/test/herd/depin/engine/integration/model/DefaultParametersConstructor.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,21 @@ | ||
shared class DefaultParametersConstructor(shared String nonDefault,shared String defaultedParameter=fixture.defaultParameter.text) { | ||
|
||
|
||
shared actual Boolean equals(Object that) { | ||
if (is DefaultParametersConstructor that) { | ||
return nonDefault==that.nonDefault && | ||
defaultedParameter==that.defaultedParameter; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
|
||
shared actual Integer hash { | ||
variable value hash = 1; | ||
hash = 31*hash + nonDefault.hash; | ||
hash = 31*hash + defaultedParameter.hash; | ||
return hash; | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
test/test/herd/depin/engine/integration/model/DefaultedParameterFunction.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,18 @@ | ||
shared class DefaultedParameterFunction(shared String fun()=> fixture.defaultedParameterFunction.param) { | ||
|
||
shared actual Boolean equals(Object that) { | ||
if (is DefaultedParameterFunction that) { | ||
return true; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
|
||
shared actual Integer hash { | ||
variable value hash = 1; | ||
return hash; | ||
} | ||
|
||
|
||
} |
15 changes: 15 additions & 0 deletions
15
test/test/herd/depin/engine/integration/model/DefaultedParametersByFunction.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,15 @@ | ||
shared class DefaultedParametersByFunction(shared String defaultedByFunction) { | ||
|
||
|
||
shared actual Boolean equals(Object that) { | ||
if (is DefaultedParametersByFunction that) { | ||
return defaultedByFunction==that.defaultedByFunction; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
|
||
shared actual Integer hash => defaultedByFunction.hash; | ||
|
||
} |
Oops, something went wrong.