Skip to content

Instantly share code, notes, and snippets.

@ianoc
Created April 2, 2015 21:49
Show Gist options
  • Save ianoc/4785645d8c586aae1eb7 to your computer and use it in GitHub Desktop.
Save ianoc/4785645d8c586aae1eb7 to your computer and use it in GitHub Desktop.
Accessing nested type
val mappedName = "com.blah.X.y.MyType"
val splitName = mappedName.split('.')
val exceptLast = splitName.dropRight(1)
val terms = exceptLast.map(newTermName(_))
val (first, second) = (terms(0), terms(1))
val accessorSelect = terms.drop(2).foldLeft(Select(Ident(first), second)) {
case (existing, next) =>
Select(existing, next)
}
val finalType = Select(accessorSelect, newTypeName(splitName.last))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment