Scala Universe
A resolved view of JVM types, generics and annotations.
The idea
Scala Universe turns Java reflection into a structured model of resolved types. Inspect fields, methods, constructors, bean properties and annotations without losing the concrete types behind inherited generics.
What it does.
Resolved generic types
Inspect inherited members with type parameters resolved against the concrete subclass.
Unified members
Find fields, methods, constructors and parameters through one consistent type model.
Property introspection
Build bean or annotation-based property models for framework code.
Installation
libraryDependencies += "com.anjunar" %% "scala-universe" % "1.0.3"
Package: com.anjunar:scala-universe
Start building.
Resolve a JVM class with TypeResolver, then inspect its members or build a property model with BeanIntrospector.
Resolve inherited generic members
The method is declared with T, but the resolved return type is String for StringBox.
import com.anjunar.scala.universe.TypeResolver
abstract class Box[T] { def getValue: T }
class StringBox extends Box[String] {
override def getValue: String = "hello"
}
val resolved = TypeResolver.resolve(classOf[StringBox])
val method = resolved.findMethod("getValue")
println(method.returnType.raw) // class java.lang.StringInspect a bean property
The property model exposes its type and can read or update the underlying instance.
import com.anjunar.scala.universe.introspector.BeanIntrospector
class Person {
private var firstName = "Ada"
def getFirstName: String = firstName
def setFirstName(value: String): Unit = firstName = value
}
val model = BeanIntrospector.createWithType(classOf[Person])
val property = model.findProperty("firstName")
val person = new Person
property.set(person, "Grace")
println(property.get(person)) // GraceBy design.
The resolved class model keeps generic substitutions attached to every member. Frameworks can work with concrete types instead of repeatedly interpreting raw reflection values.
Make it part of your stack.
Explore further.
Scala.js UI
A Scala 3 and Scala.js UI framework for server-rendered applications.
↗Hibernate DDL Manager
Controlled schema evolution from Hibernate metadata.
↗JSON Mapper
JSON mapping for existing object graphs and domain models.
↗Scala JS Ember
A modular rich-text editor built on one immutable document model.
↗Scala Reflect
Type metadata generated at compile time for the JVM and Scala.js.
↗