Language (@NotNull PsiElement elt) { if (!(elt instanceof PsiFile) && elt.getFirstChild() == null) { //is leaf final PsiElement parent = elt.getParent(); if (parent != null) { return parent.getLanguage(); } } return elt.getLanguage(); }