Skip to content

Commit

Permalink
surface (feature): Add Surface.isEnum for Scala 3 Enum (#3271)
Browse files Browse the repository at this point in the history
  • Loading branch information
xerial committed Nov 12, 2023
1 parent bbacaf6 commit 188e2e9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ trait Surface extends Serializable {
def isMap: Boolean = classOf[Map[_, _]].isAssignableFrom(rawType)
def isArray: Boolean = this.isInstanceOf[ArraySurface]

/**
* True if this surface is a Scala3 enum
*/
def isEnum: Boolean = classOf[scala.reflect.Enum].isAssignableFrom(rawType)

def objectFactory: Option[ObjectFactory] = None
def withOuter(outer: AnyRef): Surface = this
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package wvlet.airframe.surface

import wvlet.airspec.AirSpec
import scala.jdk.CollectionConverters.*

object Scala3EnumTest extends AirSpec:

enum Color:
case Red, Green, Blue

test("scala 3 enum") {
val s = Surface.of[Color]

s.name shouldBe "Color"
s.fullName shouldBe "wvlet.airframe.surface.Scala3EnumTest.Color"
s.params shouldBe empty

s.isEnum shouldBe true
}

0 comments on commit 188e2e9

Please sign in to comment.