mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-12 02:35:37 +02:00
Bug 425787: Reindex projects when Qt nature is added
If a project description is changed to add the Qt nature then the PDOM needs to be rebuilt. Since index rebuilds are potentially expensive, this first checks to make sure the PDOM does not already contain the QtLinkage. If the linkage already exists, then it will be updated by the normal triggers. The reindex operation should only be needed to add the linkage the first time the nature is added. This does not trigger a reindex if the nature is removed. Without the nature, the extra linkage will be safely ignored. The C++ linkage is (proportionally) much larger than the Qt linkage, so it doesn't make sense to spend significant time rebuilding the index just for the small space savings. Change-Id: I263b05e4de407775979843f5d6a9c8c172948d72 Signed-off-by: Andrew Eidsness <eclipse@jfront.com> Reviewed-on: https://git.eclipse.org/r/20680 Tested-by: Hudson CI Reviewed-by: Doug Schaefer <dschaefer@qnx.com> IP-Clean: Doug Schaefer <dschaefer@qnx.com>
This commit is contained in:
parent
801c10d789
commit
25a0992a63
1 changed files with 36 additions and 6 deletions
|
@ -10,15 +10,28 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.qt.core;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.index.IIndexLinkage;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.internal.core.index.CIndex;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexFragment;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IProjectDescription;
|
||||
import org.eclipse.core.resources.IProjectNature;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
|
||||
@SuppressWarnings("restriction")
|
||||
public class QtNature implements IProjectNature {
|
||||
private static final String ID = "org.eclipse.cdt.qt.core.qtNature";
|
||||
|
||||
private IProject project;
|
||||
|
||||
public static boolean hasNature(IProject project) {
|
||||
try {
|
||||
return project.hasNature(ID);
|
||||
|
@ -32,25 +45,43 @@ public class QtNature implements IProjectNature {
|
|||
if (project.isOpen()) {
|
||||
if (hasNature(project))
|
||||
return;
|
||||
|
||||
|
||||
IProjectDescription desc = project.getDescription();
|
||||
String[] oldIds = desc.getNatureIds();
|
||||
String[] newIds = new String[oldIds.length + 1];
|
||||
System.arraycopy(oldIds, 0, newIds, 0, oldIds.length);
|
||||
String[] newIds = Arrays.copyOf(oldIds, oldIds.length + 1);
|
||||
newIds[oldIds.length] = ID;
|
||||
desc.setNatureIds(newIds);
|
||||
project.setDescription(desc, monitor);
|
||||
}
|
||||
}
|
||||
|
||||
private IProject project;
|
||||
|
||||
@Override
|
||||
public void configure() throws CoreException {
|
||||
ICProject cProject = CCorePlugin.getDefault().getCoreModel().create(project);
|
||||
if (cProject == null)
|
||||
return;
|
||||
|
||||
IIndex index = CCorePlugin.getIndexManager().getIndex(cProject);
|
||||
if (!(index instanceof CIndex))
|
||||
return;
|
||||
|
||||
// Don't reindex the project if it already has a Qt linkage. The index will be updated
|
||||
// by the normal triggers.
|
||||
for(IIndexFragment fragment : ((CIndex) index).getFragments())
|
||||
for(IIndexLinkage linkage : fragment.getLinkages())
|
||||
if (linkage.getLinkageID() == ILinkage.QT_LINKAGE_ID)
|
||||
return;
|
||||
|
||||
// We need to force the index to be rebuilt the first time the Qt nature is added. If
|
||||
// this doesn't happen then the PDOM could have the current version (so nothing would trigger
|
||||
// an update) but no Qt content.
|
||||
CCorePlugin.log(IStatus.INFO, "Reindexing " + project.getName() + " because Qt nature has been added");
|
||||
CCorePlugin.getIndexManager().reindex(cProject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deconfigure() throws CoreException {
|
||||
// This space intentionally left blank.
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -62,5 +93,4 @@ public class QtNature implements IProjectNature {
|
|||
public void setProject(IProject project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue