Questions tagged [scala-reflect]

In Scala 2.10, a new reflection library was introduced to add a more powerful toolkit of general reflective capabilities to Scala. Along with full-featured runtime reflection for Scala types and generics, Scala 2.10 also ships with compile-time reflection capabilities, in the form of macros, as well as the ability to reify Scala expressions into abstract syntax trees.

278 questions
0
votes
1 answer

Scala macro does not compile when code is crafted without reify

I've been working on complex compile-time reflection and have come across the need to craft Scala code manually, using the AST. While experimenting I noticed a weird compilation error which doesn't really make sense to me, so I tried reproducing it…
Adi Gerber
  • 636
  • 7
  • 22
0
votes
2 answers

Scala reflect string to singleton object

I'm looking for a way to convert a Scala singleton object given as a string (for example: package1.Main) to the actual instance of Main, so that I can invoke methods on it. Example of the problem: package x { object Main extends App { val…
Devabc
  • 4,782
  • 5
  • 27
  • 40
0
votes
1 answer

How to prevent typecheck in StaticAnnotation?

I am creating some macro libraries that reads some information from annotation on the enclosing method. @info(foo(bar, baz)) def enclosing() = { myMacro() } These information are encoded as foo(bar, baz) in a StaticAnnotation @info. foo(bar, baz)…
Yang Bo
  • 3,586
  • 3
  • 22
  • 35
0
votes
1 answer

how to call scala REPL console from scala program?

I need embed Scala REPL functionality in my Scala Application. How can I do that ? Which Scala method/class I need to call ? I take a look at scala.tools.nsc.interpreter package but I don't see how to do that.
João Paraná
  • 1,031
  • 1
  • 9
  • 18
0
votes
1 answer

How to load implicit Manifest from polymorphic type field

I am trying to build an interpreter for my ADT but I don't know how to solve the problem of loading the implicit manifests in a nice way sealed trait Polymorphic[T] case class Type1[T: Manifest](field1: T) extends Polymorphic[T] case class Type2[T:…
Mikel San Vicente
  • 3,831
  • 2
  • 21
  • 39
0
votes
1 answer

sbt-android: unable to use scala-reflect on android: java.rmi.Remote not found

I'm trying to use the scala-reflect package for android development. I have added the scala-reflect dependency in my build.sbt: libraryDependencies += "org.scala-lang" % "scala-reflect" % "2.11.8" but I get an…
0
votes
1 answer

Performing an explicit cast based on `Class` instance

Assume there is a class X. At some point in my code, I get an o of type Object and I want to explicitly cast it to X. Normally, I would do val x: X = o.asInstanceOf[X]. However, X is not in scope, all I have is X's instance of Class, like so: I…
typeduke
  • 6,494
  • 6
  • 25
  • 34
0
votes
2 answers

Scala: get outer class from inner class in constructor

I have an anonymous inner class, and I want to acces the (anonymous) outer class of it in the constructor. So I want to implement this method: new Outer { new Inner { } } class Outer { } class Inner { def outerClass: Outer = ??? }
0
votes
1 answer

How to access to generic class field via scala-reflect and TypeTag (Scala 2.10)

I am trying to check if a field exists in a generic class. import scala.reflect.runtime.{universe => ru} class Example[T:ru.TypeTag](val value:T) object Example { def apply[T:ru.TypeTag](value:T, fieldName: String) : Example[T] = { val t…
Mikel San Vicente
  • 3,831
  • 2
  • 21
  • 39
0
votes
1 answer

Testing Scala on Android : "Couldn't find scala.reflect.ScalaSignature.bytes"

I am trying to write instrumentation test in Scala (full code is here). Any ideas what might be causing the java.lang.IncompatibleClassChangeError: Couldn't find scala.reflect.ScalaSignature.bytes run-time error ? I am trying to keep…
jhegedus
  • 20,244
  • 16
  • 99
  • 167
0
votes
0 answers

How do I import scala.reflect.io.File into my project?

I am using IntelliJ IDE. I want to import scala.reflect.io.File from the package - scala-reflect-2.11.4. But when I type in import scala.reflect, the compiler thinks that I am trying to use the class reflect from the package scala-library-2.11.8.…
Soren Goyal
  • 196
  • 4
0
votes
2 answers

Scala: Using TypeTag in a method

I am trying to write a method like this: def foo[T:TypeTag](value: Int):String = { (/* do something */).mapTo[T].map(_.toJson) } where mapTo has the signature: def mapTo[S](implicit tag: ClassTag[S]): Future[S] = { ... } using…
Randomize
  • 8,651
  • 18
  • 78
  • 133
0
votes
1 answer

In Scala, How to get the returned TypeTag of a class method?

I have a class: package org.apache.project class Foo { def bar: List[Bar] = ... } is it a way in scala reflection that allows me to get typeOf[List[Bar]] from the className "org.apache.project.Foo" and the method name "bar"? Thanks a lot for your…
tribbloid
  • 4,026
  • 14
  • 64
  • 103
0
votes
0 answers

Passing type information in scala

If I have some class heirarchy defined like this sealed trait A case class B() extends A case class C() extends A // and so on .. and in a different location I want to call some method dynamically passing above classes as type to that function (eg:…
0
votes
2 answers

Obtain Java Class from Scala TypeTag in Macros

According to this question/answer Any way to obtain a Java class from a Scala (2.10) type tag or symbol? I should use runtimeClass to obtain the Class from a type. But if I do reflection in Macros I don't have access to runtimeClass. How can I do?
Joan
  • 4,079
  • 2
  • 28
  • 37
1 2 3
18
19