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

          extempore Paul Phillips created issue -
          extempore Paul Phillips made changes -
          Field Original Value New Value
          Description {noformat}
          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, constructor StringBuilder, constructor StringBuilder, constructor StringBuilder, method reverse, method reverse, method insert, method insert, method insert, method insert, method insert, method insert, method insert, method insert, method insert, method insert, method insert, method insert, method insert, method insert, method insert, method insert, method insert, method insert, method insert, method insert, method insert, method insert, method insert, method insert, method deleteCharAt, method deleteCharAt, method delete, method delete, method appendCodePoint, method appendCodePoint, method setCharAt, method setLength, method trimToSize, method ensureCapacity, method capacity, met...
          scala> rootMirror.staticPackage("java.lang").typeSignature.members.size
          res2: Int = 31
          {noformat}
          {noformat}
          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
          {noformat}
          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.
          moors Adriaan Moors made changes -
          Affects Version/s Scala 2.11.0-M1 [ 11305 ]
          Affects Version/s Unreleased-2.11.x [ 11201 ]
          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 }
          moors Adriaan Moors made changes -
          Fix Version/s Ping [ 12105 ]
          moors Adriaan Moors made changes -
          Workflow Open-Closed Workflow v3 [ 36626 ] Copy of Open-Closed Workflow v3 [ 40667 ]
          sethtisue Seth Tisue made changes -
          Fix Version/s Backlog [ 11701 ]
          Fix Version/s Ping [ 12105 ]

            People

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

              Dates

              • Created:
                Updated: