private static IModelTextChangeListener[] gatherListeners(IBaseModel editModel) {
   IModelTextChangeListener[] listeners = new IModelTextChangeListener[0];
   if (editModel instanceof AbstractEditingModel)
     listeners =
         new IModelTextChangeListener[] {
           ((AbstractEditingModel) editModel).getLastTextChangeListener()
         };
   if (editModel instanceof IBundlePluginModelBase) {
     IBundlePluginModelBase modelBase = (IBundlePluginModelBase) editModel;
     listeners = new IModelTextChangeListener[2];
     listeners[F_Bi] = gatherListener(modelBase.getBundleModel());
     listeners[F_Xi] = gatherListener(modelBase.getExtensionsModel());
     return listeners;
   }
   return listeners;
 }
  private static IBaseModel prepareBundlePluginModel(
      IFile[] files, IDocument[] docs, boolean generateEditNames) throws CoreException {
    AbstractEditingModel[] models = new AbstractEditingModel[docs.length];

    boolean isFragment = false;
    models[F_Bi] = prepareAbstractEditingModel(files[F_Bi], docs[F_Bi], generateEditNames);
    if (models[F_Bi] instanceof IBundleModel)
      isFragment =
          ((IBundleModel) models[F_Bi]).getBundle().getHeader(Constants.FRAGMENT_HOST) != null;

    IBundlePluginModelBase pluginModel;
    if (isFragment) pluginModel = new BundleFragmentModel();
    else pluginModel = new BundlePluginModel();

    pluginModel.setBundleModel((IBundleModel) models[F_Bi]);
    if (files.length > F_Xi && files[F_Xi] != null) {
      models[F_Xi] = prepareAbstractEditingModel(files[F_Xi], docs[F_Xi], generateEditNames);
      pluginModel.setExtensionsModel((ISharedExtensionsModel) models[F_Xi]);
    }
    return pluginModel;
  }