@Nullable
 public static GrTypeDefinition findContainingClass(GrIntroduceContext context) {
   PsiElement place = context.getPlace();
   while (true) {
     final GrTypeDefinition typeDefinition =
         PsiTreeUtil.getParentOfType(place, GrTypeDefinition.class, true, GroovyFileBase.class);
     if (typeDefinition == null) return null;
     if (!typeDefinition.isAnonymous()
         && (typeDefinition.hasModifierProperty(PsiModifier.STATIC)
             || typeDefinition.getContainingClass() == null)) {
       return typeDefinition;
     }
     place = typeDefinition;
   }
 }