-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Autowire refactor #188
Merged
Merged
Autowire refactor #188
Changes from 24 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
45c1e63
Add support for resource factory methods
mbore 34cfb78
add pure autowire
mbore 0f93867
Test allocation order
mbore 190fa64
Add resource reusability in factory methods
mbore 21639ff
Fallback to autowire in factory method
mbore 75942fc
Extract providers
mbore 91a74a9
Sort incomming factory methods dependencies
mbore cc584a6
Mixed factory method params test
mbore 37ec5f7
Add empty constructor fallback test
mbore eaa4bc2
WIP graph based autowire
mbore 886e938
Extract providers
mbore 1ade7e3
Futher breakdown
mbore 87f6d17
Green tests
mbore 7e4357d
Add support for copanion object
mbore e357521
Fix scala 2.12 compilation
mbore 3a8c55b
Fix imports in tests
mbore 6b9cad5
clean up
mbore 0cd49ca
remove pure aoutowire
mbore d3d7d6e
Order improvements
mbore 0def472
Fix test name resolution
mbore 608fc63
constructor -> creator
mbore 8a4ea17
Fix error msg
mbore 37c26d6
another factory method test
mbore df5b354
rename test
mbore dd64e49
Use FactoryMethod instead of creator
mbore bd3c407
Make Provider sealed
mbore b1d057f
Improve ambiguity check
mbore a78010f
Fix class name
mbore aec8757
Simplify rawProviders iterations
mbore 97ef382
Update readme
mbore e55d614
Add comments
mbore 2f3e465
Test for at least one wire step
mbore File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
40 changes: 40 additions & 0 deletions
40
macros/src/main/scala-2/com/softwaremill/macwire/internals/package.scala
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,40 @@ | ||
package com.softwaremill.macwire | ||
|
||
import scala.reflect.macros.blackbox | ||
|
||
package object internals { | ||
//FIXME any built-in solution? | ||
def sequence[A](l: List[Option[A]]) = (Option(List.empty[A]) /: l) { | ||
case (Some(sofar), Some(value)) => Some(value :: sofar); | ||
case (_, _) => None | ||
} | ||
|
||
def composeOpts[A, B](f: A => Option[B], fs: A => Option[B]*): A => Option[B] = fs.fold(f) { case (f1, f2) => | ||
(a: A) => f1(a).orElse(f2(a)) | ||
} | ||
def composeWithFallback[A, B](f: A => Option[B], fs: A => Option[B]*)(value: A => B): A => B = (a: A) => | ||
composeOpts(f, fs: _*)(a).getOrElse(value(a)) | ||
|
||
def combine[A, B](fs: Seq[A => B])(op: B => B => B): A => B = fs.reduce { (f1, f2) => (a: A) => op(f1(a))(f2(a)) } | ||
|
||
def isWireable[C <: blackbox.Context](c: C)(tpe: c.Type): Boolean = { | ||
val name = tpe.typeSymbol.fullName | ||
|
||
!name.startsWith("java.lang.") && !name.startsWith("scala.") | ||
} | ||
|
||
def paramType[C <: blackbox.Context](c: C)(targetTypeD: c.Type, param: c.Symbol): c.Type = { | ||
import c.universe._ | ||
|
||
val (sym: Symbol, tpeArgs: List[Type]) = targetTypeD match { | ||
case TypeRef(_, sym, tpeArgs) => (sym, tpeArgs) | ||
case t => | ||
c.abort( | ||
c.enclosingPosition, | ||
s"Target type not supported for wiring: $t. Please file a bug report with your use-case." | ||
) | ||
} | ||
val pTpe = param.typeSignature.substituteTypes(sym.asClass.typeParams, tpeArgs) | ||
if (param.asTerm.isByNameParam) pTpe.typeArgs.head else pTpe | ||
} | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[minor] name doesn't match file name :)