mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-28 11:25:35 +02:00
Fix for 150075, progress indication for indexer
This commit is contained in:
parent
0132200353
commit
2d8f966f3b
33 changed files with 453 additions and 213 deletions
|
@ -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)));
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -36,7 +36,6 @@ public class ASTInternal {
|
|||
if (scope instanceof IASTInternalScope) {
|
||||
return ((IASTInternalScope) scope).getPhysicalNode();
|
||||
}
|
||||
assert false;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1132,7 +1132,6 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
break;
|
||||
}
|
||||
if (subC instanceof _CompositeContext) {
|
||||
assert !subC.containsInContext(globalOffset);
|
||||
externalCount+= subC.getContextLength();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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() {
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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$
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<names.size(); i++) {
|
||||
|
@ -213,15 +194,23 @@ abstract class PDOMFullIndexerJob extends PDOMIndexerTask implements IPDOMIndexe
|
|||
}
|
||||
}
|
||||
|
||||
for (Iterator iter = symbolMap.entrySet().iterator(); iter.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) iter.next();
|
||||
String path= (String) entry.getKey();
|
||||
addToIndex(path, (ArrayList[]) entry.getValue());
|
||||
index.acquireWriteLock(0);
|
||||
try {
|
||||
for (Iterator iter = symbolMap.entrySet().iterator(); iter.hasNext();) {
|
||||
if (pm.isCanceled()) {
|
||||
return;
|
||||
}
|
||||
Map.Entry entry = (Map.Entry) iter.next();
|
||||
String path= (String) entry.getKey();
|
||||
addToIndex(path, (ArrayList[]) entry.getValue());
|
||||
}
|
||||
} finally {
|
||||
index.releaseWriteLock(0);
|
||||
}
|
||||
}
|
||||
|
||||
private void addToMap(HashMap map, int idx, String path, Object thing) {
|
||||
if (filePathsToParse.contains(path)) {
|
||||
if (filePathsToParse.get(path) != null) {
|
||||
List[] lists= (List[]) map.get(path);
|
||||
if (lists == null) {
|
||||
lists= new ArrayList[]{new ArrayList(), new ArrayList(), new ArrayList()};
|
||||
|
@ -232,10 +221,13 @@ abstract class PDOMFullIndexerJob extends PDOMIndexerTask implements IPDOMIndexe
|
|||
}
|
||||
|
||||
private void addToIndex(String location, ArrayList[] lists) throws CoreException {
|
||||
if (!filePathsToParse.remove(location)) {
|
||||
Boolean required= (Boolean) filePathsToParse.remove(location);
|
||||
if (required == null) {
|
||||
return;
|
||||
}
|
||||
fFilesToIndex--;
|
||||
if (!required.booleanValue()) {
|
||||
fTotalTasks++;
|
||||
}
|
||||
|
||||
// Remove the old symbols in the tu
|
||||
Path path= new Path(location);
|
||||
|
@ -267,9 +259,6 @@ abstract class PDOMFullIndexerJob extends PDOMIndexerTask implements IPDOMIndexe
|
|||
for (int i = 0; i < list.size(); i++) {
|
||||
index.addName(file, (IASTName) list.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
final public int getFilesToIndexCount() {
|
||||
return fFilesToIndex;
|
||||
fCompletedTasks++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
package org.eclipse.cdt.internal.core.pdom.indexer.full;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -30,23 +31,33 @@ class PDOMFullReindex extends PDOMFullIndexerJob {
|
|||
|
||||
public PDOMFullReindex(PDOMFullIndexer 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;
|
||||
|
||||
if (fFilesToIndex == 1 || monitor.isCanceled()) {
|
||||
return;
|
||||
long start = System.currentTimeMillis();
|
||||
boolean allfiles= getIndexAllFiles();
|
||||
List optional= new ArrayList();
|
||||
|
||||
collectSources(indexer.getProject(), fTUs, optional, allfiles);
|
||||
if (allfiles) {
|
||||
fTUs.addAll(optional);
|
||||
optional.clear();
|
||||
}
|
||||
|
||||
fTotalTasks+= fTUs.size()+1;
|
||||
fCompletedTasks++;
|
||||
|
||||
setupIndexAndReaderFactory();
|
||||
clearIndex(index);
|
||||
registerTUsInReaderFactory(fTUs);
|
||||
fFilesToIndex--;
|
||||
|
||||
if (getRemainingSubtaskCount() == 1 || monitor.isCanceled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
registerTUsInReaderFactory(fTUs, optional);
|
||||
fCompletedTasks++;
|
||||
|
||||
parseTUs(fTUs, monitor);
|
||||
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
PDOMIndexerTask_collectingFilesTask=Collecting files to parse
|
||||
PDOMIndexerTask_parsingFileTask=parsing {0} ({1})
|
|
@ -69,8 +69,16 @@ public class PDOMNullIndexer implements IPDOMIndexer {
|
|||
}
|
||||
}
|
||||
|
||||
public int getFilesToIndexCount() {
|
||||
return 1;
|
||||
public String getMonitorMessageDetail() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getCompletedSubtaskCount() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getRemainingSubtaskCount() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,4 +3,3 @@ PDOMManager_notifyJob_label=Notify Index Change Listeners
|
|||
PDOMManager_JoinIndexerTask=Join Indexer
|
||||
PDOMManager_savePrefsJob=Save Project Preferences
|
||||
PDOMManager_notifyTask_message=Notify Listeners
|
||||
PDOMManager_FilesToIndexSubtask={0} files to index
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
/*******************************************************************************
|
||||
* 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;
|
||||
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
||||
public class Messages extends NLS {
|
||||
private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.core.messages"; //$NON-NLS-1$
|
||||
public static String Util_unexpectedError;
|
||||
static {
|
||||
// initialize resource bundle
|
||||
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
|
||||
}
|
||||
|
||||
private Messages() {
|
||||
}
|
||||
}
|
|
@ -376,7 +376,11 @@ public class Util {
|
|||
* @return an IStatus object based on the given Throwable.
|
||||
*/
|
||||
public static IStatus createStatus(Throwable t) {
|
||||
return new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, 0, t.getMessage(), t);
|
||||
String msg= t.getMessage();
|
||||
if (msg == null) {
|
||||
msg= Messages.Util_unexpectedError;
|
||||
}
|
||||
return new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, 0, msg, t);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,3 +55,4 @@ convention.enum.dollarName= Enum name has $
|
|||
convention.enum.leadingUnderscore= Enum name starts with underscore
|
||||
convention.enum.lowercaseName= Enum name starts with lower case
|
||||
convention.enum.invalidName= Enum name is invalid
|
||||
Util_unexpectedError=Unexpected error
|
||||
|
|
|
@ -284,6 +284,7 @@ public class IBViewPart extends ViewPart
|
|||
fContentProvider= new IBContentProvider(display);
|
||||
fLabelProvider= new IBLabelProvider(display, fContentProvider);
|
||||
fTreeViewer= new ExtendedTreeViewer(fViewerPage);
|
||||
fTreeViewer.setUseHashlookup(true);
|
||||
fTreeViewer.setContentProvider(fContentProvider);
|
||||
fTreeViewer.setLabelProvider(fLabelProvider);
|
||||
fTreeViewer.setAutoExpandLevel(2);
|
||||
|
|
Loading…
Add table
Reference in a new issue