protected List addToClasspath(List elements, IJavaProject project, IOutputFolderQuery query, IProgressMonitor monitor) throws OperationCanceledException, CoreException {
protected List addToClasspath(List elements, IJavaProject project, OutputFolderQuery query, IProgressMonitor monitor) throws OperationCanceledException, CoreException {
    protected List addToClasspath(List elements, IJavaProject project, IOutputFolderQuery query, IProgressMonitor monitor) throws OperationCanceledException, CoreException {        if (monitor == null)            monitor= new NullProgressMonitor();        try {            monitor.beginTask(NewWizardMessages.getString("ClasspathModifier.Monitor.AddToBuildpath"), 2 * elements.size() + 3); //$NON-NLS-1$            IWorkspaceRoot workspaceRoot= JavaPlugin.getWorkspace().getRoot();                        if (project.getProject().hasNature(JavaCore.NATURE_ID)) {                IPath outputLocation= project.getOutputLocation();                IPath projPath= project.getProject().getFullPath();                List existingEntries= getExistingEntries(project);                if (!(elements.size() == 1 && elements.get(0) instanceof IJavaProject) && //if only the project should be added, then the query does not need to be executed                         (outputLocation.equals(projPath) || query.getDesiredOutputLocation().segmentCount() == 1)) {                    if (query.doQuery(false, getValidator(elements, project), project)) {                        project.setOutputLocation(query.getOutputLocation(), null);                        // remove the project                        if (query.removeProjectFromClasspath()) {                            removeFromClasspath(project, existingEntries, null);                        }                                                IRemoveOldBinariesQuery reorgQuery= BuildPathsBlock.getRemoveOldBinariesQuery(null);                        if (BuildPathsBlock.hasClassfiles(project.getProject()) && outputLocation.equals(projPath) && reorgQuery.doQuery(projPath)) {                            IResource res= workspaceRoot.findMember(outputLocation);                            if (res instanceof IContainer && BuildPathsBlock.hasClassfiles(res)) {                                BuildPathsBlock.removeOldClassfiles(res);                            }                        }                        outputLocation= project.getOutputLocation();                    } else                        return new ArrayList();                }                                List newEntries= new ArrayList();                for(int i= 0; i < elements.size(); i++) {                    Object element= elements.get(i);                    CPListElement entry;                    if (element instanceof IResource)                        entry= addToClasspath((IResource)element, existingEntries, newEntries, project, monitor);                    else                        entry= addToClasspath((IJavaElement)element, existingEntries, newEntries, project, monitor);                    newEntries.add(entry);                }                                setNewEntry(existingEntries, newEntries, project, new SubProgressMonitor(monitor, 1));                                updateClasspath(existingEntries, project, new SubProgressMonitor(monitor, 1));                                List result= new ArrayList();                for(int i= 0; i < newEntries.size(); i++) {                    IClasspathEntry entry= ((CPListElement)newEntries.get(i)).getClasspathEntry();                    IJavaElement root;                    if (entry.getPath().equals(project.getPath()))                        root= project;                    else                        root= project.findPackageFragmentRoot(entry.getPath());                    result.add(root);                }                                return result;            }            else {                StatusInfo rootStatus= new StatusInfo();                rootStatus.setError(NewWizardMessages.getString("ClasspathModifier.Error.NoNatures")); //$NON-NLS-1$                throw new CoreException(rootStatus);            }        } finally {            monitor.done();        }    }