From ad8800e44733c0d46d0121cf3c34f9a022c681e0 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Tue, 3 Apr 2007 11:52:00 +0000 Subject: [PATCH] Fix for 178088, options to skip references during indexing. --- .../cdt/core/model/AbstractLanguage.java | 37 +++++++- .../core/dom/parser/c/AbstractCLanguage.java | 26 ++++-- .../dom/parser/cpp/AbstractCPPLanguage.java | 26 ++++-- .../cdt/internal/core/pdom/PDOMWriter.java | 76 +++++++++++++++-- .../cdt/internal/core/pdom/dom/PDOMFile.java | 22 ++--- .../pdom/indexer/AbstractPDOMIndexer.java | 2 + .../core/pdom/indexer/IndexerPreferences.java | 4 + .../core/pdom/indexer/PDOMIndexerTask.java | 85 +++++++++++++------ .../indexer/fast/PDOMFastIndexerTask.java | 29 +------ .../indexer/full/PDOMFullIndexerTask.java | 22 ++--- .../cdt/ui/dialogs/AbstractIndexerPage.java | 41 ++++++++- .../cdt/ui/dialogs/DialogsMessages.java | 2 + .../cdt/ui/dialogs/DialogsMessages.properties | 2 + 13 files changed, 277 insertions(+), 97 deletions(-) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/AbstractLanguage.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/AbstractLanguage.java index c6bba004cb2..233feb3454b 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/AbstractLanguage.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/AbstractLanguage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2007 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 @@ -13,6 +13,10 @@ package org.eclipse.cdt.core.model; 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.parser.CodeReader; +import org.eclipse.cdt.core.parser.IParserLogService; +import org.eclipse.cdt.core.parser.IScannerInfo; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.PlatformObject; @@ -21,13 +25,44 @@ import org.eclipse.core.runtime.PlatformObject; * @since 4.0 */ public abstract class AbstractLanguage extends PlatformObject implements ILanguage { + /** + * Option for {@link #getASTTranslationUnit(CodeReader, IScannerInfo, ICodeReaderFactory, IIndex, int, IParserLogService)} + * Instructs the parser to skip function and method bodies. + */ + public final static int OPTION_SKIP_FUNCTION_BODIES= 1; + /** + * @deprecated, throws an UnsupportedOperationException + */ final public IASTTranslationUnit getASTTranslationUnit(ITranslationUnit file, int style) throws CoreException { throw new UnsupportedOperationException(); } + /** + * @deprecated, throws an UnsupportedOperationException + */ final public IASTTranslationUnit getASTTranslationUnit(ITranslationUnit file, ICodeReaderFactory codeReaderFactory, int style) throws CoreException { throw new UnsupportedOperationException(); } + + /** + * Construct an AST for the source code provided by reader. + * As an option you can supply + * @param reader source code to be parsed. + * @param scanInfo provides include paths and defined symbols. + * @param fileCreator factory that provides CodeReaders for files included + * by the source code being parsed. + * @param index (optional) index to use to provide support for ambiguity + * resolution. + * @param options {@link #OPTION_SKIP_FUNCTION_BODIES} or 0. + * @param log logger + * @return an AST for the source code provided by reader. + * @throws CoreException + */ + public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IIndex index, int options, IParserLogService log) + throws CoreException { + // for backwards compatibility + return getASTTranslationUnit(reader, scanInfo, fileCreator, index, log); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/AbstractCLanguage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/AbstractCLanguage.java index bbfe685bede..24c1fd3c147 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/AbstractCLanguage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/AbstractCLanguage.java @@ -7,6 +7,7 @@ * * Contributors: * Anton Leherbauer (Wind River Systems) - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.dom.parser.c; @@ -88,10 +89,15 @@ public abstract class AbstractCLanguage extends AbstractLanguage implements ICLa } public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo, - ICodeReaderFactory codeReaderFactory, IIndex index, IParserLogService log) throws CoreException { + ICodeReaderFactory fileCreator, IIndex index, IParserLogService log) throws CoreException { + return getASTTranslationUnit(reader, scanInfo, fileCreator, index, 0, log); + } + + public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo, + ICodeReaderFactory codeReaderFactory, IIndex index, int options, IParserLogService log) throws CoreException { IScanner scanner= createScanner(reader, scanInfo, codeReaderFactory, log); - ISourceCodeParser parser= createParser(scanner, log, index, false); + ISourceCodeParser parser= createParser(scanner, log, index, false, options); // Parse IASTTranslationUnit ast= parser.parse(); @@ -104,7 +110,7 @@ public abstract class AbstractCLanguage extends AbstractLanguage implements ICLa IScanner scanner= createScanner(reader, scanInfo, fileCreator, log); scanner.setContentAssistMode(offset); - ISourceCodeParser parser= createParser(scanner, log, index, true); + ISourceCodeParser parser= createParser(scanner, log, index, true, 0); // Run the parse and return the completion node parser.parse(); @@ -153,10 +159,20 @@ public abstract class AbstractCLanguage extends AbstractLanguage implements ICLa * @param log the parser log service * @param index the index to help resolve bindings * @param forCompletion whether the parser is used for code completion + * @param options for valid options see {@link AbstractLanguage#getASTTranslationUnit(CodeReader, IScannerInfo, ICodeReaderFactory, IIndex, int, IParserLogService)} * @return an instance of ISourceCodeParser */ - protected ISourceCodeParser createParser(IScanner scanner, IParserLogService log, IIndex index, boolean forCompletion) { - ParserMode mode= forCompletion ? ParserMode.COMPLETION_PARSE : ParserMode.COMPLETE_PARSE; + protected ISourceCodeParser createParser(IScanner scanner, IParserLogService log, IIndex index, boolean forCompletion, int options) { + ParserMode mode= null; + if (forCompletion) { + mode= ParserMode.COMPLETION_PARSE; + } + else if ((options & OPTION_SKIP_FUNCTION_BODIES) != 0) { + mode= ParserMode.STRUCTURAL_PARSE; + } + else { + mode= ParserMode.COMPLETE_PARSE; + } return new GNUCSourceParser(scanner, mode, log, getParserExtensionConfiguration(), index); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/AbstractCPPLanguage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/AbstractCPPLanguage.java index f4a0f98f543..2d2b22322fb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/AbstractCPPLanguage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/AbstractCPPLanguage.java @@ -7,6 +7,7 @@ * * Contributors: * Anton Leherbauer (Wind River Systems) - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.dom.parser.cpp; @@ -87,10 +88,15 @@ public abstract class AbstractCPPLanguage extends AbstractLanguage implements IC } public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo, - ICodeReaderFactory codeReaderFactory, IIndex index, IParserLogService log) throws CoreException { + ICodeReaderFactory codeReaderFactory, IIndex index,IParserLogService log) throws CoreException { + return getASTTranslationUnit(reader, scanInfo, codeReaderFactory, index, 0, log); + } + + public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo, + ICodeReaderFactory codeReaderFactory, IIndex index, int options, IParserLogService log) throws CoreException { IScanner scanner= createScanner(reader, scanInfo, codeReaderFactory, log); - ISourceCodeParser parser= createParser(scanner, log, index, false); + ISourceCodeParser parser= createParser(scanner, log, index, false, options); // Parse IASTTranslationUnit ast= parser.parse(); @@ -102,7 +108,7 @@ public abstract class AbstractCPPLanguage extends AbstractLanguage implements IC IScanner scanner= createScanner(reader, scanInfo, fileCreator, log); scanner.setContentAssistMode(offset); - ISourceCodeParser parser= createParser(scanner, log, index, true); + ISourceCodeParser parser= createParser(scanner, log, index, true, 0); // Run the parse and return the completion node parser.parse(); @@ -150,10 +156,20 @@ public abstract class AbstractCPPLanguage extends AbstractLanguage implements IC * @param log the parser log service * @param index the index to help resolve bindings * @param forCompletion whether the parser is used for code completion + * @param options for valid options see {@link AbstractLanguage#getASTTranslationUnit(CodeReader, IScannerInfo, ICodeReaderFactory, IIndex, int, IParserLogService)} * @return an instance of ISourceCodeParser */ - protected ISourceCodeParser createParser(IScanner scanner, IParserLogService log, IIndex index, boolean forCompletion) { - ParserMode mode= forCompletion ? ParserMode.COMPLETION_PARSE : ParserMode.COMPLETE_PARSE; + protected ISourceCodeParser createParser(IScanner scanner, IParserLogService log, IIndex index, boolean forCompletion, int options) { + ParserMode mode= null; + if (forCompletion) { + mode= ParserMode.COMPLETION_PARSE; + } + else if ((options & OPTION_SKIP_FUNCTION_BODIES) != 0) { + mode= ParserMode.STRUCTURAL_PARSE; + } + else { + mode= ParserMode.COMPLETE_PARSE; + } return new GNUCPPSourceParser(scanner, mode, log, getParserExtensionConfiguration(), index); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMWriter.java index f51329778f4..44d1f379de5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMWriter.java @@ -17,13 +17,22 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.ICompositeType; +import org.eclipse.cdt.core.dom.ast.IEnumeration; import org.eclipse.cdt.core.dom.ast.IProblemBinding; +import org.eclipse.cdt.core.dom.ast.ITypedef; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; import org.eclipse.cdt.core.index.IIndexFile; import org.eclipse.cdt.core.index.IIndexFileLocation; import org.eclipse.cdt.internal.core.index.IIndexFragmentFile; @@ -40,12 +49,17 @@ import org.eclipse.core.runtime.IProgressMonitor; * @since 4.0 */ abstract public class PDOMWriter { + public static int SKIP_ALL_REFERENCES= -1; + public static int SKIP_TYPE_REFERENCES= 1; + public static int SKIP_NO_REFERENCES= 0; + protected boolean fShowActivity; protected boolean fShowProblems; protected IndexerStatistics fStatistics; private IndexerProgress fInfo= new IndexerProgress(); - + private int fSkipReferences= SKIP_NO_REFERENCES; + public PDOMWriter() { fStatistics= new IndexerStatistics(); } @@ -58,6 +72,14 @@ abstract public class PDOMWriter { fShowProblems= val; } + /** + * Determines whether references are skipped or not. Provide one of + * {@link #SKIP_ALL_REFERENCES}, {@link #SKIP_TYPE_REFERENCES} or {@link #SKIP_NO_REFERENCES}. + */ + public void setSkipReferences(int options) { + fSkipReferences= options; + } + /** * Called to check whether a translation unit still needs to be updated. * @see #addSymbols(IASTTranslationUnit, IWritableIndex, int, IProgressMonitor) @@ -103,14 +125,23 @@ abstract public class PDOMWriter { long start= System.currentTimeMillis(); ArrayList names= arrayLists[2]; for (int j=0; jnull. + * Called to create the ast for a translation unit or a pre-parsed file. + * May return null. * @see #parseTUs(IWritableIndex, int, Collection, Collection, IProgressMonitor) * @since 4.0 */ - abstract protected IASTTranslationUnit createAST(ITranslationUnit tu, IProgressMonitor pm) throws CoreException; - - /** - * Called to create the ast for pre-parsed files. May return null. - * @throws CoreException - * @since 4.0 - */ - protected IASTTranslationUnit createAST(ILanguage lang, CodeReader codeReader, IScannerInfo scanInfo, IProgressMonitor pm) throws CoreException { - return null; - } + abstract protected IASTTranslationUnit createAST(AbstractLanguage lang, CodeReader codeReader, IScannerInfo scanInfo, int options, IProgressMonitor pm) throws CoreException; /** * Convenience method for subclasses, parses the files calling out to the methods - * {@link #createAST(ITranslationUnit, IProgressMonitor)}, + * {@link #createAST(AbstractLanguage, CodeReader, IScannerInfo, int, IProgressMonitor)}, * {@link #needToUpdate(IIndexFileLocation)}, * {@link #addSymbols(IASTTranslationUnit, IWritableIndex, int, IProgressMonitor)} * {@link #postAddToIndex(IIndexFileLocation, IIndexFile)}, @@ -142,9 +167,13 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer * @since 4.0 */ protected void parseTUs(IWritableIndex index, int readlockCount, Collection sources, Collection headers, IProgressMonitor monitor) throws CoreException, InterruptedException { + int options= 0; + if (checkProperty(IndexerPreferences.KEY_SKIP_ALL_REFERENCES)) { + options |= AbstractLanguage.OPTION_SKIP_FUNCTION_BODIES; + } for (Iterator iter = fFilesUpFront.iterator(); iter.hasNext();) { String upfront= (String) iter.next(); - parseUpFront(upfront, index, readlockCount, monitor); + parseUpFront(upfront, options, index, readlockCount, monitor); } // sources first @@ -157,7 +186,7 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer updateInfo(0,0,-1); } else if (needToUpdate(ifl)) { - parseTU(tu, index, readlockCount, monitor); + parseTU(tu, options, index, readlockCount, monitor); } } @@ -177,7 +206,7 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer else { ITranslationUnit context= findContext(index, location); if (context != null) { - parseTU(context, index, readlockCount, monitor); + parseTU(context, options, index, readlockCount, monitor); } } } @@ -197,7 +226,7 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer iter.remove(); } else { - parseTU(tu, index, readlockCount, monitor); + parseTU(tu, options, index, readlockCount, monitor); } } } @@ -218,7 +247,7 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer } - private void parseTU(ITranslationUnit tu, IWritableIndex index, int readlockCount, IProgressMonitor pm) throws CoreException, InterruptedException { + private void parseTU(ITranslationUnit tu, int options, IWritableIndex index, int readlockCount, IProgressMonitor pm) throws CoreException, InterruptedException { IPath path= tu.getPath(); try { if (fShowActivity) { @@ -227,7 +256,7 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer pm.subTask(MessageFormat.format(Messages.PDOMIndexerTask_parsingFileTask, new Object[]{path.lastSegment(), path.removeLastSegments(1).toString()})); long start= System.currentTimeMillis(); - IASTTranslationUnit ast= createAST(tu, pm); + IASTTranslationUnit ast= createAST(tu, options, pm); fStatistics.fParsingTime += System.currentTimeMillis()-start; if (ast != null) { addSymbols(ast, index, readlockCount, pm); @@ -244,7 +273,7 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer } } - private void parseUpFront(String file, IWritableIndex index, int readlockCount, IProgressMonitor pm) throws CoreException, InterruptedException { + private void parseUpFront(String file, int options, IWritableIndex index, int readlockCount, IProgressMonitor pm) throws CoreException, InterruptedException { file= file.trim(); if (file.length() == 0) { return; @@ -262,8 +291,9 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer final IProject project = getProject().getProject(); IContentType ct= CContentTypes.getContentType(project, file); if (ct != null) { - ILanguage lang = LanguageManager.getInstance().getLanguage(ct); - if (lang != null) { + ILanguage l = LanguageManager.getInstance().getLanguage(ct); + if (l instanceof AbstractLanguage) { + AbstractLanguage lang= (AbstractLanguage) l; IScannerInfoProvider provider= CCorePlugin.getDefault().getScannerInfoProvider(project); IScannerInfo scanInfo; if (provider != null) { @@ -278,7 +308,7 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer fDummyFileURI= findLocation(fDummyFileName).getURI(); } CodeReader codeReader= new CodeReader(fDummyFileName, code.toCharArray()); - ast= createAST(lang, codeReader, scanInfo, pm); + ast= createAST(lang, codeReader, scanInfo, options, pm); } } @@ -387,7 +417,14 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer System.out.println(name + " " + getProject().getElementName() //$NON-NLS-1$ + " (" + info.fCompletedSources + " sources, " //$NON-NLS-1$ //$NON-NLS-2$ + info.fCompletedHeaders + " headers)"); //$NON-NLS-1$ - + boolean allFiles= getIndexAllFiles(); + boolean skipRefs= checkProperty(IndexerPreferences.KEY_SKIP_ALL_REFERENCES); + boolean skipTypeRefs= skipRefs || checkProperty(IndexerPreferences.KEY_SKIP_TYPE_REFERENCES); + System.out.println(name + " Options: " //$NON-NLS-1$ + + "parseAllFiles=" + allFiles //$NON-NLS-1$ + + ",skipReferences=" + skipRefs //$NON-NLS-1$ + + ", skipTypeReferences=" + skipTypeRefs //$NON-NLS-1$ + + "."); //$NON-NLS-1$ System.out.println(name + " Timings: " //$NON-NLS-1$ + (System.currentTimeMillis() - start) + " total, " //$NON-NLS-1$ + fStatistics.fParsingTime + " parser, " //$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexerTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexerTask.java index ac8ef1757ef..64887dd5014 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexerTask.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexerTask.java @@ -25,7 +25,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.index.IIndexFile; import org.eclipse.cdt.core.index.IIndexFileLocation; import org.eclipse.cdt.core.index.IndexLocationFactory; -import org.eclipse.cdt.core.model.ILanguage; +import org.eclipse.cdt.core.model.AbstractLanguage; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.IScannerInfo; @@ -36,7 +36,6 @@ import org.eclipse.cdt.internal.core.index.IndexBasedCodeReaderFactory; import org.eclipse.cdt.internal.core.index.IndexBasedCodeReaderFactory.FileInfo; import org.eclipse.cdt.internal.core.pdom.indexer.PDOMIndexerTask; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; class PDOMFastIndexerTask extends PDOMIndexerTask { @@ -128,31 +127,9 @@ class PDOMFastIndexerTask extends PDOMIndexerTask { return result; } - protected IASTTranslationUnit createAST(ITranslationUnit tu, IProgressMonitor pm) throws CoreException { - IPath path = tu.getLocation(); - if (path == null) { - return null; - } - ILanguage language = tu.getLanguage(); - if (language == null) - return null; - - // skip if no scanner info - IScannerInfo scanner= tu.getScannerInfo(getIndexAllFiles()); - if (scanner == null) { - return null; - } - CodeReader codeReader = tu.getCodeReader(); - if (codeReader == null) { - return null; - } - - return createAST(language, codeReader, scanner, pm); - } - - protected IASTTranslationUnit createAST(ILanguage lang, CodeReader codeReader, IScannerInfo scanInfo, IProgressMonitor pm) throws CoreException { + protected IASTTranslationUnit createAST(AbstractLanguage lang, CodeReader codeReader, IScannerInfo scanInfo, int options, IProgressMonitor pm) throws CoreException { // get the AST in a "Fast" way - IASTTranslationUnit ast= lang.getASTTranslationUnit(codeReader, scanInfo, fCodeReaderFactory, fIndex, ParserUtil.getParserLogService()); + IASTTranslationUnit ast= lang.getASTTranslationUnit(codeReader, scanInfo, fCodeReaderFactory, fIndex, options, ParserUtil.getParserLogService()); if (pm.isCanceled()) { return null; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexerTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexerTask.java index 665b7088cf7..7f8b47d7e23 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexerTask.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexerTask.java @@ -25,7 +25,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.index.IIndexFile; import org.eclipse.cdt.core.index.IIndexFileLocation; import org.eclipse.cdt.core.index.IndexLocationFactory; -import org.eclipse.cdt.core.model.ILanguage; +import org.eclipse.cdt.core.model.AbstractLanguage; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.IScannerInfo; @@ -35,7 +35,6 @@ import org.eclipse.cdt.internal.core.index.IWritableIndex; import org.eclipse.cdt.internal.core.index.IWritableIndexManager; import org.eclipse.cdt.internal.core.pdom.indexer.PDOMIndexerTask; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; /** @@ -110,6 +109,9 @@ class PDOMFullIndexerTask extends PDOMIndexerTask { } private void setupIndex() throws CoreException { + // there is no mechanism to clear dirty files from the cache, so flush it. + SavedCodeReaderFactory.getInstance().getCodeReaderCache().flush(); + fIndex = ((IWritableIndexManager) CCorePlugin.getIndexManager()).getWritableIndex(getProject()); fIndex.resetCacheCounters(); } @@ -132,21 +134,9 @@ class PDOMFullIndexerTask extends PDOMIndexerTask { return result; } - protected IASTTranslationUnit createAST(ITranslationUnit tu, IProgressMonitor pm) throws CoreException { - IPath path = tu.getLocation(); - if (path == null) { - return null; - } - int options= 0; - if (!getIndexAllFiles()) { - options |= ITranslationUnit.AST_SKIP_IF_NO_BUILD_INFO; - } - return tu.getAST(null, options); - } - - protected IASTTranslationUnit createAST(ILanguage lang, CodeReader codeReader, IScannerInfo scanInfo, IProgressMonitor pm) throws CoreException { + protected IASTTranslationUnit createAST(AbstractLanguage lang, CodeReader codeReader, IScannerInfo scanInfo, int options, IProgressMonitor pm) throws CoreException { SavedCodeReaderFactory codeReaderFactory= SavedCodeReaderFactory.getInstance(); - IASTTranslationUnit ast= lang.getASTTranslationUnit(codeReader, scanInfo, codeReaderFactory, null, ParserUtil.getParserLogService()); + IASTTranslationUnit ast= lang.getASTTranslationUnit(codeReader, scanInfo, codeReaderFactory, null, options, ParserUtil.getParserLogService()); if (pm.isCanceled()) { return null; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/AbstractIndexerPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/AbstractIndexerPage.java index 3f3c00b6d1c..bb6f0e924c5 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/AbstractIndexerPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/AbstractIndexerPage.java @@ -16,6 +16,8 @@ import java.util.Properties; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; @@ -35,6 +37,8 @@ public abstract class AbstractIndexerPage extends AbstractCOptionPage { private Button fAllFiles; private Text fFilesToParseUpFront; + private Button fSkipReferences; + private Button fSkipTypeReferences; protected AbstractIndexerPage() { super(); @@ -51,7 +55,15 @@ public abstract class AbstractIndexerPage extends AbstractCOptionPage { public void createControl(Composite parent) { Composite page = ControlFactory.createComposite(parent, 1); fAllFiles= createAllFilesButton(page); + fSkipReferences= createSkipReferencesButton(page); + fSkipTypeReferences= createSkipTypeReferencesButton(page); fFilesToParseUpFront= createParseUpFrontTextField(page); + + fSkipReferences.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + updateEnablement(); + } + }); setControl(page); } @@ -65,10 +77,19 @@ public abstract class AbstractIndexerPage extends AbstractCOptionPage { boolean indexAllFiles= TRUE.equals(properties.get(IndexerPreferences.KEY_INDEX_ALL_FILES)); fAllFiles.setSelection(indexAllFiles); } + if (fSkipReferences != null) { + boolean skipReferences= TRUE.equals(properties.get(IndexerPreferences.KEY_SKIP_ALL_REFERENCES)); + fSkipReferences.setSelection(skipReferences); + } + if (fSkipTypeReferences != null) { + boolean skipTypeReferences= TRUE.equals(properties.get(IndexerPreferences.KEY_SKIP_TYPE_REFERENCES)); + fSkipTypeReferences.setSelection(skipTypeReferences); + } if (fFilesToParseUpFront != null) { String files = getNotNull(properties, IndexerPreferences.KEY_FILES_TO_PARSE_UP_FRONT); fFilesToParseUpFront.setText(files); } + updateEnablement(); } /** @@ -83,6 +104,12 @@ public abstract class AbstractIndexerPage extends AbstractCOptionPage { if (fFilesToParseUpFront != null) { props.put(IndexerPreferences.KEY_FILES_TO_PARSE_UP_FRONT, fFilesToParseUpFront.getText()); } + if (fSkipReferences != null) { + props.put(IndexerPreferences.KEY_SKIP_ALL_REFERENCES, String.valueOf(fSkipReferences.getSelection())); + } + if (fSkipTypeReferences != null) { + props.put(IndexerPreferences.KEY_SKIP_TYPE_REFERENCES, String.valueOf(fSkipTypeReferences.getSelection())); + } return props; } @@ -100,10 +127,10 @@ public abstract class AbstractIndexerPage extends AbstractCOptionPage { throw new UnsupportedOperationException(); } - /** - * @deprecated, never called. - */ public void updateEnablement() { + if (fSkipReferences != null && fSkipTypeReferences != null) { + fSkipTypeReferences.setEnabled(!fSkipReferences.getSelection()); + } } private String getNotNull(Properties properties, String key) { @@ -123,4 +150,12 @@ public abstract class AbstractIndexerPage extends AbstractCOptionPage { private Button createAllFilesButton(Composite page) { return ControlFactory.createCheckBox(page, INDEX_ALL_FILES); } + + private Button createSkipReferencesButton(Composite page) { + return ControlFactory.createCheckBox(page, DialogsMessages.AbstractIndexerPage_skipAllReferences); + } + + private Button createSkipTypeReferencesButton(Composite page) { + return ControlFactory.createCheckBox(page, DialogsMessages.AbstractIndexerPage_skipTypeReferences); + } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/DialogsMessages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/DialogsMessages.java index 12394c80292..11f8671989a 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/DialogsMessages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/DialogsMessages.java @@ -17,6 +17,8 @@ public class DialogsMessages extends NLS { private static final String BUNDLE_NAME = "org.eclipse.cdt.ui.dialogs.DialogsMessages"; //$NON-NLS-1$ public static String AbstractIndexerPage_indexAllFiles; public static String AbstractIndexerPage_indexUpFront; + public static String AbstractIndexerPage_skipAllReferences; + public static String AbstractIndexerPage_skipTypeReferences; public static String PreferenceScopeBlock_enableProjectSettings; public static String PreferenceScopeBlock_preferenceLink; public static String PreferenceScopeBlock_storeWithProject; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/DialogsMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/DialogsMessages.properties index 75e6c292621..85b88284abe 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/DialogsMessages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/DialogsMessages.properties @@ -12,4 +12,6 @@ PreferenceScopeBlock_enableProjectSettings=Enable project specific settings PreferenceScopeBlock_storeWithProject=Store settings with project PreferenceScopeBlock_preferenceLink=Configure Workspace Settings... AbstractIndexerPage_indexAllFiles=Index all files (files neither built nor included, also) +AbstractIndexerPage_skipAllReferences=Skip all references (Call Hierarchy and Search will not work) +AbstractIndexerPage_skipTypeReferences=Skip type references (Search for type references will not work) AbstractIndexerPage_indexUpFront=Files to index up-front: