Scala Reflect
Reflection without runtime reflection. Macros describe your types at compile time; at runtime you read descriptors and call generated accessors, on the JVM and in Scala.js alike.
Installation
A cross-built artifact. With sbt 2, %% adds the right platform suffix for the JVM and for Scala.js.
Describe a case class
reflect expands to a ClassDescriptor at compile time. The values below are read from it while this page renders.
- descriptor.typeName
- demo.Person
- descriptor.simpleName
- Person
- descriptor.isCaseClass
- true
- descriptor.constructors.head.parameterNames
- name, age
- descriptor.getProperty("age").map(_.propertyType.typeName)
- Some(scala.Int)
Metadata from macros
The structure of a type is read by the compiler, not discovered at runtime. Nothing is guessed and nothing is missing on Scala.js.
Accessors instead of Method.invoke
Getters and setters are generated code. A read-only property gets no setter at all.
The same descriptors everywhere
Server and browser share one model of your types. scalajs-ui and json-mapper build on it.
From a descriptor to a registry
Describe types, access their properties, then register them to look them up by name at runtime.