Scala Programming Language
  1. Scala Programming Language
  2. SI-7072

runtime reflection java interop: inner classes are read in a weird way

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: Scala 2.10.0
    • Fix Version/s: None
    • Component/s: Reflection
    • Labels:
      None

      Description

      package foo;
      
      public class JavaClass_1 {
        private class PrivateJavaClass {}
        protected class ProtectedJavaClass {}
        public class PublicJavaClass {}
      }
      
      =====
      
      import scala.reflect.runtime.universe._
      
      package object foo {
        def testAll(): Unit = {
          test(typeOf[foo.JavaClass_1].typeSymbol)
        }
      
        def test(sym: Symbol): Unit = {
          printSymbolDetails(sym)
          if (sym.isClass || sym.isModule) {
            sym.typeSignature.declarations.toList.sortBy(_.name.toString) foreach test
          }
        }
      
        def printSymbolDetails(sym: Symbol): Unit = {
          def stableSignature(sym: Symbol) = sym.typeSignature match {
            case ClassInfoType(_, _, _) => "ClassInfoType(...)"
            case tpe => tpe.toString
          }
          println("============")
          println(s"sym = $sym, signature = ${stableSignature(sym)}, owner = ${sym.owner}")
          println(s"isPrivate = ${sym.isPrivate}")
          println(s"isProtected = ${sym.isProtected}")
          println(s"isPublic = ${sym.isPublic}")
          println(s"privateWithin = ${sym.privateWithin}")
        }
      }
      
      object Test extends App {
        foo.testAll()
      }
      
      ============
      sym = class JavaClass_1, signature = ClassInfoType(...), owner = package foo
      isPrivate = false
      isProtected = false
      isPublic = true
      privateWithin = <none>
      ============
      sym = class $PrivateJavaClass, signature = ClassInfoType(...), owner = class JavaClass_1
      isPrivate = true
      isProtected = false
      isPublic = false
      privateWithin = <none>
      ============
      sym = value this$0, signature = foo.JavaClass_1, owner = class $PrivateJavaClass
      isPrivate = false
      isProtected = false
      isPublic = false
      privateWithin = package foo
      ============
      sym = object $PrivateJavaClass, signature = JavaClass_1.this.$PrivateJavaClass.type, owner = class JavaClass_1
      isPrivate = true
      isProtected = false
      isPublic = false
      privateWithin = <none>
      ============
      sym = class $ProtectedJavaClass, signature = ClassInfoType(...), owner = class JavaClass_1
      isPrivate = false
      isProtected = true
      isPublic = false
      privateWithin = package foo
      ============
      sym = value this$0, signature = foo.JavaClass_1, owner = class $ProtectedJavaClass
      isPrivate = false
      isProtected = false
      isPublic = false
      privateWithin = package foo
      ============
      sym = object $ProtectedJavaClass, signature = JavaClass_1.this.$ProtectedJavaClass.type, owner = class JavaClass_1
      isPrivate = false
      isProtected = false
      isPublic = false
      privateWithin = package foo
      ============
      sym = class $PublicJavaClass, signature = ClassInfoType(...), owner = class JavaClass_1
      isPrivate = false
      isProtected = false
      isPublic = true
      privateWithin = <none>
      ============
      sym = constructor $PublicJavaClass, signature = (x$1: foo.JavaClass_1)JavaClass_1.this.$PublicJavaClass, owner = class $PublicJavaClass
      isPrivate = false
      isProtected = false
      isPublic = true
      privateWithin = <none>
      ============
      sym = value this$0, signature = foo.JavaClass_1, owner = class $PublicJavaClass
      isPrivate = false
      isProtected = false
      isPublic = false
      privateWithin = package foo
      ============
      sym = object $PublicJavaClass, signature = JavaClass_1.this.$PublicJavaClass.type, owner = class JavaClass_1
      isPrivate = false
      isProtected = false
      isPublic = true
      privateWithin = <none>
      ============
      sym = constructor JavaClass_1, signature = ()foo.JavaClass_1, owner = class JavaClass_1
      isPrivate = false
      isProtected = false
      isPublic = true
      privateWithin = <none>
      

      Problems:
      1) Names of inner classes begin with a dollar.
      2) Inner classes get a strange this$0 value.
      3) Non-public inner classes appear to not have any constructors (possibly related to SI-7071).
      4) Inner classes get companion modules, even though they don't have static definitions.

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Eugene Burmako
            Reporter:
            Eugene Burmako
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:

              Development