score:5
This will work as-is when called from inside an ordinary instance of a class, so I'll assume you're trying it from inside an object, in which case you'll need to match against ModuleDef
as well as ClassDef
:
case ModuleDef(mods, name, impl) => c.universe.reify(
printf(
"\n mods %s\n name %s\n impl %s\n",
c.literal(mods.toString).splice,
c.literal(name.toString).splice,
c.literal(impl.toString).splice
)
)
Note that one easy way to debug something like this is to print out the raw representation of whatever unexpected thing you're getting:
case x => c.abort(c.enclosingPosition, "NoEnclosingClass: " + showRaw(x))
This would print the following when called inside a singleton object:
<console>:7: error: NoEnclosingClass: ModuleDef(Modifiers(), ...
Which gives us a pretty good idea of where we need to start.
Source: stackoverflow.com
Related Query
- get calling class
- Get field names list from case class
- How to get around the Scala case class limit of 22 fields?
- Get companion object of class by given generic type Scala
- How to get rid of : class type required but T found
- Scala - No TypeTag Available Exception when using case class to try to get TypeTag?
- Can I get a Scala case class definition from an Avro schema definition?
- How do I get an instance of the type class associated with a context bound?
- Why do I get "expected class or object definition" when defining a type in scala?
- How to get the name of a case class field as a string/symbol at compile time using shapeless?
- Get source code of any class from within a Java program
- scala - get class from a string
- Is there a way to get a warning when a Scala Value Class needs to become instantiated?
- How to get probabilities corresponding to the class from Spark ML random forest
- How to get the class of a singleton object at compile time?
- Scala: How to get class of mixin composition?
- Java calling Scala case class w/ implicit parameter?
- Java/Scala reflection: Get class methods in order and force object init
- Get ClassTag from reflected Java Class instance
- Can you get a class name as a constant for scala annotations?
- Is there a way to get a JSON-Schema from a Scala Case Class hierarchy?
- How to get the TypeTag for a class in Java
- Converting Java to Scala, how to deal with calling super class constructor?
- Getting "how can getCommonSuperclass() do its job if different class symbols get the same bytecode-level internal name" compile error
- How do I get the runtime Class of a parameterized Type in a Scala trait
- Scala: Get companion class in companion object
- Get caller class and method name
- get all the class names in a package with scala
- Get values of all variables in a case class without using reflection
- scala: How to get the class in its own constructor
More Query from same tag
- How to group by using Spark Scala in order to build nested DataFrame?
- Cross product of two Strings
- Can Spark code in Scala be converted to Java?
- What's wrong with \W on non UTF-8 encodings using Scala?
- Changing a parameter in a function in Scala
- for..else for Option types in Scala?
- Reuse class members in Scala
- Not able to use AllRowsReader using Astyanax
- How to convert an Int to a String of a given length with leading zeros to align?
- aggregating multiple values at once
- Migrating for Json4S to Circe
- Scala fast generation of upper triangular matrix coordinates
- Reference is not fully initialized
- Injecting database methods from the service layer to the storage layer
- How to SparkSQL load csv with header on FROM statement
- Does asyncronous I/O consume threads?
- How to get some certain field only from a recordset?
- Akka Actor Restart After a Time lapse
- When to design for scalability?
- Understand Spark WindowSpec#rangeBetween
- functional approach suggestions instead of using mutablelist
- scala spark partitionby and get current partition name
- How to split a Play application into several parts
- Spark dataframe: Pivot and Group based on columns
- Spark DataFrame Add Column with Value
- Type-safe Builder Library for Scala and Java
- Scala Method Parameters - Combining variable arguments and default parameters
- Running .sh file on Windows in git bash gives an error: Unable to find Digest::SHA or Digest::SHA::PurePerl
- How to add every element of a list at the end of every element of another list in scala?
- Substitute for thread executor pool in Scala