282 questions
0
votes
1
answer
62
views
How do I get the evaluated value from a StaticAnnotation's member?
So I have an annotation that looks like this:
class FakeAnnotation(val strings: String*) extends StaticAnnotation
val someVar = "Test"
@FakeAnnotation(someVar)
class TestClass
I can't see ...
1
vote
0
answers
121
views
How to address the performance impact of executing multiple functions dynamically compiled with Scala 2's runtime reflection?
I have an entity that generates Scala functions compiled dynamically using Scala 2's runtime reflection. My case is slightly more convoluted, but the following showcases the issue:
import scala....
1
vote
1
answer
121
views
Creating syntactic sugar for a scala argument to give the illusion of a different type
I am creating a library and am exposing a class called A that has in it defined a function func(f: SomeType => A). It is imperative that func is called with the following syntax:
val x = new A()
...
0
votes
0
answers
77
views
How to create Instance of a case class (which extends trait with some value) in generic function
Let's assume I have the code:
trait Session {
val value: Option[String] = None
}
case class A(v: Int) extends Session
case class B(v: Int, s: String) extends Session
def injectSession[T <: ...
1
vote
1
answer
416
views
Determine the function signature of an anonymous function in scala
The context is to register a UserDefinedFunction(UDF) in spark, where the UDF is an anonymous function obtained via reflection. Since the function signature of the function is determined at runtime, I ...
0
votes
1
answer
280
views
Reflection to call method that had its name changed in an upgrade?
My code compiled with Spark 3.1.2:
private def work(plan: LogicalPlan): LogicalPlan = {
val result = plan.transformDown {
// irrelevant details
}
}
When run with Spark 3.3.0, I run into:
java....
1
vote
0
answers
244
views
Evaluate expression of implicit TypeTag on Intellij debugger fails, why? and how can i enable it?
package spark.course.example
import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.functions.typedLit
object Example extends App{
val spark: SparkSession = SparkSession.builder....
0
votes
2
answers
176
views
Scala case classes and recursive reflection
Given 2 Scala case classes
case class Bar(x: Int)
case class Foo(b: Bar, z: Double)
I have a piece of code that prints the types of Foo fields using reflection:
import scala.reflect.runtime.universe....
0
votes
1
answer
203
views
Invoke all methods on a Scala object using reflection
Given the following object
object functions {
type MyOutput = String
def f1: MyOutput = "res1"
def f2: MyOutput = "res2"
def f3(foo: String): Boolean = foo.equals("...
0
votes
2
answers
160
views
Scala Reflection issue on accessing case class attributes
I have been able to get a List of attributes for a case class using scala with Reflection.
import scala.reflect.runtime.universe._
def classAccessors[T: TypeTag]: List[MethodSymbol] = typeOf[T]....
0
votes
1
answer
262
views
scala cast object based on reflection symbol
I have a Scala reflection Symbol.
val symbol = scala.reflect.api.Symbol
how can I cast an object
val obj: Any
to the type of that Symbol ?
reason why I am asking is that I have a implicit method to ...
0
votes
1
answer
348
views
Scala whitebox macro how to check if class fields are of type of a case class
I am trying to generate a case class from a given case class that strips of Option from the fields. It needs to this recursively, so if the field itself is a case class then it must remove Option from ...
0
votes
1
answer
264
views
Trying to extract the TypeTag of a Sequence of classes that extend a trait with different generic type parameters
The following code example shows the core of my question:
// This is the base trait that the classes are extending
trait Operation[T] {
def operate(x: T): T
}
// Here are 2 case classes that exist ...
0
votes
0
answers
147
views
Named parameters in Scala annotation
I have a Scala annotation with parameters, some with default values:
case class A(x: String, y: Option[String] = None, z: Option[Boolean] = None)
extends scala.annotation.StaticAnnotation
The ...
0
votes
1
answer
135
views
How do I fetch the overridden member of a sealed trait via reflection?
I'm trying to write a generalised function that takes a Type of SomeSealedClass and uses reflection to return a list of values overridden by the trait's child classes/objects.
sealed abstract class ...
4
votes
1
answer
582
views
What Scala 3 syntax can match on a Type and its Type parameters in the context of a macro?
From the context of a Scala 3 Macro:
def aMacroImpl[T](using Type[T], Quotes): Expr[SpecialMap[_, _, _]] = {
import quotes.reflect._
val TRepr: TypeRepr = TypeRepr.of[T]
val TSym: Symbol ...
0
votes
1
answer
362
views
Scala - How to extract Json4s with dynamic case class created with ToolBox
I defined the case class dynamically using Toolbox.
And when I do extract of json4s, I get the following exception:
import org.json4s._
import scala.reflect.runtime._
import scala.tools.reflect....
-1
votes
1
answer
137
views
in scala how can i reflection creates the underlying type
Let's say I have the following:
val int_string = "Int"
I want to get a map. In the process of running the program, I need to infer its type from the data, and then create a map,like in spark ...
1
vote
1
answer
377
views
Scala runtime compilation: how to get line number of the error message?
I have found that scala compiler report compile error differently depends on whether it is used in compile-time or run-time.
E.g. for a simple implicit not found case, in compile time the report is:
...
1
vote
1
answer
695
views
Extract the default argument value in method
I am trying to create a UI to test a scala interface. To do so, I am extracting all the declared methods from the interface using java reflection.
I am able to get the method names via
Class[MyClass]....
0
votes
0
answers
97
views
Ad-hoc polymorphism for reflection created case classes Scala
I need to implement Ad-hoc polymorphism, consider this code:
trait BlockInputRequest
case class StaticBlockInput(
content: String
) extends BlockInputRequest
case class StaticBlockOutput(...
2
votes
0
answers
71
views
How to recognize an outer variable which is listed between members by reflection?
I have a function which constructs a map by reflection from an object literal (the purpose is to make porting some JavaScript code easier). The function works fine, but I have found a case in which ...
1
vote
0
answers
191
views
Convert Map[String, Any] to nested case class with controlled Type casting
I'd like to convert a Map[String, Any] to a given case class, and the map can be a nested map.
The case class can have certain fields as Optional, and if the map doesn't have the field in question , ...
0
votes
0
answers
134
views
In scala 2.13, how to use actual TypeTag in macro?
This capability seems to be dropped by SI-6186, and no mechanism could be used to replace it
I found the following remarks in its commit message:
Now we restore the broken balance by banning TypeTag ...
1
vote
1
answer
216
views
How to get the name of a class as a string literal at compile time using shapeless?
This is a follow-up question of:
How to get the name of a case class field as a string/symbol at compile time using shapeless?
Assuming that I want to write a recursive converter that can convert a ...