Get outer class's this from PsiElement
Hello guys:
I want to developer a postfix template plugin to generate some codes.
E.g: if I input ["hello".m] ,it will generate [Bar.m(this,"hello") ]
the first arg is a reference of outer class.
so there are the following two cases:
- generate code at outer class scope
- generate code at inner class scope
I need to get the outer PsiClass,but now I only hold the PsiElement of "hello"
How can I get the PsiClass from psiElement?
Thanks
public class Foo{
protected void m(){
//1) Generate Bar.m(this,"hello") here
new AnnoClass(){
public void a(){
//2) Generate Bar.m(Foo.this,"hello") here
}
}
}
}
Please sign in to leave a comment.
Hello Wei,
with these PsiElement methods:
getContext()
getParent()
getChildren()
getPrevSibling()
getNextSibling()
you can traverse across Psi tree.
see if this works for you.
Call PsiTreeUtil.getParentOfType(element, PsiClass.class) twice (the first call will give you the inner class, the second will give you the outer class).