Bug 54430 - bug in IType.isLocal
Summary: bug in IType.isLocal
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.0 M8   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-03-11 04:40 EST by Martin Aeschlimann CLA
Modified: 2004-03-22 12:43 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Aeschlimann CLA 2004-03-11 04:40:26 EST
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)
Comment 1 Jerome Lanneluc CLA 2004-03-19 05:32:21 EST
An anonymous type is not a local type. It will answer true to isAnonymous() and 
false to isLocal().

Closing as invalid.
Comment 2 Martin Aeschlimann CLA 2004-03-19 05:45:28 EST
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
	 */
Comment 3 Jerome Lanneluc CLA 2004-03-19 08:02:50 EST
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.
Comment 4 Martin Aeschlimann CLA 2004-03-19 09:15:01 EST
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?
Comment 5 Jim des Rivieres CLA 2004-03-19 09:37:52 EST
Lamentably, there is a subtle difference between the Java model and AST 
defnitions of isLocal.  I'm afraid we're stuck with this.
Comment 6 Martin Aeschlimann CLA 2004-03-19 09:59:05 EST
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.
Comment 7 Philipe Mulet CLA 2004-03-22 12:07:53 EST
Jerome - I wouldn't distinguish them either. An anonymous is a particular kind 
of a local type (exactly an anonymous local type).
Comment 8 Jerome Lanneluc CLA 2004-03-22 12:43:10 EST
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).