From 30ddbb87084f3c4d8c7e273d61ddef1b9d91868b Mon Sep 17 00:00:00 2001 From: Mike Kucera Date: Mon, 14 Jul 2008 21:44:45 +0000 Subject: [PATCH] bug 240371, standalone indexer needs a scanner info provider --- .../IStandaloneScannerInfoProvider.java | 28 ++++++++ .../core/indexer/StandaloneFastIndexer.java | 49 ++++++++++--- .../indexer/StandaloneFastIndexerTask.java | 2 +- .../core/indexer/StandaloneFullIndexer.java | 35 +++++++--- .../indexer/StandaloneFullIndexerTask.java | 4 +- .../core/indexer/StandaloneIndexer.java | 68 +++++++++++++++++-- .../core/indexer/StandaloneIndexerTask.java | 2 +- .../core/indexer/StdoutLogService.java | 1 - 8 files changed, 161 insertions(+), 28 deletions(-) create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/IStandaloneScannerInfoProvider.java diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/IStandaloneScannerInfoProvider.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/IStandaloneScannerInfoProvider.java new file mode 100644 index 00000000000..0e33a448c19 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/IStandaloneScannerInfoProvider.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * 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.IScannerInfo; +import org.eclipse.cdt.core.parser.IScannerInfoProvider; + +/** + * Returns a IScannerInfo for the given file by a path. + * + * Similar to IScannerInfoProvider but computes the IScannerInfo + * based on a String path instead of IResource. + * + * @see IScannerInfoProvider + */ +public interface IStandaloneScannerInfoProvider { + + IScannerInfo getScannerInformation(String path); +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneFastIndexer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneFastIndexer.java index dd94f3728f0..75a748c4981 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneFastIndexer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneFastIndexer.java @@ -39,7 +39,7 @@ import org.eclipse.core.runtime.CoreException; * * @since 4.0 */ -public class StandaloneFastIndexer extends StandaloneIndexer{ +public class StandaloneFastIndexer extends StandaloneIndexer { /** * Construct a fast standalone indexer. @@ -53,16 +53,46 @@ public class StandaloneFastIndexer extends StandaloneIndexer{ */ public StandaloneFastIndexer(File writableIndexFile, IIndexLocationConverter converter, Map linkageFactoryMappings, IScannerInfo scanner, ILanguageMapper mapper, IParserLogService log) throws CoreException { - WritablePDOM pdom = new WritablePDOM(writableIndexFile, converter, linkageFactoryMappings); - fIndex = new WritableCIndex( - pdom, - new IIndexFragment[0]); - fIndexAllFiles = false; - fScanner = scanner; - fMapper = mapper; - fLog = log; + super(new WritableCIndex(new WritablePDOM(writableIndexFile, converter, linkageFactoryMappings),new IIndexFragment[0]), + false, mapper, log, scanner); + } + /** + * Construct a fast standalone indexer. + * @param writableIndexFile - the file where the PDOM index is stored + * @param converter - a converter used to convert between String locations and IIndexLocations + * @param linkageFactoryMappings - all of the available IPDOMLinkageFactories the index can use during indexing + * @param scannerProvider - provides include paths and defined symbols + * @param mapper - a mapper used to determine ICLanguage for a particular file + * @param log - logger + * @throws CoreException + */ + public StandaloneFastIndexer(File writableIndexFile, IIndexLocationConverter converter, Map linkageFactoryMappings, + IStandaloneScannerInfoProvider scannerProvider, ILanguageMapper mapper, IParserLogService log) throws CoreException { + super(new WritableCIndex(new WritablePDOM(writableIndexFile, converter, linkageFactoryMappings),new IIndexFragment[0]), + false, mapper, log, scannerProvider); + + } + + /** + * Construct a fast standalone indexer. + * @param writableIndexFile - the file where the PDOM index is stored + * @param converter - a converter used to convert between String locations and IIndexLocations + * @param linkageFactoryMappings - all of the available IPDOMLinkageFactories the index can use during indexing + * @param scannerProvider - provides include paths and defined symbols + * @param mapper - a mapper used to determine ICLanguage for a particular file + * @param log - logger + * @throws CoreException + */ + public StandaloneFastIndexer(File writableIndexFile, IIndexLocationConverter converter, Map linkageFactoryMappings, + ILanguageMapper mapper, IParserLogService log) throws CoreException { + super(new WritableCIndex(new WritablePDOM(writableIndexFile, converter, linkageFactoryMappings),new IIndexFragment[0]), + false, mapper, log, (IStandaloneScannerInfoProvider)null); + + } + + /** * Create a delegate standalone indexing task */ @@ -71,4 +101,5 @@ public class StandaloneFastIndexer extends StandaloneIndexer{ return new StandaloneFastIndexerTask(this, added, changed, removed); } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneFastIndexerTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneFastIndexerTask.java index 3c37d1fdf55..64dc7feca98 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneFastIndexerTask.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneFastIndexerTask.java @@ -30,7 +30,7 @@ import org.eclipse.cdt.core.dom.ICodeReaderFactory; * @since 4.0 */ public class StandaloneFastIndexerTask extends StandaloneIndexerTask { - public StandaloneFastIndexerTask(StandaloneFastIndexer indexer, List added, List changed, List removed) { + public StandaloneFastIndexerTask(StandaloneFastIndexer indexer, List added, List changed, List removed) { super(indexer, added, changed, removed, true); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneFullIndexer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneFullIndexer.java index beac8025b60..ae048c1f8a5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneFullIndexer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneFullIndexer.java @@ -24,6 +24,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; /** @@ -55,19 +56,33 @@ public class StandaloneFullIndexer extends StandaloneIndexer{ * by the source code being parsed. * @throws CoreException */ - public StandaloneFullIndexer(File writableIndexFile, IIndexLocationConverter converter, Map linkageFactoryMappings, + public StandaloneFullIndexer(File writableIndexFile, IIndexLocationConverter converter, Map linkageFactoryMappings, IScannerInfo scanner, ILanguageMapper mapper, IParserLogService log, ICodeReaderFactory codeReaderFactory) throws CoreException { - WritablePDOM pdom = new WritablePDOM(writableIndexFile, converter, linkageFactoryMappings); - fIndex = new WritableCIndex( - pdom, - new IIndexFragment[0]); - fIndexAllFiles = false; - fScanner = scanner; - fMapper = mapper; + super(new WritableCIndex(new WritablePDOM(writableIndexFile, converter, linkageFactoryMappings),new IIndexFragment[0]), + false, mapper, log, scanner); fCodeReaderFactory = codeReaderFactory; - fLog = log; } + /** + * Create a full indexer. + * @param writableIndexFile - the file where the PDOM index is stored + * @param converter - a converter used to convert between String locations and IIndexLocations + * @param linkageFactoryMappings - all of the available IPDOMLinkageFactories the index can use during indexing + * @param scannerProvider - provides include paths and defined symbols + * @param mapper - a mapper used to determine ICLanguage for a particular file + * @param log - logger + * @param codeReaderFactory - factory that provides CodeReaders for files included + * by the source code being parsed. + * @throws CoreException + */ + public StandaloneFullIndexer(File writableIndexFile, IIndexLocationConverter converter, Map linkageFactoryMappings, + IStandaloneScannerInfoProvider scannerProvider, ILanguageMapper mapper, IParserLogService log, ICodeReaderFactory codeReaderFactory) throws CoreException { + super(new WritableCIndex(new WritablePDOM(writableIndexFile, converter, linkageFactoryMappings),new IIndexFragment[0]), + false, mapper, log, scannerProvider); + fCodeReaderFactory = codeReaderFactory; + } + + /** * Returns the factory that provides CodeReaders for files included * by the source code being parsed. @@ -80,7 +95,7 @@ public class StandaloneFullIndexer extends StandaloneIndexer{ * Creates a delegate standalone indexing task */ @Override - protected StandaloneIndexerTask createTask(List added, List changed, List removed) { + protected StandaloneIndexerTask createTask(List added, List changed, List removed) { return new StandaloneFullIndexerTask(this, added, changed, removed); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneFullIndexerTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneFullIndexerTask.java index 7ddfa60d59b..7a4d9642557 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneFullIndexerTask.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneFullIndexerTask.java @@ -30,8 +30,8 @@ import org.eclipse.cdt.core.dom.ICodeReaderFactory; * @since 4.0 */ public class StandaloneFullIndexerTask extends StandaloneIndexerTask { - public StandaloneFullIndexerTask(StandaloneFullIndexer indexer, List added, - List changed, List removed) { + public StandaloneFullIndexerTask(StandaloneFullIndexer indexer, List added, + List changed, List removed) { super(indexer, added, changed, removed, false); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexer.java index d8574193552..63c2fac60f6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexer.java @@ -16,14 +16,21 @@ import java.io.File; import java.io.FilenameFilter; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Set; +import org.eclipse.cdt.core.index.IIndexLocationConverter; import org.eclipse.cdt.core.parser.IParserLogService; import org.eclipse.cdt.core.parser.IScannerInfo; +import org.eclipse.cdt.internal.core.index.IIndexFragment; import org.eclipse.cdt.internal.core.index.IWritableIndex; +import org.eclipse.cdt.internal.core.index.WritableCIndex; import org.eclipse.cdt.internal.core.pdom.IndexerProgress; +import org.eclipse.cdt.internal.core.pdom.WritablePDOM; +import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; @@ -72,7 +79,9 @@ public abstract class StandaloneIndexer { /** * Empty list. */ - protected static final List NO_TUS = new ArrayList(); + protected static final List NO_TUS = Collections.emptyList(); + + /** * The IWritableIndex that stores all bindings and names. */ @@ -87,13 +96,22 @@ public abstract class StandaloneIndexer { /** * Collection of valid file extensions for C/C++ source. */ - protected Set fValidSourceUnitNames; + protected Set fValidSourceUnitNames; /** * The IScannerInfo that provides include paths and defined symbols. + * Either a single scanner info or a IStandaloneScannerInfoProvider must + * be provided, but not both. If a single IScannerInfo object is provided + * it will always be used. Otherwise the provider will be used. */ protected IScannerInfo fScanner; + /** + * Creates IScannerInfo objects from file paths, allows there + * to be separate scanner infos for specific files and folders. + */ + protected IStandaloneScannerInfoProvider fScannerInfoProvider; + /** * The ILanguageMapper that determines the ILanguage for a file. */ @@ -146,6 +164,33 @@ public abstract class StandaloneIndexer { } }; + public StandaloneIndexer(IWritableIndex index, boolean indexAllFiles, + ILanguageMapper mapper, IParserLogService log, IScannerInfo scanner) { + fIndex = index; + fIndexAllFiles = indexAllFiles; + fMapper = mapper; + fLog = log; + fScanner = scanner; + fScannerInfoProvider = null; + } + + + public StandaloneIndexer(IWritableIndex index, boolean indexAllFiles, + ILanguageMapper mapper, IParserLogService log, IStandaloneScannerInfoProvider scannerProvider) { + fIndex = index; + fIndexAllFiles = indexAllFiles; + fMapper = mapper; + fLog = log; + fScanner = null; + fScannerInfoProvider = scannerProvider; + } + + + public void setScannerInfoProvider(IStandaloneScannerInfoProvider provider) { + fScannerInfoProvider = provider; + fScanner = null; + } + /** * Returns the index. * @return the IWritable index the indexer is writing to @@ -165,14 +210,14 @@ public abstract class StandaloneIndexer { /** * Returns the collection of valid file extensions for C/C++ source. */ - public Set getValidSourceUnitNames() { + public Set getValidSourceUnitNames() { return fValidSourceUnitNames; } /** * Sets the collection of valid file extensions for C/C++ source. */ - public void setValidSourceUnitNames(Set validSourceUnitNames) { + public void setValidSourceUnitNames(Set validSourceUnitNames) { fValidSourceUnitNames = validSourceUnitNames; } @@ -183,6 +228,21 @@ public abstract class StandaloneIndexer { return fScanner; } + + /** + * Returns the IScannerInfo for the given path. + * If the current instance was created with an IScannerInfo instead of + * an IScannerInfoProvider then the path will be ignored and + * that IScannerInfo will always be returned. + */ + public IScannerInfo getScannerInfo(String path) { + if(fScanner != null) + return fScanner; + + return fScannerInfoProvider.getScannerInformation(path); + } + + /** * Returns the ILanguageMapper that determines the ILanguage for a file. */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexerTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexerTask.java index 28294b96d6c..073a2efe17a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexerTask.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexerTask.java @@ -43,7 +43,7 @@ public abstract class StandaloneIndexerTask extends AbstractIndexerTask { protected StandaloneIndexer fIndexer; - protected StandaloneIndexerTask(StandaloneIndexer indexer, Collection added, Collection changed, Collection removed, boolean isFast) { + protected StandaloneIndexerTask(StandaloneIndexer indexer, Collection added, Collection changed, Collection removed, boolean isFast) { super(concat(added, changed), removed.toArray(), new StandaloneIndexerInputAdapter(indexer), isFast); fIndexer= indexer; setShowActivity(fIndexer.getShowActivity()); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StdoutLogService.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StdoutLogService.java index ccfd22f7f91..7ecc1abe3e9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StdoutLogService.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StdoutLogService.java @@ -11,7 +11,6 @@ package org.eclipse.cdt.internal.core.indexer; import org.eclipse.cdt.core.parser.AbstractParserLogService; -import org.eclipse.cdt.core.parser.IParserLogService; /** * @author crecoskie