Community
Participate
Working Groups
For the following class: public final class OuterClass { void outerMethod() { new Object() { class Subroutine { } private void innerMethod() { Subroutine sub = null; } }; } } When one presses ctrl+shift+o the following statement is added: import OuterClass..Subroutine;
it actually puts something even stranger: import OuterClass.$local$.Subroutine;
the type binding for A reports as 'isMember()' and 'isLocal' at the same time.
You mean the type binding for 'sub'?
Martin, isMember() and isLocal() answers true in this specific case. This is normal. Strictly speaking this type is a member type and it is also a local type. So in your algorithm you should check first isLocal() and then isMember(). Ok with that?
I think what you mean is isNested: The Javadoc of ITypeBinding.isMember says: * <p> * A member type is any class or interface declared as a member of * another class or interface. A member type is a subspecies of nested * type, and mutually exclusive with local types. * </p>
Then the doc of isMember() should be fixed.
I agree with Martin that the problem is that Subroutine is being classified as isLocal and isMember. It should be classified as !isLocal and isMember, because it is a member of a type. This aspect of the spec is consistent with JLS 14.3 ("A local class is a nested class that is not a member of any class and that has a name.") Our API is inconsistent with the JLS wrt local and anonymous classes (JLS says anonymous classes are not local classes, whereas our API says that anonymous classes are a subspecies of local classes). While I wish we were better aligned with the JLS in all aspects, I believe we should leave the API as is and bring the implementation into line with it. Expected outcome: OuterClass - isClass, isTopLevel, !isLocal, !isAnonymous, !isMember, !isNested anon #1 - isClass, !isTopLevel, isLocal, isAnonymous, !isMember, isNested Subroutine - isClass, !isTopLevel, !isLocal, !isAnonymous, isMember, isNested
I will implement Jim's last statement. Is this ok for you?
I have a fix for this one, but I won't release it as long as the JDT/UI tests are not green. Even if without my changes, I have many errors, so it is impossible for me to check that this fix doesn't break anything. All JDT Core tests are green with the fix.
I fixed the tests. Please try again. Is there a name for all types that are visibile, e.g can be imported (top level or a member where no declaring type is anonymous or local)? This is a test I have to perform often and which I thought is solved with binding.isTopLevel || binding.isMember. From this PR I see that isMember is not enough and that I have to test the parents.
Your test binding.isTopLevel || binding.isMember is not enough anyway. You really need to find out that all parents are members or top levels. So I will release my change as soon as I run all the tests. We will have a consistent behavior according to the specs, but that won't solve your problem if you don't look through the parents.
I still have numerous errors in ExtractInterfacesTests.
I fixed the bug with isLocal() answering true for a member class of a local class. Fixed and released in 2.1 stream. Regression test added.
Verified.