Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: Scala 2.10.0-RC1, Scala 2.11.0-M1
    • Fix Version/s: Backlog
    • Component/s: Reflection
    • Labels:
      None

      Description

      scala> import scala.reflect.runtime.universe._
      import scala.reflect.runtime.universe._
       
      scala> rootMirror.staticPackage("java.lang").typeSignature.members.size
      res0: Int = 16
       
      scala> rootMirror.staticPackage("java.lang").typeSignature.members.flatMap(_.typeSignature.members)
      res1: Iterable[reflect.runtime.universe.Symbol] = List(value serialVersionUID, constructor StringBuilder, ....)
       
      scala> rootMirror.staticPackage("java.lang").typeSignature.members.size
      res2: Int = 31
      

        Attachments

          Activity

          Hide
          burmako Eugene Burmako added a comment - - edited

          Reflection uses classloaders, therefore it cannot exhaustively enumerate members of packages. Any ideas how to defeat that?

          Show
          burmako Eugene Burmako added a comment - - edited Reflection uses classloaders, therefore it cannot exhaustively enumerate members of packages. Any ideas how to defeat that?
          Hide
          retronym Jason Zaugg added a comment -

          While it can't enumerate members of packages in general, it can be done if you make some assumptions about the classloader (See, for example, Spring's PathMatchingResourcePatternResolver.)

          I don't suggest to offer that functionality out of the box (maintaining and supporting that sort of code is expensive), but you might offer a hook at the point of mirror creation where the caller could provide a package enumerator.

          Show
          retronym Jason Zaugg added a comment - While it can't enumerate members of packages in general, it can be done if you make some assumptions about the classloader (See, for example, Spring's PathMatchingResourcePatternResolver .) I don't suggest to offer that functionality out of the box (maintaining and supporting that sort of code is expensive), but you might offer a hook at the point of mirror creation where the caller could provide a package enumerator.
          Hide
          clhodapp Chris Hodapp added a comment -

          Also see Reflections, which is more focused on finding classes.

          Show
          clhodapp Chris Hodapp added a comment - Also see Reflections , which is more focused on finding classes.
          Hide
          clhodapp Chris Hodapp added a comment - - edited

          It's worse than you claim: simply being loaded is not enough to make a class show up:

           
          package foo
           
          import reflect.runtime.universe._
          import reflect.runtime.{currentMirror=>cm}
           
          class C
           
          object Main extends App {
           
          	val pkg = cm.staticPackage("foo")
          	println(pkg.moduleClass.typeSignature.members)
           
          	pkg.moduleClass.typeSignature.member(newTypeName("Main"))
          	println(pkg.moduleClass.typeSignature.members)
           
          	cm.classLoader.loadClass("foo.C")
          	println(pkg.moduleClass.typeSignature.members)
           
          	pkg.moduleClass.typeSignature.member(newTypeName("C"))
          	println(pkg.moduleClass.typeSignature.members)
           
          }
          

          [info] Running foo.Main
          Scope{
           
          }
          Scope{
            object Main;
            class Main extends
          }
          Scope{
            object Main;
            class Main extends
          }
          Scope{
            object C;
            class C extends ;
            object Main;
            class Main extends
          }
          

          Show
          clhodapp Chris Hodapp added a comment - - edited It's worse than you claim: simply being loaded is not enough to make a class show up:   package foo   import reflect.runtime.universe._ import reflect.runtime.{currentMirror=>cm}   class C   object Main extends App {   val pkg = cm.staticPackage("foo") println(pkg.moduleClass.typeSignature.members)   pkg.moduleClass.typeSignature.member(newTypeName("Main")) println(pkg.moduleClass.typeSignature.members)   cm.classLoader.loadClass("foo.C") println(pkg.moduleClass.typeSignature.members)   pkg.moduleClass.typeSignature.member(newTypeName("C")) println(pkg.moduleClass.typeSignature.members)   } [info] Running foo.Main Scope{   } Scope{ object Main; class Main extends } Scope{ object Main; class Main extends } Scope{ object C; class C extends ; object Main; class Main extends }

            People

            • Assignee:
              Unassigned
              Reporter:
              extempore Paul Phillips
            • Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

              • Created:
                Updated: