Symbol => [java class name]

100 views
Skip to first unread message

Eugene Burmako

unread,
Jul 12, 2012, 4:45:01 AM7/12/12
to scala-internals
Is there an existing way to find out a java class name (with all $'s
and $$'s) from a symbol?

Grzegorz Kossakowski

unread,
Jul 12, 2012, 4:49:01 AM7/12/12
to scala-i...@googlegroups.com
On 12 July 2012 10:45, Eugene Burmako <eugene....@epfl.ch> wrote:
Is there an existing way to find out a java class name (with all $'s
and $$'s) from a symbol?

I hope you mean binary name (it's good to learn this terminology), have a look at:

/** These should be moved somewhere like JavaPlatform.
     */
    def javaSimpleName: Name = addModuleSuffix(nme.dropLocalSuffix(simpleName))
    def javaBinaryName: Name = addModuleSuffix(fullNameInternal('/'))
    def javaClassName: String  = addModuleSuffix(fullNameInternal('.')).toString


--
Grzegorz Kossakowski

Eugene Burmako

unread,
Jul 12, 2012, 4:51:55 AM7/12/12
to scala-i...@googlegroups.com
What I need is a name that I can path to Class.forName. I though binary name is something different, no?

Yeah, just found those out methods, but I don't know which of them to use :) Will try all of them out.

Eugene Burmako

unread,
Jul 12, 2012, 5:08:02 AM7/12/12
to scala-internals
For the record, none of those work for non-toplevel classes.

For instance for class B { class B1 } we have the following printout:
javaSimpleName = B1
javaBinaryName = B/B1
javaClassName = B.B1
calculatedName = B$B1 (stuff that I wrote myself)

On Jul 12, 10:51 am, Eugene Burmako <eugene.burm...@epfl.ch> wrote:
> What I need is a name that I can path to Class.forName. I though binary
> name is something different, no?
>
> Yeah, just found those out methods, but I don't know which of them to use
> :) Will try all of them out.
>
> On 12 July 2012 10:49, Grzegorz Kossakowski
> <grzegorz.kossakow...@gmail.com>wrote:
>
>
>
>
>
>
>
> > On 12 July 2012 10:45, Eugene Burmako <eugene.burm...@epfl.ch> wrote:
>
> >> Is there an existing way to find out a java class name (with all $'s
> >> and $$'s) from a symbol?
>
> > I hope you mean binary name (it's good to learn this terminology), have a
> > look at:
>
> > /** These should be moved somewhere like JavaPlatform.
> >      */
> >     def javaSimpleName: Name =
> > addModuleSuffix(nme.dropLocalSuffix(simpleName))
> >     def javaBinaryName: Name = addModuleSuffix(fullNameInternal('/'))
> >     def javaClassName: String  =
> > addModuleSuffix(fullNameInternal('.')).toString
>
> > in Symbol (
> >https://github.com/scala/scala/blob/2.10.x/src/reflect/scala/reflect/...
> > )
>
> > --
> > Grzegorz Kossakowski

Grzegorz Kossakowski

unread,
Jul 12, 2012, 5:22:09 AM7/12/12
to scala-i...@googlegroups.com
On 12 July 2012 11:08, Eugene Burmako <eugene....@epfl.ch> wrote:
For the record, none of those work for non-toplevel classes.

For instance for class B { class B1 } we have the following printout:
javaSimpleName = B1
javaBinaryName = B/B1
javaClassName = B.B1
calculatedName = B$B1 (stuff that I wrote myself)

Actually,

I just found out that our names are wrong. What's called `binary name` by us should be called `internal name` (it's the name that contains slashes instead of dots as separators). Then `binary name` should be a name that contains dollar signs for nested classes and uses dots for separating packages. The simple name should use dots as separators everywhere.

I think it would be good to fix this by introducing javaInternalName method (that has the same implementation as an existing javaBinaryName), deprecating javaBinaryName and by introducing javaBinaryNameReal with a comment explaining why it's called like that. Once we remove old javaBinaryName we can deprecate javaBinaryNameReal and introduce real javaBinaryName.

--
Grzegorz Kossakowski

Roland Kuhn

unread,
Jul 12, 2012, 5:22:43 AM7/12/12
to scala-i...@googlegroups.com
Just to register my interest: where may I find that “stuff you wrote yourself”? I’ll probably have to write something like that very soon myself …
Roland Kuhn
Typesafe – The software stack for applications that scale.
twitter: @rolandkuhn


Eugene Burmako

unread,
Jul 12, 2012, 5:24:31 AM7/12/12
to scala-internals, Greg
I also found `signature :: Type => String`, and it mostly works, but
it messes up classes nested into objects:

object B { class B1 }
signature(<B1 symbol>.asType) = B$$BB$B1
actual class name = B$BB$B1

Grzegorz Kossakowski

unread,
Jul 12, 2012, 5:25:41 AM7/12/12
to Eugene Burmako, scala-internals
On 12 July 2012 11:24, Eugene Burmako <eugene....@epfl.ch> wrote:
I also found `signature :: Type => String`, and it mostly works, but
it messes up classes nested into objects:

object B { class B1 }
signature(<B1 symbol>.asType) = B$$BB$B1
actual class name = B$BB$B1

I really think we should use Symbols for that.

--
Grzegorz Kossakowski

Eugene Burmako

unread,
Jul 12, 2012, 5:26:31 AM7/12/12
to scala-internals
That "stuff" is in the pull request:
https://github.com/scalamacros/kepler/commit/75c9cd5a58cfb423bf2befb2a1eb65a7f45d98e6#L0R933,
though from what I've learned in this discussion it probably
duplicates some pre-existing functionality.

Roland Kuhn

unread,
Jul 12, 2012, 5:29:05 AM7/12/12
to scala-i...@googlegroups.com
Thanks for the pointer, I’m interested in the mechanics of such an implementation as well.

Eugene Burmako

unread,
Jul 12, 2012, 5:30:41 AM7/12/12
to scala-internals
Mechanics? Nothing more than going through all possible cases and
writing an algorithm that captures everything I saw.

On Jul 12, 11:29 am, Roland Kuhn <goo...@rkuhn.info> wrote:
> Thanks for the pointer, I’m interested in the mechanics of such an implementation as well.
>
> 12 jul 2012 kl. 11:26 skrev Eugene Burmako:
>
>
>
>
>
>
>
>
>
> > That "stuff" is in the pull request:
> >https://github.com/scalamacros/kepler/commit/75c9cd5a58cfb423bf2befb2...,

Roland Kuhn

unread,
Jul 12, 2012, 5:32:57 AM7/12/12
to scala-i...@googlegroups.com
precisely :-)

Eugene Burmako

unread,
Jul 12, 2012, 6:04:46 AM7/12/12
to scala-internals
Speaking of going through all cases, here's a printout of testing
various methods of obtaining name-like strings from symbols:
https://gist.github.com/3097064.

Eugene Burmako

unread,
Jul 12, 2012, 6:21:52 AM7/12/12
to scala-internals
From what I can see, javaSimpleName and javaBinaryName are used in
codegen, so, I think, they are okay for what they do.

However signature and javaClassName are only used in reflection. I
think, we can kill `signature` and rewrite `javaClassName` to
correctly allow for all cases.

Miguel Garcia

unread,
Jul 12, 2012, 6:57:07 AM7/12/12
to scala-i...@googlegroups.com

> However signature and javaClassName are only used in reflection.

Symbol.javaClassName is used in ICodeReader too.

Miguel
http://lampwww.epfl.ch/~magarcia/ScalaCompilerCornerReloaded

Paul Phillips

unread,
Jul 12, 2012, 8:59:01 AM7/12/12
to scala-i...@googlegroups.com


On Thu, Jul 12, 2012 at 2:08 AM, Eugene Burmako <eugene....@epfl.ch> wrote:
For the record, none of those work for non-toplevel classes.

That's because you're at the wrong phase.  B1 is B/B1 until flatten, then it's B$B1.

Reply all
Reply to author
Forward
0 new messages