From 856b684824f92718f81d19a7d4d6bf16d68705f5 Mon Sep 17 00:00:00 2001 From: Wei Li Date: Mon, 6 Oct 2014 07:57:29 +0000 Subject: [PATCH] Bug 426675: fix "index update with modified files" for a sub-directory Change-Id: I3dad716cd11a464c97ee35fdabb8b9762238ccf3 Signed-off-by: Wei Li Reviewed-on: https://git.eclipse.org/r/34434 Reviewed-by: Sergey Prigogin Tested-by: Sergey Prigogin --- .../ui/actions/AbstractUpdateIndexAction.java | 24 +++++++++---------- .../ui/actions/RebuildIndexAction.java | 20 +++++++++++----- .../FindUnresolvedIncludesProjectAction.java | 8 +++---- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/AbstractUpdateIndexAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/AbstractUpdateIndexAction.java index 763ffb36fa4..b5e88a5dbe6 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/AbstractUpdateIndexAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/AbstractUpdateIndexAction.java @@ -44,13 +44,13 @@ public abstract class AbstractUpdateIndexAction implements IObjectActionDelegate if(!(fSelection instanceof IStructuredSelection) && !(fSelection instanceof ITextSelection)) { return; } - ICProject[] projects = getSelectedCProjects(); - doRun(projects); + ICElement[] elements = getSelectedCElements(); + doRun(elements); } - protected void doRun(ICProject[] projects) { + protected void doRun(ICElement[] elements) { try { - CCorePlugin.getIndexManager().update(projects, getUpdateOptions()); + CCorePlugin.getIndexManager().update(elements, getUpdateOptions()); } catch (CoreException e) { CUIPlugin.log(e); } @@ -70,20 +70,20 @@ public abstract class AbstractUpdateIndexAction implements IObjectActionDelegate public boolean isEnabledFor(ISelection selection) { selectionChanged(null, selection); - ICProject[] project = getSelectedCProjects(); - return project.length > 0; + ICElement[] elements = getSelectedCElements(); + return elements.length > 0; } - protected ICProject[] getSelectedCProjects() { - ArrayList tuSelection= new ArrayList(); + protected ICElement[] getSelectedCElements() { + ArrayList tuSelection= new ArrayList(); if(fSelection instanceof IStructuredSelection) { IStructuredSelection resources = SelectionConverter.convertSelectionToResources(fSelection); for (Iterator i= resources.iterator(); i.hasNext();) { Object o= i.next(); if(o instanceof IResource) { - ICProject cproject= CCorePlugin.getDefault().getCoreModel().create(((IResource)o).getProject()); - if(cproject != null) { - tuSelection.add(cproject); + ICElement celement= CCorePlugin.getDefault().getCoreModel().create((IResource)o); + if(celement != null) { + tuSelection.add(celement); } } } @@ -96,6 +96,6 @@ public abstract class AbstractUpdateIndexAction implements IObjectActionDelegate } } } - return tuSelection.toArray(new ICProject[tuSelection.size()]); + return tuSelection.toArray(new ICElement[tuSelection.size()]); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/RebuildIndexAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/RebuildIndexAction.java index a21c823e17a..22bac5f8462 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/RebuildIndexAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/RebuildIndexAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2013 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2014 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,21 +7,29 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.ui.actions; +import java.util.LinkedHashSet; +import java.util.Set; + import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; public class RebuildIndexAction extends AbstractUpdateIndexAction { - @Override - protected void doRun(ICProject[] projects) { - for (ICProject proj : projects) { - if(proj != null) { - CCorePlugin.getIndexManager().reindex(proj); + protected void doRun(ICElement[] elements) { + Set projects = new LinkedHashSet<>(); + for (ICElement element : elements) { + if (element != null) { + projects.add(element.getCProject()); } } + for (ICProject project : projects) { + CCorePlugin.getIndexManager().reindex(project); + } } @Override diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindUnresolvedIncludesProjectAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindUnresolvedIncludesProjectAction.java index 45fd549cfd8..bee7d5b32be 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindUnresolvedIncludesProjectAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindUnresolvedIncludesProjectAction.java @@ -16,7 +16,7 @@ import org.eclipse.search.ui.NewSearchUI; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.internal.ui.actions.AbstractUpdateIndexAction; import org.eclipse.cdt.internal.ui.search.CSearchMessages; @@ -34,13 +34,13 @@ public class FindUnresolvedIncludesProjectAction extends AbstractUpdateIndexActi } @Override - protected void doRun(ICProject[] projects) { - if (projects.length == 0) { + protected void doRun(ICElement[] elements) { + if (elements.length == 0) { StatusLineHandler.showStatusLineMessage(fSite, CSearchMessages.CSearchOperation_operationUnavailable_message); return; } - ISearchQuery searchJob= new CSearchUnresolvedIncludesQuery(projects); + ISearchQuery searchJob= new CSearchUnresolvedIncludesQuery(elements); StatusLineHandler.clearStatusLine(fSite); NewSearchUI.activateSearchResultView();