mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fix for 186533, picking up indexer project preferences.
This commit is contained in:
parent
b6e7f83844
commit
6d75f34f60
8 changed files with 72 additions and 45 deletions
|
@ -117,7 +117,9 @@ public class PDOMManager implements IWritableIndexManager, IListener {
|
||||||
fProject= prj;
|
fProject= prj;
|
||||||
}
|
}
|
||||||
public void preferenceChange(PreferenceChangeEvent event) {
|
public void preferenceChange(PreferenceChangeEvent event) {
|
||||||
onPreferenceChange(fProject, event);
|
if (fProject.getProject().isOpen()) {
|
||||||
|
onPreferenceChange(fProject, event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,9 +391,14 @@ public class PDOMManager implements IWritableIndexManager, IListener {
|
||||||
|
|
||||||
private void changeIndexer(ICProject cproject) throws CoreException {
|
private void changeIndexer(ICProject cproject) throws CoreException {
|
||||||
assert !Thread.holdsLock(fProjectToPDOM);
|
assert !Thread.holdsLock(fProjectToPDOM);
|
||||||
IPDOMIndexer oldIndexer= null;
|
|
||||||
IProject prj= cproject.getProject();
|
|
||||||
|
|
||||||
|
// if there is no indexer, don't touch the preferences.
|
||||||
|
IPDOMIndexer oldIndexer= getIndexer(cproject);
|
||||||
|
if (oldIndexer == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
IProject prj= cproject.getProject();
|
||||||
String newid= IndexerPreferences.get(prj, IndexerPreferences.KEY_INDEXER_ID, IPDOMManager.ID_NO_INDEXER);
|
String newid= IndexerPreferences.get(prj, IndexerPreferences.KEY_INDEXER_ID, IPDOMManager.ID_NO_INDEXER);
|
||||||
Properties props= IndexerPreferences.getProperties(prj);
|
Properties props= IndexerPreferences.getProperties(prj);
|
||||||
|
|
||||||
|
@ -640,8 +647,7 @@ public class PDOMManager implements IWritableIndexManager, IListener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean allFiles= IndexerPreferences.getIndexAllFiles(project.getProject());
|
DeltaAnalyzer deltaAnalyzer = new DeltaAnalyzer();
|
||||||
DeltaAnalyzer deltaAnalyzer = new DeltaAnalyzer(allFiles);
|
|
||||||
deltaAnalyzer.analyzeDelta(delta);
|
deltaAnalyzer.analyzeDelta(delta);
|
||||||
ITranslationUnit[] added= deltaAnalyzer.getAddedTUs();
|
ITranslationUnit[] added= deltaAnalyzer.getAddedTUs();
|
||||||
ITranslationUnit[] changed= deltaAnalyzer.getChangedTUs();
|
ITranslationUnit[] changed= deltaAnalyzer.getChangedTUs();
|
||||||
|
|
|
@ -15,7 +15,6 @@ import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
|
||||||
import org.eclipse.cdt.core.model.ICContainer;
|
import org.eclipse.cdt.core.model.ICContainer;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ICElementDelta;
|
import org.eclipse.cdt.core.model.ICElementDelta;
|
||||||
|
@ -24,13 +23,11 @@ import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
|
|
||||||
public class DeltaAnalyzer {
|
public class DeltaAnalyzer {
|
||||||
private boolean fAllFiles;
|
|
||||||
private List fAdded= new ArrayList();
|
private List fAdded= new ArrayList();
|
||||||
private List fChanged= new ArrayList();
|
private List fChanged= new ArrayList();
|
||||||
private List fRemoved= new ArrayList();
|
private List fRemoved= new ArrayList();
|
||||||
|
|
||||||
public DeltaAnalyzer(boolean allFiles) {
|
public DeltaAnalyzer() {
|
||||||
fAllFiles= allFiles;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void analyzeDelta(ICElementDelta delta) throws CoreException {
|
public void analyzeDelta(ICElementDelta delta) throws CoreException {
|
||||||
|
@ -55,15 +52,11 @@ public class DeltaAnalyzer {
|
||||||
switch (delta.getKind()) {
|
switch (delta.getKind()) {
|
||||||
case ICElementDelta.CHANGED:
|
case ICElementDelta.CHANGED:
|
||||||
if ((flags & ICElementDelta.F_CONTENT) != 0) {
|
if ((flags & ICElementDelta.F_CONTENT) != 0) {
|
||||||
if (fAllFiles || !CoreModel.isScannerInformationEmpty(tu.getResource()) || tu.isHeaderUnit()) {
|
fChanged.add(tu);
|
||||||
fChanged.add(tu);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ICElementDelta.ADDED:
|
case ICElementDelta.ADDED:
|
||||||
if (fAllFiles || !CoreModel.isScannerInformationEmpty(tu.getResource()) || tu.isHeaderUnit()) {
|
fAdded.add(tu);
|
||||||
fAdded.add(tu);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case ICElementDelta.REMOVED:
|
case ICElementDelta.REMOVED:
|
||||||
fRemoved.add(tu);
|
fRemoved.add(tu);
|
||||||
|
@ -81,7 +74,7 @@ public class DeltaAnalyzer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void collectSources(ICContainer container, Collection sources) throws CoreException {
|
private void collectSources(ICContainer container, Collection sources) throws CoreException {
|
||||||
container.accept(new TranslationUnitCollector(sources, sources, fAllFiles, new NullProgressMonitor()));
|
container.accept(new TranslationUnitCollector(sources, sources, true, new NullProgressMonitor()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ITranslationUnit[] getAddedTUs() {
|
public ITranslationUnit[] getAddedTUs() {
|
||||||
|
|
|
@ -380,7 +380,7 @@ public class IndexerPreferences {
|
||||||
|
|
||||||
public static int getUpdatePolicy(IProject project) {
|
public static int getUpdatePolicy(IProject project) {
|
||||||
// no support for project specific policies
|
// no support for project specific policies
|
||||||
Preferences[] prefs= getPreferences(null);
|
Preferences[] prefs= getInstancePreferencesArray();
|
||||||
return getUpdatePolicy(prefs);
|
return getUpdatePolicy(prefs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -402,8 +402,4 @@ public class IndexerPreferences {
|
||||||
}
|
}
|
||||||
return DEFAULT_UPDATE_POLICY;
|
return DEFAULT_UPDATE_POLICY;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean getIndexAllFiles(IProject project) {
|
|
||||||
return "true".equals(IndexerPreferences.get(project.getProject(), IndexerPreferences.KEY_INDEX_ALL_FILES, null)); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,6 +71,7 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer
|
||||||
private String fDummyFileName;
|
private String fDummyFileName;
|
||||||
private URI fDummyFileURI;
|
private URI fDummyFileURI;
|
||||||
private int fUpdateFlags= IIndexManager.UPDATE_ALL;
|
private int fUpdateFlags= IIndexManager.UPDATE_ALL;
|
||||||
|
private boolean fAllFilesProvided= true;
|
||||||
|
|
||||||
protected PDOMIndexerTask(AbstractPDOMIndexer indexer) {
|
protected PDOMIndexerTask(AbstractPDOMIndexer indexer) {
|
||||||
fIndexer= indexer;
|
fIndexer= indexer;
|
||||||
|
@ -116,6 +117,14 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer
|
||||||
fFilesUpFront.addAll(Arrays.asList(fIndexer.getFilesToParseUpFront()));
|
fFilesUpFront.addAll(Arrays.asList(fIndexer.getFilesToParseUpFront()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final public void setAllFilesProvided(boolean allFiles) {
|
||||||
|
fAllFilesProvided= allFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
final public boolean getAllFilesProvided() {
|
||||||
|
return fAllFilesProvided;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether a given debug option is enabled. See {@link IPDOMIndexerTask}
|
* Checks whether a given debug option is enabled. See {@link IPDOMIndexerTask}
|
||||||
* for valid values.
|
* for valid values.
|
||||||
|
@ -128,7 +137,7 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Figurues out whether all files (sources without config, headers not included)
|
* Figures out whether all files (sources without configuration, headers not included)
|
||||||
* should be parsed.
|
* should be parsed.
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -101,8 +101,10 @@ public class PDOMRebuildTask implements IPDOMIndexerTask {
|
||||||
ITranslationUnit[] tus= (ITranslationUnit[]) sources.toArray(new ITranslationUnit[sources.size()]);
|
ITranslationUnit[] tus= (ITranslationUnit[]) sources.toArray(new ITranslationUnit[sources.size()]);
|
||||||
fDelegate= fIndexer.createTask(tus, NO_TUS, NO_TUS);
|
fDelegate= fIndexer.createTask(tus, NO_TUS, NO_TUS);
|
||||||
if (fDelegate instanceof PDOMIndexerTask) {
|
if (fDelegate instanceof PDOMIndexerTask) {
|
||||||
((PDOMIndexerTask) fDelegate).setUpateFlags(IIndexManager.UPDATE_ALL);
|
final PDOMIndexerTask delegate = (PDOMIndexerTask) fDelegate;
|
||||||
((PDOMIndexerTask) fDelegate).setParseUpFront();
|
delegate.setUpateFlags(IIndexManager.UPDATE_ALL);
|
||||||
|
delegate.setParseUpFront();
|
||||||
|
delegate.setAllFilesProvided(allFiles);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,6 +92,7 @@ public class PDOMUpdateTask implements IPDOMIndexerTask {
|
||||||
if (fDelegate instanceof PDOMIndexerTask) {
|
if (fDelegate instanceof PDOMIndexerTask) {
|
||||||
final PDOMIndexerTask task = (PDOMIndexerTask) fDelegate;
|
final PDOMIndexerTask task = (PDOMIndexerTask) fDelegate;
|
||||||
task.setUpateFlags(fUpdateOptions);
|
task.setUpateFlags(fUpdateOptions);
|
||||||
|
task.setAllFilesProvided(allFiles);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,10 @@ package org.eclipse.cdt.internal.core.pdom.indexer.fast;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -25,6 +27,7 @@ import org.eclipse.cdt.core.index.IIndexFile;
|
||||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||||
import org.eclipse.cdt.core.index.IndexLocationFactory;
|
import org.eclipse.cdt.core.index.IndexLocationFactory;
|
||||||
import org.eclipse.cdt.core.model.AbstractLanguage;
|
import org.eclipse.cdt.core.model.AbstractLanguage;
|
||||||
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.cdt.core.parser.CodeReader;
|
import org.eclipse.cdt.core.parser.CodeReader;
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||||
|
@ -39,7 +42,7 @@ import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
|
||||||
class PDOMFastIndexerTask extends PDOMIndexerTask implements CallbackHandler {
|
class PDOMFastIndexerTask extends PDOMIndexerTask implements CallbackHandler {
|
||||||
private List fChanged = new ArrayList();
|
private List fChanged = new LinkedList();
|
||||||
private List fRemoved = new ArrayList();
|
private List fRemoved = new ArrayList();
|
||||||
private IWritableIndex fIndex;
|
private IWritableIndex fIndex;
|
||||||
private IndexBasedCodeReaderFactory fCodeReaderFactory;
|
private IndexBasedCodeReaderFactory fCodeReaderFactory;
|
||||||
|
@ -58,10 +61,29 @@ class PDOMFastIndexerTask extends PDOMIndexerTask implements CallbackHandler {
|
||||||
public void run(IProgressMonitor monitor) {
|
public void run(IProgressMonitor monitor) {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
try {
|
try {
|
||||||
|
// separate headers remove files that have no scanner configuration
|
||||||
|
final boolean filterFiles= !getIndexAllFiles() && getAllFilesProvided();
|
||||||
|
List headers= new ArrayList();
|
||||||
|
List sources= fChanged;
|
||||||
|
for (Iterator iter = fChanged.iterator(); iter.hasNext();) {
|
||||||
|
ITranslationUnit tu = (ITranslationUnit) iter.next();
|
||||||
|
if (tu.isSourceUnit()) {
|
||||||
|
if (filterFiles && CoreModel.isScannerInformationEmpty(tu.getResource())) {
|
||||||
|
iter.remove();
|
||||||
|
updateInfo(0, 0, -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
headers.add(tu);
|
||||||
|
iter.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setupIndexAndReaderFactory();
|
setupIndexAndReaderFactory();
|
||||||
fIndex.acquireReadLock();
|
fIndex.acquireReadLock();
|
||||||
try {
|
try {
|
||||||
registerTUsInReaderFactory();
|
registerTUsInReaderFactory(sources);
|
||||||
|
registerTUsInReaderFactory(headers);
|
||||||
|
|
||||||
Iterator i= fRemoved.iterator();
|
Iterator i= fRemoved.iterator();
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
|
@ -77,17 +99,6 @@ class PDOMFastIndexerTask extends PDOMIndexerTask implements CallbackHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// separate headers
|
|
||||||
List headers= new ArrayList();
|
|
||||||
List sources= fChanged;
|
|
||||||
for (Iterator iter = fChanged.iterator(); iter.hasNext();) {
|
|
||||||
ITranslationUnit tu = (ITranslationUnit) iter.next();
|
|
||||||
if (!tu.isSourceUnit()) {
|
|
||||||
headers.add(tu);
|
|
||||||
iter.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
parseTUs(fIndex, 1, sources, headers, monitor);
|
parseTUs(fIndex, 1, sources, headers, monitor);
|
||||||
if (monitor.isCanceled()) {
|
if (monitor.isCanceled()) {
|
||||||
return;
|
return;
|
||||||
|
@ -111,9 +122,9 @@ class PDOMFastIndexerTask extends PDOMIndexerTask implements CallbackHandler {
|
||||||
fCodeReaderFactory.setCallbackHandler(this);
|
fCodeReaderFactory.setCallbackHandler(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerTUsInReaderFactory() throws CoreException {
|
private void registerTUsInReaderFactory(Collection tus) throws CoreException {
|
||||||
int removed= 0;
|
int removed= 0;
|
||||||
for (Iterator iter = fChanged.iterator(); iter.hasNext();) {
|
for (Iterator iter = tus.iterator(); iter.hasNext();) {
|
||||||
ITranslationUnit tu = (ITranslationUnit) iter.next();
|
ITranslationUnit tu = (ITranslationUnit) iter.next();
|
||||||
IIndexFileLocation ifl = IndexLocationFactory.getIFL(tu);
|
IIndexFileLocation ifl = IndexLocationFactory.getIFL(tu);
|
||||||
IndexFileInfo info= fCodeReaderFactory.createFileInfo(ifl);
|
IndexFileInfo info= fCodeReaderFactory.createFileInfo(ifl);
|
||||||
|
|
|
@ -26,6 +26,7 @@ import org.eclipse.cdt.core.index.IIndexFile;
|
||||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||||
import org.eclipse.cdt.core.index.IndexLocationFactory;
|
import org.eclipse.cdt.core.index.IndexLocationFactory;
|
||||||
import org.eclipse.cdt.core.model.AbstractLanguage;
|
import org.eclipse.cdt.core.model.AbstractLanguage;
|
||||||
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.cdt.core.parser.CodeReader;
|
import org.eclipse.cdt.core.parser.CodeReader;
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||||
|
@ -65,20 +66,28 @@ class PDOMFullIndexerTask extends PDOMIndexerTask {
|
||||||
public void run(IProgressMonitor monitor) {
|
public void run(IProgressMonitor monitor) {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
try {
|
try {
|
||||||
setupIndex();
|
// separate headers remove files that have no scanner configuration
|
||||||
registerTUsInReaderFactory(fChanged);
|
final boolean filterFiles= !getIndexAllFiles() && getAllFilesProvided();
|
||||||
|
|
||||||
// separate headers
|
|
||||||
List headers= new ArrayList();
|
List headers= new ArrayList();
|
||||||
List sources= fChanged;
|
List sources= fChanged;
|
||||||
for (Iterator iter = fChanged.iterator(); iter.hasNext();) {
|
for (Iterator iter = fChanged.iterator(); iter.hasNext();) {
|
||||||
ITranslationUnit tu = (ITranslationUnit) iter.next();
|
ITranslationUnit tu = (ITranslationUnit) iter.next();
|
||||||
if (!tu.isSourceUnit()) {
|
if (tu.isSourceUnit()) {
|
||||||
|
if (filterFiles && CoreModel.isScannerInformationEmpty(tu.getResource())) {
|
||||||
|
iter.remove();
|
||||||
|
updateInfo(0, 0, -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
headers.add(tu);
|
headers.add(tu);
|
||||||
iter.remove();
|
iter.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setupIndex();
|
||||||
|
registerTUsInReaderFactory(sources);
|
||||||
|
registerTUsInReaderFactory(headers);
|
||||||
|
|
||||||
Iterator i= fRemoved.iterator();
|
Iterator i= fRemoved.iterator();
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
if (monitor.isCanceled())
|
if (monitor.isCanceled())
|
||||||
|
|
Loading…
Add table
Reference in a new issue