[jboss-jira] [JBoss JIRA] (JASSIST-235) CtClassType.getEnclosingBehavior()

Maximilian Scherr (JIRA) issues at jboss.org
Wed Oct 22 11:31:35 EDT 2014


Maximilian Scherr created JASSIST-235:
-----------------------------------------

             Summary: 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


The method getEnclosingMethod() in CtClassType (or CtClass) only works with methods.

However, the Enclosing Method Attribute is not restricted to (Ct)Methods, e.g. method-local inner classes declared within constructors.

I suggest the addition of a getEnclosingBehavior() method as follows:

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;        
}



--
This message was sent by Atlassian JIRA
(v6.3.1#6329)


More information about the jboss-jira mailing list