/**
   * SIMPLY COPIED;
   *
   * @param currentProject
   * @param containerProject
   * @param className
   * @throws CoreException
   */
  private void doProjectReferenceChange(
      IProject currentProject, IJavaProject containerProject, String className)
      throws CoreException {
    if (currentProject == null || currentProject.equals(containerProject.getProject())) {
      return;
    }

    IProjectDescription desc = currentProject.getDescription();
    IProject[] refs = desc.getReferencedProjects();
    IProject[] newRefs = new IProject[refs.length + 1];
    System.arraycopy(refs, 0, newRefs, 0, refs.length);
    newRefs[refs.length] = containerProject.getProject();
    desc.setReferencedProjects(newRefs);
    currentProject.setDescription(desc, new NullProgressMonitor());

    IPath dependsOnPath = containerProject.getProject().getFullPath();

    IJavaProject javaProject = (IJavaProject) currentProject.getNature(JavaCore.NATURE_ID);
    IClasspathEntry prjEntry = JavaCore.newProjectEntry(dependsOnPath, true);

    boolean dependsOnPresent = false;
    for (IClasspathEntry cpEntry : javaProject.getRawClasspath()) {
      if (cpEntry.equals(prjEntry)) {
        dependsOnPresent = true;
      }
    }

    if (!dependsOnPresent) {
      IClasspathEntry[] entryList = new IClasspathEntry[1];
      entryList[0] = prjEntry;
      ArrayList<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>();
      newEntries.addAll(Arrays.asList(javaProject.getRawClasspath()));
      newEntries.addAll(Arrays.asList(entryList));
      javaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[0]), null);
    }
  }
  public static void updateProjectReferences(
      IIncludePathEntry[] newEntries,
      IIncludePathEntry[] oldEntries,
      final IProject project,
      SubProgressMonitor monitor) {
    try {
      boolean changedReferences = false;
      final IProjectDescription projectDescription = project.getDescription();
      List<IProject> referenced = new ArrayList<IProject>();
      List<String> referencedNames = new ArrayList<String>();
      IProject[] referencedProjects = projectDescription.getReferencedProjects();
      for (IProject refProject : referencedProjects) {
        referenced.add(refProject);
        referencedNames.add(refProject.getName());
      }

      for (IIncludePathEntry oldEntry : oldEntries) {
        if (oldEntry.getEntryKind() == IIncludePathEntry.IPE_PROJECT) {
          String projectName = oldEntry.getPath().lastSegment();
          if (!containsProject(newEntries, projectName)) {
            if (((IncludePathEntry) oldEntry).createdReference) {
              int index = referencedNames.indexOf(projectName);
              if (index >= 0) {
                changedReferences = true;
                referencedNames.remove(index);
                referenced.remove(index);
              }
            }
          }
        }
      }

      for (IIncludePathEntry newEntry : newEntries) {
        if (newEntry.getEntryKind() == IIncludePathEntry.IPE_PROJECT) {
          String projectName = newEntry.getPath().lastSegment();
          if (!containsProject(oldEntries, projectName)) {
            if (!referencedNames.contains(projectName)) {
              changedReferences = true;
              ((IncludePathEntry) newEntry).createdReference = true;
              referenced.add(ResourcesPlugin.getWorkspace().getRoot().getProject(projectName));
              referencedNames.add(projectName);
            }
          }
        }
      }
      if (changedReferences) {
        IProject[] referenceProjects =
            (IProject[]) referenced.toArray(new IProject[referenced.size()]);
        projectDescription.setReferencedProjects(referenceProjects);
        WorkspaceJob job =
            new WorkspaceJob(CoreMessages.getString("IncludePathEntry_2")) // $NON-NLS-1$
            {
              public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
                project.setDescription(projectDescription, monitor);
                return Status.OK_STATUS;
              }
            };
        job.setRule(project.getParent());
        job.schedule();
      }
    } catch (CoreException e) {
      PHPEplPlugin.logError(e);
    }
  }