Community
Participate
Working Groups
20040311 In public class Test { Object a= new Runnable() { public void run() { } }; } type.isLocal returns false for the anonymous type (problem is that the parent is a IField, but the code tests only for methods and initializers)
An anonymous type is not a local type. It will answer true to isAnonymous() and false to isLocal(). Closing as invalid.
A anonymous type is a local type. See e.g. definition in the AST: ITypeBinding.isLocal(): /** * Returns whether this type binding represents a local class. * <p> * A local class is any nested class not declared as a member of * another class or interface. A local class is a subspecies of nested * type, and mutually exclusive with member types. Note that anonymous * classes are a subspecies of local classes. * </p> * <p> * Also note that an interface cannot be local. * </p> * * @return <code>true</code> if this type binding is for a local class, * and <code>false</code> otherwise */
That's AST not Java model. According to the spec (http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#2477 66) "a local class is a nested class (ยง8) that is not a member of any class and that has a name". Since anonymous class doesn't have a name, it is not a local class.
I don't think it's a good idea to introduce two different definitions of 'isLocal' in the AST and in the Java Model. Jeem, what do you think?
Lamentably, there is a subtle difference between the Java model and AST defnitions of isLocal. I'm afraid we're stuck with this.
I think it's not problem to change. IType.isLocal is only useful since 3.0 and the Javadoc spec is not precise at all.
Jerome - I wouldn't distinguish them either. An anonymous is a particular kind of a local type (exactly an anonymous local type).
This is a 2.0 API. We cannot change it now. Martin, whenever an API is fuzzy we always make reference to the Java Language Specification. We cannot change the semantic of "local" or "anonymous" (even if we accidently did it in the DOM AST).