mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 10:46:02 +02:00
Index is rebuilt in presence of team-shared index, bug 239464.
This commit is contained in:
parent
e173a7fb80
commit
a2777c2661
6 changed files with 59 additions and 71 deletions
|
@ -102,6 +102,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
private List<Object> fFilesToRemove = new ArrayList<Object>();
|
||||
private List<String> fFilesUpFront= new ArrayList<String>();
|
||||
private int fASTOptions;
|
||||
private int fForceNumberFiles= 0;
|
||||
|
||||
protected IWritableIndex fIndex;
|
||||
private ITodoTaskUpdater fTodoTaskUpdater;
|
||||
|
@ -128,6 +129,9 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
public final void setParseUpFront(String[] astFilePaths) {
|
||||
fFilesUpFront.addAll(Arrays.asList(astFilePaths));
|
||||
}
|
||||
public final void setForceFirstFiles(int number) {
|
||||
fForceNumberFiles= number;
|
||||
}
|
||||
|
||||
protected abstract IWritableIndex createIndex();
|
||||
protected abstract ICodeReaderFactory createReaderFactory();
|
||||
|
@ -248,15 +252,17 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
}
|
||||
|
||||
private void extractFiles(Map<Integer, List<Object>> files, List<IIndexFragmentFile> iFilesToRemove, IProgressMonitor monitor) throws CoreException {
|
||||
final boolean force= (fUpdateFlags & IIndexManager.UPDATE_ALL) != 0;
|
||||
final boolean forceAll= (fUpdateFlags & IIndexManager.UPDATE_ALL) != 0;
|
||||
final boolean checkTimestamps= (fUpdateFlags & IIndexManager.UPDATE_CHECK_TIMESTAMPS) != 0;
|
||||
final boolean checkConfig= (fUpdateFlags & IIndexManager.UPDATE_CHECK_CONFIGURATION) != 0;
|
||||
|
||||
int count= 0;
|
||||
int forceFirst= fForceNumberFiles;
|
||||
for (final Object tu : fFilesToUpdate) {
|
||||
if (monitor.isCanceled())
|
||||
return;
|
||||
|
||||
final boolean force= forceAll || --forceFirst >= 0;
|
||||
final IIndexFileLocation ifl= fResolver.resolveFile(tu);
|
||||
if (ifl == null)
|
||||
continue;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2006, 2008 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
|
||||
|
@ -8,7 +8,6 @@
|
|||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.pdom;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -39,9 +38,9 @@ public class CModelListener implements IElementChangedListener, IResourceChangeL
|
|||
private static final int UPDATE_LR_CHANGED_FILES_COUNT = 5;
|
||||
|
||||
private PDOMManager fManager;
|
||||
private LinkedHashMap fLRUs= new LinkedHashMap(UPDATE_LR_CHANGED_FILES_COUNT, 0.75f, true) {
|
||||
private LinkedHashMap<ITranslationUnit, ITranslationUnit> fLRUs= new LinkedHashMap<ITranslationUnit,ITranslationUnit>(UPDATE_LR_CHANGED_FILES_COUNT, 0.75f, true) {
|
||||
@Override
|
||||
protected boolean removeEldestEntry(Map.Entry eldest) {
|
||||
protected boolean removeEldestEntry(Map.Entry<ITranslationUnit, ITranslationUnit> eldest) {
|
||||
return size() > UPDATE_LR_CHANGED_FILES_COUNT;
|
||||
}
|
||||
};
|
||||
|
@ -56,21 +55,21 @@ public class CModelListener implements IElementChangedListener, IResourceChangeL
|
|||
return;
|
||||
|
||||
// Walk the delta collecting tu's per project
|
||||
HashMap changeMap= new HashMap();
|
||||
HashMap<ICProject, DeltaAnalyzer> changeMap= new HashMap<ICProject, DeltaAnalyzer>();
|
||||
processDelta(event.getDelta(), changeMap);
|
||||
|
||||
// bug 171834 update last recently changed sources
|
||||
addLastRecentlyUsed(changeMap);
|
||||
|
||||
for (Iterator it = changeMap.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
for (Iterator<?> it = changeMap.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry<?, ?> entry = (Map.Entry<?, ?>) it.next();
|
||||
ICProject cproject = (ICProject) entry.getKey();
|
||||
DeltaAnalyzer analyzer= (DeltaAnalyzer) entry.getValue();
|
||||
fManager.changeProject(cproject, analyzer.getAddedTUs(), analyzer.getChangedTUs(), analyzer.getRemovedTUs());
|
||||
fManager.changeProject(cproject, analyzer.getForcedTUs(), analyzer.getChangedTUs(), analyzer.getRemovedTUs());
|
||||
}
|
||||
}
|
||||
|
||||
private void processDelta(ICElementDelta delta, HashMap changeMap) {
|
||||
private void processDelta(ICElementDelta delta, HashMap<ICProject, DeltaAnalyzer> changeMap) {
|
||||
int type = delta.getElement().getElementType();
|
||||
switch (type) {
|
||||
case ICElement.C_MODEL:
|
||||
|
@ -99,7 +98,7 @@ public class CModelListener implements IElementChangedListener, IResourceChangeL
|
|||
}
|
||||
}
|
||||
|
||||
private void processProjectDelta(ICProject project, ICElementDelta delta, HashMap changeMap) {
|
||||
private void processProjectDelta(ICProject project, ICElementDelta delta, HashMap<ICProject, DeltaAnalyzer> changeMap) {
|
||||
IPDOMIndexer indexer = fManager.getIndexer(project);
|
||||
if (indexer != null && indexer.getID().equals(IPDOMManager.ID_NO_INDEXER)) {
|
||||
return;
|
||||
|
@ -114,23 +113,15 @@ public class CModelListener implements IElementChangedListener, IResourceChangeL
|
|||
changeMap.put(project, deltaAnalyzer);
|
||||
}
|
||||
|
||||
private void addLastRecentlyUsed(HashMap changeMap) {
|
||||
private void addLastRecentlyUsed(HashMap<ICProject, DeltaAnalyzer> changeMap) {
|
||||
boolean addLRUs= false;
|
||||
int count= 0;
|
||||
ITranslationUnit[] newLRUs= new ITranslationUnit[UPDATE_LR_CHANGED_FILES_COUNT];
|
||||
|
||||
for (Iterator iterator = changeMap.values().iterator(); iterator.hasNext();) {
|
||||
DeltaAnalyzer analyzer = (DeltaAnalyzer) iterator.next();
|
||||
List l= analyzer.getAddedList();
|
||||
for (Iterator it = l.iterator(); it.hasNext();) {
|
||||
ITranslationUnit tu= (ITranslationUnit) it.next();
|
||||
newLRUs[count++ % UPDATE_LR_CHANGED_FILES_COUNT]= tu;
|
||||
if (!addLRUs && tu.isHeaderUnit()) {
|
||||
addLRUs= true;
|
||||
}
|
||||
}
|
||||
l= analyzer.getChangedList();
|
||||
for (Iterator it = l.iterator(); it.hasNext();) {
|
||||
for (Iterator<DeltaAnalyzer> iterator = changeMap.values().iterator(); iterator.hasNext();) {
|
||||
DeltaAnalyzer analyzer = iterator.next();
|
||||
List<?> l= analyzer.getChangedList();
|
||||
for (Iterator<?> it = l.iterator(); it.hasNext();) {
|
||||
ITranslationUnit tu= (ITranslationUnit) it.next();
|
||||
newLRUs[count++ % UPDATE_LR_CHANGED_FILES_COUNT]= tu;
|
||||
if (!addLRUs && tu.isHeaderUnit()) {
|
||||
|
@ -141,16 +132,16 @@ public class CModelListener implements IElementChangedListener, IResourceChangeL
|
|||
|
||||
if (count > 0) {
|
||||
if (addLRUs) {
|
||||
for (Iterator it = fLRUs.keySet().iterator(); it.hasNext();) {
|
||||
final ITranslationUnit tu = (ITranslationUnit) it.next();
|
||||
for (Iterator<ITranslationUnit> it = fLRUs.keySet().iterator(); it.hasNext();) {
|
||||
final ITranslationUnit tu = it.next();
|
||||
if (tu.getResource().exists()) {
|
||||
final ICProject cproject= tu.getCProject();
|
||||
DeltaAnalyzer analyzer= (DeltaAnalyzer) changeMap.get(cproject);
|
||||
DeltaAnalyzer analyzer= changeMap.get(cproject);
|
||||
if (analyzer == null) {
|
||||
analyzer= new DeltaAnalyzer();
|
||||
changeMap.put(cproject, analyzer);
|
||||
}
|
||||
analyzer.getChangedList().add(tu);
|
||||
analyzer.getForcedList().add(tu);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.pdom;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
@ -30,8 +29,8 @@ public class IndexUpdatePolicy {
|
|||
private final ICProject fCProject;
|
||||
private int fKind;
|
||||
|
||||
private HashSet<ITranslationUnit> fAdded= new HashSet<ITranslationUnit>();
|
||||
private HashSet<ITranslationUnit> fChanged= new HashSet<ITranslationUnit>();
|
||||
private HashSet<ITranslationUnit> fForce= new HashSet<ITranslationUnit>();
|
||||
private HashSet<ITranslationUnit> fTimestamp= new HashSet<ITranslationUnit>();
|
||||
private HashSet<ITranslationUnit> fRemoved= new HashSet<ITranslationUnit>();
|
||||
private IPDOMIndexer fIndexer;
|
||||
private boolean fReindexRequested;
|
||||
|
@ -56,25 +55,13 @@ public class IndexUpdatePolicy {
|
|||
}
|
||||
|
||||
public void clearTUs() {
|
||||
fAdded.clear();
|
||||
fChanged.clear();
|
||||
fForce.clear();
|
||||
fTimestamp.clear();
|
||||
fRemoved.clear();
|
||||
}
|
||||
|
||||
public boolean hasTUs() {
|
||||
return !(fAdded.isEmpty() && fChanged.isEmpty() && fRemoved.isEmpty());
|
||||
}
|
||||
|
||||
private ITranslationUnit[] getAdded() {
|
||||
return fAdded.toArray(new ITranslationUnit[fAdded.size()]);
|
||||
}
|
||||
|
||||
private ITranslationUnit[] getChanged() {
|
||||
return fChanged.toArray(new ITranslationUnit[fChanged.size()]);
|
||||
}
|
||||
|
||||
private ITranslationUnit[] getRemoved() {
|
||||
return fRemoved.toArray(new ITranslationUnit[fRemoved.size()]);
|
||||
return !(fForce.isEmpty() && fTimestamp.isEmpty() && fRemoved.isEmpty());
|
||||
}
|
||||
|
||||
public void setIndexer(IPDOMIndexer indexer) {
|
||||
|
@ -85,7 +72,7 @@ public class IndexUpdatePolicy {
|
|||
return fIndexer;
|
||||
}
|
||||
|
||||
public IPDOMIndexerTask handleDelta(ITranslationUnit[] added, ITranslationUnit[] changed, ITranslationUnit[] removed) {
|
||||
public IPDOMIndexerTask handleDelta(ITranslationUnit[] force, ITranslationUnit[] changed, ITranslationUnit[] removed) {
|
||||
if (isNullIndexer()) {
|
||||
return null;
|
||||
}
|
||||
|
@ -95,28 +82,27 @@ public class IndexUpdatePolicy {
|
|||
return null;
|
||||
case IndexUpdatePolicy.POST_CHANGE:
|
||||
if (fIndexer != null) {
|
||||
return fIndexer.createTask(added, changed, removed);
|
||||
return fIndexer.createTask(force, changed, removed);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < removed.length; i++) {
|
||||
ITranslationUnit tu = removed[i];
|
||||
fAdded.remove(tu);
|
||||
fChanged.remove(tu);
|
||||
fForce.remove(tu);
|
||||
fTimestamp.remove(tu);
|
||||
fRemoved.add(tu);
|
||||
}
|
||||
for (int i = 0; i < added.length; i++) {
|
||||
ITranslationUnit tu = added[i];
|
||||
if (!fChanged.contains(tu)) {
|
||||
fAdded.add(tu);
|
||||
}
|
||||
for (int i = 0; i < force.length; i++) {
|
||||
ITranslationUnit tu = force[i];
|
||||
fForce.add(tu);
|
||||
fTimestamp.remove(tu);
|
||||
fRemoved.remove(tu);
|
||||
}
|
||||
for (int i = 0; i < changed.length; i++) {
|
||||
ITranslationUnit tu = changed[i];
|
||||
if (!fAdded.contains(tu)) {
|
||||
fChanged.add(tu);
|
||||
if (!fForce.contains(tu)) {
|
||||
fTimestamp.add(tu);
|
||||
}
|
||||
fRemoved.remove(tu);
|
||||
}
|
||||
|
@ -127,13 +113,17 @@ public class IndexUpdatePolicy {
|
|||
IPDOMIndexerTask task= null;
|
||||
if (fIndexer != null && hasTUs()) {
|
||||
if (fKind != IndexUpdatePolicy.MANUAL && !isNullIndexer()) {
|
||||
task= fIndexer.createTask(getAdded(), getChanged(), getRemoved());
|
||||
task= fIndexer.createTask(toarray(fForce), toarray(fTimestamp), toarray(fRemoved));
|
||||
}
|
||||
clearTUs();
|
||||
}
|
||||
return task;
|
||||
}
|
||||
|
||||
private ITranslationUnit[] toarray(HashSet<ITranslationUnit> set) {
|
||||
return set.toArray(new ITranslationUnit[set.size()]);
|
||||
}
|
||||
|
||||
private boolean isNullIndexer() {
|
||||
return fIndexer != null && fIndexer.getID().equals(IPDOMManager.ID_NO_INDEXER);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2007, 2008 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
|
||||
|
@ -8,7 +8,6 @@
|
|||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.pdom.indexer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -23,7 +22,7 @@ import org.eclipse.core.runtime.CoreException;
|
|||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
|
||||
public class DeltaAnalyzer {
|
||||
private List<ITranslationUnit> fAdded= new ArrayList<ITranslationUnit>();
|
||||
private List<ITranslationUnit> fForce= new ArrayList<ITranslationUnit>();
|
||||
private List<ITranslationUnit> fChanged= new ArrayList<ITranslationUnit>();
|
||||
private List<ITranslationUnit> fRemoved= new ArrayList<ITranslationUnit>();
|
||||
|
||||
|
@ -56,7 +55,7 @@ public class DeltaAnalyzer {
|
|||
}
|
||||
break;
|
||||
case ICElementDelta.ADDED:
|
||||
fAdded.add(tu);
|
||||
fChanged.add(tu);
|
||||
break;
|
||||
case ICElementDelta.REMOVED:
|
||||
fRemoved.add(tu);
|
||||
|
@ -67,7 +66,7 @@ public class DeltaAnalyzer {
|
|||
case ICElement.C_CCONTAINER:
|
||||
ICContainer folder= (ICContainer) element;
|
||||
if (delta.getKind() == ICElementDelta.ADDED) {
|
||||
collectSources(folder, fAdded);
|
||||
collectSources(folder, fChanged);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -77,8 +76,8 @@ public class DeltaAnalyzer {
|
|||
container.accept(new TranslationUnitCollector(sources, sources, new NullProgressMonitor()));
|
||||
}
|
||||
|
||||
public ITranslationUnit[] getAddedTUs() {
|
||||
return fAdded.toArray(new ITranslationUnit[fAdded.size()]);
|
||||
public ITranslationUnit[] getForcedTUs() {
|
||||
return fForce.toArray(new ITranslationUnit[fForce.size()]);
|
||||
}
|
||||
|
||||
public ITranslationUnit[] getChangedTUs() {
|
||||
|
@ -89,8 +88,8 @@ public class DeltaAnalyzer {
|
|||
return fRemoved.toArray(new ITranslationUnit[fRemoved.size()]);
|
||||
}
|
||||
|
||||
public List<ITranslationUnit> getAddedList() {
|
||||
return fAdded;
|
||||
public List<ITranslationUnit> getForcedList() {
|
||||
return fForce;
|
||||
}
|
||||
|
||||
public List<ITranslationUnit> getChangedList() {
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
* Markus Schorn - initial API and implementation
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.pdom.indexer;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
|
@ -20,6 +19,7 @@ import org.eclipse.cdt.core.CCorePlugin;
|
|||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
import org.eclipse.cdt.core.dom.IPDOMIndexer;
|
||||
import org.eclipse.cdt.core.dom.IPDOMIndexerTask;
|
||||
import org.eclipse.cdt.core.index.IIndexManager;
|
||||
import org.eclipse.cdt.core.model.AbstractLanguage;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
|
@ -54,9 +54,9 @@ public abstract class PDOMIndexerTask extends AbstractIndexerTask implements IPD
|
|||
private AbstractPDOMIndexer fIndexer;
|
||||
private boolean fWriteInfoToLog;
|
||||
|
||||
protected PDOMIndexerTask(ITranslationUnit[] addFiles, ITranslationUnit[] updateFiles, ITranslationUnit[] removeFiles,
|
||||
protected PDOMIndexerTask(ITranslationUnit[] forceFiles, ITranslationUnit[] updateFiles, ITranslationUnit[] removeFiles,
|
||||
AbstractPDOMIndexer indexer, boolean isFastIndexer) {
|
||||
super(concat(addFiles, updateFiles), removeFiles, new ProjectIndexerInputAdapter(indexer.getProject()), isFastIndexer);
|
||||
super(concat(forceFiles, updateFiles), removeFiles, new ProjectIndexerInputAdapter(indexer.getProject()), isFastIndexer);
|
||||
fIndexer= indexer;
|
||||
setShowActivity(checkDebugOption(TRACE_ACTIVITY, TRUE));
|
||||
setShowInclusionProblems(checkDebugOption(TRACE_INCLUSION_PROBLEMS, TRUE));
|
||||
|
@ -86,6 +86,8 @@ public abstract class PDOMIndexerTask extends AbstractIndexerTask implements IPD
|
|||
setIndexFilesWithoutBuildConfiguration(false);
|
||||
setIndexHeadersWithoutContext(false);
|
||||
}
|
||||
setUpdateFlags(IIndexManager.UPDATE_CHECK_TIMESTAMPS);
|
||||
setForceFirstFiles(forceFiles.length);
|
||||
}
|
||||
|
||||
private static ITranslationUnit[] concat(ITranslationUnit[] added, ITranslationUnit[] changed) {
|
||||
|
|
|
@ -87,7 +87,7 @@ public class PDOMUpdateTask implements IPDOMIndexerTask {
|
|||
}
|
||||
}
|
||||
ITranslationUnit[] tus= set.toArray(new ITranslationUnit[set.size()]);
|
||||
IPDOMIndexerTask delegate= fIndexer.createTask(tus, NO_TUS, NO_TUS);
|
||||
IPDOMIndexerTask delegate= fIndexer.createTask(NO_TUS, tus, NO_TUS);
|
||||
if (delegate instanceof PDOMIndexerTask) {
|
||||
final PDOMIndexerTask task = (PDOMIndexerTask) delegate;
|
||||
task.setUpdateFlags(fUpdateOptions);
|
||||
|
|
Loading…
Add table
Reference in a new issue