From 9d9b443c935f9de608fc7d59ef0d4791001411ef Mon Sep 17 00:00:00 2001 From: Lloyd Date: Mon, 29 Aug 2016 20:04:24 +0900 Subject: [PATCH] Feature/2.10 valueenums (#68) Backport ValueEnums to 2.10.x - Ported macros by adding more shims to ContextUtils - Move integration lib ValueEnum code into main src from compat directories --- .travis.yml | 4 +-- README.md | 1 - .../main/scala}/enumeratum/values/Size.scala | 0 .../values/ValueEnumBenchmarks.scala | 0 .../main/scala}/enumeratum/values/Circe.scala | 0 .../enumeratum/values/CirceValueEnum.scala | 0 .../values/CirceValueEnumSpec.scala | 0 .../scala}/enumeratum/values/ValueEnum.scala | 0 .../enumeratum/values/ValueEnumEntry.scala | 0 .../scala}/enumeratum/values/Animal.scala | 0 .../enumeratum/values/ContentType.scala | 0 .../values/CustomEnumPrivateConstructor.scala | 0 .../scala}/enumeratum/values/Drinks.scala | 0 .../enumeratum/values/LibraryItem.scala | 0 .../scala}/enumeratum/values/MovieGenre.scala | 2 +- .../enumeratum/values/OperatingSystem.scala | 0 .../enumeratum/values/ValueEnumHelpers.scala | 0 .../enumeratum/values/ValueEnumSpec.scala | 12 +++++++++ .../enumeratum/values/EnumFormats.scala | 0 .../enumeratum/values/PlayJsonValueEnum.scala | 0 .../enumeratum/values/EnumFormatsSpec.scala | 0 .../values/EnumJsonFormatHelpers.scala | 0 .../scala}/enumeratum/values/JsonDrinks.scala | 0 .../main/scala}/enumeratum/values/Forms.scala | 0 .../enumeratum/values/PlayFormValueEnum.scala | 0 .../values/PlayPathBindableValueEnum.scala | 0 .../values/PlayQueryBindableValueEnum.scala | 0 .../enumeratum/values/PlayValueEnums.scala | 0 .../scala}/enumeratum/values/UrlBinders.scala | 0 .../values/PlayValueEnumHelpers.scala | 0 .../enumeratum/values/PlayValueEnumSpec.scala | 0 .../enumeratum/values/BSONValueHandlers.scala | 0 .../enumeratum/values/EnumHandler.scala | 0 .../values/ReactiveMongoBsonValueEnum.scala | 0 .../scala}/enumeratum/values/BsonEnums.scala | 0 .../values/EnumBsonHandlerHelpers.scala | 0 .../values/EnumBsonHandlerSpec.scala | 0 .../enumeratum/values/UPickleValueEnum.scala | 0 .../scala}/enumeratum/values/UPickler.scala | 0 .../enumeratum/values/UPicklerSpec.scala | 0 .../scala-2.10/enumeratum/ContextUtils.scala | 10 +++++++ .../scala-2.11/enumeratum/ContextUtils.scala | 10 +++++++ .../scala}/enumeratum/ValueEnumMacros.scala | 27 +++++++++---------- project/Build.scala | 7 ----- 44 files changed, 48 insertions(+), 25 deletions(-) rename benchmarking/{compat/src/main/scala-2.11 => src/main/scala}/enumeratum/values/Size.scala (100%) rename benchmarking/{compat/src/main/scala-2.11 => src/main/scala}/enumeratum/values/ValueEnumBenchmarks.scala (100%) rename enumeratum-circe/{compat/src/main/scala-2.11 => src/main/scala}/enumeratum/values/Circe.scala (100%) rename enumeratum-circe/{compat/src/main/scala-2.11 => src/main/scala}/enumeratum/values/CirceValueEnum.scala (100%) rename enumeratum-circe/{compat/src/test/scala-2.11 => src/test/scala}/enumeratum/values/CirceValueEnumSpec.scala (100%) rename enumeratum-core/{compat/src/main/scala-2.11 => src/main/scala}/enumeratum/values/ValueEnum.scala (100%) rename enumeratum-core/{compat/src/main/scala-2.11 => src/main/scala}/enumeratum/values/ValueEnumEntry.scala (100%) rename enumeratum-core/{compat/src/test/scala-2.11 => src/test/scala}/enumeratum/values/Animal.scala (100%) rename enumeratum-core/{compat/src/test/scala-2.11 => src/test/scala}/enumeratum/values/ContentType.scala (100%) rename enumeratum-core/{compat/src/test/scala-2.11 => src/test/scala}/enumeratum/values/CustomEnumPrivateConstructor.scala (100%) rename enumeratum-core/{compat/src/test/scala-2.11 => src/test/scala}/enumeratum/values/Drinks.scala (100%) rename enumeratum-core/{compat/src/test/scala-2.11 => src/test/scala}/enumeratum/values/LibraryItem.scala (100%) rename enumeratum-core/{compat/src/test/scala-2.11 => src/test/scala}/enumeratum/values/MovieGenre.scala (99%) rename enumeratum-core/{compat/src/test/scala-2.11 => src/test/scala}/enumeratum/values/OperatingSystem.scala (100%) rename enumeratum-core/{compat/src/test/scala-2.11 => src/test/scala}/enumeratum/values/ValueEnumHelpers.scala (100%) rename enumeratum-core/{compat/src/test/scala-2.11 => src/test/scala}/enumeratum/values/ValueEnumSpec.scala (92%) rename enumeratum-play-json/{compat/src/main/scala-2.11 => src/main/scala}/enumeratum/values/EnumFormats.scala (100%) rename enumeratum-play-json/{compat/src/main/scala-2.11 => src/main/scala}/enumeratum/values/PlayJsonValueEnum.scala (100%) rename enumeratum-play-json/{compat/src/test/scala-2.11 => src/test/scala}/enumeratum/values/EnumFormatsSpec.scala (100%) rename enumeratum-play-json/{compat/src/test/scala-2.11 => src/test/scala}/enumeratum/values/EnumJsonFormatHelpers.scala (100%) rename enumeratum-play-json/{compat/src/test/scala-2.11 => src/test/scala}/enumeratum/values/JsonDrinks.scala (100%) rename enumeratum-play/{compat/src/main/scala-2.11 => src/main/scala}/enumeratum/values/Forms.scala (100%) rename enumeratum-play/{compat/src/main/scala-2.11 => src/main/scala}/enumeratum/values/PlayFormValueEnum.scala (100%) rename enumeratum-play/{compat/src/main/scala-2.11 => src/main/scala}/enumeratum/values/PlayPathBindableValueEnum.scala (100%) rename enumeratum-play/{compat/src/main/scala-2.11 => src/main/scala}/enumeratum/values/PlayQueryBindableValueEnum.scala (100%) rename enumeratum-play/{compat/src/main/scala-2.11 => src/main/scala}/enumeratum/values/PlayValueEnums.scala (100%) rename enumeratum-play/{compat/src/main/scala-2.11 => src/main/scala}/enumeratum/values/UrlBinders.scala (100%) rename enumeratum-play/{compat/src/test/scala-2.11 => src/test/scala}/enumeratum/values/PlayValueEnumHelpers.scala (100%) rename enumeratum-play/{compat/src/test/scala-2.11 => src/test/scala}/enumeratum/values/PlayValueEnumSpec.scala (100%) rename enumeratum-reactivemongo-bson/{compat/src/main/scala-2.11 => src/main/scala}/enumeratum/values/BSONValueHandlers.scala (100%) rename enumeratum-reactivemongo-bson/{compat/src/main/scala-2.11 => src/main/scala}/enumeratum/values/EnumHandler.scala (100%) rename enumeratum-reactivemongo-bson/{compat/src/main/scala-2.11 => src/main/scala}/enumeratum/values/ReactiveMongoBsonValueEnum.scala (100%) rename enumeratum-reactivemongo-bson/{compat/src/test/scala-2.11 => src/test/scala}/enumeratum/values/BsonEnums.scala (100%) rename enumeratum-reactivemongo-bson/{compat/src/test/scala-2.11 => src/test/scala}/enumeratum/values/EnumBsonHandlerHelpers.scala (100%) rename enumeratum-reactivemongo-bson/{compat/src/test/scala-2.11 => src/test/scala}/enumeratum/values/EnumBsonHandlerSpec.scala (100%) rename enumeratum-upickle/{compat/src/main/scala-2.11 => src/main/scala}/enumeratum/values/UPickleValueEnum.scala (100%) rename enumeratum-upickle/{compat/src/main/scala-2.11 => src/main/scala}/enumeratum/values/UPickler.scala (100%) rename enumeratum-upickle/{compat/src/test/scala-2.11 => src/test/scala}/enumeratum/values/UPicklerSpec.scala (100%) rename macros/{compat/src/main/scala-2.11 => src/main/scala}/enumeratum/ValueEnumMacros.scala (85%) diff --git a/.travis.yml b/.travis.yml index 8c8683cf..89abc138 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,9 +8,9 @@ script: - sbt clean +test:compile - sbt +test # Manually select the JVM projects to run coverage on until Scoverage is compatible with ScalaJS - - sbt coverage coreJVM/test enumeratum-play/test enumeratum-play-json/test enumeratumCirceJVM/test enumeratumUPickleJVM/test enumeratum-reactivemongo-bson/test + - sbt coverage coreJVM/test enumeratum-play/test enumeratum-play-json/test enumeratumCirceJVM/test enumeratumUPickleJVM/test enumeratum-reactivemongo-bson/test coverageReport && sbt coverageAggregate after_success: - - sbt coverageReport coverageAggregate coveralls + - sbt coveralls - '[ "${TRAVIS_PULL_REQUEST}" = "false" ] && sbt coreJVM/updateImpactSubmit || true' cache: directories: diff --git a/README.md b/README.md index 2064eaff..3a072d34 100644 --- a/README.md +++ b/README.md @@ -229,7 +229,6 @@ LibraryItem.withValue(10) // => java.util.NoSuchElementException: **Restrictions** - `ValueEnum`s must have their value members implemented as literal values. -- `ValueEnum`s are not available in Scala 2.10.x because work needs to be done to bridge all Macro API differences (e.g. `isConstructor`) ## ScalaJS diff --git a/benchmarking/compat/src/main/scala-2.11/enumeratum/values/Size.scala b/benchmarking/src/main/scala/enumeratum/values/Size.scala similarity index 100% rename from benchmarking/compat/src/main/scala-2.11/enumeratum/values/Size.scala rename to benchmarking/src/main/scala/enumeratum/values/Size.scala diff --git a/benchmarking/compat/src/main/scala-2.11/enumeratum/values/ValueEnumBenchmarks.scala b/benchmarking/src/main/scala/enumeratum/values/ValueEnumBenchmarks.scala similarity index 100% rename from benchmarking/compat/src/main/scala-2.11/enumeratum/values/ValueEnumBenchmarks.scala rename to benchmarking/src/main/scala/enumeratum/values/ValueEnumBenchmarks.scala diff --git a/enumeratum-circe/compat/src/main/scala-2.11/enumeratum/values/Circe.scala b/enumeratum-circe/src/main/scala/enumeratum/values/Circe.scala similarity index 100% rename from enumeratum-circe/compat/src/main/scala-2.11/enumeratum/values/Circe.scala rename to enumeratum-circe/src/main/scala/enumeratum/values/Circe.scala diff --git a/enumeratum-circe/compat/src/main/scala-2.11/enumeratum/values/CirceValueEnum.scala b/enumeratum-circe/src/main/scala/enumeratum/values/CirceValueEnum.scala similarity index 100% rename from enumeratum-circe/compat/src/main/scala-2.11/enumeratum/values/CirceValueEnum.scala rename to enumeratum-circe/src/main/scala/enumeratum/values/CirceValueEnum.scala diff --git a/enumeratum-circe/compat/src/test/scala-2.11/enumeratum/values/CirceValueEnumSpec.scala b/enumeratum-circe/src/test/scala/enumeratum/values/CirceValueEnumSpec.scala similarity index 100% rename from enumeratum-circe/compat/src/test/scala-2.11/enumeratum/values/CirceValueEnumSpec.scala rename to enumeratum-circe/src/test/scala/enumeratum/values/CirceValueEnumSpec.scala diff --git a/enumeratum-core/compat/src/main/scala-2.11/enumeratum/values/ValueEnum.scala b/enumeratum-core/src/main/scala/enumeratum/values/ValueEnum.scala similarity index 100% rename from enumeratum-core/compat/src/main/scala-2.11/enumeratum/values/ValueEnum.scala rename to enumeratum-core/src/main/scala/enumeratum/values/ValueEnum.scala diff --git a/enumeratum-core/compat/src/main/scala-2.11/enumeratum/values/ValueEnumEntry.scala b/enumeratum-core/src/main/scala/enumeratum/values/ValueEnumEntry.scala similarity index 100% rename from enumeratum-core/compat/src/main/scala-2.11/enumeratum/values/ValueEnumEntry.scala rename to enumeratum-core/src/main/scala/enumeratum/values/ValueEnumEntry.scala diff --git a/enumeratum-core/compat/src/test/scala-2.11/enumeratum/values/Animal.scala b/enumeratum-core/src/test/scala/enumeratum/values/Animal.scala similarity index 100% rename from enumeratum-core/compat/src/test/scala-2.11/enumeratum/values/Animal.scala rename to enumeratum-core/src/test/scala/enumeratum/values/Animal.scala diff --git a/enumeratum-core/compat/src/test/scala-2.11/enumeratum/values/ContentType.scala b/enumeratum-core/src/test/scala/enumeratum/values/ContentType.scala similarity index 100% rename from enumeratum-core/compat/src/test/scala-2.11/enumeratum/values/ContentType.scala rename to enumeratum-core/src/test/scala/enumeratum/values/ContentType.scala diff --git a/enumeratum-core/compat/src/test/scala-2.11/enumeratum/values/CustomEnumPrivateConstructor.scala b/enumeratum-core/src/test/scala/enumeratum/values/CustomEnumPrivateConstructor.scala similarity index 100% rename from enumeratum-core/compat/src/test/scala-2.11/enumeratum/values/CustomEnumPrivateConstructor.scala rename to enumeratum-core/src/test/scala/enumeratum/values/CustomEnumPrivateConstructor.scala diff --git a/enumeratum-core/compat/src/test/scala-2.11/enumeratum/values/Drinks.scala b/enumeratum-core/src/test/scala/enumeratum/values/Drinks.scala similarity index 100% rename from enumeratum-core/compat/src/test/scala-2.11/enumeratum/values/Drinks.scala rename to enumeratum-core/src/test/scala/enumeratum/values/Drinks.scala diff --git a/enumeratum-core/compat/src/test/scala-2.11/enumeratum/values/LibraryItem.scala b/enumeratum-core/src/test/scala/enumeratum/values/LibraryItem.scala similarity index 100% rename from enumeratum-core/compat/src/test/scala-2.11/enumeratum/values/LibraryItem.scala rename to enumeratum-core/src/test/scala/enumeratum/values/LibraryItem.scala diff --git a/enumeratum-core/compat/src/test/scala-2.11/enumeratum/values/MovieGenre.scala b/enumeratum-core/src/test/scala/enumeratum/values/MovieGenre.scala similarity index 99% rename from enumeratum-core/compat/src/test/scala-2.11/enumeratum/values/MovieGenre.scala rename to enumeratum-core/src/test/scala/enumeratum/values/MovieGenre.scala index 5caf9fd3..be5b2922 100644 --- a/enumeratum-core/compat/src/test/scala-2.11/enumeratum/values/MovieGenre.scala +++ b/enumeratum-core/src/test/scala/enumeratum/values/MovieGenre.scala @@ -21,4 +21,4 @@ case object MovieGenre extends IntEnum[MovieGenre] { val values = findValues -} +} \ No newline at end of file diff --git a/enumeratum-core/compat/src/test/scala-2.11/enumeratum/values/OperatingSystem.scala b/enumeratum-core/src/test/scala/enumeratum/values/OperatingSystem.scala similarity index 100% rename from enumeratum-core/compat/src/test/scala-2.11/enumeratum/values/OperatingSystem.scala rename to enumeratum-core/src/test/scala/enumeratum/values/OperatingSystem.scala diff --git a/enumeratum-core/compat/src/test/scala-2.11/enumeratum/values/ValueEnumHelpers.scala b/enumeratum-core/src/test/scala/enumeratum/values/ValueEnumHelpers.scala similarity index 100% rename from enumeratum-core/compat/src/test/scala-2.11/enumeratum/values/ValueEnumHelpers.scala rename to enumeratum-core/src/test/scala/enumeratum/values/ValueEnumHelpers.scala diff --git a/enumeratum-core/compat/src/test/scala-2.11/enumeratum/values/ValueEnumSpec.scala b/enumeratum-core/src/test/scala/enumeratum/values/ValueEnumSpec.scala similarity index 92% rename from enumeratum-core/compat/src/test/scala-2.11/enumeratum/values/ValueEnumSpec.scala rename to enumeratum-core/src/test/scala/enumeratum/values/ValueEnumSpec.scala index 65474bb7..f433c7ad 100644 --- a/enumeratum-core/compat/src/test/scala-2.11/enumeratum/values/ValueEnumSpec.scala +++ b/enumeratum-core/src/test/scala/enumeratum/values/ValueEnumSpec.scala @@ -104,6 +104,18 @@ class ValueEnumSpec extends FunSpec with Matchers with ValueEnumHelpers { describe("trying to use with improper types") { + it("should fail to compile when value types do not match with the kind of value enum") { + """ + |sealed abstract class IceCream(val value: String) extends IntEnumEntry + | + |case object IceCream extends IntEnum[IceCream] { + | val value = findValues + | + | case object Sandwich extends IceCream("sandwich") + |} + """ shouldNot compile + } + it("should fail to compile for unsealed traits") { """ trait NotSealed extends IntEnumEntry diff --git a/enumeratum-play-json/compat/src/main/scala-2.11/enumeratum/values/EnumFormats.scala b/enumeratum-play-json/src/main/scala/enumeratum/values/EnumFormats.scala similarity index 100% rename from enumeratum-play-json/compat/src/main/scala-2.11/enumeratum/values/EnumFormats.scala rename to enumeratum-play-json/src/main/scala/enumeratum/values/EnumFormats.scala diff --git a/enumeratum-play-json/compat/src/main/scala-2.11/enumeratum/values/PlayJsonValueEnum.scala b/enumeratum-play-json/src/main/scala/enumeratum/values/PlayJsonValueEnum.scala similarity index 100% rename from enumeratum-play-json/compat/src/main/scala-2.11/enumeratum/values/PlayJsonValueEnum.scala rename to enumeratum-play-json/src/main/scala/enumeratum/values/PlayJsonValueEnum.scala diff --git a/enumeratum-play-json/compat/src/test/scala-2.11/enumeratum/values/EnumFormatsSpec.scala b/enumeratum-play-json/src/test/scala/enumeratum/values/EnumFormatsSpec.scala similarity index 100% rename from enumeratum-play-json/compat/src/test/scala-2.11/enumeratum/values/EnumFormatsSpec.scala rename to enumeratum-play-json/src/test/scala/enumeratum/values/EnumFormatsSpec.scala diff --git a/enumeratum-play-json/compat/src/test/scala-2.11/enumeratum/values/EnumJsonFormatHelpers.scala b/enumeratum-play-json/src/test/scala/enumeratum/values/EnumJsonFormatHelpers.scala similarity index 100% rename from enumeratum-play-json/compat/src/test/scala-2.11/enumeratum/values/EnumJsonFormatHelpers.scala rename to enumeratum-play-json/src/test/scala/enumeratum/values/EnumJsonFormatHelpers.scala diff --git a/enumeratum-play-json/compat/src/test/scala-2.11/enumeratum/values/JsonDrinks.scala b/enumeratum-play-json/src/test/scala/enumeratum/values/JsonDrinks.scala similarity index 100% rename from enumeratum-play-json/compat/src/test/scala-2.11/enumeratum/values/JsonDrinks.scala rename to enumeratum-play-json/src/test/scala/enumeratum/values/JsonDrinks.scala diff --git a/enumeratum-play/compat/src/main/scala-2.11/enumeratum/values/Forms.scala b/enumeratum-play/src/main/scala/enumeratum/values/Forms.scala similarity index 100% rename from enumeratum-play/compat/src/main/scala-2.11/enumeratum/values/Forms.scala rename to enumeratum-play/src/main/scala/enumeratum/values/Forms.scala diff --git a/enumeratum-play/compat/src/main/scala-2.11/enumeratum/values/PlayFormValueEnum.scala b/enumeratum-play/src/main/scala/enumeratum/values/PlayFormValueEnum.scala similarity index 100% rename from enumeratum-play/compat/src/main/scala-2.11/enumeratum/values/PlayFormValueEnum.scala rename to enumeratum-play/src/main/scala/enumeratum/values/PlayFormValueEnum.scala diff --git a/enumeratum-play/compat/src/main/scala-2.11/enumeratum/values/PlayPathBindableValueEnum.scala b/enumeratum-play/src/main/scala/enumeratum/values/PlayPathBindableValueEnum.scala similarity index 100% rename from enumeratum-play/compat/src/main/scala-2.11/enumeratum/values/PlayPathBindableValueEnum.scala rename to enumeratum-play/src/main/scala/enumeratum/values/PlayPathBindableValueEnum.scala diff --git a/enumeratum-play/compat/src/main/scala-2.11/enumeratum/values/PlayQueryBindableValueEnum.scala b/enumeratum-play/src/main/scala/enumeratum/values/PlayQueryBindableValueEnum.scala similarity index 100% rename from enumeratum-play/compat/src/main/scala-2.11/enumeratum/values/PlayQueryBindableValueEnum.scala rename to enumeratum-play/src/main/scala/enumeratum/values/PlayQueryBindableValueEnum.scala diff --git a/enumeratum-play/compat/src/main/scala-2.11/enumeratum/values/PlayValueEnums.scala b/enumeratum-play/src/main/scala/enumeratum/values/PlayValueEnums.scala similarity index 100% rename from enumeratum-play/compat/src/main/scala-2.11/enumeratum/values/PlayValueEnums.scala rename to enumeratum-play/src/main/scala/enumeratum/values/PlayValueEnums.scala diff --git a/enumeratum-play/compat/src/main/scala-2.11/enumeratum/values/UrlBinders.scala b/enumeratum-play/src/main/scala/enumeratum/values/UrlBinders.scala similarity index 100% rename from enumeratum-play/compat/src/main/scala-2.11/enumeratum/values/UrlBinders.scala rename to enumeratum-play/src/main/scala/enumeratum/values/UrlBinders.scala diff --git a/enumeratum-play/compat/src/test/scala-2.11/enumeratum/values/PlayValueEnumHelpers.scala b/enumeratum-play/src/test/scala/enumeratum/values/PlayValueEnumHelpers.scala similarity index 100% rename from enumeratum-play/compat/src/test/scala-2.11/enumeratum/values/PlayValueEnumHelpers.scala rename to enumeratum-play/src/test/scala/enumeratum/values/PlayValueEnumHelpers.scala diff --git a/enumeratum-play/compat/src/test/scala-2.11/enumeratum/values/PlayValueEnumSpec.scala b/enumeratum-play/src/test/scala/enumeratum/values/PlayValueEnumSpec.scala similarity index 100% rename from enumeratum-play/compat/src/test/scala-2.11/enumeratum/values/PlayValueEnumSpec.scala rename to enumeratum-play/src/test/scala/enumeratum/values/PlayValueEnumSpec.scala diff --git a/enumeratum-reactivemongo-bson/compat/src/main/scala-2.11/enumeratum/values/BSONValueHandlers.scala b/enumeratum-reactivemongo-bson/src/main/scala/enumeratum/values/BSONValueHandlers.scala similarity index 100% rename from enumeratum-reactivemongo-bson/compat/src/main/scala-2.11/enumeratum/values/BSONValueHandlers.scala rename to enumeratum-reactivemongo-bson/src/main/scala/enumeratum/values/BSONValueHandlers.scala diff --git a/enumeratum-reactivemongo-bson/compat/src/main/scala-2.11/enumeratum/values/EnumHandler.scala b/enumeratum-reactivemongo-bson/src/main/scala/enumeratum/values/EnumHandler.scala similarity index 100% rename from enumeratum-reactivemongo-bson/compat/src/main/scala-2.11/enumeratum/values/EnumHandler.scala rename to enumeratum-reactivemongo-bson/src/main/scala/enumeratum/values/EnumHandler.scala diff --git a/enumeratum-reactivemongo-bson/compat/src/main/scala-2.11/enumeratum/values/ReactiveMongoBsonValueEnum.scala b/enumeratum-reactivemongo-bson/src/main/scala/enumeratum/values/ReactiveMongoBsonValueEnum.scala similarity index 100% rename from enumeratum-reactivemongo-bson/compat/src/main/scala-2.11/enumeratum/values/ReactiveMongoBsonValueEnum.scala rename to enumeratum-reactivemongo-bson/src/main/scala/enumeratum/values/ReactiveMongoBsonValueEnum.scala diff --git a/enumeratum-reactivemongo-bson/compat/src/test/scala-2.11/enumeratum/values/BsonEnums.scala b/enumeratum-reactivemongo-bson/src/test/scala/enumeratum/values/BsonEnums.scala similarity index 100% rename from enumeratum-reactivemongo-bson/compat/src/test/scala-2.11/enumeratum/values/BsonEnums.scala rename to enumeratum-reactivemongo-bson/src/test/scala/enumeratum/values/BsonEnums.scala diff --git a/enumeratum-reactivemongo-bson/compat/src/test/scala-2.11/enumeratum/values/EnumBsonHandlerHelpers.scala b/enumeratum-reactivemongo-bson/src/test/scala/enumeratum/values/EnumBsonHandlerHelpers.scala similarity index 100% rename from enumeratum-reactivemongo-bson/compat/src/test/scala-2.11/enumeratum/values/EnumBsonHandlerHelpers.scala rename to enumeratum-reactivemongo-bson/src/test/scala/enumeratum/values/EnumBsonHandlerHelpers.scala diff --git a/enumeratum-reactivemongo-bson/compat/src/test/scala-2.11/enumeratum/values/EnumBsonHandlerSpec.scala b/enumeratum-reactivemongo-bson/src/test/scala/enumeratum/values/EnumBsonHandlerSpec.scala similarity index 100% rename from enumeratum-reactivemongo-bson/compat/src/test/scala-2.11/enumeratum/values/EnumBsonHandlerSpec.scala rename to enumeratum-reactivemongo-bson/src/test/scala/enumeratum/values/EnumBsonHandlerSpec.scala diff --git a/enumeratum-upickle/compat/src/main/scala-2.11/enumeratum/values/UPickleValueEnum.scala b/enumeratum-upickle/src/main/scala/enumeratum/values/UPickleValueEnum.scala similarity index 100% rename from enumeratum-upickle/compat/src/main/scala-2.11/enumeratum/values/UPickleValueEnum.scala rename to enumeratum-upickle/src/main/scala/enumeratum/values/UPickleValueEnum.scala diff --git a/enumeratum-upickle/compat/src/main/scala-2.11/enumeratum/values/UPickler.scala b/enumeratum-upickle/src/main/scala/enumeratum/values/UPickler.scala similarity index 100% rename from enumeratum-upickle/compat/src/main/scala-2.11/enumeratum/values/UPickler.scala rename to enumeratum-upickle/src/main/scala/enumeratum/values/UPickler.scala diff --git a/enumeratum-upickle/compat/src/test/scala-2.11/enumeratum/values/UPicklerSpec.scala b/enumeratum-upickle/src/test/scala/enumeratum/values/UPicklerSpec.scala similarity index 100% rename from enumeratum-upickle/compat/src/test/scala-2.11/enumeratum/values/UPicklerSpec.scala rename to enumeratum-upickle/src/test/scala/enumeratum/values/UPicklerSpec.scala diff --git a/macros/compat/src/main/scala-2.10/enumeratum/ContextUtils.scala b/macros/compat/src/main/scala-2.10/enumeratum/ContextUtils.scala index 1ceedf22..794cb8eb 100644 --- a/macros/compat/src/main/scala-2.10/enumeratum/ContextUtils.scala +++ b/macros/compat/src/main/scala-2.10/enumeratum/ContextUtils.scala @@ -4,6 +4,10 @@ object ContextUtils { type Context = scala.reflect.macros.Context + // In 2.10, the constants have Java boxed types at compile time for some reason + type CTLong = java.lang.Long + type CTInt = java.lang.Integer + /** * Returns a TermName */ @@ -16,4 +20,10 @@ object ContextUtils { */ def companion(c: Context)(sym: c.Symbol): c.universe.Symbol = sym.companionSymbol + /** + * Returns a PartialFunction for turning symbols into names + */ + def constructorsToParamNamesPF(c: Context): PartialFunction[c.universe.Symbol, List[c.universe.Name]] = { + case m if m.isMethod && m.asMethod.isConstructor => m.asMethod.paramss.flatten.map(_.asTerm.name) + } } \ No newline at end of file diff --git a/macros/compat/src/main/scala-2.11/enumeratum/ContextUtils.scala b/macros/compat/src/main/scala-2.11/enumeratum/ContextUtils.scala index a574c7df..50d406e2 100644 --- a/macros/compat/src/main/scala-2.11/enumeratum/ContextUtils.scala +++ b/macros/compat/src/main/scala-2.11/enumeratum/ContextUtils.scala @@ -4,6 +4,10 @@ object ContextUtils { type Context = scala.reflect.macros.blackbox.Context + // Constant types + type CTLong = Long + type CTInt = Int + /** * Returns a TermName */ @@ -16,4 +20,10 @@ object ContextUtils { */ def companion(c: Context)(sym: c.Symbol): c.universe.Symbol = sym.companion + /** + * Returns a PartialFunction for turning symbols into names + */ + def constructorsToParamNamesPF(c: Context): PartialFunction[c.universe.Symbol, List[c.universe.Name]] = { + case m if m.isConstructor => m.asMethod.paramLists.flatten.map(_.asTerm.name) + } } \ No newline at end of file diff --git a/macros/compat/src/main/scala-2.11/enumeratum/ValueEnumMacros.scala b/macros/src/main/scala/enumeratum/ValueEnumMacros.scala similarity index 85% rename from macros/compat/src/main/scala-2.11/enumeratum/ValueEnumMacros.scala rename to macros/src/main/scala/enumeratum/ValueEnumMacros.scala index dc896c45..9d4bc44e 100644 --- a/macros/compat/src/main/scala-2.11/enumeratum/ValueEnumMacros.scala +++ b/macros/src/main/scala/enumeratum/ValueEnumMacros.scala @@ -1,7 +1,8 @@ package enumeratum +import enumeratum.ContextUtils.Context + import scala.reflect.ClassTag -import ContextUtils.Context object ValueEnumMacros { @@ -11,7 +12,7 @@ object ValueEnumMacros { * Note, requires the ValueEntryType to have a 'value' member that has a literal value */ def findIntValueEntriesImpl[ValueEntryType: c.WeakTypeTag](c: Context): c.Expr[IndexedSeq[ValueEntryType]] = { - findValueEntriesImpl[ValueEntryType, Int, Int](c)(identity) + findValueEntriesImpl[ValueEntryType, ContextUtils.CTInt, Int](c)(identity) } /** @@ -20,7 +21,7 @@ object ValueEnumMacros { * Note, requires the ValueEntryType to have a 'value' member that has a literal value */ def findLongValueEntriesImpl[ValueEntryType: c.WeakTypeTag](c: Context): c.Expr[IndexedSeq[ValueEntryType]] = { - findValueEntriesImpl[ValueEntryType, Long, Long](c)(identity) + findValueEntriesImpl[ValueEntryType, ContextUtils.CTLong, Long](c)(identity) } /** @@ -32,7 +33,7 @@ object ValueEnumMacros { * - the Short value should be a literal Int (do no need to cast .toShort). */ def findShortValueEntriesImpl[ValueEntryType: c.WeakTypeTag](c: Context): c.Expr[IndexedSeq[ValueEntryType]] = { - findValueEntriesImpl[ValueEntryType, Int, Short](c)(_.toShort) // do a transform because there is no such thing as Short literals + findValueEntriesImpl[ValueEntryType, ContextUtils.CTInt, Short](c)(_.toShort) // do a transform because there is no such thing as Short literals } /** @@ -71,7 +72,7 @@ object ValueEnumMacros { * * Will abort compilation if not all the trees provided have a literal value member/constructor argument */ - private[this] def findValuesForSubclassTrees[ValueType: ClassTag, ProcessedValueType](c: Context)(valueEntryCTorsParams: List[List[c.universe.TermName]], memberTrees: Seq[c.universe.Tree], processFoundValues: ValueType => ProcessedValueType): Seq[TreeWithVal[c.universe.Tree, ProcessedValueType]] = { + private[this] def findValuesForSubclassTrees[ValueType: ClassTag, ProcessedValueType](c: Context)(valueEntryCTorsParams: List[List[c.universe.Name]], memberTrees: Seq[c.universe.Tree], processFoundValues: ValueType => ProcessedValueType): Seq[TreeWithVal[c.universe.Tree, ProcessedValueType]] = { val treeWithValues = toTreeWithMaybeVals[ValueType, ProcessedValueType](c)(valueEntryCTorsParams, memberTrees, processFoundValues) val (hasValueMember, lacksValueMember) = treeWithValues.partition(_.maybeValue.isDefined) if (lacksValueMember.nonEmpty) { @@ -100,7 +101,7 @@ object ValueEnumMacros { * * Aborts compilation if the value declaration/constructor is of the wrong type, */ - private[this] def toTreeWithMaybeVals[ValueType: ClassTag, ProcessedValueType](c: Context)(valueEntryCTorsParams: List[List[c.universe.TermName]], memberTrees: Seq[c.universe.Tree], processFoundValues: ValueType => ProcessedValueType): Seq[TreeWithMaybeVal[c.universe.Tree, ProcessedValueType]] = { + private[this] def toTreeWithMaybeVals[ValueType: ClassTag, ProcessedValueType](c: Context)(valueEntryCTorsParams: List[List[c.universe.Name]], memberTrees: Seq[c.universe.Tree], processFoundValues: ValueType => ProcessedValueType): Seq[TreeWithMaybeVal[c.universe.Tree, ProcessedValueType]] = { import c.universe._ val classTag = implicitly[ClassTag[ValueType]] val valueTerm = ContextUtils.termName(c)("value") @@ -122,14 +123,12 @@ object ValueEnumMacros { case (`valueTerm`, Literal(Constant(i))) => c.abort(c.enclosingPosition, s"${declTree.symbol} has a value with the wrong type: $i:${i.getClass}, instead of ${classTag.runtimeClass}.") /* * found a (_, NamedArgument(argName, argument)) parameter-named pair where the argument is named "value" and the argument itself is of the right type - * - * Note: Can't match without using Ident(ContextUtils.termName(c)(" ")) extractor ??! */ - case (_, AssignOrNamedArg(Ident(TermName("value")), Literal(Constant(i: ValueType)))) => i + case (_, AssignOrNamedArg(Ident(`valueTerm`), Literal(Constant(i: ValueType)))) => i /* * found a (_, NamedArgument(argName, argument)) parameter-named pair where the argument is named "value" and the argument itself is of the wrong type */ - case (_, AssignOrNamedArg(Ident(TermName("value")), Literal(Constant(i)))) => c.abort(c.enclosingPosition, s"${declTree.symbol} has a value with the wrong type: $i:${i.getClass}, instead of ${classTag.runtimeClass}") + case (_, AssignOrNamedArg(Ident(`valueTerm`), Literal(Constant(i)))) => c.abort(c.enclosingPosition, s"${declTree.symbol} has a value with the wrong type: $i:${i.getClass}, instead of ${classTag.runtimeClass}") } } } @@ -145,12 +144,12 @@ object ValueEnumMacros { /** * Given a type, finds the constructor params lists for it */ - private[this] def findConstructorParamsLists[ValueEntryType: c.WeakTypeTag](c: Context): List[List[c.universe.TermName]] = { + private[this] def findConstructorParamsLists[ValueEntryType: c.WeakTypeTag](c: Context): List[List[c.universe.Name]] = { val valueEntryTypeTpe = implicitly[c.WeakTypeTag[ValueEntryType]].tpe val valueEntryTypeTpeMembers = valueEntryTypeTpe.members - valueEntryTypeTpeMembers.collect { - case m if m.isMethod && m.isConstructor => m.asMethod.paramLists.flatten.map(_.asTerm.name) - }.toList + valueEntryTypeTpeMembers + .collect(ContextUtils.constructorsToParamNamesPF(c)) + .toList } /** diff --git a/project/Build.scala b/project/Build.scala index f630b6ff..b771d835 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -51,7 +51,6 @@ object Enumeratum extends Build { .settings( name := "enumeratum" ) - .settings(withCompatUnmanagedSources(jsJvmCrossProject = true, include_210Dir = false, includeTestSrcs = true):_*) .settings(testSettings:_*) .settings(commonWithPublishSettings:_*) .dependsOn(macros) @@ -89,7 +88,6 @@ object Enumeratum extends Build { "org.reactivemongo" %% "reactivemongo" % reactiveMongoVersion ) ) - .settings(withCompatUnmanagedSources(jsJvmCrossProject = false, include_210Dir = false, includeTestSrcs = true):_*) .settings(testSettings:_*) .dependsOn(coreJvm % "test->test;compile->compile") @@ -99,7 +97,6 @@ object Enumeratum extends Build { "com.typesafe.play" %% "play-json" % thePlayVersion(scalaVersion.value) ) ) - .settings(withCompatUnmanagedSources(jsJvmCrossProject = false, include_210Dir = false, includeTestSrcs = true):_*) .settings(testSettings:_*) .dependsOn(coreJvm % "test->test;compile->compile") @@ -109,7 +106,6 @@ object Enumeratum extends Build { "com.typesafe.play" %% "play" % thePlayVersion(scalaVersion.value) ) ) - .settings(withCompatUnmanagedSources(jsJvmCrossProject = false, include_210Dir = false, includeTestSrcs = true):_*) .settings(testSettings:_*) .dependsOn(coreJvm, enumeratumPlayJson % "test->test;compile->compile") @@ -139,7 +135,6 @@ object Enumeratum extends Build { additionalMacroDeps } ) - .settings(withCompatUnmanagedSources(jsJvmCrossProject = true, include_210Dir = false, includeTestSrcs = true):_*) .settings(testSettings:_*) .dependsOn(core % "test->test;compile->compile") lazy val enumeratumUPickleJs = enumeratumUPickle.js @@ -160,7 +155,6 @@ object Enumeratum extends Build { Seq(impl.ScalaJSGroupID.withCross("io.circe", "circe-core", cross) % "0.4.1") } ) - .settings(withCompatUnmanagedSources(jsJvmCrossProject = true, include_210Dir = false, includeTestSrcs = true):_*) .settings(testSettings:_*) .dependsOn(core % "test->test;compile->compile") lazy val enumeratumCirceJs = enumeratumCirce.js @@ -267,7 +261,6 @@ object Enumeratum extends Build { publishArtifact := false, publishLocal := {} ) - .settings(withCompatUnmanagedSources(jsJvmCrossProject = false, include_210Dir = false, includeTestSrcs = false):_*) .dependsOn(macrosJs, macrosJvm, coreJs, coreJvm, coreJVMTests, enumeratumPlay, enumeratumPlayJson, enumeratumUPickleJs, enumeratumUPickleJvm, enumeratumCirceJs, enumeratumCirceJvm, enumeratumReactiveMongoBson) .enablePlugins(JmhPlugin) .settings(libraryDependencies += "org.slf4j" % "slf4j-simple" % "1.7.21")