Bug 10468 - DOM/AST: TypeDeclaration#isLocalTypeDeclaration doesn't consider anonymous types
Summary: DOM/AST: TypeDeclaration#isLocalTypeDeclaration doesn't consider anonymous types
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 2.0 M4   Edit
Assignee: Jim des Rivieres CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-02-28 08:32 EST by Dirk Baeumer CLA
Modified: 2002-03-01 04:35 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 Dirk Baeumer CLA 2002-02-28 08:32:32 EST
Build 20020226

Anonymous types can also be local. As well checking for member types if the are 
anonymous is incorrect too. Either these methods (yes I have read the comment) 
do what the name suggests or we remove them. Currently they are only a source 
for problems.
Comment 1 Olivier Thomann CLA 2002-02-28 09:29:14 EST
I vote to remove them. They simply don't check what they should. An anonymous type is a local type, 
but this method cannot be used for them.

public boolean isMemberTypeDeclaration() 
{
	ASTNode parent = getParent();
	return (parent instanceof TypeDeclaration)
		|| 
(parent instanceof ClassInstanceCreation);
}
should be:

public boolean 
isMemberTypeDeclaration() {
	return getParent() instanceof TypeDeclaration;
}
Comment 2 Dirk Baeumer CLA 2002-02-28 09:37:51 EST
I know that removing them is the easiest for you but actual we need methods to 
deceide if a type declaration is local or not. Since you know the AST and its 
structure I think the node should provide corresponding methods. Otherwise 
clients have to implement it by themselves and for sure they will do it 
incorrect. 
Comment 3 Olivier Thomann CLA 2002-02-28 09:43:35 EST
Then I suggest the following code:
	public boolean isMemberTypeDeclaration() {
		return getParent() instanceof TypeDeclaration;
	}

and:
	public boolean isLocalTypeDeclaration() {
		return getParent() instanceof TypeDeclarationStatement;
	}
We should add a isLocalTypeDeclaration on the ClassInstanceCreation node which 
would return:
	public boolean isLocalTypeDeclaration() {
		return hasBody;
	}

NOTE: A local type is a type which is contained in a statement. Its parent 
should be a TypeDeclarationStatement.
A member type is a type for which the parent is a type declaration. An 
anonymous type is not a "member" type in the inner specification. It is a local 
type.
I need to add tests to ensure these APIs work as expected.
What do you think?
Comment 4 Jim des Rivieres CLA 2002-02-28 10:42:10 EST
Anonymous types are represented by ClassInstanceCreation expressions;
they are not represented by TypeDeclaration nodes.

isLocalTypeDeclaration is specified (and implemented) incorrectly:
a TypeDeclaration declares a local type if it's parent is a 
TypeDeclarationStatement (not a Block). 

If class C is declared as a member of a local (including anonymous) type,
then it is considered a member type - even when the type it is nested inside
is not.