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
1
vote
0 answers

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 =…
1
vote
1 answer

Reflection does not see companion of subclass case class when defined in companion of extending trait

Given a code which takes a type, takes it's known direct subclasses, filters the ones that are case classes and then takes the companion of that case class: def firstSubclassWithCompanion[T: TypeTag]: String = { val superclass =…
Random42
  • 8,989
  • 6
  • 55
  • 86
1
vote
1 answer

Scala 3 macro: generic type from class

I am writing a serialization library using Scala 3 macro programming. I want to generate the serializer dynamicly. Because this is a library, so I do not know what class to serializer during compile. So I need a runtime compile feature. Code: object…
HalfLegend
  • 314
  • 4
  • 15
1
vote
0 answers

Does the Scala.js ecosystem offer any way(s) to augment or replace the auto-generated setter/mutator methods for property fields of scala classes?

Please consider a family of plain and case classes, cross-compiled to JVM and Scala.js, which make mixed use of properties with automatically and manually defined accessor methods. Many come from external libraries but all inherit from a specific…
Ben McKenneby
  • 481
  • 4
  • 15
1
vote
1 answer

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: newSource1.scala:6: error: type mismatch; L|R …
tribbloid
  • 4,026
  • 14
  • 64
  • 103
1
vote
1 answer

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].getDeclaredMethods.map(_.getName) I am also able…
Kyuubi
  • 1,228
  • 3
  • 18
  • 32
1
vote
0 answers

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 , it'll have a default value. eg. case class CC(a:…
ni_i_ru_sama
  • 304
  • 1
  • 13
1
vote
0 answers

How do you output the runtime type of an object in Scala 3?

Use case: I'm writing tests for a Scala 3 program using scalatest. I want to print a meaningful fail message saying that the expected parameterized type did not equal the found parameterized type. eg: Expected: scala.util.Failure[…
Leo Orientis
  • 841
  • 11
  • 19
1
vote
1 answer

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 product type: case class Prod ( a: Int, b:…
tribbloid
  • 4,026
  • 14
  • 64
  • 103
1
vote
1 answer

Sbt: call subproject's source code from root project

So my project structure looks like this: My root project contains the settings, tasks and configs. In addition is has a subprojects folder which contains all subprojects. I have created a task on the root project that depends on some code in a…
Helix112
  • 305
  • 3
  • 12
1
vote
1 answer

How to manually construct an Scala runtime AST that instantiates a Class?

I am having trouble constructing correct Scala (2.13.3) syntax trees at runtime. Suppose we define the following class. class Foo(x: Int) I would like to construct the syntax tree for the following line of code. new Foo(1) For reference, we can…
Erp12
  • 600
  • 3
  • 16
1
vote
1 answer

dynamically parse json in flink map

I'm using flink to dynamically analyze json type data,to keyby and sum with the given column,in my mapFunction,I convert json to case class,but the result stream don't get compiler in keyBy function,got error Exception in thread "main"…
xrz
  • 13
  • 4
1
vote
1 answer

Load Dataset from Dynamically generated Case Class

What is Needed: number of tables in source database are changing rapidly and thus I don't want to edit case classes so I dynamically generate them through SCALA code and put in package. But now not able to read it dynamically. If this works than I…
user9946307
1
vote
1 answer

How to distinguish parameteric types?

I am confused about subtypes in Scala. My major question is how to distinguish C[T1] from C[T2]. There are two scenarios: C[T1] "equals" C[T2] because they are all subtypes of C. C[T1] does not "equal" C[T2] because C[T1] and C[T2] are different…
calvin
  • 2,125
  • 2
  • 21
  • 38
1
vote
1 answer

Is there some way in scala that I can return a type?

I have a lot of classes such as DataFrameFlow, TextFlow, RDDFlow. They all derive from base class Flow. Now I want to write a function judgeFlow which can read from a path: String and return something representing exact Flow type from which I can…
calvin
  • 2,125
  • 2
  • 21
  • 38