GroovyPsiElement (PsiElement context) { while (context != null) { if (context instanceof GrTypeDefinition) { return (GroovyPsiElement)context; } else if (context instanceof GroovyFileBase && context.isPhysical()) { return (GroovyPsiElement)context; } context = context.getContext(); } return null; }