Patson Luk created JASSIST-251:
----------------------------------
Summary: Support looking up nested class with non standard anonymous class
name (from Scala)
Key: JASSIST-251
URL:
https://issues.jboss.org/browse/JASSIST-251
Project: Javassist
Issue Type: Feature Request
Reporter: Patson Luk
Assignee: Shigeru Chiba
Attachments: Test$$anonfun$main$1.class, Test$.class
The existing code within CtClassType.getNestedClasses() uses check
{code}
if (name.lastIndexOf('$') < thisName.length())
{code}
To check if the names from the "InnerClasses" attribute are the immediate nested
class of the current CtClassType instance.
This works fine for well formatted anonymous class name that adheres to the Java Language
spec that:
{quote}
The binary name of an anonymous class (ยง15.9.5) consists of the binary
name of its immediately enclosing type, followed by $, followed by a nonempty
sequence of digits.
{quote}
However, for JVM language like Scala that converts anonymous class to names that do not
follow that standard, for sample code like
{code}
object Test {
def main(args: Array[String]): Unit = {
val list = List(1, 2, 3)
println(list.map(_ * 2))
}
}
{code}
generates several java class files. Two class files (attached) in particular
"Test$.class" and "Test$$anonfun$main$1.class" show "immediate
nested classes" relationship in the generated byte code as
# Test$ has InnerClasses attribute entry with name "Test$$anonfun$main$1"
# Test$$anonfun$main$1 has EnclosingMethod attribute value "Test$.main"
But "Test$$anonfun$main$1.class" does not conform to the JLS naming (otherwise
it should have been "Test$$1.class" instead)
With the current check in place for getNestedClasses(), the anonymous class will not be
returned as an immediate nested class of "Test$", however with a minor change it
should be able to do that:
{code}
// if it is an immediate nested class
//if (name.lastIndexOf('$') < thisName.length()) instead of checking name,
check the actual declaring class
CtClass nestedClass = classPool.get(name);
CtClass declaringClass = nestedClass.getDeclaringClass();
if (declaringClass == null || declaringClass.equals(this)) {
list.add(nestedClass);
}
{code}
I tagged this as a feature request as i do not know the policy of supporting non Java
language.
Please kindly advise and many thanks in advance!
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)