ANN: SMirror - Simple Scala Reflection

44 Aufrufe
Direkt zur ersten ungelesenen Nachricht

Flavio W. Brasil

ungelesen,
08.02.2013, 11:31:4908.02.13
an scala...@googlegroups.com


SMirror is a simpler way to do reflection that provides a higher level of abstraction over the Scala 2.10 runtime reflection.

Examples:
scala> class Product(val category: String) {
     |     var tags = Set[String]()
     |     def clearTags =
     |         tags = Set()
     | }
defined class Product
scala> val sClass = sClassOf[Product]
sClass: net.fwbrasil.smirror.SClass[Product] = Product

scala> sClass.vals
res2: List[net.fwbrasil.smirror.SVal[Product]] = List(val category: java.lang.String)

scala> sClass.vars
res3: List[net.fwbrasil.smirror.SVar[Product]] = List(var tags: scala.collection.immutable.Set)

scala> sClass.methods
res4: List[net.fwbrasil.smirror.SMethod[Product]] = List(clearTags(): scala.Unit)
scala> val constructor = sClass.constructors.head
constructor: net.fwbrasil.smirror.SConstructor[Product] = <init>(category: java.lang.String): Product

scala> val product = constructor.invoke("sports")
product: Product = Product@6c6c7d22

scala> val tagsVar = sClass.vars.head
tagsVar: net.fwbrasil.smirror.SVar[Product] = var tags: scala.collection.immutable.Set

scala> tagsVar.set(product, Set("tennis"))
res6: Any = ()

scala> tagsVar.get(product)
res7: Any = Set(tennis)
scala> product.reflect.vals.head.get
res11: Any = sports

scala> product.reflect.vars.head.set(Set("tennis"))
res12: Any = ()

scala> product.tags
res13: scala.collection.immutable.Set[String] = Set(tennis)

-- 
Flávio W. Brasil
{persistence as it should be}

Eugene Burmako

ungelesen,
10.02.2013, 04:46:0510.02.13
an Flavio W. Brasil, scala-user
Hey!

Thanks for putting up the list of really important operations as opposed to the extensive list of everything supported by Scala, which we have in scala.reflect.api at the moment. Do you have some sort of a doc (or a scaladoc) with the exposed API? I browsed the sources, but, from what I understand, not everything from there is supposed to be available to the user?

Cheers,
Eugene


--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Flavio W. Brasil

ungelesen,
10.02.2013, 11:00:3310.02.13
an Eugene Burmako, scala-user
Hello Eugene,

There isn't a scaladoc for now, I will add it and review methods visibility for the next versions.
I'm now trying to add thread safety to the lib by using locks, this is important for the project that I use SMirror.
Someday the scala reflection will be thread safe? Use locks isn't a good solution...

-- 
Flávio W. Brasil
{persistence as it should be}

Allen antworten
Antwort an Autor
Weiterleiten
0 neue Nachrichten