From 25a0992a6370fcc181cd715f2fac9b4dccb5a633 Mon Sep 17 00:00:00 2001 From: Andrew Eidsness Date: Wed, 15 Jan 2014 14:15:43 -0500 Subject: [PATCH] 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 Reviewed-on: https://git.eclipse.org/r/20680 Tested-by: Hudson CI Reviewed-by: Doug Schaefer IP-Clean: Doug Schaefer --- .../src/org/eclipse/cdt/qt/core/QtNature.java | 42 ++++++++++++++++--- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/QtNature.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/QtNature.java index cb7d2610980..52786918e02 100644 --- a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/QtNature.java +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/QtNature.java @@ -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; } - }