[
https://issues.jboss.org/browse/JASSIST-235?page=com.atlassian.jira.plugi...
]
Maximilian Scherr updated JASSIST-235:
--------------------------------------
Description:
The method {{getEnclosingMethod()}} in {{CtClassType}} (or {{CtClass}}) only works with
methods.
However, the JVM's {{Enclosing Method Attribute}} is not restricted to non-constructor
methods ({{CtMethod}}).
Method-local inner classes can be declared within constructors.
I suggest the addition of a {{getEnclosingBehavior()}} method as follows:
{code:title=getEnclosingBehavior|borderStyle=solid}
public CtBehavior getEnclosingBehavior() throws NotFoundException {
ClassFile cf = getClassFile2();
EnclosingMethodAttribute ema
= (EnclosingMethodAttribute)cf.getAttribute(
EnclosingMethodAttribute.tag);
if (ema != null) {
CtClass enc = classPool.get(ema.className());
String name = ema.methodName();
switch (name) {
case MethodInfo.nameInit:
return enc.getConstructor(ema.methodDescriptor());
case MethodInfo.nameClinit:
return enc.getClassInitializer();
default:
return enc.getMethod(name, ema.methodDescriptor());
}
}
return null;
}
{code}
was:
The method getEnclosingMethod() in CtClassType (or CtClass) only works with methods.
However, the JVM's Enclosing Method Attribute is not restricted to non-constructor
methods (CtMethod).
Method-local inner classes can be declared within constructors.
I suggest the addition of a getEnclosingBehavior() method as follows:
{code:title=getEnclosingBehavior|borderStyle=solid}
public CtBehavior getEnclosingBehavior() throws NotFoundException {
ClassFile cf = getClassFile2();
EnclosingMethodAttribute ema
= (EnclosingMethodAttribute)cf.getAttribute(
EnclosingMethodAttribute.tag);
if (ema != null) {
CtClass enc = classPool.get(ema.className());
String name = ema.methodName();
switch (name) {
case MethodInfo.nameInit:
return enc.getConstructor(ema.methodDescriptor());
case MethodInfo.nameClinit:
return enc.getClassInitializer();
default:
return enc.getMethod(name, ema.methodDescriptor());
}
}
return null;
}
{code}
CtClassType.getEnclosingBehavior()
----------------------------------
Key: JASSIST-235
URL:
https://issues.jboss.org/browse/JASSIST-235
Project: Javassist
Issue Type: Enhancement
Affects Versions: 3.19.0-GA
Reporter: Maximilian Scherr
Assignee: Shigeru Chiba
Priority: Minor
Labels: CtBehavior, class, enclosing, inner, method
Original Estimate: 2 days
Remaining Estimate: 2 days
The method {{getEnclosingMethod()}} in {{CtClassType}} (or {{CtClass}}) only works with
methods.
However, the JVM's {{Enclosing Method Attribute}} is not restricted to
non-constructor methods ({{CtMethod}}).
Method-local inner classes can be declared within constructors.
I suggest the addition of a {{getEnclosingBehavior()}} method as follows:
{code:title=getEnclosingBehavior|borderStyle=solid}
public CtBehavior getEnclosingBehavior() throws NotFoundException {
ClassFile cf = getClassFile2();
EnclosingMethodAttribute ema
= (EnclosingMethodAttribute)cf.getAttribute(
EnclosingMethodAttribute.tag);
if (ema != null) {
CtClass enc = classPool.get(ema.className());
String name = ema.methodName();
switch (name) {
case MethodInfo.nameInit:
return enc.getConstructor(ema.methodDescriptor());
case MethodInfo.nameClinit:
return enc.getClassInitializer();
default:
return enc.getMethod(name, ema.methodDescriptor());
}
}
return null;
}
{code}
--
This message was sent by Atlassian JIRA
(v6.3.1#6329)