Skip to content

Add refinedType to object ClassManifest #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 23, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/library/scala/reflect/ClassManifest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,17 @@ object ClassManifest {
override val typeArguments = args.toList
override def toString = prefix.toString+"#"+name+argString
}

/** Manifest for the refined type
* `parent { val fieldNames(0) : fieldTypes(0) ; ... ; val fieldNames(n) : fieldTypes(n) }`.
*/
def refinedType[T](parent: Manifest[_], fieldNames: List[String], fieldTypes: List[Manifest[_]]): Manifest[T] =
new RefinedManifest[T] {
def erasure = parent.erasure
def fields = fieldNames zip fieldTypes
override def toString = parent + (fieldNames zip fieldTypes).map{case(n, t) => "val "+ n +" : "+ t}.mkString("{","; ", "}")
}

}

/** Manifest for the class type `clazz[args]`, where `clazz` is
Expand Down
3 changes: 3 additions & 0 deletions src/library/scala/reflect/Manifest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ object Manifest {
override def toString = parents.mkString(" with ")
}

/** Manifest for the refined type
* `parent { val fieldNames(0) : fieldTypes(0) ; ... ; val fieldNames(n) : fieldTypes(n) }`.
*/
def refinedType[T](parent: Manifest[_], fieldNames: List[String], fieldTypes: List[Manifest[_]]): Manifest[T] =
new RefinedManifest[T] {
def erasure = parent.erasure
Expand Down