I am trying to get parent Method of a PsiElement. I get null by using the PsiTreeUtil.getParentOfType method.
PsiMethod m = PsiTreeUtil.getParentOfType(psiElement, PsiClass.class);
But it works when I iterate through the tree :
PsiMethod m;
while(true){
psiElement = psiElement.getParent();
try{
m = (PsiMethod)psiElement ;
break;
}
catch(ClassCastException e)
{
}
}
Can somebody explain me why PsiTreeUtil.getParentOfType gives null while by iterating it doesn't give null and I get required result?
I used this and it works now.