PsiElement (final GroovyResolveResult result) { final PsiElement elem = result.getElement(); if (elem != null) { if (elem instanceof PsiMember) { return ((PsiMember)elem).getContainingClass(); } else { return PsiUtil.getContextClass(elem); } } return null; }