Skip to content
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

Optimized empty list methods and Removed reduntant braces #2596

Merged
merged 1 commit into from May 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 17 additions & 17 deletions mimedb-generator/src/main/scala/mimegenerator/MimeGenerator.scala
Expand Up @@ -36,7 +36,7 @@ object MimeLoader {
obj.toMap
.map(x => (x._1.split("/").toList, x._2))
.collect {
case ((m :: s :: Nil), d) =>
case (m :: s :: Nil, d) =>
d.as[MimeDescr] match {
case Right(md) => Some(Mime(m, s, md))
case Left(_) => None
Expand All @@ -60,8 +60,8 @@ object MimeLoader {
objectName: String,
mimes: List[Mime]): Tree = {
val all
: Tree = (LAZYVAL(listVal, ListClass.TYPE_OF(TYPE_REF(REF(mediaTypeClassName))))) := LIST(
mimes.map(m => REF((m.valName))))
: Tree = LAZYVAL(listVal, ListClass.TYPE_OF(TYPE_REF(REF(mediaTypeClassName)))) := LIST(
mimes.map(m => REF(m.valName)))
val mediaTypeClass = RootClass.newClass(mediaTypeClassName)
val vals: List[Tree] = mimes.map(_.toTree(mediaTypeClass))
val allVals = vals :+ all
Expand All @@ -85,11 +85,11 @@ object MimeLoader {
a.SEQ_++(b)
}
val all
: Tree = (LAZYVAL("all", ListClass.TYPE_OF(TYPE_REF(REF(mediaTypeClassName)))) := reducedAll)
val objectPartsDefinition = (OBJECTDEF(s"${objectName}_parts")
.withFlags(PRIVATEWITHIN("http4s"))) := BLOCK(subObjects.map(_._1))
val objectDefinition = (OBJECTDEF(objectName).withParents(subObjects.map(x =>
s"${objectName}_parts.${x._2}"))) := BLOCK(all)
: Tree = LAZYVAL("all", ListClass.TYPE_OF(TYPE_REF(REF(mediaTypeClassName)))) := reducedAll
val objectPartsDefinition = OBJECTDEF(s"${objectName}_parts")
.withFlags(PRIVATEWITHIN("http4s")) := BLOCK(subObjects.map(_._1))
val objectDefinition = OBJECTDEF(objectName).withParents(subObjects.map(x =>
s"${objectName}_parts.${x._2}")) := BLOCK(all)
(List(objectPartsDefinition, objectDefinition), mainType)
}
}
Expand All @@ -109,14 +109,14 @@ object MimeLoader {
a.SEQ_++(b)
}
val all
: Tree = (LAZYVAL("allMediaTypes", ListClass.TYPE_OF(TYPE_REF(REF(mediaTypeClassName)))) := reducedAll)
val compressible: Tree = (VAL("Compressible", BooleanClass) := TRUE)
val uncompressible: Tree = (VAL("Uncompressible", BooleanClass) := FALSE)
val binary: Tree = (VAL("Binary", BooleanClass) := TRUE)
val notBinary: Tree = (VAL("NotBinary", BooleanClass) := FALSE)
: Tree = LAZYVAL("allMediaTypes", ListClass.TYPE_OF(TYPE_REF(REF(mediaTypeClassName)))) := reducedAll
val compressible: Tree = VAL("Compressible", BooleanClass) := TRUE
val uncompressible: Tree = VAL("Uncompressible", BooleanClass) := FALSE
val binary: Tree = VAL("Binary", BooleanClass) := TRUE
val notBinary: Tree = VAL("NotBinary", BooleanClass) := FALSE

(((TRAITDEF(objectName).withFlags(PRIVATEWITHIN(privateWithin))) := BLOCK(
List(all, compressible, uncompressible, binary, notBinary) ::: l.flatMap(_._1))))
(TRAITDEF(objectName).withFlags(PRIVATEWITHIN(privateWithin)) := BLOCK(
List(all, compressible, uncompressible, binary, notBinary) ::: l.flatMap(_._1)))
.inPackage(topLevelPackge)
.withComment("Autogenerated file, don't edit")
}
Expand Down Expand Up @@ -236,7 +236,7 @@ final case class Mime(mainType: String, secondaryType: String, descr: MimeDescr)
if (descr.compressible.forall(_ == true)) Mime.CompressibleRef else Mime.UncompressibleRef
val binaryRef = if (isBinary) Mime.BinaryRef else Mime.NotBinaryRef
val extensions: Tree =
descr.extensions.filter(_.length > 0).map(x => LIST(x.map(LIT))).getOrElse(NIL)
descr.extensions.filter(_.nonEmpty).map(x => LIST(x.map(LIT))).getOrElse(NIL)
val valName: String = s"`$secondaryType`"
def toTree(mediaTypeClass: ClassSymbol): Tree =
if (descr.extensions.isEmpty) {
Expand Down Expand Up @@ -270,7 +270,7 @@ object Mime {
*/
object MimeLoaderApp extends IOApp {
def run(args: List[String]): IO[ExitCode] = {
val dir = args.lift(0).getOrElse(".")
val dir = args.headOption.getOrElse(".")
MimeLoader
.toFile(new File(dir, "MimeDB.scala"), "org.http4s", s"MimeDB", "MediaType")
.map(_ => ExitCode.Success)
Expand Down