[jboss-jira] [JBoss JIRA] (JASSIST-235) CtClassType.getEnclosingBehavior()
Maximilian Scherr (JIRA)
issues at jboss.org
Wed Oct 22 11:36:35 EDT 2014
[ https://issues.jboss.org/browse/JASSIST-235?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Maximilian Scherr updated JASSIST-235:
--------------------------------------
Description:
The method {{getEnclosingMethod()}} in {{CtClassType}} (or {{CtClass}}) only works with non-constructor methods ({{CtMethod}}).
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 non-constructor methods ({{CtMethod}}).
> 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)
More information about the jboss-jira
mailing list