Community
Participate
Working Groups
Eclipse compiler does not provide info about enclosing class and enclosing method for local classes. The following test being compiled with javac prints needed names while Eclipse compiler prints null: import java.lang.reflect.*; public class TestLocalClass { public void test() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { class LocalClass { public void method() { } }; LocalClass localClass = new LocalClass(); Class cc = localClass.getClass(); System.out.println("enclosing class = " + cc.getEnclosingClass()); System.out.println("enclosing method = " + cc.getEnclosingMethod()); } public static void main(String args[]) { TestLocalClass t = new TestLocalClass(); try { t.test(); } catch (Exception e) { e.printStackTrace(); } } }
Olivier - are we missing some classfile attributes ?
I get: enclosing class = class TestLocalClass enclosing method = public void TestLocalClass.test() throws java.lang.NoSuchMethodException,java.lang.IllegalAccessException,java.lang.reflect.InvocationTargetException Using latest and 3.2.0 (v_671). Are you compiling in 1.5 compliance ?
Those attributes are only available in compliance 1.5. Could you please provide your compiler settings?
Added regression test in: org.eclipse.jdt.core.tests.compiler.regression.EnclosingMethodAttributeTest#test003
Closing as INVALID. Please reopen if you are using compliance 1.5.
Checked with 3.2.0: indeed the requested attributes are present if compiled with "-1.5" option.