Local class PsiClass.getContainingClass() returns null? Is this a bug?

I have a class for which PsiUtil.isLocalClass(cls) returns true, and
cls.getContainingClass() returns null. Local classes are inner classes,
aren't they? They do have enclosing classes, don't they?

I'll use PsiTreeUtil.getParentOfType for now, but I want to know if this
is a bug or if I need to use getParentOfType for good.

0
Avatar
Permanently deleted user

If the PSI follows the way the JVM does it, then "local" inner classes
(anonymous or not) are not members and thus don't have a containing
class. In that case it wouldn't be a bug.

Vince.


0
Avatar
Permanently deleted user

That's interesting, then, how come I can use private fields from "outer"
class of anonymous/local class? Why did they design the language this
way, do you know?

Vincent Mallet wrote:

If the PSI follows the way the JVM does it, then "local" inner classes
(anonymous or not) are not members and thus don't have a containing
class. In that case it wouldn't be a bug.

Vince.

0

The compiler generates an accessor class. $access$100 or something like that.

0
Avatar
Permanently deleted user

Even though they are not member of the class, they still have access
to the scope they were defined in (local variables of method and other
class members).

Here's another way to look at it. If you had:
class Foo {
public void foo() {
class Bar {
...
}
}
}

It wouldn't make sense to say "Foo.Bar" because Bar can only exist
within the scope of foo(), so it's really not a member of Foo. Even more
so with anonymous classes.

Vince.


0
Avatar
Permanently deleted user

getContainingClass() is a method inherited from PsiMember.
Only true inner classes are class members, aren't they?
Eugene.

"Keith Lea" <keith@cs.oswego.edu> wrote in message
news:d7jkas$5f3$2@is.intellij.net...

I have a class for which PsiUtil.isLocalClass(cls) returns true, and
cls.getContainingClass() returns null. Local classes are inner classes,
aren't they? They do have enclosing classes, don't they?

>

I'll use PsiTreeUtil.getParentOfType for now, but I want to know if this
is a bug or if I need to use getParentOfType for good.



0

请先登录再写评论。