1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-10 03:53:21 +02:00

Bug 421289 - Preferences for indexing all versions of all or specific

headers

Change-Id: If0788d35af7aea0f95ffbff10b4e5d1b9f30ba62
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/19033
Tested-by: Hudson CI
Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
This commit is contained in:
Marc-Andre Laperle 2013-11-25 12:48:58 -05:00
parent 3c01b0d5f1
commit 431dff5671
10 changed files with 146 additions and 16 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2011 QNX Software Systems and others.
* Copyright (c) 2005, 2013 QNX Software Systems 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
@ -12,11 +12,13 @@
* Anton Leherbauer (Wind River Systems)
* IBM Corporation
* Sergey Prigogin (Google)
* Marc-Andre Laperle (Ericsson)
*******************************************************************************/
package org.eclipse.cdt.internal.core.index;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
@ -42,6 +44,7 @@ import org.eclipse.cdt.internal.core.pdom.ASTFilePathResolver;
import org.eclipse.cdt.internal.core.pdom.AbstractIndexerTask;
import org.eclipse.cdt.internal.core.pdom.AbstractIndexerTask.IndexFileContent;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
/**
* Code reader factory, that fakes code readers for header files already stored in the index.
@ -58,6 +61,9 @@ public final class IndexBasedFileContentProvider extends InternalFileContentProv
private long fFileSizeLimit= 0;
private IIndexFile[] fContextToHeaderGap;
private final Map<IIndexFileLocation, IFileNomination> fPragmaOnce= new HashMap<IIndexFileLocation, IFileNomination>();
private Set<String> fHeadersToIndexAllVersions = Collections.emptySet();
private boolean fIndexAllHeaderVersions;
public IndexBasedFileContentProvider(IIndex index,
ASTFilePathResolver pathResolver, int linkage, IncludeFileContentProvider fallbackFactory) {
@ -305,4 +311,22 @@ public final class IndexBasedFileContentProvider extends InternalFileContentProv
}
return null;
}
public void setHeadersToIndexAllVersions(Set<String> headers) {
fHeadersToIndexAllVersions = headers;
}
public void setIndexAllHeaderVersions(boolean indexAllHeaderVersions) {
fIndexAllHeaderVersions = indexAllHeaderVersions;
}
@Override
public boolean shouldIndexAllHeaderVersions(String fileName) {
if (fIndexAllHeaderVersions) {
return true;
}
String last = new Path(fileName).lastSegment();
return fHeadersToIndexAllVersions.contains(last);
}
}

View file

@ -10,6 +10,7 @@
* Anton Leherbauer (Wind River Systems)
* Markus Schorn (Wind River Systems)
* Sergey Prigogin (Google)
* Marc-Andre Laperle (Ericsson)
*******************************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner;
@ -322,16 +323,19 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
}
private char[] detectIncludeGuard(String filePath, AbstractCharArray source, ScannerContext ctx) {
final char[] guard = IncludeGuardDetection.detectIncludeGuard(source, fLexOptions, fPPKeywords);
if (guard != null) {
IFileNomination nom= fLocationMap.reportPragmaOnceSemantics(ctx.getLocationCtx());
fFileContentProvider.reportPragmaOnceSemantics(filePath, nom);
ctx.internalModification(guard);
ctx.setPragmaOnce(true);
return guard;
} else {
ctx.trackSignificantMacros();
if (!fFileContentProvider.shouldIndexAllHeaderVersions(filePath)) {
final char[] guard = IncludeGuardDetection.detectIncludeGuard(source, fLexOptions, fPPKeywords);
if (guard != null) {
IFileNomination nom= fLocationMap.reportPragmaOnceSemantics(ctx.getLocationCtx());
fFileContentProvider.reportPragmaOnceSemantics(filePath, nom);
ctx.internalModification(guard);
ctx.setPragmaOnce(true);
return guard;
}
}
ctx.trackSignificantMacros();
if (ctx != fRootContext) {
if (fLog.isTracing(TRACE_NO_GUARD)) {
if (fTracedGuards == null)

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2011 Wind River Systems, Inc. and others.
* Copyright (c) 2009, 2013 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
@ -8,6 +8,7 @@
* Contributors:
* Markus Schorn - initial API and implementation
* Sergey Prigogin (Google)
* Marc-Andre Laperle (Ericsson)
*******************************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner;
@ -154,5 +155,12 @@ public abstract class InternalFileContentProvider extends IncludeFileContentProv
*/
public String getContextPath() {
return null;
}
}
/**
* Returns whether or not the header file should be indexed for all versions
*/
public boolean shouldIndexAllHeaderVersions(String headerFileName) {
return false;
}
}

View file

@ -10,6 +10,7 @@
* IBM Corporation
* Sergey Prigogin (Google)
* Thomas Corbat (IFS)
* Marc-Andre Laperle (Ericsson)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom;
@ -295,6 +296,8 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
private int fUpdateFlags= IIndexManager.UPDATE_ALL;
private UnusedHeaderStrategy fIndexHeadersWithoutContext= UnusedHeaderStrategy.useDefaultLanguage;
private boolean fIndexFilesWithoutConfiguration= true;
private boolean fIndexAllHeaderVersions = false;
private Set<String> fHeadersToIndexAllVersions = Collections.emptySet();
private List<LinkageTask> fRequestsPerLinkage= new ArrayList<LinkageTask>();
private Map<IIndexFile, IndexFileContent> fIndexContentCache= new LRUCache<IIndexFile, IndexFileContent>(500);
private Map<IIndexFileLocation, IIndexFragmentFile[]> fIndexFilesCache= new LRUCache<IIndexFileLocation, IIndexFragmentFile[]>(5000);
@ -357,6 +360,14 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
fFileSizeLimit= limit;
}
public void setIndexAllHeaderVersions(boolean indexAllHeaderVersions) {
fIndexAllHeaderVersions = indexAllHeaderVersions;
}
public void setHeadersToIndexAllVersions(Set<String> headers) {
fHeadersToIndexAllVersions = headers;
}
/**
* @see IPDOMIndexerTask#acceptUrgentTask(IPDOMIndexerTask)
*/
@ -1159,6 +1170,8 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
language.getLinkageID(), fileContentProvider, this);
ibfcp.setContextToHeaderGap(ctx2header);
ibfcp.setFileSizeLimit(fFileSizeLimit);
ibfcp.setHeadersToIndexAllVersions(fHeadersToIndexAllVersions);
ibfcp.setIndexAllHeaderVersions(fIndexAllHeaderVersions);
fCodeReaderFactory= ibfcp;
} else {
fCodeReaderFactory= fileContentProvider;

View file

@ -35,6 +35,8 @@ public abstract class AbstractPDOMIndexer implements IPDOMIndexer {
fProperties.put(IndexerPreferences.KEY_SKIP_IMPLICIT_REFERENCES, String.valueOf(false));
fProperties.put(IndexerPreferences.KEY_SKIP_TYPE_REFERENCES, String.valueOf(false));
fProperties.put(IndexerPreferences.KEY_SKIP_MACRO_REFERENCES, String.valueOf(false));
fProperties.put(IndexerPreferences.KEY_INDEX_ALL_HEADER_VERSIONS, String.valueOf(false));
fProperties.put(IndexerPreferences.KEY_INDEX_ALL_VERSIONS_SPECIFIC_HEADERS, ""); //$NON-NLS-1$
}
@Override

View file

@ -10,6 +10,7 @@
* Sergey Prigogin (Google)
* Anton Gorenkov - Enable the "Index unused headers" preference by default (Bug 377992)
* IBM Corporation
* Marc-Andre Laperle (Ericsson)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.indexer;
@ -64,6 +65,8 @@ public class IndexerPreferences {
public static final String KEY_REINDEX_ON_CONFIG_CHANGE = "reindexOnConfigChange"; //$NON-NLS-1$
public static final String KEY_REINDEX_ON_INDEXER_CHANGE = "reindexOnIndexerChange"; //$NON-NLS-1$
public static final String KEY_INDEX_ALL_HEADER_VERSIONS= "indexAllHeaderVersions"; //$NON-NLS-1$
public static final String KEY_INDEX_ALL_VERSIONS_SPECIFIC_HEADERS= "indexAllVersionsSpecificHeaders"; //$NON-NLS-1$
private static final String DEFAULT_INDEX_IMPORT_LOCATION = ".settings/cdt-index.zip"; //$NON-NLS-1$
private static final int DEFAULT_UPDATE_POLICY= 0;
@ -329,6 +332,7 @@ public class IndexerPreferences {
prefs.putBoolean(KEY_SKIP_TYPE_REFERENCES, false);
prefs.putBoolean(KEY_SKIP_MACRO_REFERENCES, false);
prefs.put(KEY_INDEX_IMPORT_LOCATION, DEFAULT_INDEX_IMPORT_LOCATION);
prefs.putBoolean(KEY_INDEX_ALL_HEADER_VERSIONS, false);
}
public static void setDefaultIndexerId(String defaultId) {

View file

@ -8,13 +8,16 @@
* Contributors:
* Markus Schorn - initial API and implementation
* Sergey Prigogin (Google)
* Marc-Andre Laperle (Ericsson)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.indexer;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CCorePreferenceConstants;
@ -61,6 +64,8 @@ public abstract class PDOMIndexerTask extends AbstractIndexerTask implements IPD
setShowProblems(checkDebugOption(TRACE_PROBLEMS, TRUE));
final long limit = getIntProperty(IndexerPreferences.KEY_SKIP_FILES_LARGER_THAN_MB, 0);
setFileSizeLimit(limit * 1024 * 1024);
setIndexAllHeaderVersions(checkProperty(IndexerPreferences.KEY_INDEX_ALL_HEADER_VERSIONS));
setHeadersToIndexAllVersions(getStringSet(IndexerPreferences.KEY_INDEX_ALL_VERSIONS_SPECIFIC_HEADERS));
if (checkProperty(IndexerPreferences.KEY_SKIP_ALL_REFERENCES)) {
setSkipReferences(SKIP_ALL_REFERENCES);
} else {
@ -157,6 +162,15 @@ public abstract class PDOMIndexerTask extends AbstractIndexerTask implements IPD
return TRUE.equals(getIndexer().getProperty(key));
}
private Set<String> getStringSet(String key) {
String prefSetting = getIndexer().getProperty(key);
if (prefSetting != null && !prefSetting.isEmpty()) {
return new HashSet<String>(Arrays.asList(prefSetting.split(","))); //$NON-NLS-1$
}
return Collections.emptySet();
}
private int getIntProperty(String key, int defaultValue) {
final String value = getIndexer().getProperty(key);
if (value != null) {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2011 IBM Corporation and others.
* Copyright (c) 2005, 2013 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
@ -9,6 +9,7 @@
* Bogdan Gheorghe (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
* Sergey Prigogin (Google)
* Marc-Andre Laperle (Ericsson)
*******************************************************************************/
package org.eclipse.cdt.ui.dialogs;
@ -28,6 +29,7 @@ import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
@ -53,6 +55,8 @@ public abstract class AbstractIndexerPage extends AbstractCOptionPage {
private Button fSkipReferences;
private Button fSkipImplicitReferences;
private Button fSkipMacroAndTypeReferences;
private Button fIndexAllHeaderVersions;
private Text fIndexAllVersionsSpecificHeaders;
private IPropertyChangeListener validityChangeListener = new IPropertyChangeListener() {
@Override
@ -97,6 +101,26 @@ public abstract class AbstractIndexerPage extends AbstractCOptionPage {
fAllHeadersDefault= createAllCppHeadersButton(group);
fAllHeadersAlt= createAllCHeadersButton(group);
}
fIndexAllHeaderVersions = ControlFactory.createCheckBox(group, DialogsMessages.AbstractIndexerPage_indexAllHeaderVersions);
fIndexAllHeaderVersions.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
updateEnablement();
}
});
Label label = ControlFactory.createLabel(group, DialogsMessages.AbstractIndexerPage_indexAllVersionsSpecificHeaders);
GridData layoutData = new GridData();
layoutData.horizontalSpan = 3;
layoutData.horizontalIndent = 10;
label.setLayoutData(layoutData);
fIndexAllVersionsSpecificHeaders = ControlFactory.createTextField(group);
layoutData = new GridData(GridData.FILL_HORIZONTAL);
layoutData.horizontalSpan = 3;
layoutData.horizontalIndent = 10;
fIndexAllVersionsSpecificHeaders.setLayoutData(layoutData);
fIndexOnOpen= createIndexOnOpenButton(group);
fIncludeHeuristics= createIncludeHeuristicsButton(group);
@ -180,7 +204,15 @@ public abstract class AbstractIndexerPage extends AbstractCOptionPage {
boolean skipTypeReferences= TRUE.equals(properties.get(IndexerPreferences.KEY_SKIP_TYPE_REFERENCES));
boolean skipMacroReferences= TRUE.equals(properties.get(IndexerPreferences.KEY_SKIP_MACRO_REFERENCES));
fSkipMacroAndTypeReferences.setSelection(skipTypeReferences && skipMacroReferences);
}
}
if (fIndexAllHeaderVersions != null) {
boolean indexAllHeaderVersions = TRUE.equals(properties.get((IndexerPreferences.KEY_INDEX_ALL_HEADER_VERSIONS)));
fIndexAllHeaderVersions.setSelection(indexAllHeaderVersions);
}
if (fIndexAllVersionsSpecificHeaders != null) {
String indexAllVersionsSpecificHeaders = properties.getProperty((IndexerPreferences.KEY_INDEX_ALL_VERSIONS_SPECIFIC_HEADERS), ""); //$NON-NLS-1$
fIndexAllVersionsSpecificHeaders.setText(indexAllVersionsSpecificHeaders);
}
updateEnablement();
}
@ -219,6 +251,25 @@ public abstract class AbstractIndexerPage extends AbstractCOptionPage {
props.put(IndexerPreferences.KEY_SKIP_TYPE_REFERENCES, value);
props.put(IndexerPreferences.KEY_SKIP_MACRO_REFERENCES, value);
}
if (fIndexAllHeaderVersions != null) {
props.put((IndexerPreferences.KEY_INDEX_ALL_HEADER_VERSIONS), String.valueOf(fIndexAllHeaderVersions.getSelection()));
}
if (fIndexAllVersionsSpecificHeaders != null) {
String[] headers = fIndexAllVersionsSpecificHeaders.getText().split(","); //$NON-NLS-1$
StringBuilder sb = new StringBuilder();
for (String header : headers) {
header = header.trim();
if (header.isEmpty()) {
continue;
}
if (sb.length() > 0) {
sb.append(","); //$NON-NLS-1$
}
sb.append(header);
}
props.put((IndexerPreferences.KEY_INDEX_ALL_VERSIONS_SPECIFIC_HEADERS), sb.toString());
}
return props;
}
@ -248,6 +299,10 @@ public abstract class AbstractIndexerPage extends AbstractCOptionPage {
fSkipMacroAndTypeReferences.setEnabled(!skipReferences);
}
}
if (fIndexAllHeaderVersions != null) {
fIndexAllVersionsSpecificHeaders.setEnabled(!fIndexAllHeaderVersions.getSelection());
}
}
private void updateValidState() {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2011 Wind River Systems, Inc. and others.
* Copyright (c) 2007, 2013 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
@ -10,6 +10,7 @@
* IBM Corporation
* Andrew Ferguson (Symbian)
* Sergey Prigogin (Google)
* Marc-Andre Laperle (Ericsson)
*******************************************************************************/
package org.eclipse.cdt.ui.dialogs;
@ -29,6 +30,8 @@ class DialogsMessages extends NLS {
public static String AbstractIndexerPage_skipTypeAndMacroReferences;
public static String AbstractIndexerPage_skipTypeReferences;
public static String AbstractIndexerPage_skipMacroReferences;
public static String AbstractIndexerPage_indexAllHeaderVersions;
public static String AbstractIndexerPage_indexAllVersionsSpecificHeaders;
public static String CacheSizeBlock_MB;
public static String IndexerBlock_fixedBuildConfig;
public static String IndexerBlock_indexerOptions;

View file

@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2007, 2011 Wind River Systems, Inc. and others.
# Copyright (c) 2007, 2013 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
@ -10,6 +10,7 @@
# IBM Corporation
# Andrew Ferguson (Symbian)
# Sergey Prigogin (Google)
# Marc-Andre Laperle (Ericsson)
###############################################################################
PreferenceScopeBlock_enableProjectSettings=Enable project specific settings
PreferenceScopeBlock_storeWithProject=Store settings with project
@ -27,6 +28,8 @@ AbstractIndexerPage_skipImplicitReferences=Skip implicit references (e.g. overlo
AbstractIndexerPage_skipTypeAndMacroReferences=Skip type and macro references (Search for these references will not work)
AbstractIndexerPage_skipTypeReferences=Skip type references (Search for type references will not work)
AbstractIndexerPage_skipMacroReferences=Skip macro references (Search for macro references will not work)
AbstractIndexerPage_indexAllHeaderVersions=Index all header variants
AbstractIndexerPage_indexAllVersionsSpecificHeaders=Index all variants of specific headers:
CacheSizeBlock_cacheLimitGroup=Cache limits
CacheSizeBlock_indexDatabaseCache=Index database cache:
CacheSizeBlock_limitRelativeToMaxHeapSize=Limit relative to the maximum heap size: