-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update sbt to 1.2.1 * Migrage to scalameta 4.0.0-RC1 * Document ScalametaUtils * Construct Term.Ref and Type.Ref by hand * Format files * Simplify command and remove unused vars * Run scalafmt
- Loading branch information
Showing
8 changed files
with
64 additions
and
22 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 +1 @@ | ||
sbt.version=1.1.0 | ||
sbt.version=1.2.3 |
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
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
src/main/scala/rocks/muki/graphql/codegen/ScalametaUtils.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 rocks.muki.graphql.codegen | ||
|
||
import scala.meta._ | ||
|
||
/** | ||
* More robust way to parse [[Type.Ref]] and [[Term.Ref]] from String. | ||
* More discussion: https://gitter.im/scalameta/scalameta?at=5b9ba14f8909f71f75d1b4bd | ||
*/ | ||
object ScalametaUtils { | ||
|
||
def typeRefOf(typeTerm: String): Type.Ref = { | ||
typeTerm.parse[Type].get.asInstanceOf[Type.Ref] | ||
} | ||
|
||
def typeRefOf(term: String, typeTerm: String): Type.Ref = { | ||
typeRefOf(term.split('.'), typeTerm) | ||
} | ||
|
||
def typeRefOf(terms: Seq[String], typeTerm: String): Type.Ref = { | ||
if (terms.isEmpty) { | ||
Type.Name(typeTerm) | ||
} else { | ||
Type.Select(termRefOf(terms), Type.Name(typeTerm)) | ||
} | ||
} | ||
|
||
// terms must not be empty | ||
def termRefOf(terms: Seq[String]): Term.Ref = { | ||
val termArray = terms.map(Term.Name(_)) | ||
termArray.headOption.fold( | ||
throw new IllegalStateException("Term must not be empty") | ||
) { head => | ||
termArray.drop(1).foldLeft[Term.Ref](head)((r, t) => Term.Select(r, t)) | ||
} | ||
} | ||
|
||
def termRefOf(term: String): Term.Ref = { | ||
termRefOf(term.split('.')) | ||
} | ||
} |