Community
Participate
Working Groups
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.
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.