mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fix for 232155 and other associated changes to get the StandaloneFastIndexer running
This commit is contained in:
parent
41132eeef2
commit
20dcecc930
6 changed files with 173 additions and 16 deletions
|
@ -23,6 +23,7 @@ import org.eclipse.cdt.core.parser.IScannerInfo;
|
|||
import org.eclipse.cdt.internal.core.index.IIndexFragment;
|
||||
import org.eclipse.cdt.internal.core.index.WritableCIndex;
|
||||
import org.eclipse.cdt.internal.core.pdom.WritablePDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
|
@ -50,7 +51,7 @@ public class StandaloneFastIndexer extends StandaloneIndexer{
|
|||
* @param log - logger
|
||||
* @throws CoreException
|
||||
*/
|
||||
public StandaloneFastIndexer(File writableIndexFile, IIndexLocationConverter converter, Map linkageFactoryMappings,
|
||||
public StandaloneFastIndexer(File writableIndexFile, IIndexLocationConverter converter, Map<String, IPDOMLinkageFactory> linkageFactoryMappings,
|
||||
IScannerInfo scanner, ILanguageMapper mapper, IParserLogService log) throws CoreException {
|
||||
WritablePDOM pdom = new WritablePDOM(writableIndexFile, converter, linkageFactoryMappings);
|
||||
fIndex = new WritableCIndex(
|
||||
|
@ -66,7 +67,7 @@ public class StandaloneFastIndexer extends StandaloneIndexer{
|
|||
* Create a delegate standalone indexing task
|
||||
*/
|
||||
@Override
|
||||
protected StandaloneIndexerTask createTask(List added, List changed, List removed) {
|
||||
protected StandaloneIndexerTask createTask(List<String> added, List<String> changed, List<String> removed) {
|
||||
return new StandaloneFastIndexerTask(this, added, changed, removed);
|
||||
}
|
||||
|
||||
|
|
|
@ -289,7 +289,7 @@ public abstract class StandaloneIndexer {
|
|||
* @param monitor
|
||||
* @throws IOException
|
||||
*/
|
||||
public void rebuild(List tus, IProgressMonitor monitor) throws IOException {
|
||||
public void rebuild(List<String> tus, IProgressMonitor monitor) throws IOException {
|
||||
fProgress = createProgress();
|
||||
|
||||
try {
|
||||
|
@ -314,7 +314,7 @@ public abstract class StandaloneIndexer {
|
|||
* @param monitor
|
||||
* @throws IOException
|
||||
*/
|
||||
public void handleDelta(List added, List changed, List removed, IProgressMonitor monitor) throws IOException {
|
||||
public void handleDelta(List<String> added, List<String> changed, List<String> removed, IProgressMonitor monitor) throws IOException {
|
||||
fProgress= new IndexerProgress();
|
||||
|
||||
fDelegate= createTask(getFilesAdded(added), changed, removed);
|
||||
|
@ -334,17 +334,17 @@ public abstract class StandaloneIndexer {
|
|||
* @param tus
|
||||
* @return
|
||||
*/
|
||||
private List getFilesAdded(List tus) {
|
||||
List added = new ArrayList();
|
||||
private List<String> getFilesAdded(List<String> tus) {
|
||||
List<String> added = new ArrayList<String>();
|
||||
|
||||
FilenameFilter filter = getExclusionFilter();
|
||||
if (filter == null) {
|
||||
filter = DEFAULT_FILTER;
|
||||
}
|
||||
|
||||
Iterator iter = tus.iterator();
|
||||
Iterator<String> iter = tus.iterator();
|
||||
while (iter.hasNext()) {
|
||||
String path = (String) iter.next();
|
||||
String path = iter.next();
|
||||
File file = new File(path);
|
||||
if (file.isDirectory()) {
|
||||
String[] files = file.list(filter);
|
||||
|
@ -364,7 +364,7 @@ public abstract class StandaloneIndexer {
|
|||
/**
|
||||
* Creates a delegate standalone indexing task
|
||||
*/
|
||||
protected abstract StandaloneIndexerTask createTask(List added, List changed, List removed);
|
||||
protected abstract StandaloneIndexerTask createTask(List<String> added, List<String> changed, List<String> removed);
|
||||
|
||||
/**
|
||||
* Return the type of references the parser should skip.
|
||||
|
|
|
@ -18,10 +18,13 @@ import java.util.Iterator;
|
|||
|
||||
import org.eclipse.cdt.core.model.AbstractLanguage;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.internal.core.index.IWritableIndex;
|
||||
import org.eclipse.cdt.internal.core.pdom.AbstractIndexerTask;
|
||||
import org.eclipse.cdt.internal.core.pdom.IndexerProgress;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
|
||||
/**
|
||||
* A task for index updates.
|
||||
|
@ -168,4 +171,53 @@ public abstract class StandaloneIndexerTask extends AbstractIndexerTask {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.pdom.AbstractIndexerTask#createStatus(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
protected IStatus createStatus(String msg) {
|
||||
return new Status(IStatus.ERROR, "org.eclipse.cdt.core", IStatus.ERROR, msg, null); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.pdom.AbstractIndexerTask#getMessage(org.eclipse.cdt.internal.core.pdom.AbstractIndexerTask.MessageKind, java.lang.Object[])
|
||||
*/
|
||||
@Override
|
||||
protected String getMessage(MessageKind kind, Object... arguments) {
|
||||
// unfortunately we don't have OSGi on the remote system so for now we'll just settle for
|
||||
// English strings
|
||||
// TODO: find a way to do non-OSGi NLS
|
||||
switch(kind) {
|
||||
case parsingFileTask:
|
||||
return new String("parsing {0} ({1})"); //$NON-NLS-1$
|
||||
|
||||
case errorWhileParsing:
|
||||
return new String("Error while parsing {0}."); //$NON-NLS-1$
|
||||
|
||||
|
||||
case tooManyIndexProblems:
|
||||
return new String("Too many errors while indexing, stopping indexer."); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.pdom.AbstractIndexerTask#getLogService()
|
||||
*/
|
||||
@Override
|
||||
protected IParserLogService getLogService() {
|
||||
return new StdoutLogService();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.pdom.AbstractIndexerTask#logError(org.eclipse.core.runtime.IStatus)
|
||||
*/
|
||||
@Override
|
||||
protected void logError(IStatus s) {
|
||||
getLogService().traceLog(s.getMessage());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.indexer;
|
||||
|
||||
import org.eclipse.cdt.core.parser.AbstractParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
|
||||
/**
|
||||
* @author crecoskie
|
||||
*
|
||||
*/
|
||||
public class StdoutLogService extends AbstractParserLogService{
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.AbstractParserLogService#errorLog(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void errorLog(String message) {
|
||||
System.out.println("Parser Error Trace: " + message); //$NON-NLS-1$
|
||||
System.out.flush();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.AbstractParserLogService#isTracing()
|
||||
*/
|
||||
@Override
|
||||
public boolean isTracing() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.AbstractParserLogService#isTracingExceptions()
|
||||
*/
|
||||
@Override
|
||||
public boolean isTracingExceptions() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.AbstractParserLogService#traceLog(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void traceLog(String message) {
|
||||
System.out.println("Parser Trace: " + message); //$NON-NLS-1$
|
||||
System.out.flush();
|
||||
}
|
||||
|
||||
}
|
|
@ -40,6 +40,7 @@ import org.eclipse.cdt.core.model.AbstractLanguage;
|
|||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.IExtendedScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.ParserUtil;
|
||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||
|
@ -54,6 +55,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
|
|||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
||||
/**
|
||||
* Task for the actual indexing. Various indexers need to implement the abstract methods.
|
||||
|
@ -90,6 +92,8 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
public ICPPUsingDirective[] fDirectives;
|
||||
}
|
||||
|
||||
protected enum MessageKind {parsingFileTask, errorWhileParsing, tooManyIndexProblems};
|
||||
|
||||
private int fUpdateFlags= IIndexManager.UPDATE_ALL;
|
||||
private boolean fIndexHeadersWithoutContext= true;
|
||||
private boolean fIndexFilesWithoutConfiguration= true;
|
||||
|
@ -182,7 +186,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
}
|
||||
|
||||
try {
|
||||
IASTTranslationUnit ast= language.getASTTranslationUnit(codeReader, scanInfo, fCodeReaderFactory, fIndex, options, ParserUtil.getParserLogService());
|
||||
IASTTranslationUnit ast= language.getASTTranslationUnit(codeReader, scanInfo, fCodeReaderFactory, fIndex, options, getLogService());
|
||||
if (pm.isCanceled()) {
|
||||
return null;
|
||||
}
|
||||
|
@ -195,6 +199,13 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
protected IParserLogService getLogService() {
|
||||
return ParserUtil.getParserLogService();
|
||||
}
|
||||
|
||||
public final void runTask(IProgressMonitor monitor) throws InterruptedException {
|
||||
if (!fIndexFilesWithoutConfiguration) {
|
||||
fIndexHeadersWithoutContext= false;
|
||||
|
@ -433,7 +444,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
if (fShowActivity) {
|
||||
System.out.println("Indexer: parsing " + filePath + " up front"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
monitor.subTask(MessageFormat.format(Messages.AbstractIndexerTask_parsingFileTask,
|
||||
monitor.subTask(MessageFormat.format(getMessage(MessageKind.parsingFileTask),
|
||||
new Object[]{fileName, path.removeLastSegments(1).toString()}));
|
||||
|
||||
AbstractLanguage[] langs= getLanguages(fileName);
|
||||
|
@ -582,7 +593,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
if (fShowActivity) {
|
||||
System.out.println("Indexer: parsing " + path.toOSString()); //$NON-NLS-1$
|
||||
}
|
||||
pm.subTask(MessageFormat.format(Messages.AbstractIndexerTask_parsingFileTask,
|
||||
pm.subTask(MessageFormat.format(getMessage(MessageKind.parsingFileTask),
|
||||
new Object[]{path.lastSegment(), path.removeLastSegments(1).toString()}));
|
||||
long start= System.currentTimeMillis();
|
||||
IASTTranslationUnit ast= createAST(tu, lang, scanInfo, fASTOptions, pm);
|
||||
|
@ -698,14 +709,21 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
}
|
||||
else {
|
||||
s= CCorePlugin.createStatus(
|
||||
MessageFormat.format(Messages.AbstractIndexerTask_errorWhileParsing, new Object[]{file}), e);
|
||||
MessageFormat.format(getMessage(MessageKind.errorWhileParsing), new Object[]{file}), e);
|
||||
}
|
||||
CCorePlugin.log(s);
|
||||
logError(s);
|
||||
if (++fStatistics.fErrorCount > MAX_ERRORS) {
|
||||
throw new CoreException(CCorePlugin.createStatus(Messages.AbstractIndexerTask_tooManyIndexProblems));
|
||||
throw new CoreException(createStatus(getMessage(MessageKind.tooManyIndexProblems)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param s
|
||||
*/
|
||||
protected void logError(IStatus s) {
|
||||
CCorePlugin.log(s);
|
||||
}
|
||||
|
||||
private static int computeHashCode(IScannerInfo scannerInfo) {
|
||||
int result= 0;
|
||||
Map<String, String> macros= scannerInfo.getDefinedSymbols();
|
||||
|
@ -777,4 +795,27 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String getMessage(MessageKind kind, Object... arguments) {
|
||||
switch (kind) {
|
||||
case parsingFileTask:
|
||||
return NLS.bind(Messages.AbstractIndexerTask_parsingFileTask,
|
||||
arguments);
|
||||
case errorWhileParsing:
|
||||
return NLS.bind(Messages.AbstractIndexerTask_errorWhileParsing,
|
||||
arguments);
|
||||
|
||||
case tooManyIndexProblems:
|
||||
return NLS.bind(Messages.AbstractIndexerTask_tooManyIndexProblems,
|
||||
arguments);
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
protected IStatus createStatus(String msg) {
|
||||
return CCorePlugin.createStatus(msg);
|
||||
}
|
||||
}
|
|
@ -47,6 +47,8 @@ import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
|
|||
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.IString;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
|
||||
/**
|
||||
* Represents a file containing names.
|
||||
|
@ -260,7 +262,7 @@ public class PDOMFile implements IIndexFragmentFile {
|
|||
final String linkageName = Linkage.getLinkageName(getLinkageID());
|
||||
fLinkage= pdom.createLinkage(linkageName);
|
||||
if (fLinkage == null) {
|
||||
throw new CoreException(CCorePlugin.createStatus("Unsupported linkage: " + linkageName)); //$NON-NLS-1$
|
||||
throw new CoreException(createStatus("Unsupported linkage: " + linkageName)); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
return fLinkage;
|
||||
|
@ -628,4 +630,9 @@ public class PDOMFile implements IIndexFragmentFile {
|
|||
}
|
||||
return ICPPUsingDirective.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
// required because we cannot reference CCorePlugin in order for StandaloneIndexer to work
|
||||
private IStatus createStatus(String msg) {
|
||||
return new Status(IStatus.ERROR, "org.eclipse.cdt.core", IStatus.ERROR, msg, null); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue