1

I am trying to insert class comments for quasi quotes like so

q"""
    package somePackage {
        /**
         * This is a comment
         */
        public class SomeClass {
        }
    }
"""

But its throwing an exception

Exception in thread "main" java.lang.IllegalArgumentException: not legal package stat: <type ?>
    at scala.reflect.internal.ReificationSupport$ReificationSupportImpl.mkPackageStat(ReificationSupport.scala:156)
    at scala.reflect.internal.ReificationSupport$ReificationSupportImpl.mkPackageStat(ReificationSupport.scala:11)
    at database.generate.jooq.JooqGenerate.generateDaos(JooqGenerate.scala:65)
    at database.generate.GenerateDao$.apply(GenerateDao.scala:25)
    at Test$.main(Test.scala:7)
    at Test.main(Test.scala)

1 Answers1

1

This works for me:

scala> import scala.reflect.runtime.universe._
import scala.reflect.runtime.universe._

scala> q"""
     | package somePackage {
     | /**
     | * This is a comment
     | */
     | class SomeClass()
     | }
     | """
res0: reflect.runtime.universe.PackageDef =
package somePackage {
  class SomeClass extends scala.AnyRef {
    def <init>() = {
      super.<init>();
      ()
    }
  }
}

scala>

scala>

Is it that you are using java class in the quotes, that is causing the problem ?

Also check which Scala version you are using

scala> util.Properties.versionString
res2: String = version 2.11.7

And the tutorial here: http://docs.scala-lang.org/overviews/quasiquotes/intro.html

tuxdna
  • 8,257
  • 4
  • 43
  • 61
  • Your response compiles, but it doesn't add the comment in the tree, which is what I am trying to do to generate files –  Oct 08 '15 at 17:11
  • Can you share the code which demonstrates the comments issue ? – tuxdna Oct 09 '15 at 14:36