Summary: | DOM/AST: TypeDeclaration#isLocalTypeDeclaration doesn't consider anonymous types | ||
---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Dirk Baeumer <dirk_baeumer> |
Component: | Core | Assignee: | Jim des Rivieres <jeem> |
Status: | RESOLVED FIXED | QA Contact: | |
Severity: | normal | ||
Priority: | P3 | CC: | Olivier_Thomann |
Version: | 2.0 | ||
Target Milestone: | 2.0 M4 | ||
Hardware: | PC | ||
OS: | Windows 2000 | ||
Whiteboard: |
Description
Dirk Baeumer
2002-02-28 08:32:32 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; } 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. 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? 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. |