From 2d8f966f3b06d96391a0bfd91b2bae084e95bcda Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Thu, 9 Nov 2006 15:09:21 +0000 Subject: [PATCH] Fix for 150075, progress indication for indexer --- .../AbstractGCCBOPConsoleParserUtility.java | 2 +- .../gnu/GCCScannerInfoConsoleParser.java | 7 +- .../scannerconfig2/PerFileSICollector.java | 15 +-- .../index/tests/IndexIncludeTest.java | 6 + .../cdt/core/testplugin/CProjectHelper.java | 1 + core/org.eclipse.cdt.core/.options | 4 + .../org.eclipse.core.resources.prefs | 3 +- .../internal/core/model/TranslationUnit.java | 11 +- .../cdt/core/dom/IPDOMIndexerTask.java | 22 +++- .../internal/core/dom/parser/ASTInternal.java | 1 - .../index/IndexBasedCodeReaderFactory.java | 12 ++ .../core/parser/scanner2/LocationMap.java | 1 - .../cdt/internal/core/pdom/Messages.java | 1 - .../eclipse/cdt/internal/core/pdom/PDOM.java | 3 + .../internal/core/pdom/PDOMIndexerJob.java | 64 +++++++++- .../cdt/internal/core/pdom/PDOMManager.java | 106 +++++++++------- .../internal/core/pdom/indexer/Messages.java | 27 ++++ .../core/pdom/indexer/PDOMIndexerTask.java | 35 +++++- .../indexer/fast/PDOMFastHandleDelta.java | 16 +-- .../pdom/indexer/fast/PDOMFastIndexer.java | 2 +- .../pdom/indexer/fast/PDOMFastIndexerJob.java | 118 +++++++++++------- .../pdom/indexer/fast/PDOMFastReindex.java | 19 +-- .../indexer/full/PDOMFullHandleDelta.java | 17 +-- .../pdom/indexer/full/PDOMFullIndexer.java | 2 +- .../pdom/indexer/full/PDOMFullIndexerJob.java | 93 ++++++-------- .../pdom/indexer/full/PDOMFullReindex.java | 29 +++-- .../core/pdom/indexer/messages.properties | 2 + .../pdom/indexer/nulli/PDOMNullIndexer.java | 12 +- .../internal/core/pdom/messages.properties | 1 - .../eclipse/cdt/internal/core/Messages.java | 26 ++++ .../org/eclipse/cdt/internal/core/Util.java | 6 +- .../cdt/internal/core/messages.properties | 1 + .../ui/includebrowser/IBViewPart.java | 1 + 33 files changed, 453 insertions(+), 213 deletions(-) create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/Messages.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/messages.properties create mode 100644 core/org.eclipse.cdt.core/utils/org/eclipse/cdt/internal/core/Messages.java diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/AbstractGCCBOPConsoleParserUtility.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/AbstractGCCBOPConsoleParserUtility.java index cb1560137f9..60a029e8aea 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/AbstractGCCBOPConsoleParserUtility.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/AbstractGCCBOPConsoleParserUtility.java @@ -99,7 +99,7 @@ public abstract class AbstractGCCBOPConsoleParserUtility { } } - protected IPath convertCygpath(IPath path) { + public static IPath convertCygpath(IPath path) { if (path.segmentCount() > 1 && path.segment(0).equals("cygdrive")) { //$NON-NLS-1$ StringBuffer buf = new StringBuffer(2); buf.append(Character.toUpperCase(path.segment(1).charAt(0))); diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/GCCScannerInfoConsoleParser.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/GCCScannerInfoConsoleParser.java index 5d3eeb5e28d..a7a916fb866 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/GCCScannerInfoConsoleParser.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/GCCScannerInfoConsoleParser.java @@ -25,6 +25,7 @@ import org.eclipse.cdt.make.internal.core.scannerconfig.util.TraceUtil; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; /** * Parses gcc and g++ output for -I and -D parameters. @@ -126,6 +127,10 @@ public class GCCScannerInfoConsoleParser extends AbstractGCCBOPConsoleParser { } } + if (fileName != null && fileName.startsWith("/cygdrive/")) { //$NON-NLS-1$ + fileName= AbstractGCCBOPConsoleParserUtility.convertCygpath(new Path(fileName)).toOSString(); + } + IProject project = getProject(); IFile file = null; List translatedIncludes = includes; @@ -221,7 +226,7 @@ public class GCCScannerInfoConsoleParser extends AbstractGCCBOPConsoleParser { if (postfix.charAt(0) == '-') { // empty -I continue; } - if (postfix.startsWith(SINGLE_QUOTE_STRING) || postfix.startsWith(DOUBLE_QUOTE_STRING)) { //$NON-NLS-1$ //$NON-NLS-2$ + if (postfix.startsWith(SINGLE_QUOTE_STRING) || postfix.startsWith(DOUBLE_QUOTE_STRING)) { delimiter = postfix.substring(0, 1); } String[] tokens = postfix.split(delimiter); diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/PerFileSICollector.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/PerFileSICollector.java index c053134d392..eaf5730749d 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/PerFileSICollector.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/PerFileSICollector.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2006 IBM Corporation 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,6 +7,7 @@ * * Contributors: * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.make.internal.core.scannerconfig2; @@ -83,22 +84,22 @@ public class PerFileSICollector implements IScannerInfoCollector2, IScannerInfoC Integer commandId = (Integer) i.next(); CCommandDSC command = (CCommandDSC) commandIdCommandMap.get(commandId); - Element cmdElem = doc.createElement(CC_ELEM); //$NON-NLS-1$ + Element cmdElem = doc.createElement(CC_ELEM); collectorElem.appendChild(cmdElem); - cmdElem.setAttribute(ID_ATTR, commandId.toString()); //$NON-NLS-1$ + cmdElem.setAttribute(ID_ATTR, commandId.toString()); cmdElem.setAttribute(FILE_TYPE_ATTR, command.appliesToCPPFileType() ? "c++" : "c"); //$NON-NLS-1$ //$NON-NLS-2$ // write command and scanner info command.serialize(cmdElem); // write files command applies to - Element filesElem = doc.createElement(APPLIES_TO_ATTR); //$NON-NLS-1$ + Element filesElem = doc.createElement(APPLIES_TO_ATTR); cmdElem.appendChild(filesElem); Set files = (Set) commandIdToFilesMap.get(commandId); if (files != null) { for (Iterator j = files.iterator(); j.hasNext(); ) { - Element fileElem = doc.createElement(FILE_ELEM); //$NON-NLS-1$ + Element fileElem = doc.createElement(FILE_ELEM); IFile file = (IFile) j.next(); IPath path = file.getProjectRelativePath(); - fileElem.setAttribute(PATH_ATTR, path.toString()); //$NON-NLS-1$ + fileElem.setAttribute(PATH_ATTR, path.toString()); filesElem.appendChild(fileElem); } } @@ -110,7 +111,7 @@ public class PerFileSICollector implements IScannerInfoCollector2, IScannerInfoC */ public void deserialize(Element collectorElem) { for (Node child = collectorElem.getFirstChild(); child != null; child = child.getNextSibling()) { - if (child.getNodeName().equals(CC_ELEM)) { //$NON-NLS-1$ + if (child.getNodeName().equals(CC_ELEM)) { Element cmdElem = (Element) child; boolean cppFileType = cmdElem.getAttribute(FILE_TYPE_ATTR).equals("c++"); //$NON-NLS-1$ CCommandDSC command = new CCommandDSC(cppFileType); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java index 4c5a1db29ae..df5e740d12f 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java @@ -23,7 +23,9 @@ import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexFile; import org.eclipse.cdt.core.index.IIndexInclude; import org.eclipse.cdt.core.index.IndexFilter; +import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.IPathEntry; import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.TestScannerProvider; import org.eclipse.cdt.core.testplugin.util.TestSourceReader; @@ -56,6 +58,10 @@ public class IndexIncludeTest extends IndexTestBase { super.setUp(); if (fProject == null) { fProject= createProject(true, "resources/indexTests/includes"); + IPathEntry[] entries= new IPathEntry[] { + CoreModel.newIncludeEntry(fProject.getPath(), + null, fProject.getResource().getLocation())}; + fProject.setRawPathEntries(entries, NPM); } fIndex= CCorePlugin.getIndexManager().getIndex(fProject); } diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/CProjectHelper.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/CProjectHelper.java index 660c4fbee27..112f49995e4 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/CProjectHelper.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/CProjectHelper.java @@ -92,6 +92,7 @@ public class CProjectHelper { } newProject[0] = CCorePlugin.getDefault().getCoreModel().create(project); if (indexerID != null) { + CCoreInternals.getPDOMManager().setIndexAllFiles(newProject[0], true); CCoreInternals.getPDOMManager().setIndexerId(newProject[0], indexerID); } } diff --git a/core/org.eclipse.cdt.core/.options b/core/org.eclipse.cdt.core/.options index 04b92bf5ec5..d32b220f8ba 100644 --- a/core/org.eclipse.cdt.core/.options +++ b/core/org.eclipse.cdt.core/.options @@ -35,3 +35,7 @@ org.eclipse.cdt.core/debug/typeresolver=false # Reports timings for PDOM org.eclipse.cdt.core/debug/pdomtimings=false + +# Reports sequence of files indexed +org.eclipse.cdt.core/debug/indexer=false + diff --git a/core/org.eclipse.cdt.core/.settings/org.eclipse.core.resources.prefs b/core/org.eclipse.cdt.core/.settings/org.eclipse.core.resources.prefs index 6661dc065ec..a40361e2f59 100644 --- a/core/org.eclipse.cdt.core/.settings/org.eclipse.core.resources.prefs +++ b/core/org.eclipse.cdt.core/.settings/org.eclipse.core.resources.prefs @@ -1,5 +1,6 @@ -#Tue Oct 10 16:32:29 CEST 2006 +#Thu Nov 09 15:08:09 CET 2006 eclipse.preferences.version=1 encoding//parser/org/eclipse/cdt/internal/core/index/messages.properties=8859_1 encoding//parser/org/eclipse/cdt/internal/core/pdom/db/messages.properties=8859_1 +encoding//parser/org/eclipse/cdt/internal/core/pdom/indexer/messages.properties=8859_1 encoding//parser/org/eclipse/cdt/internal/core/pdom/messages.properties=8859_1 diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java index 8770b911a16..12af5d5441b 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java @@ -21,6 +21,7 @@ import org.eclipse.cdt.core.dom.ICodeReaderFactory; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.IBuffer; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; @@ -796,12 +797,14 @@ public class TranslationUnit extends Openable implements ITranslationUnit { ICProject project = getCProject(); IProject rproject = project.getProject(); - IScannerInfoProvider provider = CCorePlugin.getDefault() - .getScannerInfoProvider(rproject); + if (!force && CoreModel.isScannerInformationEmpty(resource)) { + return null; + } + + IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(rproject); if (provider != null) { IResource infoResource = resource != null ? resource : rproject; - IScannerInfo scanInfo = provider - .getScannerInformation(infoResource); + IScannerInfo scanInfo = provider.getScannerInformation(infoResource); if (scanInfo != null) return scanInfo; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOMIndexerTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOMIndexerTask.java index 20800d3e864..21f3f6a49eb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOMIndexerTask.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOMIndexerTask.java @@ -7,6 +7,7 @@ * * Contributors: * QNX Software Systems - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ /** * @@ -31,6 +32,23 @@ public interface IPDOMIndexerTask { public IPDOMIndexer getIndexer(); - public int getFilesToIndexCount(); - + /** + * Returns the remaining subtasks. The count may increase over the time. + * Used by the framework to report progress. + * @since 4.0 + */ + public int getRemainingSubtaskCount(); + + /** + * Used by the framework to report progress. + * @since 4.0 + */ + public int getCompletedSubtaskCount(); + + /** + * Returns information about the current subtask. + * Used by the framework to report progress. + * @since 4.0 + */ + public String getMonitorMessageDetail(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTInternal.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTInternal.java index fbbd74b036d..71e5a8cec3a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTInternal.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTInternal.java @@ -36,7 +36,6 @@ public class ASTInternal { if (scope instanceof IASTInternalScope) { return ((IASTInternalScope) scope).getPhysicalNode(); } - assert false; return null; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexBasedCodeReaderFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexBasedCodeReaderFactory.java index e4194b2459e..a5b17cb2a7a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexBasedCodeReaderFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexBasedCodeReaderFactory.java @@ -14,6 +14,7 @@ package org.eclipse.cdt.internal.core.index; import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashSet; @@ -45,6 +46,7 @@ public class IndexBasedCodeReaderFactory implements ICodeReaderFactory { private final IIndex index; private Map fileInfoCache = new HashMap(); // filename, fileInfo private List usedMacros = new ArrayList(); + private Collection fPathCollector; private static final char[] EMPTY_CHARS = new char[0]; @@ -65,6 +67,9 @@ public class IndexBasedCodeReaderFactory implements ICodeReaderFactory { } public CodeReader createCodeReaderForTranslationUnit(String path) { + if (fPathCollector != null) { + fPathCollector.add(path); + } return ParserUtil.createReader(path, null); } @@ -113,6 +118,9 @@ public class IndexBasedCodeReaderFactory implements ICodeReaderFactory { // still try to parse the file. } + if (fPathCollector != null) { + fPathCollector.add(canonicalPath); + } return ParserUtil.createReader(canonicalPath, null); } @@ -171,4 +179,8 @@ public class IndexBasedCodeReaderFactory implements ICodeReaderFactory { public FileInfo createFileInfo(ITranslationUnit tu) throws CoreException { return createInfo(tu.getLocation().toOSString(), null); } + + public void setPathCollector(Collection paths) { + fPathCollector= paths; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java index dd456751f2d..a172403f452 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java @@ -1132,7 +1132,6 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { break; } if (subC instanceof _CompositeContext) { - assert !subC.containsInContext(globalOffset); externalCount+= subC.getContextLength(); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/Messages.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/Messages.java index 46967a00414..90c19c50ab5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/Messages.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/Messages.java @@ -15,7 +15,6 @@ import org.eclipse.osgi.util.NLS; public class Messages extends NLS { private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.core.pdom.messages"; //$NON-NLS-1$ - public static String PDOMManager_FilesToIndexSubtask; public static String PDOMManager_JoinIndexerTask; public static String PDOMManager_notifyJob_label; public static String PDOMManager_notifyTask_message; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java index f0aa230bb81..afc3b808814 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java @@ -79,6 +79,9 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { // 11 - changed how members work // 12 - one more change for members (is-a list -> has-a list) // 13 - CV-qualifiers, storage class specifiers, function/method annotations + // 14 - added timestamps for files (bug 149571) + // 15 - fixed offsets for pointer types and qualifier types and PDOMCPPVariable (bug 160540). + public static final int LINKAGES = Database.DATA_AREA; public static final int FILE_INDEX = Database.DATA_AREA + 4; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMIndexerJob.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMIndexerJob.java index 6ee02d54059..f671409e4a7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMIndexerJob.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMIndexerJob.java @@ -11,6 +11,8 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom; +import java.text.MessageFormat; + import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.IPDOMIndexer; import org.eclipse.cdt.core.dom.IPDOMIndexerTask; @@ -27,13 +29,15 @@ import org.eclipse.core.runtime.jobs.Job; public class PDOMIndexerJob extends Job { private final PDOMManager pdomManager; - + private int fCompletedSubtaskCount= 0; private IPDOMIndexerTask currentTask; private boolean cancelledByManager= false; private Object taskMutex = new Object(); private IProgressMonitor monitor; + private Job fMonitorJob; + public PDOMIndexerJob(PDOMManager manager) { super(CCorePlugin.getResourceString("pdom.indexer.name")); //$NON-NLS-1$ this.pdomManager = manager; @@ -46,10 +50,13 @@ public class PDOMIndexerJob extends Job { String taskName = CCorePlugin.getResourceString("pdom.indexer.task"); //$NON-NLS-1$ monitor.beginTask(taskName, IProgressMonitor.UNKNOWN); - + startMonitorJob(monitor); try { do { synchronized(taskMutex) { + if (currentTask != null) { + fCompletedSubtaskCount+= currentTask.getCompletedSubtaskCount(); + } currentTask= null; taskMutex.notify(); @@ -69,7 +76,7 @@ public class PDOMIndexerJob extends Job { } catch (Exception e) { CCorePlugin.log(e); - } + } } } while (currentTask != null); @@ -99,8 +106,50 @@ public class PDOMIndexerJob extends Job { } throw e; } + finally { + stopMonitorJob(); + } } + private void stopMonitorJob() { + if (fMonitorJob != null) { + fMonitorJob.cancel(); + } + } + + private void startMonitorJob(final IProgressMonitor monitor) { + fMonitorJob= new Job("cdt indexer monitor job") { //$NON-NLS-1$ + protected IStatus run(IProgressMonitor m) { + while(!m.isCanceled()) { + updateMonitor(monitor); + try { + Thread.sleep(350); + } catch (InterruptedException e) { + return Status.CANCEL_STATUS; + } + } + return Status.OK_STATUS; + } + }; + fMonitorJob.setSystem(true); + fMonitorJob.schedule(); + } + + protected void updateMonitor(IProgressMonitor monitor) { + String detail= null; + synchronized(taskMutex) { + if (currentTask != null) { + detail= currentTask.getMonitorMessageDetail(); + } + } + String msg= pdomManager.getMonitorMessage(); + if (detail != null) { + msg= MessageFormat.format("{0}: {1}", new Object[] {msg, detail}); //$NON-NLS-1$ + } + + monitor.subTask(msg); + } + public void cancelJobs(IPDOMIndexer indexer) { synchronized (taskMutex) { if (currentTask != null && currentTask.getIndexer() == indexer) { @@ -116,4 +165,13 @@ public class PDOMIndexerJob extends Job { } } } + + public int getCompletedSubtaskCount() { + synchronized (taskMutex) { + if (currentTask != null) { + return currentTask.getCompletedSubtaskCount() + fCompletedSubtaskCount; + } + } + return fCompletedSubtaskCount; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java index 025efb14fb9..02b353d1592 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java @@ -92,10 +92,10 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen /** * Protects indexerJob, currentTask and taskQueue. */ - private Object taskQueueMutex = new Object(); - private PDOMIndexerJob indexerJob; - private IPDOMIndexerTask currentTask; - private LinkedList taskQueue = new LinkedList(); + private Object fTaskQueueMutex = new Object(); + private PDOMIndexerJob fIndexerJob; + private IPDOMIndexerTask fCurrentTask; + private LinkedList fTaskQueue = new LinkedList(); /** * Stores mapping from pdom to project, used to serialize\ creation of new pdoms. @@ -420,11 +420,11 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen public void enqueue(IPDOMIndexerTask subjob) { boolean notifyBusy= false; - synchronized (taskQueueMutex) { - taskQueue.addLast(subjob); - if (indexerJob == null) { - indexerJob = new PDOMIndexerJob(this); - indexerJob.schedule(); + synchronized (fTaskQueueMutex) { + fTaskQueue.addLast(subjob); + if (fIndexerJob == null) { + fIndexerJob = new PDOMIndexerJob(this); + fIndexerJob.schedule(); notifyBusy= true; } } @@ -436,14 +436,14 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen IPDOMIndexerTask getNextTask() { boolean idle= false; IPDOMIndexerTask result= null; - synchronized (taskQueueMutex) { - if (taskQueue.isEmpty()) { - currentTask= null; - indexerJob= null; + synchronized (fTaskQueueMutex) { + if (fTaskQueue.isEmpty()) { + fCurrentTask= null; + fIndexerJob= null; idle= true; } else { - result= currentTask= (IPDOMIndexerTask)taskQueue.removeFirst(); + result= fCurrentTask= (IPDOMIndexerTask)fTaskQueue.removeFirst(); } } if (idle) { @@ -454,18 +454,18 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen void cancelledJob(boolean byManager) { boolean idle= false; - synchronized (taskQueueMutex) { - currentTask= null; + synchronized (fTaskQueueMutex) { + fCurrentTask= null; if (!byManager) { - taskQueue.clear(); + fTaskQueue.clear(); } - idle= taskQueue.isEmpty(); + idle= fTaskQueue.isEmpty(); if (idle) { - indexerJob= null; + fIndexerJob= null; } else { - indexerJob = new PDOMIndexerJob(this); - indexerJob.schedule(); + fIndexerJob = new PDOMIndexerJob(this); + fIndexerJob.schedule(); } } if (idle) { @@ -474,25 +474,11 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen } private boolean isIndexerIdle() { - synchronized (taskQueueMutex) { - return currentTask == null && taskQueue.isEmpty(); + synchronized (fTaskQueueMutex) { + return fCurrentTask == null && fTaskQueue.isEmpty(); } } - private int getFilesToIndexCount() { - int count= 0; - synchronized (taskQueueMutex) { - if (currentTask != null) { - count= currentTask.getFilesToIndexCount(); - } - for (Iterator iter = taskQueue.iterator(); iter.hasNext();) { - IPDOMIndexerTask task= (IPDOMIndexerTask) iter.next(); - count+= task.getFilesToIndexCount(); - } - } - return count; - } - public void addProject(ICProject project, ICElementDelta delta) { getIndexer(project, true); // if the indexer is new this triggers a rebuild } @@ -551,18 +537,18 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen } } PDOMIndexerJob jobToCancel= null; - synchronized (taskQueueMutex) { - for (Iterator iter = taskQueue.iterator(); iter.hasNext();) { + synchronized (fTaskQueueMutex) { + for (Iterator iter = fTaskQueue.iterator(); iter.hasNext();) { IPDOMIndexerTask task= (IPDOMIndexerTask) iter.next(); if (task.getIndexer() == indexer) { iter.remove(); } } - jobToCancel= indexerJob; + jobToCancel= fIndexerJob; } if (jobToCancel != null) { - assert !Thread.holdsLock(taskQueueMutex); + assert !Thread.holdsLock(fTaskQueueMutex); jobToCancel.cancelJobs(indexer); } } @@ -584,10 +570,10 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen } private void notifyState(final int state) { - assert !Thread.holdsLock(taskQueueMutex); + assert !Thread.holdsLock(fTaskQueueMutex); if (state == IndexerStateEvent.STATE_IDLE) { - synchronized(taskQueueMutex) { - taskQueueMutex.notifyAll(); + synchronized(fTaskQueueMutex) { + fTaskQueueMutex.notifyAll(); } } @@ -665,7 +651,8 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen if (monitor.isCanceled()) { return false; } - synchronized(taskQueueMutex) { + monitor.subTask(getMonitorMessage()); + synchronized(fTaskQueueMutex) { if (isIndexerIdle()) { return true; } @@ -680,9 +667,8 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen } } - monitor.subTask(MessageFormat.format(Messages.PDOMManager_FilesToIndexSubtask, new Object[] {new Integer(getFilesToIndexCount())})); try { - taskQueueMutex.wait(wait); + fTaskQueueMutex.wait(wait); } catch (InterruptedException e) { return false; } @@ -693,6 +679,32 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen monitor.done(); } } + + String getMonitorMessage() { + assert !Thread.holdsLock(fTaskQueueMutex); + int remainingCount= 0; + int completedCount= 0; + IPDOMIndexerTask currentTask= null; + PDOMIndexerJob currentJob= null; + synchronized (fTaskQueueMutex) { + for (Iterator iter = fTaskQueue.iterator(); iter.hasNext();) { + IPDOMIndexerTask task = (IPDOMIndexerTask) iter.next(); + remainingCount+= task.getRemainingSubtaskCount(); + } + currentTask= fCurrentTask; + currentJob= fIndexerJob; + } + if (currentTask != null) { + remainingCount += currentTask.getRemainingSubtaskCount(); + } + if (currentJob != null) { + completedCount= currentJob.getCompletedSubtaskCount(); + } + return MessageFormat.format("{0}/{1}", new Object[] { //$NON-NLS-1$ + new Integer(completedCount), new Integer(remainingCount+completedCount) + }); + } + public IWritableIndex getWritableIndex(ICProject project) throws CoreException { return fIndexFactory.getWritableIndex(project); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/Messages.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/Messages.java new file mode 100644 index 00000000000..5a4fb9803f5 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/Messages.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2006 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Markus Schorn - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.internal.core.pdom.indexer; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.core.pdom.indexer.messages"; //$NON-NLS-1$ + public static String PDOMIndexerTask_collectingFilesTask; + public static String PDOMIndexerTask_parsingFileTask; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMIndexerTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMIndexerTask.java index 6b40df6f5f1..79e6d0b3e13 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMIndexerTask.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMIndexerTask.java @@ -11,6 +11,7 @@ package org.eclipse.cdt.internal.core.pdom.indexer; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -34,14 +35,18 @@ import org.eclipse.cdt.internal.core.index.IWritableIndex; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Path; public abstract class PDOMIndexerTask implements IPDOMIndexerTask { private static final Object NO_CONTEXT = new Object(); protected static final int MAX_ERRORS = 10; + protected volatile int fTotalTasks= 0; + protected volatile int fCompletedTasks= 0; protected int fErrorCount; protected Map fContextMap= new HashMap(); + protected volatile String fMessage; protected void processDelta(ICElementDelta delta, Collection added, Collection changed, Collection removed) throws CoreException { int flags = delta.getFlags(); @@ -75,16 +80,19 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask { } } - protected void collectSources(ICProject project, final Collection sources, final Collection headers) throws CoreException { + protected void collectSources(ICProject project, final Collection sources, final Collection headers, final boolean allFiles) throws CoreException { + fMessage= Messages.PDOMIndexerTask_collectingFilesTask; project.accept(new ICElementVisitor() { public boolean visit(ICElement element) throws CoreException { switch (element.getElementType()) { case ICElement.C_UNIT: ITranslationUnit tu = (ITranslationUnit)element; if (tu.isSourceUnit()) { - sources.add(tu); + if (allFiles || !CoreModel.isScannerInformationEmpty(tu.getResource())) { + sources.add(tu); + } } - else if (tu.isHeaderUnit()) { + else if (headers != null && tu.isHeaderUnit()) { headers.add(tu); } return false; @@ -109,9 +117,12 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask { } } - protected void parseTU(ITranslationUnit tu) throws CoreException, InterruptedException { + protected void parseTU(ITranslationUnit tu, IProgressMonitor pm) throws CoreException, InterruptedException { try { - doParseTU(tu); + IPath path= tu.getPath(); + fMessage= MessageFormat.format(Messages.PDOMIndexerTask_parsingFileTask, + new Object[]{path.lastSegment(), path.removeLastSegments(1).toString()}); + doParseTU(tu, pm); } catch (CoreException e) { if (++fErrorCount <= MAX_ERRORS) { @@ -123,7 +134,7 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask { } } - abstract protected void doParseTU(ITranslationUnit tu) throws CoreException, InterruptedException; + abstract protected void doParseTU(ITranslationUnit tu, IProgressMonitor pm) throws CoreException, InterruptedException; protected void clearIndex(IWritableIndex index) throws InterruptedException, CoreException { // reset error count @@ -183,4 +194,16 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask { } return null; } + + public String getMonitorMessageDetail() { + return fMessage; + } + + final public int getRemainingSubtaskCount() { + return fTotalTasks-fCompletedTasks; + } + + final public int getCompletedSubtaskCount() { + return fCompletedTasks; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastHandleDelta.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastHandleDelta.java index 8b8feae2591..d2917aad7af 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastHandleDelta.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastHandleDelta.java @@ -31,7 +31,7 @@ class PDOMFastHandleDelta extends PDOMFastIndexerJob { public PDOMFastHandleDelta(PDOMFastIndexer indexer, ICElementDelta delta) throws CoreException { super(indexer); processDelta(delta, changed, changed, removed); - fFilesToIndex= changed.size() + removed.size(); + fTotalTasks= changed.size() + removed.size(); } public void run(IProgressMonitor monitor) { @@ -41,20 +41,20 @@ class PDOMFastHandleDelta extends PDOMFastIndexerJob { setupIndexAndReaderFactory(); registerTUsInReaderFactory(changed); - parseTUs(changed, monitor); - if (monitor.isCanceled()) { - return; - } - Iterator i= removed.iterator(); while (i.hasNext()) { if (monitor.isCanceled()) return; ITranslationUnit tu = (ITranslationUnit)i.next(); removeTU(index, tu); - fFilesToIndex--; + fCompletedTasks++; } - + + parseTUs(changed, monitor); + if (monitor.isCanceled()) { + return; + } + String showTimings = Platform.getDebugOption(CCorePlugin.PLUGIN_ID + "/debug/pdomtimings"); //$NON-NLS-1$ if (showTimings != null && showTimings.equalsIgnoreCase("true")) //$NON-NLS-1$ System.out.println("PDOM Fast Delta Time: " + (System.currentTimeMillis() - start)); //$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexer.java index 376ff1e4a0b..8f071b25e6c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexer.java @@ -46,7 +46,7 @@ public class PDOMFastIndexer implements IPDOMIndexer { public void handleDelta(ICElementDelta delta) throws CoreException { PDOMFastHandleDelta fhd= new PDOMFastHandleDelta(this, delta); - if (fhd.getFilesToIndexCount() > 0) { + if (fhd.getRemainingSubtaskCount() > 0) { CCoreInternals.getPDOMManager().enqueue(fhd); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexerJob.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexerJob.java index 8aa44a292bf..3df97222643 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexerJob.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexerJob.java @@ -16,7 +16,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; -import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -43,6 +43,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; /** * @author Doug Schaefer @@ -53,10 +54,14 @@ abstract class PDOMFastIndexerJob extends PDOMIndexerTask implements IPDOMIndexe protected final PDOMFastIndexer indexer; protected IWritableIndex index; protected IndexBasedCodeReaderFactory codeReaderFactory; - protected volatile int fFilesToIndex= 0; + private boolean fTrace= false; public PDOMFastIndexerJob(PDOMFastIndexer indexer) throws CoreException { this.indexer = indexer; + String trace = Platform.getDebugOption(CCorePlugin.PLUGIN_ID + "/debug/indexer"); //$NON-NLS-1$ + if (trace != null && trace.equalsIgnoreCase("true")) { //$NON-NLS-1$ + fTrace= true; + } } protected void setupIndexAndReaderFactory() throws CoreException { @@ -76,7 +81,7 @@ abstract class PDOMFastIndexerJob extends PDOMIndexerTask implements IPDOMIndexe return indexer; } - protected void doParseTU(ITranslationUnit tu) throws CoreException, InterruptedException { + protected void doParseTU(ITranslationUnit tu, IProgressMonitor pm) throws CoreException, InterruptedException { IPath path = tu.getLocation(); if (path == null) { return; @@ -95,30 +100,31 @@ abstract class PDOMFastIndexerJob extends PDOMIndexerTask implements IPDOMIndexe return; } + LinkedHashSet paths= new LinkedHashSet(); + paths.add(path.toOSString()); + codeReaderFactory.setPathCollector(paths); index.acquireReadLock(); try { // get the AST in a "Fast" way IASTTranslationUnit ast= language.getASTTranslationUnit(codeReader, scanner, codeReaderFactory, index); - - index.acquireWriteLock(1); - try { - // Clear the macros - codeReaderFactory.clearMacroAttachements(); - - // Add the new symbols - addSymbols(ast); - } finally { - index.releaseWriteLock(1); + if (pm.isCanceled()) { + return; } + // Clear the macros + codeReaderFactory.clearMacroAttachements(); + + // Add the new symbols + addSymbols(paths, ast, pm); } finally { index.releaseReadLock(); + codeReaderFactory.setPathCollector(null); } } - protected void addSymbols(IASTTranslationUnit ast) throws InterruptedException, CoreException { + protected void addSymbols(Collection paths, IASTTranslationUnit ast, IProgressMonitor pm) throws InterruptedException, CoreException { // Add in the includes - final LinkedHashMap symbolMap= new LinkedHashMap(); // makes bugs reproducible + final HashMap symbolMap= new HashMap(); // includes IASTPreprocessorIncludeStatement[] includes = ast.getIncludeDirectives(); @@ -162,9 +168,15 @@ abstract class PDOMFastIndexerJob extends PDOMIndexerTask implements IPDOMIndexe for (Iterator iter = symbolMap.entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); + if (pm.isCanceled()) { + return; + } String path= (String) entry.getKey(); FileInfo info= codeReaderFactory.createFileInfo(path); if (!info.fNeedToIndex && info.fFile != null) { + if (fTrace) { + System.out.println("Indexer: skipping " + path); //$NON-NLS-1$ + } iter.remove(); } else { @@ -176,12 +188,26 @@ abstract class PDOMFastIndexerJob extends PDOMIndexerTask implements IPDOMIndexe } } - for (Iterator iter = symbolMap.entrySet().iterator(); iter.hasNext();) { - Map.Entry entry = (Map.Entry) iter.next(); - String path= (String) entry.getKey(); - FileInfo info= codeReaderFactory.createFileInfo(path); - info.fNeedToIndex= false; - addToIndex(path, info, (ArrayList[]) entry.getValue()); + index.acquireWriteLock(1); + try { + for (Iterator iter = paths.iterator(); iter.hasNext();) { + String path = (String) iter.next(); + FileInfo info= codeReaderFactory.createFileInfo(path); + if (!info.fNeedToIndex) { + fTotalTasks++; + } + info.fNeedToIndex= false; + if (fTrace) { + System.out.println("Indexer: adding " + path); //$NON-NLS-1$ + } + addToIndex(path, info, (ArrayList[]) symbolMap.get(path)); + fCompletedTasks++; + if (pm.isCanceled()) { + return; + } + } + } finally { + index.releaseWriteLock(1); } } @@ -207,25 +233,27 @@ abstract class PDOMFastIndexerJob extends PDOMIndexerTask implements IPDOMIndexe } file.setTimestamp(path.toFile().lastModified()); - // includes - ArrayList list= lists[0]; - for (int i = 0; i < list.size(); i++) { - IASTPreprocessorIncludeStatement include= (IASTPreprocessorIncludeStatement) list.get(i); - IIndexFragmentFile destFile= createIndexFile(include.getPath()); - index.addInclude(file, destFile, include); - } + if (lists != null) { + // includes + ArrayList list= lists[0]; + for (int i = 0; i < list.size(); i++) { + IASTPreprocessorIncludeStatement include= (IASTPreprocessorIncludeStatement) list.get(i); + IIndexFragmentFile destFile= createIndexFile(include.getPath()); + index.addInclude(file, destFile, include); + } - // macros - list= lists[1]; - for (int i = 0; i < list.size(); i++) { - index.addMacro(file, (IASTPreprocessorMacroDefinition) list.get(i)); - } + // macros + list= lists[1]; + for (int i = 0; i < list.size(); i++) { + index.addMacro(file, (IASTPreprocessorMacroDefinition) list.get(i)); + } - // symbols - list= lists[2]; - for (int i = 0; i < list.size(); i++) { - index.addName(file, (IASTName) list.get(i)); - } + // symbols + list= lists[2]; + for (int i = 0; i < list.size(); i++) { + index.addName(file, (IASTName) list.get(i)); + } + } } private IIndexFragmentFile createIndexFile(String path) throws CoreException { @@ -244,9 +272,9 @@ abstract class PDOMFastIndexerJob extends PDOMIndexerTask implements IPDOMIndexe return; ITranslationUnit tu = (ITranslationUnit)i.next(); if (tu.isSourceUnit()) { - parseTU(tu); + parseTU(tu, monitor); i.remove(); - fFilesToIndex--; + fCompletedTasks++; } } @@ -259,12 +287,11 @@ abstract class PDOMFastIndexerJob extends PDOMIndexerTask implements IPDOMIndexe FileInfo info= codeReaderFactory.createFileInfo(tu); if (!info.fNeedToIndex) { i.remove(); - fFilesToIndex--; } else if (info.fFile != null) { ITranslationUnit context= findContext(index, info.fFile.getLocation()); if (context != null) { - parseTU(context); + parseTU(context, monitor); } } } @@ -281,14 +308,9 @@ abstract class PDOMFastIndexerJob extends PDOMIndexerTask implements IPDOMIndexe i.remove(); } else { - parseTU(tu); + parseTU(tu, monitor); } - fFilesToIndex--; } } } - - final public int getFilesToIndexCount() { - return fFilesToIndex; - } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastReindex.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastReindex.java index eac4e36cadb..50a0dfba3fe 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastReindex.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastReindex.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.pdom.indexer.fast; import java.util.ArrayList; +import java.util.Collection; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.core.runtime.CoreException; @@ -28,23 +29,27 @@ class PDOMFastReindex extends PDOMFastIndexerJob { public PDOMFastReindex(PDOMFastIndexer indexer) throws CoreException { super(indexer); - fFilesToIndex= 1; + fTotalTasks= 1; } public void run(final IProgressMonitor monitor) { try { long start = System.currentTimeMillis(); - collectSources(indexer.getProject(), fTUs, fTUs); - fFilesToIndex= fTUs.size()+1; + boolean allFiles= getIndexAllFiles(); + Collection headers= allFiles ? fTUs : null; + collectSources(indexer.getProject(), fTUs, headers, allFiles); + fTotalTasks+= fTUs.size()+1; + fCompletedTasks+= 1; - if (fFilesToIndex == 1 || monitor.isCanceled()) { + setupIndexAndReaderFactory(); + clearIndex(index); + + if (getRemainingSubtaskCount() == 1 || monitor.isCanceled()) { return; } - setupIndexAndReaderFactory(); - clearIndex(index); registerTUsInReaderFactory(fTUs); - fFilesToIndex--; + fCompletedTasks++; parseTUs(fTUs, monitor); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullHandleDelta.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullHandleDelta.java index c2ab1285cdf..2edbb7a0ff6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullHandleDelta.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullHandleDelta.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.pdom.indexer.full; import java.util.ArrayList; +import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -35,27 +36,27 @@ class PDOMFullHandleDelta extends PDOMFullIndexerJob { public PDOMFullHandleDelta(PDOMFullIndexer indexer, ICElementDelta delta) throws CoreException { super(indexer); processDelta(delta, changed, changed, removed); - fFilesToIndex= changed.size() + removed.size(); + fTotalTasks= changed.size() + removed.size(); } public void run(IProgressMonitor monitor) { try { long start = System.currentTimeMillis(); setupIndexAndReaderFactory(); - registerTUsInReaderFactory(changed); + registerTUsInReaderFactory(changed, Collections.EMPTY_LIST); - parseTUs(changed, monitor); - if (monitor.isCanceled()) { - return; - } - Iterator i= removed.iterator(); while (i.hasNext()) { if (monitor.isCanceled()) return; ITranslationUnit tu = (ITranslationUnit)i.next(); removeTU(index, tu); - fFilesToIndex--; + fCompletedTasks++; + } + + parseTUs(changed, monitor); + if (monitor.isCanceled()) { + return; } String showTimings = Platform.getDebugOption(CCorePlugin.PLUGIN_ID diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexer.java index 8475e3844ed..bb8954e0cb7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexer.java @@ -42,7 +42,7 @@ public class PDOMFullIndexer implements IPDOMIndexer { public void handleDelta(ICElementDelta delta) throws CoreException { PDOMFullHandleDelta task = new PDOMFullHandleDelta(this, delta); - if (task.getFilesToIndexCount() > 0) { + if (task.getRemainingSubtaskCount() > 0) { CCoreInternals.getPDOMManager().enqueue(task); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexerJob.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexerJob.java index 26842bbe953..985a0ec3fd9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexerJob.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexerJob.java @@ -15,12 +15,10 @@ package org.eclipse.cdt.internal.core.pdom.indexer.full; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.Set; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.IPDOMIndexer; @@ -49,8 +47,7 @@ abstract class PDOMFullIndexerJob extends PDOMIndexerTask implements IPDOMIndexe protected final PDOMFullIndexer indexer; protected IWritableIndex index= null; - private Set filePathsToParse= null; - protected volatile int fFilesToIndex= 0; + private Map filePathsToParse= null; public PDOMFullIndexerJob(PDOMFullIndexer indexer) throws CoreException { this.indexer = indexer; @@ -64,12 +61,16 @@ abstract class PDOMFullIndexerJob extends PDOMIndexerTask implements IPDOMIndexe this.index = ((IWritableIndexManager) CCorePlugin.getIndexManager()).getWritableIndex(indexer.getProject()); } - protected void registerTUsInReaderFactory(Collection tus) throws CoreException { - filePathsToParse= new HashSet(); + protected void registerTUsInReaderFactory(Collection required, Collection optional) throws CoreException { + filePathsToParse= new HashMap(); - for (Iterator iter = tus.iterator(); iter.hasNext();) { + for (Iterator iter = required.iterator(); iter.hasNext();) { ITranslationUnit tu = (ITranslationUnit) iter.next(); - filePathsToParse.add(tu.getLocation().toOSString()); + filePathsToParse.put(tu.getLocation().toOSString(), Boolean.TRUE); + } + for (Iterator iter = optional.iterator(); iter.hasNext();) { + ITranslationUnit tu = (ITranslationUnit) iter.next(); + filePathsToParse.put(tu.getLocation().toOSString(), Boolean.FALSE); } } @@ -81,11 +82,11 @@ abstract class PDOMFullIndexerJob extends PDOMIndexerTask implements IPDOMIndexe return; ITranslationUnit tu = (ITranslationUnit)i.next(); String path = tu.getLocation().toOSString(); - if (!filePathsToParse.contains(path)) { + if (filePathsToParse.get(path) == null) { i.remove(); } else if (tu.isSourceUnit()) { - parseTU(tu); + parseTU(tu, monitor); i.remove(); } } @@ -97,13 +98,13 @@ abstract class PDOMFullIndexerJob extends PDOMIndexerTask implements IPDOMIndexe return; ITranslationUnit tu = (ITranslationUnit)i.next(); String path = tu.getLocation().toOSString(); - if (!filePathsToParse.contains(path)) { + if (filePathsToParse.get(path)==null) { i.remove(); } else { ITranslationUnit context= findContext(index, path); if (context != null) { - parseTU(context); + parseTU(context, monitor); } } } @@ -114,17 +115,17 @@ abstract class PDOMFullIndexerJob extends PDOMIndexerTask implements IPDOMIndexe while (i.hasNext()) { ITranslationUnit tu = (ITranslationUnit)i.next(); String path = tu.getLocation().toOSString(); - if (!filePathsToParse.contains(path)) { + if (filePathsToParse.get(path)==null) { i.remove(); } else { - parseTU(tu); + parseTU(tu, monitor); } } } } - protected void doParseTU(ITranslationUnit tu) throws CoreException, InterruptedException { + protected void doParseTU(ITranslationUnit tu, IProgressMonitor pm) throws CoreException, InterruptedException { IPath path = tu.getLocation(); if (path == null) { return; @@ -134,34 +135,11 @@ abstract class PDOMFullIndexerJob extends PDOMIndexerTask implements IPDOMIndexe options |= ITranslationUnit.AST_SKIP_IF_NO_BUILD_INFO; } IASTTranslationUnit ast= tu.getAST(null, options); - if (ast == null) - return; - System.out.println(path.toOSString()); - index.acquireWriteLock(0); - - try { - // Remove the old symbols in the tu - IIndexFragmentFile file = (IIndexFragmentFile) index.getFile(path); - if (file != null) - index.clearFile(file); - - // Clear out the symbols in the includes - IASTPreprocessorIncludeStatement[] includes = ast.getIncludeDirectives(); - for (int i = 0; i < includes.length; ++i) { - String incname = includes[i].getPath(); - IIndexFragmentFile incfile = (IIndexFragmentFile) index.getFile(new Path(incname)); - if (incfile != null) { - index.clearFile(incfile); - } - } - - addSymbols(ast); - } finally { - index.releaseWriteLock(0); - } + if (ast != null) + addSymbols(ast, pm); } - protected void addSymbols(IASTTranslationUnit ast) throws InterruptedException, CoreException { + protected void addSymbols(IASTTranslationUnit ast, IProgressMonitor pm) throws InterruptedException, CoreException { // Add in the includes final LinkedHashMap symbolMap= new LinkedHashMap(); // makes bugs reproducible @@ -206,6 +184,9 @@ abstract class PDOMFullIndexerJob extends PDOMIndexerTask implements IPDOMIndexe }); for (Iterator iter = symbolMap.values().iterator(); iter.hasNext();) { + if (pm.isCanceled()) { + return; + } // resolve the names ArrayList names= ((ArrayList[]) iter.next())[2]; for (int i=0; i