Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBogdan Gheorghe2005-03-14 00:32:07 -0500
committerBogdan Gheorghe2005-03-14 00:32:07 -0500
commit8cb9d02daef719b4156b68223cc18ba5be7e5eec (patch)
tree9761d6a73278938aebbdd86336616c075fd38856
parentdb7314025724803c3116b9e51dbf5d02eff26b90 (diff)
downloadorg.eclipse.cdt-8cb9d02daef719b4156b68223cc18ba5be7e5eec.tar.gz
org.eclipse.cdt-8cb9d02daef719b4156b68223cc18ba5be7e5eec.tar.xz
org.eclipse.cdt-8cb9d02daef719b4156b68223cc18ba5be7e5eec.zip
New core framework for indexer
New UI framework for indexer Updates to core tests/ui tests
-rw-r--r--core/org.eclipse.cdt.core.tests/ChangeLog3
-rw-r--r--core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/DependencyTests.java88
-rw-r--r--core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/SourceIndexerTests.java (renamed from core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexManagerTests.java)365
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FileBasePluginTest.java4
-rw-r--r--core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/BaseTestFramework.java18
-rw-r--r--core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/SearchRegressionTests.java26
-rw-r--r--core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/BaseSearchTest.java10
-rw-r--r--core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java4
-rw-r--r--core/org.eclipse.cdt.core/ChangeLog9
-rw-r--r--core/org.eclipse.cdt.core/browser/ChangeLog-browser12
-rw-r--r--core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/IndexerJob.java26
-rw-r--r--core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/TypeCacheManager.java15
-rw-r--r--core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/TypeCacherJob.java6
-rw-r--r--core/org.eclipse.cdt.core/dependency/ChangeLog6
-rw-r--r--core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencyQueryJob.java31
-rw-r--r--core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/UpdateDependency.java11
-rw-r--r--core/org.eclipse.cdt.core/index/ChangeLog30
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/core/index/ICDTIndexer.java91
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/core/index/IIndexStorage.java30
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/core/index/Indexer.java6
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/IIndexer.java4
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/Index.java34
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/AbstractIndexer.java (renamed from core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AbstractIndexer.java)5
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/AddCompilationUnitToIndex.java (renamed from core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AddCompilationUnitToIndex.java)9
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/AddFileToIndex.java (renamed from core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AddFileToIndex.java)29
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/AddFolderToIndex.java (renamed from core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AddFolderToIndex.java)31
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/CIndexStorage.java544
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/CleanEncounteredHeaders.java (renamed from core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/CleanEncounteredHeaders.java)16
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/IndexAllProject.java (renamed from core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexAllProject.java)28
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/IndexRequest.java (renamed from core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexRequest.java)33
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/RemoveFolderFromIndex.java (renamed from core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/RemoveFolderFromIndex.java)16
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/RemoveFromIndex.java (renamed from core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/RemoveFromIndex.java)18
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SaveIndex.java (renamed from core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/SaveIndex.java)18
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexer.java685
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexerRequestor.java (renamed from core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexerRequestor.java)72
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexerRunner.java (renamed from core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexer.java)61
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java1055
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexerModelListener.java21
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java3
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java1
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java50
-rw-r--r--core/org.eclipse.cdt.core/plugin.xml17
-rw-r--r--core/org.eclipse.cdt.core/schema/CIndexer.exsd119
-rw-r--r--core/org.eclipse.cdt.core/search/ChangeLog3
-rw-r--r--core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/ICSearchConstants.java6
-rw-r--r--core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/IndexSelector.java14
-rw-r--r--core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/PatternSearchJob.java21
-rw-r--r--core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/ClassDeclarationPattern.java2
-rw-r--r--core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/DerivedTypesPattern.java2
-rw-r--r--core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FieldDeclarationPattern.java2
-rw-r--r--core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FriendPattern.java2
-rw-r--r--core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/IncludePattern.java2
-rw-r--r--core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MacroDeclarationPattern.java2
-rw-r--r--core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MethodDeclarationPattern.java2
-rw-r--r--core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/NamespaceDeclarationPattern.java2
-rw-r--r--core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/processing/IIndexJob.java (renamed from core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/processing/IJob.java)13
-rw-r--r--core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/processing/JobManager.java47
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java4
-rw-r--r--core/org.eclipse.cdt.ui.tests/ChangeLog3
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist/CompletionProposalsBaseTest.java3
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist/ContentAssistTests.java4
-rw-r--r--core/org.eclipse.cdt.ui/ChangeLog11
-rw-r--r--core/org.eclipse.cdt.ui/plugin.xml19
-rw-r--r--core/org.eclipse.cdt.ui/schema/IndexerPage.exsd123
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties5
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CSearchPreferencePage.java191
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/WorkInProgressPreferencePage.java210
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPreferenceInitializer.java4
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerBlock.java455
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerOptionDialogPage.java172
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerOptionPropertyPage.java154
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/SourceIndexerBlock.java301
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/index/AbstractIndexerPage.java32
73 files changed, 3381 insertions, 2090 deletions
diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog
index 2d58bc0deb..dbcae9f8d7 100644
--- a/core/org.eclipse.cdt.core.tests/ChangeLog
+++ b/core/org.eclipse.cdt.core.tests/ChangeLog
@@ -1,3 +1,6 @@
+2005-03-13 Bogdan Gheorghe
+ Updated tests to work with new index framework
+
2005-02-02 Tanya Wolff
added regression tests to AutomatedIntegrationSuite
* build.properties
diff --git a/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/DependencyTests.java b/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/DependencyTests.java
index d77bc56bab..c2bdab843d 100644
--- a/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/DependencyTests.java
+++ b/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/DependencyTests.java
@@ -20,6 +20,9 @@ import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.index.IIndexChangeListener;
+import org.eclipse.cdt.core.index.IIndexDelta;
+import org.eclipse.cdt.core.index.IndexChangeEvent;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.search.BasicSearchResultCollector;
import org.eclipse.cdt.core.search.ICSearchConstants;
@@ -30,12 +33,14 @@ import org.eclipse.cdt.core.search.IMatch;
import org.eclipse.cdt.core.search.SearchEngine;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.core.testplugin.CTestPlugin;
+import org.eclipse.cdt.internal.core.browser.cache.TypeCacheManager;
import org.eclipse.cdt.internal.core.index.impl.IFileDocument;
+import org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer;
import org.eclipse.cdt.internal.core.search.PathCollector;
import org.eclipse.cdt.internal.core.search.PatternSearchJob;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.cdt.internal.core.search.matching.CSearchPattern;
-import org.eclipse.cdt.internal.core.search.processing.IJob;
+import org.eclipse.cdt.internal.core.search.processing.IIndexJob;
import org.eclipse.cdt.internal.core.sourcedependency.DependencyQueryJob;
import org.eclipse.cdt.internal.core.sourcedependency.UpdateDependency;
import org.eclipse.core.resources.IFile;
@@ -53,7 +58,7 @@ import org.eclipse.core.runtime.Platform;
/**
* @author bgheorgh
*/
- public class DependencyTests extends TestCase {
+ public class DependencyTests extends TestCase implements IIndexChangeListener {
IFile file;
IFileDocument fileDoc;
IProject testProject;
@@ -63,12 +68,15 @@ import org.eclipse.core.runtime.Platform;
BasicSearchResultCollector resultCollector;
SearchEngine searchEngine;
ICSearchScope scope;
-
+ SourceIndexer sourceIndexer;
+ boolean fileIndexed;
+ public static final int TIMEOUT = 50;
+
public static Test suite() {
TestSuite suite = new TestSuite(DependencyTests.class.getName());
suite.addTest(new DependencyTests("testDependencyTree"));
- suite.addTest(new DependencyTests("testDepTable"));
+ //suite.addTest(new DependencyTests("testDepTable"));
suite.addTest(new DependencyTests("testDepSourceChangeTree"));
suite.addTest(new DependencyTests("testDepHeaderChangeTree"));
suite.addTest(new DependencyTests("testDepHeaderChangeReindex"));
@@ -97,7 +105,8 @@ import org.eclipse.core.runtime.Platform;
if (indexFile.exists())
indexFile.delete();
- testProject.setSessionProperty(IndexManager.activationKey,new Boolean(false));
+ testProject.setSessionProperty(IndexManager.indexerIDKey, SourceIndexerTests.sourceIndexerID);
+ testProject.setSessionProperty(SourceIndexer.activationKey,new Boolean(true));
if (testProject==null)
fail("Unable to create project");
@@ -105,6 +114,9 @@ import org.eclipse.core.runtime.Platform;
indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager();
indexManager.reset();
+ TypeCacheManager typeCacheManager = TypeCacheManager.getInstance();
+ typeCacheManager.setProcessTypeCacheEvents(false);
+
workspace = ResourcesPlugin.getWorkspace();
scope = SearchEngine.createWorkspaceScope();
@@ -112,6 +124,9 @@ import org.eclipse.core.runtime.Platform;
resultCollector = new BasicSearchResultCollector();
searchEngine = new SearchEngine();
+
+ sourceIndexer = (SourceIndexer) indexManager.getIndexerForProject(testProject);
+ sourceIndexer.addIndexChangeListener(this);
}
/*
* @see TestCase#tearDown()
@@ -121,6 +136,9 @@ import org.eclipse.core.runtime.Platform;
super.tearDown();
} catch (Exception e1) {
}
+
+ sourceIndexer.shutdown();
+
//Delete project
if (testProject.exists()){
try {
@@ -156,19 +174,13 @@ import org.eclipse.core.runtime.Platform;
importFile("DepTest2.h","resources/dependency/DepTest2.h");
IFile depTest = importFile("DepTest.cpp","resources/dependency/DepTest.cpp");
IFile depTest2 = importFile("DepTest2.cpp","resources/dependency/DepTest2.cpp");
- //Enable indexing on the created project
- //By doing this, we force the Dependency Manager to do a g()
-
- IndexManager indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager();
- //indexManager.setEnabled(testProject,true);
- testProject.setSessionProperty(IndexManager.activationKey,new Boolean(true));
-
+
String[] depTestModel = {File.separator + "DepTestProject" + File.separator + "d.h", File.separator + "DepTestProject" + File.separator + "Inc1.h", File.separator + "DepTestProject" + File.separator + "c.h", File.separator + "DepTestProject" + File.separator + "a.h", File.separator + "DepTestProject" + File.separator + "DepTest.h"};
String[] depTest2Model = {File.separator + "DepTestProject" + File.separator + "d.h", File.separator + "DepTestProject" + File.separator + "DepTest2.h"};
ArrayList includes = new ArrayList();
- indexManager.performConcurrentJob(new DependencyQueryJob(testProject,depTest,indexManager,includes),ICSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,null,null);
+ indexManager.performConcurrentJob(new DependencyQueryJob(testProject,depTest,sourceIndexer,includes),ICSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,null,null);
String[] depTestModelLocal = convertToLocalPath(depTestModel);
String[] depTestIncludes = new String[includes.size()];
@@ -191,7 +203,7 @@ import org.eclipse.core.runtime.Platform;
}
ArrayList includes2 = new ArrayList();
- indexManager.performConcurrentJob(new DependencyQueryJob(testProject,depTest2,indexManager,includes2),ICSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,null,null);
+ indexManager.performConcurrentJob(new DependencyQueryJob(testProject,depTest2,sourceIndexer,includes2),ICSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,null,null);
String[] depTest2ModelLocal = convertToLocalPath(depTest2Model);
String[] depTest2Includes = new String[includes2.size()];
@@ -226,7 +238,7 @@ import org.eclipse.core.runtime.Platform;
IFile depTestH = importFile("DepTest.h","resources/dependency/DepTest.h");
IFile depTest2H = importFile("DepTest2.h","resources/dependency/DepTest2.h");
- testProject.setSessionProperty(IndexManager.activationKey,new Boolean(true));
+ testProject.setSessionProperty(SourceIndexer.activationKey,new Boolean(true));
PathCollector pathCollector = new PathCollector();
getTableRefs(dH, pathCollector);
@@ -273,7 +285,7 @@ import org.eclipse.core.runtime.Platform;
IFile depTestH = importFile("DepTest.h","resources/dependency/DepTest.h");
IFile depTestC = importFile("DepTest.cpp","resources/dependency/DepTest.cpp");
- testProject.setSessionProperty(IndexManager.activationKey,new Boolean(true));
+ testProject.setSessionProperty(SourceIndexer.activationKey,new Boolean(true));
String[] beforeModel = {Path.SEPARATOR + "DepTestProject" + IPath.SEPARATOR + "DepTest.cpp"};
@@ -370,14 +382,14 @@ import org.eclipse.core.runtime.Platform;
IFile depTestC = importFile("DepTest.cpp","resources/dependency/DepTest.cpp");
IFile depTest2C = importFile("DepTest2.cpp","resources/dependency/DepTest2.cpp");
- testProject.setSessionProperty(IndexManager.activationKey,new Boolean(true));
+ testProject.setSessionProperty(SourceIndexer.activationKey,new Boolean(true));
IndexManager indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager();
String[] preDepTestModel = {File.separator + "DepTestProject" + File.separator + "DepTest.h", File.separator + "DepTestProject" + File.separator + "Inc1.h", File.separator + "DepTestProject" + File.separator + "a.h", File.separator + "DepTestProject" + File.separator + "c.h", File.separator + "DepTestProject" + File.separator + "d.h"};
ArrayList includes = new ArrayList();
- indexManager.performConcurrentJob(new DependencyQueryJob(testProject,depTestC,indexManager,includes),ICSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,null, null);
+ indexManager.performConcurrentJob(new DependencyQueryJob(testProject,depTestC,sourceIndexer,includes),ICSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,null, null);
String[] preDepTestModelLocal = convertToLocalPath(preDepTestModel);
String[] preDepTestIncludes = new String[includes.size()];
@@ -406,7 +418,7 @@ import org.eclipse.core.runtime.Platform;
testProject.refreshLocal(IResource.DEPTH_INFINITE,null);
- indexManager.performConcurrentJob(new DependencyQueryJob(testProject,depTestC,indexManager,includes2),ICSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,null, null);
+ indexManager.performConcurrentJob(new DependencyQueryJob(testProject,depTestC,sourceIndexer,includes2),ICSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,null, null);
String[] postDepTestModelLocal = convertToLocalPath(postDepTestModel);
@@ -439,14 +451,14 @@ import org.eclipse.core.runtime.Platform;
IFile depTest3H = importFile("DepTest3.h","resources/dependency/DepTest3.h");
IFile depTest3C = importFile("DepTest3.cpp","resources/dependency/DepTest3.cpp");
- testProject.setSessionProperty(IndexManager.activationKey,new Boolean(true));
+ testProject.setSessionProperty(SourceIndexer.activationKey,new Boolean(true));
IndexManager indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager();
String[] preDepTestModel = {File.separator + "DepTestProject" + File.separator + "DepTest3.h", File.separator + "DepTestProject" + File.separator + "a.h", File.separator + "DepTestProject" + File.separator + "c.h"};
ArrayList includes = new ArrayList();
- indexManager.performConcurrentJob(new DependencyQueryJob(testProject,depTest3C,indexManager,includes),ICSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,null, null);
+ indexManager.performConcurrentJob(new DependencyQueryJob(testProject,depTest3C,sourceIndexer,includes),ICSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,null, null);
String[] preDepTestModelLocal = convertToLocalPath(preDepTestModel);
String[] preDepTestIncludes = new String[includes.size()];
@@ -475,7 +487,7 @@ import org.eclipse.core.runtime.Platform;
testProject.refreshLocal(IResource.DEPTH_INFINITE,null);
- indexManager.performConcurrentJob(new DependencyQueryJob(testProject,depTest3C,indexManager,includes2),ICSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,null, null);
+ indexManager.performConcurrentJob(new DependencyQueryJob(testProject,depTest3C,sourceIndexer,includes2),ICSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,null, null);
String[] postDepTestModelLocal = convertToLocalPath(postDepTestModel);
@@ -508,7 +520,7 @@ import org.eclipse.core.runtime.Platform;
IFile depTest3H = importFile("DepTest3.h","resources/dependency/DepTest3.h");
IFile depTest3C = importFile("DepTest3.cpp","resources/dependency/DepTest3.cpp");
- testProject.setSessionProperty(IndexManager.activationKey,new Boolean(true));
+ testProject.setSessionProperty(SourceIndexer.activationKey,new Boolean(true));
String[] beforeModel = {Path.SEPARATOR + "DepTestProject" + IPath.SEPARATOR + "DepTest3.cpp"};
@@ -568,7 +580,7 @@ import org.eclipse.core.runtime.Platform;
assertFalse(nonExistantResource.exists());
assertNull(nonExistantResource.getLocation());
- IJob job = new UpdateDependency(nonExistantResource);
+ IIndexJob job = new UpdateDependency(nonExistantResource, sourceIndexer);
assertFalse(job.execute(new NullProgressMonitor()));
}
@@ -580,7 +592,7 @@ import org.eclipse.core.runtime.Platform;
IFile depTest3H = importFile("DepTest3.h","resources/dependency/DepTest3.h");
IFile depTest3C = importFile("DepTest3.cpp","resources/dependency/DepTest3.cpp");
- testProject.setSessionProperty(IndexManager.activationKey,new Boolean(true));
+ testProject.setSessionProperty(SourceIndexer.activationKey,new Boolean(true));
ICSearchPattern pattern = SearchEngine.createSearchPattern( "Z", ICSearchConstants.TYPE, ICSearchConstants.DECLARATIONS, true );
@@ -712,8 +724,8 @@ import org.eclipse.core.runtime.Platform;
}
- private IFile importFile(String fileName, String resourceLocation)throws Exception{
- String testCaseName = this.getName();
+ private IFile importFile(String fileName, String resourceLocation)throws Exception {
+ resetIndexState();
//Obtain file handle
file = testProject.getProject().getFile(fileName);
//Create file input stream
@@ -724,6 +736,26 @@ import org.eclipse.core.runtime.Platform;
false, monitor);
}
fileDoc = new IFileDocument(file);
+ waitForIndex(10); // only wait 20 seconds max.
return file;
- }
+ }
+
+ public void resetIndexState() {
+ fileIndexed = false;
+ }
+
+ public void waitForIndex(int maxSec) throws Exception {
+ int delay = 0;
+ while (fileIndexed != true && delay < (maxSec * 1000))
+ {
+ Thread.sleep(TIMEOUT);
+ delay += TIMEOUT;
+ }
+ }
+ public void indexChanged(IndexChangeEvent event) {
+ IIndexDelta delta = event.getDelta();
+ if (delta.getDeltaType() == IIndexDelta.MERGE_DELTA){
+ fileIndexed = true;
+ }
+ }
}
diff --git a/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexManagerTests.java b/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/SourceIndexerTests.java
index 9b8b890572..d6782854ed 100644
--- a/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexManagerTests.java
+++ b/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/SourceIndexerTests.java
@@ -33,6 +33,8 @@ import org.eclipse.cdt.internal.core.index.IEntryResult;
import org.eclipse.cdt.internal.core.index.IIndex;
import org.eclipse.cdt.internal.core.index.IQueryResult;
import org.eclipse.cdt.internal.core.index.impl.IFileDocument;
+import org.eclipse.cdt.internal.core.index.sourceindexer.CIndexStorage;
+import org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer;
import org.eclipse.cdt.internal.core.search.indexing.IIndexConstants;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.core.resources.IFile;
@@ -47,20 +49,22 @@ import org.eclipse.core.runtime.Path;
/**
* @author bgheorgh
*/
-public class IndexManagerTests extends TestCase implements IIndexChangeListener {
+public class SourceIndexerTests extends TestCase implements IIndexChangeListener {
IFile file;
IFileDocument fileDoc;
IProject testProject;
NullProgressMonitor monitor;
IndexManager indexManager;
+ SourceIndexer sourceIndexer;
boolean fileIndexed;
+ static final String sourceIndexerID = "org.eclipse.cdt.core.originalsourceindexer"; //$NON-NLS-1$
public static final int TIMEOUT = 50;
/**
* Constructor for IndexManagerTest.
* @param name
*/
- public IndexManagerTests(String name) {
+ public SourceIndexerTests(String name) {
super(name);
}
@@ -89,22 +93,28 @@ public class IndexManagerTests extends TestCase implements IIndexChangeListener
monitor = new NullProgressMonitor();
//Create temp project
- testProject = createProject("IndexerTestProject");
+ testProject = createProject("IndexerTestProject"); //$NON-NLS-1$
IPath pathLoc = CCorePlugin.getDefault().getStateLocation();
- File indexFile = new File(pathLoc.append("3915980774.index").toOSString());
+ File indexFile = new File(pathLoc.append("3915980774.index").toOSString()); //$NON-NLS-1$
if (indexFile.exists())
indexFile.delete();
+ //Set the id of the source indexer extension point as a session property to allow
+ //index manager to instantiate it
+ testProject.setSessionProperty(IndexManager.indexerIDKey, sourceIndexerID);
- testProject.setSessionProperty(IndexManager.activationKey,new Boolean(true));
+ //Enable indexing on test project
+ testProject.setSessionProperty(SourceIndexer.activationKey,new Boolean(true));
if (testProject==null)
- fail("Unable to create project");
+ fail("Unable to create project"); //$NON-NLS-1$
indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager();
indexManager.reset();
- indexManager.addIndexChangeListener(this);
+ //Get the indexer used for the test project
+ sourceIndexer = (SourceIndexer) indexManager.getIndexerForProject(testProject);
+ sourceIndexer.addIndexChangeListener(this);
}
/*
* @see TestCase#tearDown()
@@ -112,7 +122,7 @@ public class IndexManagerTests extends TestCase implements IIndexChangeListener
protected void tearDown() {
try {
super.tearDown();
- indexManager.removeIndexChangeListener(this);
+ sourceIndexer.removeIndexChangeListener(this);
} catch (Exception e1) {
}
//Delete project
@@ -128,7 +138,7 @@ public class IndexManagerTests extends TestCase implements IIndexChangeListener
}
private String getMessage(IStatus status) {
- StringBuffer message = new StringBuffer("[");
+ StringBuffer message = new StringBuffer("["); //$NON-NLS-1$
message.append(status.getMessage());
if (status.isMultiStatus()) {
IStatus children[] = status.getChildren();
@@ -136,23 +146,23 @@ public class IndexManagerTests extends TestCase implements IIndexChangeListener
message.append(getMessage(children[i]));
}
}
- message.append("]");
+ message.append("]"); //$NON-NLS-1$
return message.toString();
}
public static Test suite() {
- TestSuite suite = new TestSuite(IndexManagerTests.class.getName());
+ TestSuite suite = new TestSuite(SourceIndexerTests.class.getName());
- suite.addTest(new IndexManagerTests("testAddNewFileToIndex"));
- suite.addTest(new IndexManagerTests("testForwardDeclarations"));
- suite.addTest(new IndexManagerTests("testIndexAll"));
- suite.addTest(new IndexManagerTests("testIndexContents"));
- suite.addTest(new IndexManagerTests("testMacros"));
- suite.addTest(new IndexManagerTests("testRefs"));
- suite.addTest(new IndexManagerTests("testExactDeclarations"));
- suite.addTest(new IndexManagerTests("testRemoveFileFromIndex"));
- suite.addTest(new IndexManagerTests("testRemoveProjectFromIndex"));
- suite.addTest(new IndexManagerTests("testIndexShutdown"));
+ suite.addTest(new SourceIndexerTests("testAddNewFileToIndex")); //$NON-NLS-1$
+ suite.addTest(new SourceIndexerTests("testForwardDeclarations")); //$NON-NLS-1$
+ suite.addTest(new SourceIndexerTests("testIndexAll")); //$NON-NLS-1$
+ suite.addTest(new SourceIndexerTests("testIndexContents")); //$NON-NLS-1$
+ suite.addTest(new SourceIndexerTests("testMacros")); //$NON-NLS-1$
+ suite.addTest(new SourceIndexerTests("testRefs")); //$NON-NLS-1$
+ suite.addTest(new SourceIndexerTests("testExactDeclarations")); //$NON-NLS-1$
+ suite.addTest(new SourceIndexerTests("testRemoveFileFromIndex")); //$NON-NLS-1$
+ suite.addTest(new SourceIndexerTests("testRemoveProjectFromIndex")); //$NON-NLS-1$
+ suite.addTest(new SourceIndexerTests("testIndexShutdown")); //$NON-NLS-1$
return suite;
@@ -161,7 +171,7 @@ public class IndexManagerTests extends TestCase implements IIndexChangeListener
* Utils
*/
private IProject createProject(String projectName) throws CoreException {
- ICProject cPrj = CProjectHelper.createCCProject(projectName, "bin");
+ ICProject cPrj = CProjectHelper.createCCProject(projectName, "bin"); //$NON-NLS-1$
return cPrj.getProject();
}
@@ -188,27 +198,40 @@ public class IndexManagerTests extends TestCase implements IIndexChangeListener
//Add a file to the project
- importFile("mail.cpp","resources/indexer/mail.cpp");
+ importFile("mail.cpp","resources/indexer/mail.cpp"); //$NON-NLS-1$ //$NON-NLS-2$
- IIndex ind = indexManager.getIndex(testProject.getFullPath(),true,true);
- assertTrue("Index exists for project",ind != null);
+ IIndex ind = sourceIndexer.getIndex(testProject.getFullPath(),true,true);
+ assertTrue("Index exists for project",ind != null); //$NON-NLS-1$
- char[] prefix = "typeDecl/".toCharArray();
+ char[] prefix = "typeDecl/".toCharArray(); //$NON-NLS-1$
IQueryResult[] qresults = ind.queryPrefix(prefix);
IEntryResult[] eresults = ind.queryEntries(prefix);
- assertTrue("Query Results exist", qresults != null);
- assertTrue("Entry Results exist", eresults != null);
-
- String [] queryResultModel = {"IndexedFile(1: /IndexerTestProject/mail.cpp)"};
- String [] entryResultModel ={"EntryResult: word=typeDecl/C/Mail, refs={ 1 }", "EntryResult: word=typeDecl/C/Unknown, refs={ 1 }", "EntryResult: word=typeDecl/C/container, refs={ 1 }", "EntryResult: word=typeDecl/C/first_class, refs={ 1 }", "EntryResult: word=typeDecl/C/postcard, refs={ 1 }","EntryResult: word=typeDecl/D/Mail, refs={ 1 }", "EntryResult: word=typeDecl/D/first_class, refs={ 1 }", "EntryResult: word=typeDecl/D/postcard, refs={ 1 }","EntryResult: word=typeDecl/V/PO_Box, refs={ 1 }", "EntryResult: word=typeDecl/V/index, refs={ 1 }", "EntryResult: word=typeDecl/V/mail, refs={ 1 }","EntryResult: word=typeDecl/V/size, refs={ 1 }", "EntryResult: word=typeDecl/V/temp, refs={ 1 }", "EntryResult: word=typeDecl/V/x, refs={ 1 }"};
+ assertTrue("Query Results exist", qresults != null); //$NON-NLS-1$
+ assertTrue("Entry Results exist", eresults != null); //$NON-NLS-1$
+
+ String [] queryResultModel = {"IndexedFile(1: /IndexerTestProject/mail.cpp)"}; //$NON-NLS-1$
+ String [] entryResultModel ={"EntryResult: word=typeDecl/C/Mail, refs={ 1 }", //$NON-NLS-1$
+ "EntryResult: word=typeDecl/C/Unknown, refs={ 1 }", //$NON-NLS-1$
+ "EntryResult: word=typeDecl/C/container, refs={ 1 }", //$NON-NLS-1$
+ "EntryResult: word=typeDecl/C/first_class, refs={ 1 }", //$NON-NLS-1$
+ "EntryResult: word=typeDecl/C/postcard, refs={ 1 }", //$NON-NLS-1$
+ "EntryResult: word=typeDecl/D/Mail, refs={ 1 }", //$NON-NLS-1$
+ "EntryResult: word=typeDecl/D/first_class, refs={ 1 }", //$NON-NLS-1$
+ "EntryResult: word=typeDecl/D/postcard, refs={ 1 }", //$NON-NLS-1$
+ "EntryResult: word=typeDecl/V/PO_Box, refs={ 1 }", //$NON-NLS-1$
+ "EntryResult: word=typeDecl/V/index, refs={ 1 }", //$NON-NLS-1$
+ "EntryResult: word=typeDecl/V/mail, refs={ 1 }", //$NON-NLS-1$
+ "EntryResult: word=typeDecl/V/size, refs={ 1 }", //$NON-NLS-1$
+ "EntryResult: word=typeDecl/V/temp, refs={ 1 }", //$NON-NLS-1$
+ "EntryResult: word=typeDecl/V/x, refs={ 1 }"}; //$NON-NLS-1$
if (qresults.length != queryResultModel.length)
- fail("Query Result length different from model");
+ fail("Query Result length different from model"); //$NON-NLS-1$
if (eresults.length != entryResultModel.length)
- fail("Entry Result length different from model");
+ fail("Entry Result length different from model"); //$NON-NLS-1$
for (int i=0; i<qresults.length;i++)
{
@@ -225,28 +248,28 @@ public class IndexManagerTests extends TestCase implements IIndexChangeListener
//Add a file to the project
- importFile("mail.cpp","resources/indexer/mail.cpp");
+ importFile("mail.cpp","resources/indexer/mail.cpp"); //$NON-NLS-1$ //$NON-NLS-2$
//Make sure project got added to index
IPath testProjectPath = testProject.getFullPath();
- IIndex ind = indexManager.getIndex(testProjectPath,true,true);
- assertTrue("Index exists for project",ind != null);
+ IIndex ind = sourceIndexer.getIndex(testProjectPath,true,true);
+ assertTrue("Index exists for project",ind != null); //$NON-NLS-1$
//Add a new file to the project, give it some time to index
- importFile("DocumentManager.h","resources/indexer/DocumentManager.h");
-
- importFile("DocumentManager.cpp","resources/indexer/DocumentManager.cpp");
-
- ind = indexManager.getIndex(testProjectPath,true,true);
+ importFile("DocumentManager.h","resources/indexer/DocumentManager.h"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ importFile("DocumentManager.cpp","resources/indexer/DocumentManager.cpp"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ ind = sourceIndexer.getIndex(testProjectPath,true,true);
- char[] prefix = "typeDecl/C/CDocumentManager".toCharArray();
- String [] entryResultModel ={"EntryResult: word=typeDecl/C/CDocumentManager, refs={ 2 }"};
+ char[] prefix = "typeDecl/C/CDocumentManager".toCharArray(); //$NON-NLS-1$
+ String [] entryResultModel ={"EntryResult: word=typeDecl/C/CDocumentManager, refs={ 2 }"}; //$NON-NLS-1$
IEntryResult[] eresults =ind.queryEntries(prefix);
IEntryResult[] bogRe = ind.queryEntries(IIndexConstants.TYPE_DECL);
- assertTrue("Entry Result exists", eresults != null);
+ assertTrue("Entry Result exists", eresults != null); //$NON-NLS-1$
if (eresults.length != entryResultModel.length)
- fail("Entry Result length different from model");
+ fail("Entry Result length different from model"); //$NON-NLS-1$
for (int i=0;i<eresults.length; i++)
{
@@ -258,18 +281,18 @@ public class IndexManagerTests extends TestCase implements IIndexChangeListener
//Add a file to the project
- importFile("mail.cpp","resources/indexer/mail.cpp");
+ importFile("mail.cpp","resources/indexer/mail.cpp"); //$NON-NLS-1$ //$NON-NLS-2$
//Make sure project got added to index
IPath testProjectPath = testProject.getFullPath();
- IIndex ind = indexManager.getIndex(testProjectPath,true,true);
- assertTrue("Index exists for project",ind != null);
+ IIndex ind = sourceIndexer.getIndex(testProjectPath,true,true);
+ assertTrue("Index exists for project",ind != null); //$NON-NLS-1$
//Delete the project
safeDelete(testProject);
//See if the index is still there
- ind = indexManager.getIndex(testProjectPath,true,true);
- assertTrue("Index deleted",ind == null);
+ ind = sourceIndexer.getIndex(testProjectPath,true,true);
+ assertTrue("Index deleted",ind == null); //$NON-NLS-1$
}
/**
@@ -290,33 +313,41 @@ public class IndexManagerTests extends TestCase implements IIndexChangeListener
public void testRemoveFileFromIndex() throws Exception{
//Add a file to the project
- importFile("mail.cpp","resources/indexer/mail.cpp");
+ importFile("mail.cpp","resources/indexer/mail.cpp"); //$NON-NLS-1$ //$NON-NLS-2$
//Make sure project got added to index
IPath testProjectPath = testProject.getFullPath();
- IIndex ind = indexManager.getIndex(testProjectPath,true,true);
- assertTrue("Index exists for project",ind != null);
- importFile("DocumentManager.h","resources/indexer/DocumentManager.h");
- importFile("DocumentManager.cpp","resources/indexer/DocumentManager.cpp");
+ IIndex ind = sourceIndexer.getIndex(testProjectPath,true,true);
+ assertTrue("Index exists for project",ind != null); //$NON-NLS-1$
+ importFile("DocumentManager.h","resources/indexer/DocumentManager.h"); //$NON-NLS-1$ //$NON-NLS-2$
+ importFile("DocumentManager.cpp","resources/indexer/DocumentManager.cpp"); //$NON-NLS-1$ //$NON-NLS-2$
- ind = indexManager.getIndex(testProjectPath,true,true);
+ ind = sourceIndexer.getIndex(testProjectPath,true,true);
//Do a "before" deletion comparison
//ind = indexManager.getIndex(testProjectPath,true,true);
- char[] prefix = "typeDecl/".toCharArray();
+ char[] prefix = "typeDecl/".toCharArray(); //$NON-NLS-1$
IEntryResult[] eresults = ind.queryEntries(prefix);
- assertTrue("Entry result found for typdeDecl/", eresults != null);
+ assertTrue("Entry result found for typdeDecl/", eresults != null); //$NON-NLS-1$
- String [] entryResultBeforeModel ={"EntryResult: word=typeDecl/C/CDocumentManager, refs={ 2 }", "EntryResult: word=typeDecl/C/Mail, refs={ 3 }", "EntryResult: word=typeDecl/C/Unknown, refs={ 3 }", "EntryResult: word=typeDecl/C/container, refs={ 3 }", "EntryResult: word=typeDecl/C/first_class, refs={ 3 }", "EntryResult: word=typeDecl/C/postcard, refs={ 3 }", "EntryResult: word=typeDecl/D/Mail, refs={ 3 }", "EntryResult: word=typeDecl/D/first_class, refs={ 3 }", "EntryResult: word=typeDecl/D/postcard, refs={ 3 }", "EntryResult: word=typeDecl/V/, refs={ 1, 2 }", "EntryResult: word=typeDecl/V/PO_Box, refs={ 3 }", "EntryResult: word=typeDecl/V/index, refs={ 3 }", "EntryResult: word=typeDecl/V/mail, refs={ 3 }", "EntryResult: word=typeDecl/V/size, refs={ 3 }", "EntryResult: word=typeDecl/V/temp, refs={ 3 }", "EntryResult: word=typeDecl/V/x, refs={ 3 }"};
+ String [] entryResultBeforeModel ={"EntryResult: word=typeDecl/C/CDocumentManager, refs={ 2 }", //$NON-NLS-1$
+ "EntryResult: word=typeDecl/C/Mail, refs={ 3 }", "EntryResult: word=typeDecl/C/Unknown, refs={ 3 }", //$NON-NLS-1$ //$NON-NLS-2$
+ "EntryResult: word=typeDecl/C/container, refs={ 3 }", "EntryResult: word=typeDecl/C/first_class, refs={ 3 }", //$NON-NLS-1$ //$NON-NLS-2$
+ "EntryResult: word=typeDecl/C/postcard, refs={ 3 }", "EntryResult: word=typeDecl/D/Mail, refs={ 3 }", //$NON-NLS-1$ //$NON-NLS-2$
+ "EntryResult: word=typeDecl/D/first_class, refs={ 3 }", "EntryResult: word=typeDecl/D/postcard, refs={ 3 }", //$NON-NLS-1$ //$NON-NLS-2$
+ "EntryResult: word=typeDecl/V/, refs={ 1, 2 }", "EntryResult: word=typeDecl/V/PO_Box, refs={ 3 }", //$NON-NLS-1$ //$NON-NLS-2$
+ "EntryResult: word=typeDecl/V/index, refs={ 3 }", "EntryResult: word=typeDecl/V/mail, refs={ 3 }", //$NON-NLS-1$ //$NON-NLS-2$
+ "EntryResult: word=typeDecl/V/size, refs={ 3 }", "EntryResult: word=typeDecl/V/temp, refs={ 3 }", //$NON-NLS-1$ //$NON-NLS-2$
+ "EntryResult: word=typeDecl/V/x, refs={ 3 }"}; //$NON-NLS-1$ //$NON-NLS-2$
if (eresults.length != entryResultBeforeModel.length)
- fail("Entry Result length different from model");
+ fail("Entry Result length different from model"); //$NON-NLS-1$
for (int i=0;i<eresults.length; i++)
{
assertEquals(entryResultBeforeModel[i],eresults[i].toString());
}
//Delete mail.cpp from the project, give some time to remove index
- IResource resourceHdl = testProject.findMember("mail.cpp") ;
+ IResource resourceHdl = testProject.findMember("mail.cpp") ; //$NON-NLS-1$
// Cleaning up file handles before delete
System.gc();
System.runFinalization();
@@ -325,13 +356,13 @@ public class IndexManagerTests extends TestCase implements IIndexChangeListener
waitForIndex(10); // wait up to 10 seconds for the index to be deleted.
//See if the index is still there
- ind = indexManager.getIndex(testProjectPath,true,true);
+ ind = sourceIndexer.getIndex(testProjectPath,true,true);
eresults = ind.queryEntries(prefix);
- assertTrue("Entry exists", eresults != null);
+ assertTrue("Entry exists", eresults != null); //$NON-NLS-1$
- String [] entryResultAfterModel ={"EntryResult: word=typeDecl/C/CDocumentManager, refs={ 2 }", "EntryResult: word=typeDecl/V/, refs={ 1, 2 }"};
+ String [] entryResultAfterModel ={"EntryResult: word=typeDecl/C/CDocumentManager, refs={ 2 }", "EntryResult: word=typeDecl/V/, refs={ 1, 2 }"}; //$NON-NLS-1$ //$NON-NLS-2$
if (eresults.length != entryResultAfterModel.length)
- fail("Entry Result length different from model");
+ fail("Entry Result length different from model"); //$NON-NLS-1$
for (int i=0;i<eresults.length; i++)
{
@@ -342,180 +373,190 @@ public class IndexManagerTests extends TestCase implements IIndexChangeListener
public void testIndexContents() throws Exception{
//Add a new file to the project
- importFile("extramail.cpp","resources/indexer/extramail.cpp");
+ importFile("extramail.cpp","resources/indexer/extramail.cpp"); //$NON-NLS-1$ //$NON-NLS-2$
//Make sure project got added to index
IPath testProjectPath = testProject.getFullPath();
- IIndex ind = indexManager.getIndex(testProjectPath,true,true);
- assertTrue("Index exists for project",ind != null);
+ IIndex ind = sourceIndexer.getIndex(testProjectPath,true,true);
+ assertTrue("Index exists for project",ind != null); //$NON-NLS-1$ //$NON-NLS-2$
IEntryResult[] typerefreesults = ind.queryEntries(IIndexConstants.TYPE_REF);
- assertTrue("Type Ref Results exist", typerefreesults != null);
+ assertTrue("Type Ref Results exist", typerefreesults != null); //$NON-NLS-1$
+
+ String [] typeDeclEntryResultModel ={"EntryResult: word=typeDecl/C/Mail/Y/X/Z, refs={ 1 }","EntryResult: word=typeDecl/C/Unknown/Y/X/Z, refs={ 1 }", //$NON-NLS-1$ //$NON-NLS-2$
+ "EntryResult: word=typeDecl/C/container/Y/X/Z, refs={ 1 }","EntryResult: word=typeDecl/C/first_class/Y/X/Z, refs={ 1 }", //$NON-NLS-1$ //$NON-NLS-2$
+ "EntryResult: word=typeDecl/C/postcard/Y/X/Z, refs={ 1 }","EntryResult: word=typeDecl/D/Mail/Y/X/Z, refs={ 1 }", //$NON-NLS-1$ //$NON-NLS-2$
+ "EntryResult: word=typeDecl/D/first_class/Y/X/Z, refs={ 1 }", "EntryResult: word=typeDecl/D/postcard/Y/X/Z, refs={ 1 }", //$NON-NLS-1$ //$NON-NLS-2$
+ "EntryResult: word=typeDecl/E/test/Y/X/Z, refs={ 1 }","EntryResult: word=typeDecl/T/int32, refs={ 1 }", //$NON-NLS-1$ //$NON-NLS-2$
+ "EntryResult: word=typeDecl/V/PO_Box, refs={ 1 }","EntryResult: word=typeDecl/V/index, refs={ 1 }", //$NON-NLS-1$ //$NON-NLS-2$
+ "EntryResult: word=typeDecl/V/mail, refs={ 1 }", "EntryResult: word=typeDecl/V/size, refs={ 1 }", //$NON-NLS-1$ //$NON-NLS-2$
+ "EntryResult: word=typeDecl/V/temp, refs={ 1 }", "EntryResult: word=typeDecl/V/x, refs={ 1 }", //$NON-NLS-1$ //$NON-NLS-2$
+ "EntryResult: word=typeDecl/V/x/Z, refs={ 1 }"}; //$NON-NLS-1$
- String [] typeDeclEntryResultModel ={"EntryResult: word=typeDecl/C/Mail/Y/X/Z, refs={ 1 }","EntryResult: word=typeDecl/C/Unknown/Y/X/Z, refs={ 1 }","EntryResult: word=typeDecl/C/container/Y/X/Z, refs={ 1 }","EntryResult: word=typeDecl/C/first_class/Y/X/Z, refs={ 1 }","EntryResult: word=typeDecl/C/postcard/Y/X/Z, refs={ 1 }","EntryResult: word=typeDecl/D/Mail/Y/X/Z, refs={ 1 }", "EntryResult: word=typeDecl/D/first_class/Y/X/Z, refs={ 1 }", "EntryResult: word=typeDecl/D/postcard/Y/X/Z, refs={ 1 }","EntryResult: word=typeDecl/E/test/Y/X/Z, refs={ 1 }","EntryResult: word=typeDecl/T/int32, refs={ 1 }", "EntryResult: word=typeDecl/V/PO_Box, refs={ 1 }","EntryResult: word=typeDecl/V/index, refs={ 1 }", "EntryResult: word=typeDecl/V/mail, refs={ 1 }", "EntryResult: word=typeDecl/V/size, refs={ 1 }", "EntryResult: word=typeDecl/V/temp, refs={ 1 }", "EntryResult: word=typeDecl/V/x, refs={ 1 }", "EntryResult: word=typeDecl/V/x/Z, refs={ 1 }"};
-
IEntryResult[] typedeclresults =ind.queryEntries(IIndexConstants.TYPE_DECL);
- assertTrue("Type Decl Results exist", typedeclresults != null);
+ assertTrue("Type Decl Results exist", typedeclresults != null); //$NON-NLS-1$
if (typedeclresults.length != typeDeclEntryResultModel.length)
- fail("Entry Result length different from model for typeDecl");
+ fail("Entry Result length different from model for typeDecl"); //$NON-NLS-1$
for (int i=0;i<typedeclresults.length; i++)
{
assertEquals(typeDeclEntryResultModel[i],typedeclresults[i].toString());
}
- String [] typeDefEntryResultModel ={"EntryResult: word=typeDecl/T/int32, refs={ 1 }"};
+ String [] typeDefEntryResultModel ={"EntryResult: word=typeDecl/T/int32, refs={ 1 }"}; //$NON-NLS-1$
IEntryResult[] typedefresults =ind.queryEntries(IIndexConstants.TYPEDEF_DECL);
- assertTrue("Type Def Results exist", typedefresults != null);
+ assertTrue("Type Def Results exist", typedefresults != null); //$NON-NLS-1$
if (typedefresults.length != typeDefEntryResultModel.length)
- fail("Entry Result length different from model for typeDef");
+ fail("Entry Result length different from model for typeDef"); //$NON-NLS-1$
for (int i=0;i<typedefresults.length; i++)
{
assertEquals(typeDefEntryResultModel[i],typedefresults[i].toString());
}
- String [] namespaceResultModel = {"EntryResult: word=namespaceDecl/X/Z, refs={ 1 }", "EntryResult: word=namespaceDecl/Y/X/Z, refs={ 1 }", "EntryResult: word=namespaceDecl/Z, refs={ 1 }"};
+ String [] namespaceResultModel = {"EntryResult: word=namespaceDecl/X/Z, refs={ 1 }", "EntryResult: word=namespaceDecl/Y/X/Z, refs={ 1 }", //$NON-NLS-1$ //$NON-NLS-2$
+ "EntryResult: word=namespaceDecl/Z, refs={ 1 }"}; //$NON-NLS-1$
+
IEntryResult[] namespaceresults =ind.queryEntries(IIndexConstants.NAMESPACE_DECL);
- assertTrue("Namespace Results exist", namespaceresults != null);
+ assertTrue("Namespace Results exist", namespaceresults != null); //$NON-NLS-1$
if (namespaceresults.length != namespaceResultModel.length)
- fail("Entry Result length different from model for namespace");
+ fail("Entry Result length different from model for namespace"); //$NON-NLS-1$
for (int i=0;i<namespaceresults.length; i++)
{
assertEquals(namespaceResultModel[i],namespaceresults[i].toString());
}
- String [] fieldResultModel = {"EntryResult: word=fieldDecl/array/container/Y/X/Z, refs={ 1 }", "EntryResult: word=fieldDecl/index/container/Y/X/Z, refs={ 1 }", "EntryResult: word=fieldDecl/postage/Mail/Y/X/Z, refs={ 1 }", "EntryResult: word=fieldDecl/sz/container/Y/X/Z, refs={ 1 }", "EntryResult: word=fieldDecl/type/Mail/Y/X/Z, refs={ 1 }"};
+ String [] fieldResultModel = {"EntryResult: word=fieldDecl/array/container/Y/X/Z, refs={ 1 }", "EntryResult: word=fieldDecl/index/container/Y/X/Z, refs={ 1 }", //$NON-NLS-1$ //$NON-NLS-2$
+ "EntryResult: word=fieldDecl/postage/Mail/Y/X/Z, refs={ 1 }", "EntryResult: word=fieldDecl/sz/container/Y/X/Z, refs={ 1 }", //$NON-NLS-1$ //$NON-NLS-2$
+ "EntryResult: word=fieldDecl/type/Mail/Y/X/Z, refs={ 1 }"}; //$NON-NLS-1$ //$NON-NLS-2$
IEntryResult[] fieldresults =ind.queryEntries(IIndexConstants.FIELD_DECL);
- assertTrue("Field Results exist", fieldresults != null);
+ assertTrue("Field Results exist", fieldresults != null); //$NON-NLS-1$
if (fieldresults.length != fieldResultModel.length)
- fail("Entry Result length different from model for fieldDecl");
+ fail("Entry Result length different from model for fieldDecl"); //$NON-NLS-1$
for (int i=0;i<fieldresults.length; i++)
{
assertEquals(fieldResultModel[i],fieldresults[i].toString());
}
- String [] enumeratorResultModel = {"EntryResult: word=enumtorDecl/bye/Y/X/Z, refs={ 1 }", "EntryResult: word=enumtorDecl/cool/Y/X/Z, refs={ 1 }", "EntryResult: word=enumtorDecl/hi/Y/X/Z, refs={ 1 }", "EntryResult: word=enumtorDecl/why/Y/X/Z, refs={ 1 }"};
+ String [] enumeratorResultModel = {"EntryResult: word=enumtorDecl/bye/Y/X/Z, refs={ 1 }", "EntryResult: word=enumtorDecl/cool/Y/X/Z, refs={ 1 }", //$NON-NLS-1$ //$NON-NLS-2$
+ "EntryResult: word=enumtorDecl/hi/Y/X/Z, refs={ 1 }", "EntryResult: word=enumtorDecl/why/Y/X/Z, refs={ 1 }"}; //$NON-NLS-1$ //$NON-NLS-2$
+
IEntryResult[] enumeratorresults =ind.queryEntries(IIndexConstants.ENUMTOR_DECL);
- assertTrue("Enumerator Results exist", enumeratorresults != null);
+ assertTrue("Enumerator Results exist", enumeratorresults != null); //$NON-NLS-1$
if (enumeratorresults.length != enumeratorResultModel.length)
- fail("Entry Result length different from model for enumtorDecl");
+ fail("Entry Result length different from model for enumtorDecl"); //$NON-NLS-1$
for (int i=0;i<enumeratorresults.length; i++)
{
assertEquals(enumeratorResultModel[i],enumeratorresults[i].toString());
}
- String [] functionResultModel = {"EntryResult: word=functionDecl/doSomething, refs={ 1 }", "EntryResult: word=functionDecl/main/Y/X/Z, refs={ 1 }"};
+ String [] functionResultModel = {"EntryResult: word=functionDecl/doSomething, refs={ 1 }", "EntryResult: word=functionDecl/main/Y/X/Z, refs={ 1 }"}; //$NON-NLS-1$ //$NON-NLS-2$
IEntryResult[] functionresults =ind.queryEntries(IIndexConstants.FUNCTION_DECL);
if (functionresults.length != functionResultModel.length)
- fail("Entry Result length different from model for functionDecl");
+ fail("Entry Result length different from model for functionDecl"); //$NON-NLS-1$
for (int i=0;i<functionresults.length; i++)
{
assertEquals(functionResultModel[i],functionresults[i].toString());
}
- String [] methodResultModel = {"EntryResult: word=methodDecl/Mail/Mail/Y/X/Z, refs={ 1 }",
- "EntryResult: word=methodDecl/Unknown/Unknown/Y/X/Z, refs={ 1 }",
- "EntryResult: word=methodDecl/container/container/Y/X/Z, refs={ 1 }",
- "EntryResult: word=methodDecl/first_class/first_class/Y/X/Z, refs={ 1 }",
- "EntryResult: word=methodDecl/operator =/container/Y/X/Z, refs={ 1 }",
- "EntryResult: word=methodDecl/operator []/container/Y/X/Z, refs={ 1 }",
- "EntryResult: word=methodDecl/postcard/postcard/Y/X/Z, refs={ 1 }",
- "EntryResult: word=methodDecl/print/Mail/Y/X/Z, refs={ 1 }",
- "EntryResult: word=methodDecl/print/Unknown/Y/X/Z, refs={ 1 }",
- "EntryResult: word=methodDecl/print/first_class/Y/X/Z, refs={ 1 }",
- "EntryResult: word=methodDecl/print/postcard/Y/X/Z, refs={ 1 }",
- "EntryResult: word=methodDecl/size/container/Y/X/Z, refs={ 1 }",
- "EntryResult: word=methodDecl/~container/container/Y/X/Z, refs={ 1 }"};
+ String [] methodResultModel = {"EntryResult: word=methodDecl/Mail/Mail/Y/X/Z, refs={ 1 }", "EntryResult: word=methodDecl/Unknown/Unknown/Y/X/Z, refs={ 1 }", //$NON-NLS-1$ //$NON-NLS-2$
+ "EntryResult: word=methodDecl/container/container/Y/X/Z, refs={ 1 }", "EntryResult: word=methodDecl/first_class/first_class/Y/X/Z, refs={ 1 }", //$NON-NLS-1$ //$NON-NLS-2$
+ "EntryResult: word=methodDecl/operator =/container/Y/X/Z, refs={ 1 }","EntryResult: word=methodDecl/operator []/container/Y/X/Z, refs={ 1 }", //$NON-NLS-1$ //$NON-NLS-2$
+ "EntryResult: word=methodDecl/postcard/postcard/Y/X/Z, refs={ 1 }", "EntryResult: word=methodDecl/print/Mail/Y/X/Z, refs={ 1 }", //$NON-NLS-1$ //$NON-NLS-2$
+ "EntryResult: word=methodDecl/print/Unknown/Y/X/Z, refs={ 1 }", "EntryResult: word=methodDecl/print/first_class/Y/X/Z, refs={ 1 }", //$NON-NLS-1$ //$NON-NLS-2$
+ "EntryResult: word=methodDecl/print/postcard/Y/X/Z, refs={ 1 }", "EntryResult: word=methodDecl/size/container/Y/X/Z, refs={ 1 }", //$NON-NLS-1$ //$NON-NLS-2$
+ "EntryResult: word=methodDecl/~container/container/Y/X/Z, refs={ 1 }"}; //$NON-NLS-1$
IEntryResult[] methodresults =ind.queryEntries(IIndexConstants.METHOD_DECL);
- assertTrue("Entry exists", methodresults != null);
+ assertTrue("Entry exists", methodresults != null); //$NON-NLS-1$
if (methodresults.length != methodResultModel.length)
- fail("Entry Result length different from model for functionDecl");
+ fail("Entry Result length different from model for functionDecl"); //$NON-NLS-1$
for (int i=0;i<methodresults.length; i++)
{
- assertEquals("Index is " +i , methodResultModel[i],methodresults[i].toString());
+ assertEquals("Index is " +i , methodResultModel[i],methodresults[i].toString()); //$NON-NLS-1$
}
}
public void testRefs() throws Exception{
//Add a new file to the project
- importFile("reftest.cpp","resources/indexer/reftest.cpp");
+ importFile("reftest.cpp","resources/indexer/reftest.cpp"); //$NON-NLS-1$ //$NON-NLS-2$
//Make sure project got added to index
IPath testProjectPath = testProject.getFullPath();
- IIndex ind = indexManager.getIndex(testProjectPath,true,true);
- assertTrue("Index exists for project",ind != null);
+ IIndex ind = sourceIndexer.getIndex(testProjectPath,true,true);
+ assertTrue("Index exists for project",ind != null); //$NON-NLS-1$
+
+ String [] typeRefEntryResultModel ={"EntryResult: word=typeRef/C/C/B/A, refs={ 1 }", "EntryResult: word=typeRef/E/e1/B/A, refs={ 1 }", //$NON-NLS-1$ //$NON-NLS-2$
+ "EntryResult: word=typeRef/G/ForwardA/A, refs={ 1 }", "EntryResult: word=typeRef/V/x/B/A, refs={ 1 }"}; //$NON-NLS-1$ //$NON-NLS-2$
- String [] typeRefEntryResultModel ={"EntryResult: word=typeRef/C/C/B/A, refs={ 1 }", "EntryResult: word=typeRef/E/e1/B/A, refs={ 1 }", "EntryResult: word=typeRef/G/ForwardA/A, refs={ 1 }", "EntryResult: word=typeRef/V/x/B/A, refs={ 1 }"};
IEntryResult[] typerefresults = ind.queryEntries(IIndexConstants.TYPE_REF);
- assertTrue("Entry exists",typerefresults != null);
+ assertTrue("Entry exists",typerefresults != null); //$NON-NLS-1$
if (typerefresults.length != typeRefEntryResultModel.length)
- fail("Entry Result length different from model for typeRef");
+ fail("Entry Result length different from model for typeRef"); //$NON-NLS-1$
for (int i=0;i<typerefresults.length; i++)
{
assertEquals(typeRefEntryResultModel[i],typerefresults[i].toString());
}
- String [] funRefEntryResultModel ={"EntryResult: word=functionRef/something/A, refs={ 1 }"};
+ String [] funRefEntryResultModel ={"EntryResult: word=functionRef/something/A, refs={ 1 }"};//$NON-NLS-1$
IEntryResult[] funRefresults = ind.queryEntries(IIndexConstants.FUNCTION_REF);
- assertTrue("Entry exists",funRefresults != null);
+ assertTrue("Entry exists",funRefresults != null); //$NON-NLS-1$
if (funRefresults.length != funRefEntryResultModel.length)
- fail("Entry Result length different from model for funcRef");
+ fail("Entry Result length different from model for funcRef"); //$NON-NLS-1$
for (int i=0;i<funRefresults.length; i++)
{
assertEquals(funRefEntryResultModel[i],funRefresults[i].toString());
}
- String [] namespaceRefResultModel = {"EntryResult: word=namespaceRef/A, refs={ 1 }", "EntryResult: word=namespaceRef/B/A, refs={ 1 }"};
+ String [] namespaceRefResultModel = {"EntryResult: word=namespaceRef/A, refs={ 1 }", "EntryResult: word=namespaceRef/B/A, refs={ 1 }"}; //$NON-NLS-1$ //$NON-NLS-2$
IEntryResult[] namespacerefresults = ind.queryEntries(IIndexConstants.NAMESPACE_REF);
- assertTrue("Entry exists",namespacerefresults!=null);
+ assertTrue("Entry exists",namespacerefresults!=null); //$NON-NLS-1$
if (namespacerefresults.length != namespaceRefResultModel.length)
- fail("Entry Result length different from model for namespaceRef");
+ fail("Entry Result length different from model for namespaceRef"); //$NON-NLS-1$
for (int i=0;i<namespacerefresults.length; i++)
{
assertEquals(namespaceRefResultModel[i],namespacerefresults[i].toString());
}
- String [] fieldRefResultModel = {"EntryResult: word=fieldRef/y/C/B/A, refs={ 1 }"};
+ String [] fieldRefResultModel = {"EntryResult: word=fieldRef/y/C/B/A, refs={ 1 }"}; //$NON-NLS-1$
IEntryResult[] fieldrefresults = ind.queryEntries(IIndexConstants.FIELD_REF);
- assertTrue("Entry exists",fieldrefresults!=null);
+ assertTrue("Entry exists",fieldrefresults!=null); //$NON-NLS-1$
if (fieldrefresults.length != fieldRefResultModel.length)
- fail("Entry Result length different from model for fieldRef");
+ fail("Entry Result length different from model for fieldRef"); //$NON-NLS-1$
for (int i=0;i<fieldrefresults.length; i++)
{
assertEquals(fieldRefResultModel[i],fieldrefresults[i].toString());
}
- String [] methodRefResultModel = {"EntryResult: word=methodRef/bar/C/B/A, refs={ 1 }"};
+ String [] methodRefResultModel = {"EntryResult: word=methodRef/bar/C/B/A, refs={ 1 }"}; //$NON-NLS-1$
IEntryResult[] methodrefresults = ind.queryEntries(IIndexConstants.METHOD_REF);
- assertTrue("Entry exists", methodrefresults != null);
+ assertTrue("Entry exists", methodrefresults != null); //$NON-NLS-1$
if (methodrefresults.length != methodRefResultModel.length)
- fail("Entry Result length different from model for methodRef");
+ fail("Entry Result length different from model for methodRef");//$NON-NLS-1$
for (int i=0;i<methodrefresults.length; i++)
{
@@ -525,55 +566,55 @@ public class IndexManagerTests extends TestCase implements IIndexChangeListener
public void testExactDeclarations() throws Exception
{
- importFile("a.h","resources/dependency/a.h");
+ importFile("a.h","resources/dependency/a.h");//$NON-NLS-1$ //$NON-NLS-2$
//Make sure project got added to index
IPath testProjectPath = testProject.getFullPath();
- IIndex ind = indexManager.getIndex(testProjectPath,true,true);
- assertTrue("Index exists for project",ind != null);
-
- importFile("DepTest3.h","resources/dependency/DepTest3.h");
- importFile("DepTest3.cpp","resources/dependency/DepTest3.cpp");
+ IIndex ind = sourceIndexer.getIndex(testProjectPath,true,true);
+ assertTrue("Index exists for project",ind != null); //$NON-NLS-1$
+
+ importFile("DepTest3.h","resources/dependency/DepTest3.h");//$NON-NLS-1$ //$NON-NLS-2$
+ importFile("DepTest3.cpp","resources/dependency/DepTest3.cpp");//$NON-NLS-1$ //$NON-NLS-2$
IEntryResult[] eResult = ind.queryEntries(IIndexConstants.CLASS_DECL);
IQueryResult[] qResult = ind.queryPrefix(IIndexConstants.CLASS_DECL);
- assertTrue("Expected 2 files indexed", qResult.length == 2);
- assertTrue("Checking DepTest3.h location", qResult[0].getPath().equals("/IndexerTestProject/DepTest3.h"));
- assertTrue("Checking a.h location", qResult[1].getPath().equals("/IndexerTestProject/a.h"));
+ assertTrue("Expected 2 files indexed", qResult.length == 2); //$NON-NLS-1$
+ assertTrue("Checking DepTest3.h location", qResult[0].getPath().equals("/IndexerTestProject/DepTest3.h")); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("Checking a.h location", qResult[1].getPath().equals("/IndexerTestProject/a.h")); //$NON-NLS-1$ //$NON-NLS-2$
- assertTrue("Expect 2 class declaration entries", eResult.length == 2);
+ assertTrue("Expect 2 class declaration entries", eResult.length == 2); //$NON-NLS-1$
int[] DepTest3FileRefs = {2};
int[] fileRefs = eResult[0].getFileReferences();
- assertTrue("Check DepTest3 File Refs number", fileRefs.length == 1);
+ assertTrue("Check DepTest3 File Refs number", fileRefs.length == 1); //$NON-NLS-1$
for (int i=0; i<fileRefs.length; i++){
- assertTrue("Verify DepTest3 File Ref",fileRefs[i] == DepTest3FileRefs[i]);
+ assertTrue("Verify DepTest3 File Ref",fileRefs[i] == DepTest3FileRefs[i]); //$NON-NLS-1$
}
int[] aFileRefs = {3};
fileRefs = eResult[1].getFileReferences();
- assertTrue("Check a.h File Refs number", fileRefs.length == 1);
+ assertTrue("Check a.h File Refs number", fileRefs.length == 1); //$NON-NLS-1$
for (int i=0; i<fileRefs.length; i++){
- assertTrue("Verify a.h File Ref",fileRefs[i] == aFileRefs[i]);
+ assertTrue("Verify a.h File Ref",fileRefs[i] == aFileRefs[i]); //$NON-NLS-1$
}
}
public void testMD5() throws Exception
{
- importFile("extramail.cpp","resources/indexer/extramail.cpp");
+ importFile("extramail.cpp","resources/indexer/extramail.cpp"); //$NON-NLS-1$ //$NON-NLS-2$
//importFile("mail.cpp","resources/indexer/mail.cpp");
- MessageDigest md = MessageDigest.getInstance("MD5");
+ MessageDigest md = MessageDigest.getInstance("MD5"); //$NON-NLS-1$
//MessageDigest md = MessageDigest.getInstance("SHA");
- String fileName = testProject.getFile("extramail.cpp").getLocation().toOSString();
+ String fileName = testProject.getFile("extramail.cpp").getLocation().toOSString(); //$NON-NLS-1$
//String fileName = testProject.getFile("mail.cpp").getLocation().toOSString();
long startTime = System.currentTimeMillis();
@@ -596,20 +637,21 @@ public class IndexManagerTests extends TestCase implements IIndexChangeListener
public void testMacros() throws Exception
{
//Add a new file to the project
- importFile("extramail.cpp","resources/indexer/extramail.cpp");
+ importFile("extramail.cpp","resources/indexer/extramail.cpp"); //$NON-NLS-1$ //$NON-NLS-2$
//Make sure project got added to index
IPath testProjectPath = testProject.getFullPath();
- IIndex ind = indexManager.getIndex(testProjectPath,true,true);
- assertTrue("Index exists for project",ind != null);
+ IIndex ind = sourceIndexer.getIndex(testProjectPath,true,true);
+ assertTrue("Index exists for project",ind != null); //$NON-NLS-1$
IEntryResult[] macroresults = ind.queryEntries(IIndexConstants.MACRO_DECL);
- assertTrue("Entry exists", macroresults != null);
+ assertTrue("Entry exists", macroresults != null); //$NON-NLS-1$
- String [] macroResultModel = {"EntryResult: word=macroDecl/CASE, refs={ 1 }", "EntryResult: word=macroDecl/MAX, refs={ 1 }", "EntryResult: word=macroDecl/PRINT, refs={ 1 }"};
+ String [] macroResultModel = {"EntryResult: word=macroDecl/CASE, refs={ 1 }", "EntryResult: word=macroDecl/MAX, refs={ 1 }", //$NON-NLS-1$ //$NON-NLS-2$
+ "EntryResult: word=macroDecl/PRINT, refs={ 1 }"}; //$NON-NLS-1$
if (macroresults.length != macroResultModel.length)
- fail("Entry Result length different from model for macros");
+ fail("Entry Result length different from model for macros"); //$NON-NLS-1$
for (int i=0;i<macroresults.length; i++)
{
@@ -619,15 +661,15 @@ public class IndexManagerTests extends TestCase implements IIndexChangeListener
public void testIndexShutdown() throws Exception{
//Add a new file to the project
- importFile("reftest.cpp","resources/indexer/reftest.cpp");
+ importFile("reftest.cpp","resources/indexer/reftest.cpp"); //$NON-NLS-1$ //$NON-NLS-2$
//Make sure project got added to index
IPath testProjectPath = testProject.getFullPath();
- IIndex ind = indexManager.getIndex(testProjectPath,true,true);
- assertTrue("Index exists for project",ind != null);
+ IIndex ind = sourceIndexer.getIndex(testProjectPath,true,true);
+ assertTrue("Index exists for project",ind != null); //$NON-NLS-1$
//Create an empty index file
- String badIndexFile = CCorePlugin.getDefault().getStateLocation().append("badIndex.index").toOSString();
+ String badIndexFile = CCorePlugin.getDefault().getStateLocation().append("badIndex.index").toOSString(); //$NON-NLS-1$
FileWriter writer = null;
try {
writer = new FileWriter(badIndexFile);
@@ -645,8 +687,8 @@ public class IndexManagerTests extends TestCase implements IIndexChangeListener
File[] indexesFiles = indexesDirectory.listFiles();
if (indexesFiles != null) {
for (int i = 0, indexesFilesLength = indexesFiles.length; i < indexesFilesLength; i++) {
- if(indexesFiles[i].getName().equals("badIndex.index")){
- fail("Shutdown did not delete .index file");
+ if(indexesFiles[i].getName().equals("badIndex.index")){ //$NON-NLS-1$
+ fail("Shutdown did not delete .index file"); //$NON-NLS-1$
}
}
}
@@ -654,34 +696,33 @@ public class IndexManagerTests extends TestCase implements IIndexChangeListener
public void testForwardDeclarations() throws Exception{
//Add a new file to the project
- importFile("reftest.cpp","resources/indexer/reftest.cpp");
+ importFile("reftest.cpp","resources/indexer/reftest.cpp"); //$NON-NLS-1$ //$NON-NLS-2$
//Make sure project got added to index
IPath testProjectPath = testProject.getFullPath();
- IIndex ind = indexManager.getIndex(testProjectPath,true,true);
- assertTrue("Index exists for project",ind != null);
-
+ IIndex ind = sourceIndexer.getIndex(testProjectPath,true,true);
+ assertTrue("Index exists for project",ind != null); //$NON-NLS-1$
//IEntryResult[] fwdDclResults = ind.queryEntries("typeDecl/C/ForwardA/A".toCharArray());
- IEntryResult[] fwdDclResults = ind.queryEntries("typeDecl/G/ForwardA/A".toCharArray());
- assertTrue("Entry exists",fwdDclResults != null);
+ IEntryResult[] fwdDclResults = ind.queryEntries("typeDecl/G/ForwardA/A".toCharArray()); //$NON-NLS-1$
+ assertTrue("Entry exists",fwdDclResults != null); //$NON-NLS-1$
- String [] fwdDclModel = {"EntryResult: word=typeDecl/G/ForwardA/A, refs={ 1 }"};
+ String [] fwdDclModel = {"EntryResult: word=typeDecl/G/ForwardA/A, refs={ 1 }"}; //$NON-NLS-1$
if (fwdDclResults.length != fwdDclModel.length)
- fail("Entry Result length different from model for forward declarations");
+ fail("Entry Result length different from model for forward declarations"); //$NON-NLS-1$
for (int i=0;i<fwdDclResults.length; i++)
{
assertEquals(fwdDclModel[i],fwdDclResults[i].toString());
}
- IEntryResult[] fwdDclRefResults = ind.queryEntries("typeRef/G/ForwardA/A".toCharArray());
- assertTrue("Entry exists", fwdDclRefResults!= null);
+ IEntryResult[] fwdDclRefResults = ind.queryEntries("typeRef/G/ForwardA/A".toCharArray()); //$NON-NLS-1$
+ assertTrue("Entry exists", fwdDclRefResults!= null); //$NON-NLS-1$
- String [] fwdDclRefModel = {"EntryResult: word=typeRef/G/ForwardA/A, refs={ 1 }"};
+ String [] fwdDclRefModel = {"EntryResult: word=typeRef/G/ForwardA/A, refs={ 1 }"}; //$NON-NLS-1$
if (fwdDclRefResults.length != fwdDclRefModel.length)
- fail("Entry Result length different from model for forward declarations refs");
+ fail("Entry Result length different from model for forward declarations refs"); //$NON-NLS-1$
for (int i=0;i<fwdDclRefResults.length; i++)
{
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FileBasePluginTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FileBasePluginTest.java
index 81e8f37e98..deabeafdd5 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FileBasePluginTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FileBasePluginTest.java
@@ -70,9 +70,9 @@ import org.eclipse.cdt.core.parser.ast.IASTVariable;
import org.eclipse.cdt.core.parser.ast.IASTVariableReference;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.core.testplugin.FileManager;
+import org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer;
import org.eclipse.cdt.internal.core.parser.Parser;
import org.eclipse.cdt.internal.core.parser.ParserException;
-import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
@@ -105,7 +105,7 @@ public class FileBasePluginTest extends TestCase {
cPrj = CProjectHelper.createCCProject("ParserTestProject", "bin"); //$NON-NLS-1$ //$NON-NLS-2$
project = cPrj.getProject();
- project.setSessionProperty(IndexManager.activationKey,new Boolean(false));
+ project.setSessionProperty(SourceIndexer.activationKey,new Boolean(false));
// ugly
if (className == null || !className.equals(aClassName)) {
diff --git a/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/BaseTestFramework.java b/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/BaseTestFramework.java
index 2a14b6e6f6..42ecd3f016 100644
--- a/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/BaseTestFramework.java
+++ b/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/BaseTestFramework.java
@@ -23,7 +23,7 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.core.testplugin.FileManager;
-import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
+import org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@@ -41,7 +41,8 @@ abstract public class BaseTestFramework extends TestCase {
static protected IProject project;
static protected ICProject cproject;
static protected FileManager fileManager;
-
+ static final String sourceIndexerID = "org.eclipse.cdt.core.originalsourceindexer"; //$NON-NLS-1$
+ static protected SourceIndexer sourceIndexer;
{
if( CCorePlugin.getDefault() != null && CCorePlugin.getDefault().getCoreModel() != null){
(CCorePlugin.getDefault().getCoreModel().getIndexManager()).reset();
@@ -53,7 +54,14 @@ abstract public class BaseTestFramework extends TestCase {
cproject = CProjectHelper.createCCProject("RegressionTestProject", "bin"); //$NON-NLS-1$ //$NON-NLS-2$
project = cproject.getProject();
- project.setSessionProperty(IndexManager.activationKey, Boolean.FALSE );
+
+ /*project.setSessionProperty(SourceIndexer.activationKey, Boolean.FALSE );
+ //Set the id of the source indexer extension point as a session property to allow
+ //index manager to instantiate it
+ project.setSessionProperty(IndexManager.indexerIDKey, sourceIndexerID);*/
+
+
+
} catch ( CoreException e ) {
/*boo*/
}
@@ -69,7 +77,7 @@ abstract public class BaseTestFramework extends TestCase {
if( CCorePlugin.getDefault() != null && CCorePlugin.getDefault().getCoreModel() != null){
if( project != null )
try {
- project.setSessionProperty( IndexManager.activationKey, Boolean.TRUE );
+ project.setSessionProperty( SourceIndexer.activationKey, Boolean.TRUE );
} catch ( CoreException e ) { //boo
}
}
@@ -79,7 +87,7 @@ abstract public class BaseTestFramework extends TestCase {
if( CCorePlugin.getDefault() != null && CCorePlugin.getDefault().getCoreModel() != null){
if( project != null )
try {
- project.setSessionProperty( IndexManager.activationKey, Boolean.FALSE );
+ project.setSessionProperty( SourceIndexer.activationKey, Boolean.FALSE );
} catch ( CoreException e ) { //boo
}
}
diff --git a/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/SearchRegressionTests.java b/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/SearchRegressionTests.java
index 887e43c827..c716f95ce9 100644
--- a/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/SearchRegressionTests.java
+++ b/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/SearchRegressionTests.java
@@ -33,6 +33,8 @@ import org.eclipse.cdt.core.search.ICSearchPattern;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.IMatch;
import org.eclipse.cdt.core.search.SearchEngine;
+import org.eclipse.cdt.internal.core.browser.cache.TypeCacheManager;
+import org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
@@ -42,11 +44,10 @@ import org.eclipse.core.runtime.Path;
* @author aniefer
*/
public class SearchRegressionTests extends BaseTestFramework implements ICSearchConstants, IIndexChangeListener{
- static protected ICSearchScope scope;
- static protected SearchEngine searchEngine;
- static protected BasicSearchResultCollector resultCollector;
- static private boolean indexChanged = false;
-
+ static protected ICSearchScope scope;
+ static protected SearchEngine searchEngine;
+ static protected BasicSearchResultCollector resultCollector;
+ static private boolean indexChanged = false;
{
scope = SearchEngine.createWorkspaceScope();
resultCollector = new BasicSearchResultCollector();
@@ -67,11 +68,18 @@ public class SearchRegressionTests extends BaseTestFramework implements ICSearch
protected void setUp() throws Exception {
super.setUp();
try{
- project.setSessionProperty( IndexManager.activationKey, new Boolean( true ) );
+ project.setSessionProperty(IndexManager.indexerIDKey, sourceIndexerID);
+ project.setSessionProperty( SourceIndexer.activationKey, new Boolean( true ) );
} catch ( CoreException e ) { //boo
}
+ TypeCacheManager typeCacheManager = TypeCacheManager.getInstance();
+ typeCacheManager.setProcessTypeCacheEvents(false);
+
IndexManager indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager();
- indexManager.addIndexChangeListener( this );
+ indexManager.reset();
+
+ sourceIndexer = (SourceIndexer) CCorePlugin.getDefault().getCoreModel().getIndexManager().getIndexerForProject(project);
+ sourceIndexer.addIndexChangeListener( this );
}
protected void tearDown() throws Exception {
@@ -79,9 +87,9 @@ public class SearchRegressionTests extends BaseTestFramework implements ICSearch
return;
IndexManager indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager();
- indexManager.removeIndexChangeListener( this );
+ sourceIndexer.removeIndexChangeListener( this );
try{
- project.setSessionProperty( IndexManager.activationKey, new Boolean( false ) );
+ project.setSessionProperty( SourceIndexer.activationKey, new Boolean( false ) );
} catch ( CoreException e ) { //boo
}
super.tearDown();
diff --git a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/BaseSearchTest.java b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/BaseSearchTest.java
index 5b6dd8a408..e2c466bb74 100644
--- a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/BaseSearchTest.java
+++ b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/BaseSearchTest.java
@@ -28,6 +28,7 @@ import org.eclipse.cdt.core.search.SearchEngine;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.core.testplugin.CTestPlugin;
import org.eclipse.cdt.core.testplugin.FileManager;
+import org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@@ -53,6 +54,8 @@ public class BaseSearchTest extends TestCase implements ICSearchConstants {
static protected BasicSearchResultCollector resultCollector;
static protected SearchEngine searchEngine;
static protected FileManager fileManager;
+ static final String sourceIndexerID = "org.eclipse.cdt.core.originalsourceindexer"; //$NON-NLS-1$
+
{
(CCorePlugin.getDefault().getCoreModel().getIndexManager()).reset();
@@ -63,7 +66,12 @@ public class BaseSearchTest extends TestCase implements ICSearchConstants {
try {
//Create temp project
testProject = createProject("SearchTestProject");
- testProject.setSessionProperty(IndexManager.activationKey,new Boolean(true));
+
+ testProject.setSessionProperty(SourceIndexer.activationKey,new Boolean(true));
+
+ //Set the id of the source indexer extension point as a session property to allow
+ //index manager to instantiate it
+ testProject.setSessionProperty(IndexManager.indexerIDKey, sourceIndexerID);
} catch (CoreException e) {}
diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java
index bdc5aa1942..235ff200e2 100644
--- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java
+++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java
@@ -13,7 +13,7 @@ import org.eclipse.cdt.core.build.managed.tests.StandardBuildTests;
import org.eclipse.cdt.core.cdescriptor.tests.CDescriptorTests;
import org.eclipse.cdt.core.filetype.tests.ResolverTests;
import org.eclipse.cdt.core.indexer.tests.DependencyTests;
-import org.eclipse.cdt.core.indexer.tests.IndexManagerTests;
+import org.eclipse.cdt.core.indexer.tests.SourceIndexerTests;
import org.eclipse.cdt.core.model.tests.AllCoreTests;
import org.eclipse.cdt.core.model.tests.BinaryTests;
import org.eclipse.cdt.core.model.tests.ElementDeltaTests;
@@ -65,7 +65,7 @@ public class AutomatedIntegrationSuite extends TestSuite {
suite.addTest(RegressionTestSuite.suite());
//Indexer Tests need to be run after any indexer client tests
//as the last test shuts down the indexing thread
- suite.addTest(IndexManagerTests.suite());
+ suite.addTest(SourceIndexerTests.suite());
// Last test to trigger report generation
// Add all failed tests
diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog
index e2c9fbe0ec..0bddce3a4a 100644
--- a/core/org.eclipse.cdt.core/ChangeLog
+++ b/core/org.eclipse.cdt.core/ChangeLog
@@ -1,3 +1,12 @@
+2005-03-13 Bogdan Gheorghe
+ Added support for new indexer framework
+
+ * model/org/eclipse/cdt/core/model/CoreModel.java
+ * model/org/eclipse/cdt/internal/core/model/CModelManager.java
+ * model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java
+ * src/org/eclipse/cdt/core/CCorePlugin.java
+ * plugin.xml
+
2005-03-12 Alain Magloire
Plan item 79518: for PathEntry variable manager.
* model/org/eclipse/cdt/internal/core/model/PathEntryManager.java
diff --git a/core/org.eclipse.cdt.core/browser/ChangeLog-browser b/core/org.eclipse.cdt.core/browser/ChangeLog-browser
index 37a8e65ea2..48c5186560 100644
--- a/core/org.eclipse.cdt.core/browser/ChangeLog-browser
+++ b/core/org.eclipse.cdt.core/browser/ChangeLog-browser
@@ -1,3 +1,15 @@
+2005-03-13 Bogdan Gheorghe
+ Updated references to IndexManager to reflect new multi-indexer framework.
+ * browser/org/eclipse/cdt/internal/core/browser/cache/IndexerDependencies.java
+ * browser/org/eclipse/cdt/internal/core/browser/cache/IndexerJob.java
+ * browser/org/eclipse/cdt/internal/core/browser/cache/IndexerTypesJob.java
+ * browser/org/eclipse/cdt/internal/core/browser/cache/TypeCache.java
+ * browser/org/eclipse/cdt/internal/core/browser/cache/TypeCacherJob.java
+
+ Added temporary flag to TypeCacheManager to prevent deadlocks during JUnit runs, pending
+ changes to Index Storage framework.
+ * browser/org/eclipse/cdt/internal/core/browser/cache/TypeCacheManager.java
+
2005-01-06 Chris Wiebe
added parser timeout to TypeParser
* browser/org/eclipse/cdt/internal/core/browser/cache/TypeParser.java
diff --git a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/IndexerJob.java b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/IndexerJob.java
index d5fe7b9d71..6690958230 100644
--- a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/IndexerJob.java
+++ b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/IndexerJob.java
@@ -13,10 +13,12 @@ package org.eclipse.cdt.internal.core.browser.cache;
import java.io.IOException;
+import org.eclipse.cdt.core.index.ICDTIndexer;
import org.eclipse.cdt.internal.core.index.IIndex;
+import org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.cdt.internal.core.search.indexing.ReadWriteMonitor;
-import org.eclipse.cdt.internal.core.search.processing.IJob;
+import org.eclipse.cdt.internal.core.search.processing.IIndexJob;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
@@ -25,16 +27,23 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
-public abstract class IndexerJob implements IJob {
+public abstract class IndexerJob implements IIndexJob {
private IndexManager fIndexManager;
private IProject fProject;
private IIndex fProjectIndex = null;
+ private SourceIndexer fSourceIndexer = null;
+
public static final String FAMILY= "BasicTypeIndexerJob"; //$NON-NLS-1$
public IndexerJob(IndexManager indexManager, IProject project) {
fIndexManager = indexManager;
fProject = project;
+ //Get the indexer assigned to this project; check to see if it's
+ //a Source Indexder
+ ICDTIndexer indexer = indexManager.getIndexerForProject(project);
+ if (indexer instanceof SourceIndexer)
+ fSourceIndexer = (SourceIndexer) indexer;
}
public boolean belongsTo(String family) {
@@ -94,7 +103,11 @@ public abstract class IndexerJob implements IJob {
if (index == null)
return COMPLETE;
- ReadWriteMonitor monitor = fIndexManager.getMonitorFor(index);
+ if (fSourceIndexer == null)
+ return FAILED;
+
+ ReadWriteMonitor monitor = fSourceIndexer.getMonitorFor(index);
+
if (monitor == null)
return COMPLETE; // index got deleted since acquired
@@ -105,7 +118,7 @@ public abstract class IndexerJob implements IJob {
try {
monitor.exitRead(); // free read lock
monitor.enterWrite(); // ask permission to write
- fIndexManager.saveIndex(index);
+ fSourceIndexer.saveIndex(index);
} catch (IOException e) {
return FAILED;
} finally {
@@ -135,7 +148,10 @@ public abstract class IndexerJob implements IJob {
}
// may trigger some index recreation work
- return fIndexManager.getIndex(path, true /*reuse index file*/, false /*do not create if none*/);
+ if (fSourceIndexer != null)
+ return fSourceIndexer.getIndex(path, true /*reuse index file*/, false /*do not create if none*/);
+
+ return null;
}
}
diff --git a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/TypeCacheManager.java b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/TypeCacheManager.java
index d604511b21..0fd2df7cfb 100644
--- a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/TypeCacheManager.java
+++ b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/TypeCacheManager.java
@@ -50,7 +50,8 @@ public class TypeCacheManager implements ITypeCacheChangedListener {
//TODO make this a WeakHashMap or LRUCache
private Map fTypeToElementMap = new HashMap(INITIAL_TYPE_MAP_SIZE);
private Map fElementToTypeMap = new HashMap(INITIAL_TYPE_MAP_SIZE);
-
+ private boolean processTypeCacheEvents = true;
+
private TypeCacheManager() {
fCacheMap = new HashMap();
}
@@ -227,6 +228,9 @@ public class TypeCacheManager implements ITypeCacheChangedListener {
}
public synchronized void reconcile(boolean enableIndexing, int priority, int delay) {
+ if (!(processTypeCacheEvents))
+ return;
+
TypeSearchScope workspaceScope = new TypeSearchScope(true);
IProject[] projects = workspaceScope.getEnclosingProjects();
for (int i = 0; i < projects.length; ++i) {
@@ -236,6 +240,9 @@ public class TypeCacheManager implements ITypeCacheChangedListener {
}
public synchronized void reconcileAndWait(boolean enableIndexing, int priority, IProgressMonitor monitor) {
+ if (!(processTypeCacheEvents))
+ return;
+
TypeSearchScope workspaceScope = new TypeSearchScope(true);
IProject[] projects = workspaceScope.getEnclosingProjects();
for (int i = 0; i < projects.length; ++i) {
@@ -444,4 +451,10 @@ public class TypeCacheManager implements ITypeCacheChangedListener {
}
return null;
}
+ public boolean getProcessTypeCacheEvents() {
+ return processTypeCacheEvents;
+ }
+ public void setProcessTypeCacheEvents(boolean processTypeCacheEvents) {
+ this.processTypeCacheEvents = processTypeCacheEvents;
+ }
}
diff --git a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/TypeCacherJob.java b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/TypeCacherJob.java
index de7f1dc706..b864e69744 100644
--- a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/TypeCacherJob.java
+++ b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/TypeCacherJob.java
@@ -141,16 +141,16 @@ public class TypeCacherJob extends BasicJob {
private void update(ITypeSearchScope scope, IProgressMonitor monitor) throws InterruptedException {
boolean success = true;
IProject project = fTypeCache.getProject();
-
+
monitor.beginTask("", 100); //$NON-NLS-1$
if (project.exists() && project.isOpen()) {
success = doIndexerJob(new IndexerTypesJob(fIndexManager, fTypeCache, scope), monitor);
}
-
+
if (!success || monitor.isCanceled()) {
throw new InterruptedException();
}
-
+
monitor.done();
}
diff --git a/core/org.eclipse.cdt.core/dependency/ChangeLog b/core/org.eclipse.cdt.core/dependency/ChangeLog
index 5fd1465f6c..05411b253a 100644
--- a/core/org.eclipse.cdt.core/dependency/ChangeLog
+++ b/core/org.eclipse.cdt.core/dependency/ChangeLog
@@ -1,3 +1,9 @@
+2005-03-12 Bogdan Gheorghe
+ - Updated references from IndexManager to SourceIndexer due to new indexer framework
+
+ * src/org/eclipse/cdt/internal/core/sourcedependency/DependencyQueryJob.java
+ * src/org/eclipse/cdt/internal/core/sourcedependency/UpdateDependency.java
+
2004-02-25 Bogdan Gheorghe
- Check to see if the resource has a location before using it in
UpdateDependency
diff --git a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencyQueryJob.java b/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencyQueryJob.java
index be478daf83..0d78403cf4 100644
--- a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencyQueryJob.java
+++ b/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencyQueryJob.java
@@ -7,6 +7,8 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.index.IIndexStorage;
import org.eclipse.cdt.core.search.SearchEngine;
import org.eclipse.cdt.internal.core.index.IDocument;
import org.eclipse.cdt.internal.core.index.IIndex;
@@ -15,10 +17,12 @@ import org.eclipse.cdt.internal.core.index.impl.IFileDocument;
import org.eclipse.cdt.internal.core.index.impl.IncludeEntry;
import org.eclipse.cdt.internal.core.index.impl.IndexInput;
import org.eclipse.cdt.internal.core.index.impl.IndexedFile;
+import org.eclipse.cdt.internal.core.index.sourceindexer.CIndexStorage;
+import org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer;
import org.eclipse.cdt.internal.core.search.IndexSelector;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.cdt.internal.core.search.indexing.ReadWriteMonitor;
-import org.eclipse.cdt.internal.core.search.processing.IJob;
+import org.eclipse.cdt.internal.core.search.processing.IIndexJob;
import org.eclipse.cdt.internal.core.search.processing.JobManager;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@@ -28,20 +32,22 @@ import org.eclipse.core.runtime.OperationCanceledException;
/**
* @author bgheorgh
*/
-public class DependencyQueryJob implements IJob {
+public class DependencyQueryJob implements IIndexJob {
IProject project;
IFile file;
ArrayList includeFiles;
+ SourceIndexer indexer;
IndexManager indexManager;
protected IndexSelector indexSelector;
protected long executionTime = 0;
- public DependencyQueryJob(IProject project, IFile file, IndexManager inMan, List includeFiles) {
+ public DependencyQueryJob(IProject project, IFile file, SourceIndexer indexer, List includeFiles) {
this.project = project;
this.file = file;
- this.indexManager = inMan;
+ this.indexer = indexer;
this.includeFiles = (ArrayList) includeFiles;
+ this.indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager();
}
/* (non-Javadoc)
@@ -69,11 +75,12 @@ public class DependencyQueryJob implements IJob {
executionTime = 0;
if (this.indexSelector == null) {
this.indexSelector =
- new IndexSelector(SearchEngine.createWorkspaceScope(), null, false, this.indexManager);
+ new IndexSelector(SearchEngine.createWorkspaceScope(), null, false, indexManager);
}
IIndex[] searchIndexes = this.indexSelector.getIndexes();
try {
int max = searchIndexes.length;
+ int min=0;
if (progressMonitor != null) {
progressMonitor.beginTask("", max); //$NON-NLS-1$
}
@@ -115,7 +122,15 @@ public class DependencyQueryJob implements IJob {
if (index == null)
return COMPLETE;
- ReadWriteMonitor monitor = indexManager.getMonitorFor(index);
+
+
+ if (!(indexer instanceof SourceIndexer))
+ return FAILED;
+
+
+ SourceIndexer sourceIndexer = (SourceIndexer)indexer;
+
+ ReadWriteMonitor monitor = sourceIndexer.getMonitorFor(index);
if (monitor == null)
return COMPLETE; // index got deleted since acquired
try {
@@ -126,7 +141,7 @@ public class DependencyQueryJob implements IJob {
try {
monitor.exitRead(); // free read lock
monitor.enterWrite(); // ask permission to write
- this.indexManager.saveIndex(index);
+ sourceIndexer.saveIndex(index);
} catch (IOException e) {
return FAILED;
} finally {
@@ -219,7 +234,7 @@ public class DependencyQueryJob implements IJob {
*/
public boolean isReadyToRun() {
if (this.indexSelector == null) { // only check once. As long as this job is used, it will keep the same index picture
- this.indexSelector = new IndexSelector(SearchEngine.createWorkspaceScope(), null, false, this.indexManager);
+ this.indexSelector = new IndexSelector(SearchEngine.createWorkspaceScope(), null, false, indexManager);
this.indexSelector.getIndexes(); // will only cache answer if all indexes were available originally
}
return true;
diff --git a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/UpdateDependency.java b/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/UpdateDependency.java
index 20ba9ba99d..4f8a722bae 100644
--- a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/UpdateDependency.java
+++ b/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/UpdateDependency.java
@@ -20,11 +20,12 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.SearchEngine;
+import org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer;
import org.eclipse.cdt.internal.core.search.PathCollector;
import org.eclipse.cdt.internal.core.search.PatternSearchJob;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.cdt.internal.core.search.matching.CSearchPattern;
-import org.eclipse.cdt.internal.core.search.processing.IJob;
+import org.eclipse.cdt.internal.core.search.processing.IIndexJob;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
@@ -38,15 +39,17 @@ import org.eclipse.core.runtime.Path;
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
-public class UpdateDependency implements IJob {
+public class UpdateDependency implements IIndexJob {
PathCollector pathCollector;
IResource resource;
+ SourceIndexer indexer;
/**
* @param resource
*/
- public UpdateDependency(IResource resource) {
+ public UpdateDependency(IResource resource, SourceIndexer indexer) {
this.resource = resource;
+ this.indexer = indexer;
}
/* (non-Javadoc)
@@ -99,7 +102,7 @@ public class UpdateDependency implements IJob {
if (fileToReindex!=null && fileToReindex.exists() ) {
// if (VERBOSE)
// System.out.println("Going to reindex " + fileToReindex.getName());
- indexManager.addSource(fileToReindex,fileToReindex.getProject().getProject().getFullPath());
+ indexer.addSource(fileToReindex,fileToReindex.getProject().getProject().getFullPath());
}
}
return false;
diff --git a/core/org.eclipse.cdt.core/index/ChangeLog b/core/org.eclipse.cdt.core/index/ChangeLog
index db3ef48be8..327c31240a 100644
--- a/core/org.eclipse.cdt.core/index/ChangeLog
+++ b/core/org.eclipse.cdt.core/index/ChangeLog
@@ -1,3 +1,33 @@
+2005-03-12 Bogdan Gheorghe
+ Restructured indexer framework to allow for multiple indexers in a workspace.
+
+ * index/org/eclipse/cdt/core/index/ICDTIndexer.java
+ * index/org/eclipse/cdt/core/index/IIndexStorage.java
+ * index/org/eclipse/cdt/core/index/Indexer.java
+ * index/org/eclipse/cdt/core/index/IndexManager.java
+ * index/org/eclipse/cdt/internal/core/index/IIndexer.java
+ * index/org/eclipse/cdt/internal/core/index/impl/Index.java
+ * index/org/eclipse/cdt/internal/core/index/impl/MergeFactory.java
+ * index/org/eclipse/cdt/internal/core/search/indexing/IndexerModelListener.java
+
+ Moved following classes to new source indexer folder:
+
+ * index/org/eclipse/cdt/internal/core/index/sourceindexer/AbstractIndexer.java
+ * index/org/eclipse/cdt/internal/core/index/sourceindexer/AddCompilationUnit.java
+ * index/org/eclipse/cdt/internal/core/index/sourceindexer/AddFileToIndex.java
+ * index/org/eclipse/cdt/internal/core/index/sourceindexer/AddFolderToIndex.java
+ * index/org/eclipse/cdt/internal/core/index/sourceindexer/CIndexStorage.java
+ * index/org/eclipse/cdt/internal/core/index/sourceindexer/CleanEncounteredHeaders.java
+ * index/org/eclipse/cdt/internal/core/index/sourceindexer/IndexAllProject.java
+ * index/org/eclipse/cdt/internal/core/index/sourceindexer/IndexRequest.java
+ * index/org/eclipse/cdt/internal/core/index/sourceindexer/RemoveFolderFromIndex.java
+ * index/org/eclipse/cdt/internal/core/index/sourceindexer/RemoveFromIndex.java
+ * index/org/eclipse/cdt/internal/core/index/sourceindexer/SaveIndex.java
+ * index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexer.java
+ * index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexerRequestor.java
+ * index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexerRunner.java
+
+
2004-11-17 Bogdan Gheorghe
Fix for Bug 78678: Indexer stops reindexing file after repeated saves
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/core/index/ICDTIndexer.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/core/index/ICDTIndexer.java
new file mode 100644
index 0000000000..743ca8099e
--- /dev/null
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/core/index/ICDTIndexer.java
@@ -0,0 +1,91 @@
+/**********************************************************************
+ * Copyright (c) 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.cdt.core.index;
+
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.internal.core.index.IIndexer;
+import org.eclipse.cdt.internal.core.search.processing.IIndexJob;
+import org.eclipse.core.resources.IResourceDelta;
+
+/**
+ * @author Bogdan Gheorghe
+ */
+/**
+ * An <code>ICDTIndexer</code> indexes ONE document at each time. It adds the document names and
+ * the words references to an IIndex. Each IIndexer can index certain types of document, and should
+ * not index the other files.
+ *
+ * Warning: This interface is still under development - API may change.
+ * @since 3.0
+ */
+public interface ICDTIndexer extends IIndexer {
+
+ /**
+ * Indexer Support bit flags
+ */
+ static public final int _DECLARATIONS = 1;
+ static public final int _DEFINITIONS = 2;
+ static public final int _REFERENCES = 4;
+ static public final int _LINENUMBERS = 8;
+ static public final int _OFFSETINFO = 16;
+ static public final int _CPP = 32;
+ static public final int _C = 64;
+
+ /**
+ * Indexer Policy bit flags
+ */
+ static public final int _NORMAL= 1;
+ static public final int _POSTBUILD = 2;
+ static public final int _MANUAL = 4;
+ static public final int _STATIC = 8;
+ static public final int _DELAYUNTILBUILDINFO = 16;
+
+
+ /**
+ * Returns what features this <code>ICDTIndexer</code> provides.
+ */
+ public int getIndexerFeatures();
+
+ /**
+ * The <code>IndexManager</code> calls addRequest when it receives an event from the <code>DeltaProcessor</code>.
+ * The <code>IResourcDelta</code> and (TODO: <code>IResourceChangeEvent</code> are provided for indexers
+ * to decide how to schedule this event).
+ */
+ public void addRequest(ICElement cElement, IResourceDelta delta/*, IResourceChangeEvent event*/);
+
+ /**
+ * The <code>IndexManager</code> calls addRequest when it receives an event from the <code>DeltaProcessor</code>.
+ * The <code>IResourcDelta</code> and (TODO:<code>IResourceChangeEvent</code> are provided for the indexder
+ * to decide how to schedule this event).
+ */
+ public void removeRequest(ICElement cElement, IResourceDelta delta/*, IResourceChangeEvent event*/);
+
+ /**
+ * The <code>IndexManager</code> will send out a jobFinishedEvent to the indexer that
+ * had scheduled the previous runnign job to give that indexer a chance to update its
+ * state info.
+ */
+ public void indexJobFinishedNotification(IIndexJob job);
+
+ /**
+ * The <code>IndexManager</code> will notify all indexers of impending shutdown events
+ * in order to allow indexers to perform whatever clean up they need to do.
+ */
+ public void shutdown();
+
+ /**
+ * Called by the index manager when there are no index jobs queued up - can be
+ * used by the indexer to save indexes etc.
+ * @param idlingTime
+ */
+ public void notifyIdle(long idlingTime);
+
+}
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/core/index/IIndexStorage.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/core/index/IIndexStorage.java
new file mode 100644
index 0000000000..180081fa35
--- /dev/null
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/core/index/IIndexStorage.java
@@ -0,0 +1,30 @@
+/**********************************************************************
+ * Copyright (c) 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.cdt.core.index;
+
+/**
+ * @author Bogdan Gheorghe
+ *
+ * IIndexStorage must be implemented by all indexStorage providers
+ */
+public interface IIndexStorage {
+
+ //Indexer that use this indexer storage
+ public ICDTIndexer[] getIndexers();
+
+ //Get path variables that are used
+ public String[] getPathVariables();
+ public void resolvePathVariables();
+
+ //Merge functionality for the storage
+ public void merge();
+ public boolean canMergeWith(IIndexStorage storage);
+}
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/core/index/Indexer.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/core/index/Indexer.java
index 51200f167d..ea0c6165f1 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/core/index/Indexer.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/core/index/Indexer.java
@@ -19,7 +19,6 @@ package org.eclipse.cdt.core.index;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
/**
* @author bgheorgh
@@ -63,7 +62,8 @@ public class Indexer {
public static boolean indexEnabledOnProject(IProject project){
boolean allEnabled = true;
- try {
+ //TODO: BOG make this generic
+ /*try {
Boolean indexValue = (Boolean) project.getSessionProperty(IndexManager.activationKey);
if (indexValue != null){
if(!indexValue.booleanValue()){
@@ -76,7 +76,7 @@ public class Indexer {
}
}
- } catch (CoreException e) {}
+ } catch (CoreException e) {}*/
return allEnabled;
}
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/IIndexer.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/IIndexer.java
index efb318497c..2c7f2c6e8f 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/IIndexer.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/IIndexer.java
@@ -26,11 +26,7 @@ public interface IIndexer {
*/
void index(IDocument document, IIndexerOutput output) throws java.io.IOException;
- /**
- * Sets the document types the <code>IIndexer</code> handles.
- */
- public void setFileTypes(String[] fileTypes);
/**
* Returns whether the <code>IIndexer</code> can index the given IFile or not.
*/
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/Index.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/Index.java
index 69841fbb7c..e2f369a25f 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/Index.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/Index.java
@@ -18,12 +18,14 @@ import java.util.List;
import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.index.ICDTIndexer;
import org.eclipse.cdt.core.index.IIndexDelta;
import org.eclipse.cdt.internal.core.index.IDocument;
import org.eclipse.cdt.internal.core.index.IEntryResult;
import org.eclipse.cdt.internal.core.index.IIndex;
import org.eclipse.cdt.internal.core.index.IIndexer;
import org.eclipse.cdt.internal.core.index.IQueryResult;
+import org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IPath;
@@ -66,32 +68,21 @@ public class Index implements IIndex {
protected static final int CAN_MERGE= 0;
protected static final int MERGED= 1;
private File indexFile;
+
+ private ICDTIndexer indexer = null;
+
/**
* String representation of this index.
*/
public String toString;
- public Index(File indexDirectory, boolean reuseExistingFile) throws IOException {
- this(indexDirectory,".index", reuseExistingFile); //$NON-NLS-1$
- }
-
- public Index(File indexDirectory, String indexName, boolean reuseExistingFile) throws IOException {
- super();
- state= MERGED;
- indexFile= new File(indexDirectory, indexName);
- initialize(reuseExistingFile);
- }
-
- public Index(String indexName, boolean reuseExistingFile) throws IOException {
- this(indexName, null, reuseExistingFile);
- }
-
- public Index(String indexName, String toString, boolean reuseExistingFile) throws IOException {
+ public Index(String indexName, String toString, boolean reuseExistingFile, ICDTIndexer indexer) throws IOException {
super();
state= MERGED;
indexFile= new File(indexName);
this.toString = toString;
+ this.indexer = indexer;
initialize(reuseExistingFile);
}
/**
@@ -278,8 +269,10 @@ public class Index implements IIndex {
CCorePlugin.getDefault().cdtLog.flushLog();
//Send out notification to listeners;
- IndexDelta indexDelta = new IndexDelta(null,null,IIndexDelta.MERGE_DELTA);
- CCorePlugin.getDefault().getCoreModel().getIndexManager().notifyListeners(indexDelta);
+ if (indexer instanceof SourceIndexer){
+ IndexDelta indexDelta = new IndexDelta(null,null,IIndexDelta.MERGE_DELTA);
+ ((SourceIndexer) indexer).notifyListeners(indexDelta);
+ }
}
}
/**
@@ -443,6 +436,11 @@ public class Index implements IIndex {
str += "(length: "+ getIndexFile().length() +")"; //$NON-NLS-1$ //$NON-NLS-2$
return str;
}
+
+ public org.eclipse.cdt.core.index.ICDTIndexer getIndexer(){
+ return (org.eclipse.cdt.core.index.ICDTIndexer) indexer;
+ }
+
}
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AbstractIndexer.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/AbstractIndexer.java
index 8c0d2739bc..488073f9d7 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AbstractIndexer.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/AbstractIndexer.java
@@ -9,7 +9,7 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.cdt.internal.core.search.indexing;
+package org.eclipse.cdt.internal.core.index.sourceindexer;
import java.io.IOException;
import java.util.Iterator;
@@ -38,9 +38,10 @@ import org.eclipse.cdt.internal.core.CharOperation;
import org.eclipse.cdt.internal.core.index.IDocument;
import org.eclipse.cdt.internal.core.index.IIndexer;
import org.eclipse.cdt.internal.core.index.IIndexerOutput;
+import org.eclipse.cdt.internal.core.search.indexing.IIndexConstants;
import org.eclipse.core.resources.IFile;
-public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSearchConstants {
+public abstract class AbstractIndexer implements IIndexer,IIndexConstants, ICSearchConstants {
IIndexerOutput output;
final static int CLASS = 1;
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AddCompilationUnitToIndex.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/AddCompilationUnitToIndex.java
index 49121a3b9b..f80ffcbb12 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AddCompilationUnitToIndex.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/AddCompilationUnitToIndex.java
@@ -9,7 +9,7 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.cdt.internal.core.search.indexing;
+package org.eclipse.cdt.internal.core.index.sourceindexer;
import java.io.IOException;
@@ -21,12 +21,13 @@ import org.eclipse.core.runtime.IPath;
public class AddCompilationUnitToIndex extends AddFileToIndex {
char[] contents;
- public AddCompilationUnitToIndex(IFile resource, IPath indexedContainer, IndexManager manager, boolean checkEncounteredHeaders) {
- super(resource, indexedContainer, manager, checkEncounteredHeaders);
+ public AddCompilationUnitToIndex(IFile resource, IPath indexedContainer, SourceIndexer indexer, boolean checkEncounteredHeaders) {
+ super(resource, indexedContainer, indexer, checkEncounteredHeaders);
}
protected boolean indexDocument(IIndex index) throws IOException {
if (!initializeContents()) return false;
- index.add(new IFileDocument(resource, this.contents), new SourceIndexer(resource, manager.getTimeout()));
+ index.add(new IFileDocument(resource, this.contents), new SourceIndexerRunner(resource, indexer));
+
return true;
}
public boolean initializeContents() {
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AddFileToIndex.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/AddFileToIndex.java
index 762d43915d..d1913da377 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AddFileToIndex.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/AddFileToIndex.java
@@ -8,7 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.cdt.internal.core.search.indexing;
+package org.eclipse.cdt.internal.core.index.sourceindexer;
import java.io.IOException;
@@ -16,9 +16,12 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICLogConstants;
import org.eclipse.cdt.core.filetype.ICFileType;
import org.eclipse.cdt.internal.core.index.IIndex;
+import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
+import org.eclipse.cdt.internal.core.search.indexing.ReadWriteMonitor;
import org.eclipse.cdt.internal.core.search.processing.JobManager;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -26,19 +29,19 @@ public abstract class AddFileToIndex extends IndexRequest {
IFile resource;
private boolean checkEncounteredHeaders;
- public AddFileToIndex(IFile resource, IPath indexPath, IndexManager manager, boolean checkEncounteredHeaders) {
- super(indexPath, manager);
+ public AddFileToIndex(IFile resource, IPath indexPath, SourceIndexer indexer, boolean checkEncounteredHeaders) {
+ super(indexPath, indexer);
this.resource = resource;
this.checkEncounteredHeaders = checkEncounteredHeaders;
}
- public AddFileToIndex(IFile resource, IPath indexPath, IndexManager manager) {
- this(resource,indexPath,manager,false);
+ public AddFileToIndex(IFile resource, IPath indexPath, SourceIndexer indexer) {
+ this(resource,indexPath,indexer,false);
}
public boolean execute(IProgressMonitor progressMonitor) {
if (progressMonitor != null && progressMonitor.isCanceled()) return true;
-
+
if (checkEncounteredHeaders) {
IProject resourceProject = resource.getProject();
/* Check to see if this is a header file */
@@ -46,13 +49,13 @@ public abstract class AddFileToIndex extends IndexRequest {
/* See if this file has been encountered before */
if (type.isHeader() &&
- manager.haveEncounteredHeader(resourceProject.getFullPath(),resource.getLocation()))
+ indexer.haveEncounteredHeader(resourceProject.getFullPath(),resource.getLocation()))
return true;
}
/* ensure no concurrent write access to index */
- IIndex index = manager.getIndex(this.indexPath, true, /*reuse index file*/ true /*create if none*/);
+ IIndex index = indexer.getIndex(this.indexPath, true, /*reuse index file*/ true /*create if none*/);
if (index == null) return true;
- ReadWriteMonitor monitor = manager.getMonitorFor(index);
+ ReadWriteMonitor monitor = indexer.getMonitorFor(index);
if (monitor == null) return true; // index got deleted since acquired
try {
monitor.enterWrite(); // ask permission to write
@@ -75,4 +78,12 @@ public abstract class AddFileToIndex extends IndexRequest {
public String toString() {
return "indexing " + this.resource.getFullPath(); //$NON-NLS-1$
}
+
+ /**
+ * The resource being indexed
+ * @return
+ */
+ public IResource getResource(){
+ return resource;
+ }
}
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AddFolderToIndex.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/AddFolderToIndex.java
index 211ab828fe..158c51d615 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AddFolderToIndex.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/AddFolderToIndex.java
@@ -9,7 +9,7 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.cdt.internal.core.search.indexing;
+package org.eclipse.cdt.internal.core.index.sourceindexer;
import java.util.ArrayList;
@@ -18,6 +18,8 @@ import org.eclipse.cdt.core.filetype.ICFileType;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.index.IIndex;
+import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
+import org.eclipse.cdt.internal.core.search.indexing.ReadWriteMonitor;
import org.eclipse.cdt.internal.core.search.processing.JobManager;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@@ -28,7 +30,7 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
-class AddFolderToIndex extends IndexRequest {
+public class AddFolderToIndex extends IndexRequest {
IPath folderPath;
IProject project;
char[][] exclusionPattern;
@@ -36,8 +38,8 @@ class AddFolderToIndex extends IndexRequest {
ArrayList headerFilesToIndex;
boolean cleanEncouteredHeaders;
- public AddFolderToIndex(IPath folderPath, IProject project, char[][] exclusionPattern, IndexManager manager) {
- super(project.getFullPath(), manager);
+ public AddFolderToIndex(IPath folderPath, IProject project, char[][] exclusionPattern, SourceIndexer indexer) {
+ super(project.getFullPath(), indexer);
this.folderPath = folderPath;
this.project = project;
this.exclusionPattern = exclusionPattern;
@@ -46,8 +48,8 @@ class AddFolderToIndex extends IndexRequest {
this.cleanEncouteredHeaders = false;
}
- public AddFolderToIndex(IPath folderPath, IProject project, char[][] exclusionPattern, IndexManager manager, boolean cleanEncounteredHeaders) {
- super(project.getFullPath(), manager);
+ public AddFolderToIndex(IPath folderPath, IProject project, char[][] exclusionPattern, SourceIndexer indexer, boolean cleanEncounteredHeaders) {
+ super(project.getFullPath(), indexer);
this.folderPath = folderPath;
this.project = project;
this.exclusionPattern = exclusionPattern;
@@ -58,21 +60,22 @@ class AddFolderToIndex extends IndexRequest {
public boolean execute(IProgressMonitor progressMonitor) {
if (progressMonitor != null && progressMonitor.isCanceled()) return true;
+
if (!project.isAccessible()) return true; // nothing to do
IResource folder = this.project.getParent().findMember(this.folderPath);
if (folder == null || folder.getType() == IResource.FILE) return true; // nothing to do, source folder was removed
- /* ensure no concurrent write access to index */
- IIndex index = manager.getIndex(this.indexPath, true, /*reuse index file*/ true /*create if none*/);
+ /* ensure no concurrent write access to index */
+ IIndex index = indexer.getIndex(this.indexPath, true, /*reuse index file*/ true /*create if none*/);
if (index == null) return true;
- ReadWriteMonitor monitor = manager.getMonitorFor(index);
+ ReadWriteMonitor monitor = indexer.getMonitorFor(index);
if (monitor == null) return true; // index got deleted since acquired
try {
monitor.enterRead(); // ask permission to read
final IPath container = this.indexPath;
- final IndexManager indexManager = this.manager;
+ //final IndexManager indexManager = this.manager;
final char[][] pattern = exclusionPattern;
folder.accept(
new IResourceProxyVisitor() {
@@ -114,14 +117,14 @@ class AddFolderToIndex extends IndexRequest {
private void scheduleJobs() {
//Schedule the source jobs first, then the headers
for (int i=0; i<sourceFilesToIndex.size(); i++)
- this.manager.addSource((IFile)sourceFilesToIndex.get(i), this.indexPath, false);
+ this.indexer.addSource((IFile)sourceFilesToIndex.get(i), this.indexPath, false);
for (int i=0;i<headerFilesToIndex.size(); i++)
- this.manager.addSource((IFile)headerFilesToIndex.get(i), this.indexPath, true);
+ this.indexer.addSource((IFile)headerFilesToIndex.get(i), this.indexPath, true);
if (cleanEncouteredHeaders){
- CleanEncounteredHeaders cleanHeaders = new CleanEncounteredHeaders(this.manager);
- this.manager.request(cleanHeaders);
+ CleanEncounteredHeaders cleanHeaders = new CleanEncounteredHeaders(this.indexer);
+ this.indexer.request(cleanHeaders);
}
}
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/CIndexStorage.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/CIndexStorage.java
new file mode 100644
index 0000000000..0b7cf85441
--- /dev/null
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/CIndexStorage.java
@@ -0,0 +1,544 @@
+/**********************************************************************
+ * Copyright (c) 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.cdt.internal.core.index.sourceindexer;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.zip.CRC32;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.index.ICDTIndexer;
+import org.eclipse.cdt.core.index.IIndexStorage;
+import org.eclipse.cdt.internal.core.CharOperation;
+import org.eclipse.cdt.internal.core.index.IIndex;
+import org.eclipse.cdt.internal.core.index.impl.Index;
+import org.eclipse.cdt.internal.core.search.CWorkspaceScope;
+import org.eclipse.cdt.internal.core.search.IndexSelector;
+import org.eclipse.cdt.internal.core.search.SimpleLookupTable;
+import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
+import org.eclipse.cdt.internal.core.search.indexing.ReadWriteMonitor;
+import org.eclipse.cdt.internal.core.search.processing.IIndexJob;
+import org.eclipse.cdt.internal.core.search.processing.JobManager;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+
+/**
+ * @author Bogdan Gheorghe
+ */
+public class CIndexStorage implements IIndexStorage {
+
+ /* number of file contents in memory */
+ public static int MAX_FILES_IN_MEMORY = 0;
+
+ public IWorkspace workspace;
+ public SimpleLookupTable indexNames = new SimpleLookupTable();
+ private Map indexes = new HashMap(5);
+
+ /* read write monitors */
+ private Map monitors = new HashMap(5);
+
+ /* need to save ? */
+ private boolean needToSave = false;
+ private static final CRC32 checksumCalculator = new CRC32();
+ private IPath cCorePluginLocation = null;
+
+ /* can only replace a current state if its less than the new one */
+ private SimpleLookupTable indexStates = null;
+ private File savedIndexNamesFile =
+ new File(getCCorePluginWorkingLocation().append("savedIndexNames.txt").toOSString()); //$NON-NLS-1$
+
+ private SimpleLookupTable encounteredHeaders = null;
+
+ public static Integer SAVED_STATE = new Integer(0);
+ public static Integer UPDATING_STATE = new Integer(1);
+ public static Integer UNKNOWN_STATE = new Integer(2);
+ public static Integer REBUILDING_STATE = new Integer(3);
+
+ public static boolean VERBOSE = false;
+
+ private SourceIndexer indexer = null;
+ private IndexManager indexManager = null;
+
+ public ReadWriteMonitor indexAccessMonitor = null;
+
+ public CIndexStorage(ICDTIndexer indexer){
+ if (indexer instanceof SourceIndexer)
+ this.indexer = (SourceIndexer) indexer;
+
+ this.indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager();
+ }
+
+ public synchronized void aboutToUpdateIndex(IPath path, Integer newIndexState) {
+ // newIndexState is either UPDATING_STATE or REBUILDING_STATE
+ // must tag the index as inconsistent, in case we exit before the update job is started
+ String indexName = computeIndexName(path);
+ Object state = getIndexStates().get(indexName);
+ Integer currentIndexState = state == null ? UNKNOWN_STATE : (Integer) state;
+ if (currentIndexState.equals(REBUILDING_STATE)) return; // already rebuilding the index
+
+ int compare = newIndexState.compareTo(currentIndexState);
+ if (compare > 0) {
+ // so UPDATING_STATE replaces SAVED_STATE and REBUILDING_STATE replaces everything
+ updateIndexState(indexName, newIndexState);
+ } else if (compare < 0 && this.indexes.get(path) == null) {
+ // if already cached index then there is nothing more to do
+ rebuildIndex(indexName, path);
+ }
+ }
+
+ String computeIndexName(IPath path) {
+ String name = (String) indexNames.get(path);
+ if (name == null) {
+ String pathString = path.toOSString();
+ checksumCalculator.reset();
+ checksumCalculator.update(pathString.getBytes());
+ String fileName = Long.toString(checksumCalculator.getValue()) + ".index"; //$NON-NLS-1$
+ if (IndexManager.VERBOSE)
+ JobManager.verbose("-> index name for " + pathString + " is " + fileName); //$NON-NLS-1$ //$NON-NLS-2$
+ name = getCCorePluginWorkingLocation().append(fileName).toOSString();
+ indexNames.put(path, name);
+ }
+ return name;
+ }
+
+
+ /**
+ * Returns the index for a given project, according to the following algorithm:
+ * - if index is already in memory: answers this one back
+ * - if (reuseExistingFile) then read it and return this index and record it in memory
+ * - if (createIfMissing) then create a new empty index and record it in memory
+ *
+ * Warning: Does not check whether index is consistent (not being used)
+ */
+ public synchronized IIndex getIndex(IPath path, boolean reuseExistingFile, boolean createIfMissing) {
+ // Path is already canonical per construction
+ IIndex index = (IIndex) indexes.get(path);
+ if (index == null) {
+ String indexName = computeIndexName(path);
+ Object state = getIndexStates().get(indexName);
+ Integer currentIndexState = state == null ? UNKNOWN_STATE : (Integer) state;
+ if (currentIndexState == UNKNOWN_STATE) {
+ // should only be reachable for query jobs
+ // IF you put an index in the cache, then AddJarFileToIndex fails because it thinks there is nothing to do
+ rebuildIndex(indexName, path);
+ return null;
+ }
+
+ // index isn't cached, consider reusing an existing index file
+ if (reuseExistingFile) {
+ File indexFile = new File(indexName);
+ if (indexFile.exists()) { // check before creating index so as to avoid creating a new empty index if file is missing
+ try {
+ index = new Index(indexName, "Index for " + path.toOSString(), true /*reuse index file*/, indexer); //$NON-NLS-1$
+ indexes.put(path, index);
+ monitors.put(index, new ReadWriteMonitor());
+ return index;
+ } catch (IOException e) {
+ // failed to read the existing file or its no longer compatible
+ if (currentIndexState != REBUILDING_STATE) { // rebuild index if existing file is corrupt, unless the index is already being rebuilt
+ if (IndexManager.VERBOSE)
+ JobManager.verbose("-> cannot reuse existing index: "+indexName+" path: "+path.toOSString()); //$NON-NLS-1$ //$NON-NLS-2$
+ rebuildIndex(indexName, path);
+ return null;
+ }
+ index = null; // will fall thru to createIfMissing & create a empty index for the rebuild all job to populate
+ }
+ }
+ if (currentIndexState == SAVED_STATE) { // rebuild index if existing file is missing
+ rebuildIndex(indexName, path);
+ return null;
+ }
+ }
+ // index wasn't found on disk, consider creating an empty new one
+ if (createIfMissing) {
+ try {
+ if (VERBOSE)
+ JobManager.verbose("-> create empty index: "+indexName+" path: "+path.toOSString()); //$NON-NLS-1$ //$NON-NLS-2$
+ index = new Index(indexName, "Index for " + path.toOSString(), false /*do not reuse index file*/, indexer); //$NON-NLS-1$
+ indexes.put(path, index);
+ monitors.put(index, new ReadWriteMonitor());
+ return index;
+ } catch (IOException e) {
+ if (VERBOSE)
+ JobManager.verbose("-> unable to create empty index: "+indexName+" path: "+path.toOSString()); //$NON-NLS-1$ //$NON-NLS-2$
+ // The file could not be created. Possible reason: the project has been deleted.
+ return null;
+ }
+ }
+ }
+ //System.out.println(" index name: " + path.toOSString() + " <----> " + index.getIndexFile().getName());
+ return index;
+ }
+
+ private SimpleLookupTable getIndexStates() {
+ if (indexStates != null) return indexStates;
+
+ this.indexStates = new SimpleLookupTable();
+ char[] savedIndexNames = readIndexState();
+ if (savedIndexNames.length > 0) {
+ char[][] names = CharOperation.splitOn('\n', savedIndexNames);
+ for (int i = 0, l = names.length; i < l; i++) {
+ char[] name = names[i];
+ if (name.length > 0)
+ this.indexStates.put(new String(name), SAVED_STATE);
+ }
+ }
+ return this.indexStates;
+ }
+
+ public SimpleLookupTable getEncounteredHeaders(){
+
+ if (encounteredHeaders == null){
+ this.encounteredHeaders = new SimpleLookupTable();
+ }
+
+
+ return this.encounteredHeaders;
+ }
+
+ /**
+ * Resets the headers table
+ */
+ public void resetEncounteredHeaders() {
+ this.encounteredHeaders = null;
+ }
+
+ private IPath getCCorePluginWorkingLocation() {
+ if (this.cCorePluginLocation != null) return this.cCorePluginLocation;
+
+ return this.cCorePluginLocation = CCorePlugin.getDefault().getStateLocation();
+ }
+ /**
+ * Index access is controlled through a read-write monitor so as
+ * to ensure there is no concurrent read and write operations
+ * (only concurrent reading is allowed).
+ */
+ public ReadWriteMonitor getMonitorFor(IIndex index){
+ return (ReadWriteMonitor) monitors.get(index);
+ }
+ private void rebuildIndex(String indexName, IPath path) {
+ Object target = org.eclipse.cdt.internal.core.Util.getTarget(ResourcesPlugin.getWorkspace().getRoot(), path, true);
+ if (target == null) return;
+
+ if (IndexManager.VERBOSE)
+ JobManager.verbose("-> request to rebuild index: "+indexName+" path: "+path.toOSString()); //$NON-NLS-1$ //$NON-NLS-2$
+
+ updateIndexState(indexName, REBUILDING_STATE);
+ IndexRequest request = null;
+ if (target instanceof IProject) {
+ IProject p = (IProject) target;
+ if( p.exists() && indexer.isIndexEnabled( p ) )
+ request = new IndexAllProject(p, indexer);
+ }
+
+ if (request != null)
+ indexManager.request(request);
+ }
+
+ /**
+ * Recreates the index for a given path, keeping the same read-write monitor.
+ * Returns the new empty index or null if it didn't exist before.
+ * Warning: Does not check whether index is consistent (not being used)
+ */
+ public synchronized IIndex recreateIndex(IPath path) {
+ // only called to over write an existing cached index...
+ try {
+ IIndex index = (IIndex) this.indexes.get(path);
+ ReadWriteMonitor monitor = (ReadWriteMonitor) this.monitors.remove(index);
+
+ // Path is already canonical
+ String indexPath = computeIndexName(path);
+ if (IndexManager.VERBOSE)
+ JobManager.verbose("-> recreating index: "+indexPath+" for path: "+path.toOSString()); //$NON-NLS-1$ //$NON-NLS-2$
+ index = new Index(indexPath, "Index for " + path.toOSString(), false /*reuse index file*/,indexer); //$NON-NLS-1$
+ indexes.put(path, index);
+ monitors.put(index, monitor);
+ return index;
+ } catch (IOException e) {
+ // The file could not be created. Possible reason: the project has been deleted.
+ if (IndexManager.VERBOSE) {
+ JobManager.verbose("-> failed to recreate index for path: "+path.toOSString()); //$NON-NLS-1$ //$NON-NLS-2$
+ e.printStackTrace();
+ }
+ return null;
+ }
+ }
+
+ /**
+ * Removes the index for a given path.
+ * This is a no-op if the index did not exist.
+ */
+ public synchronized void removeIndex(IPath path) {
+ if (IndexManager.VERBOSE)
+ JobManager.verbose("removing index " + path); //$NON-NLS-1$
+ String indexName = computeIndexName(path);
+ File indexFile = new File(indexName);
+ if (indexFile.exists())
+ indexFile.delete();
+ Object o = this.indexes.get(path);
+ if (o instanceof IIndex)
+ this.monitors.remove(o);
+ this.indexes.remove(path);
+ updateIndexState(indexName, null);
+ }
+
+ /**
+ * Removes all indexes whose paths start with (or are equal to) the given path.
+ */
+ public synchronized void removeIndexFamily(IPath path) {
+ // only finds cached index files... shutdown removes all non-cached index files
+ ArrayList toRemove = null;
+ Iterator iterator = this.indexes.keySet().iterator();
+ while (iterator.hasNext()) {
+ IPath indexPath = (IPath) iterator.next();
+ if (path.isPrefixOf(indexPath)) {
+ if (toRemove == null)
+ toRemove = new ArrayList();
+ toRemove.add(indexPath);
+ }
+ }
+ if (toRemove != null)
+ for (int i = 0, length = toRemove.size(); i < length; i++)
+ this.removeIndex((IPath) toRemove.get(i));
+ }
+
+ public void saveIndex(IIndex index) throws IOException {
+ // must have permission to write from the write monitor
+ if (index.hasChanged()) {
+ if (IndexManager.VERBOSE)
+ JobManager.verbose("-> saving index " + index.getIndexFile()); //$NON-NLS-1$
+ index.save();
+ }
+ String indexName = index.getIndexFile().getPath();
+ if (indexManager.getJobEnd() > indexManager.getJobStart()) {
+ Object indexPath = indexNames.keyForValue(indexName);
+ if (indexPath != null) {
+ for (int i = indexManager.getJobEnd(); i > indexManager.getJobStart(); i--) { // skip the current job
+ IIndexJob job = indexManager.getAwaitingJobAt(i);
+ if (job instanceof IndexRequest)
+ if (((IndexRequest) job).indexPath.equals(indexPath)) return;
+ }
+ }
+ }
+ updateIndexState(indexName, SAVED_STATE);
+ }
+
+ /**
+ * Commit all index memory changes to disk
+ */
+ public void saveIndexes() {
+ // only save cached indexes... the rest were not modified
+ ArrayList toSave = new ArrayList();
+ synchronized(this) {
+ for (Iterator iter = this.indexes.values().iterator(); iter.hasNext();) {
+ Object o = iter.next();
+ if (o instanceof IIndex)
+ toSave.add(o);
+ }
+ }
+
+ for (int i = 0, length = toSave.size(); i < length; i++) {
+ IIndex index = (IIndex) toSave.get(i);
+ ReadWriteMonitor monitor = getMonitorFor(index);
+ if (monitor == null) continue; // index got deleted since acquired
+ try {
+ monitor.enterWrite();
+ try {
+ saveIndex(index);
+ } catch(IOException e){
+ if (IndexManager.VERBOSE) {
+ JobManager.verbose("-> got the following exception while saving:"); //$NON-NLS-1$
+ e.printStackTrace();
+ }
+ //Util.log(e);
+ }
+ } finally {
+ monitor.exitWrite();
+ }
+ }
+ needToSave = false;
+ }
+
+
+ public void shutdown() {
+ if (IndexManager.VERBOSE)
+ JobManager.verbose("Shutdown"); //$NON-NLS-1$
+ //Get index entries for all projects in the workspace, store their absolute paths
+ IndexSelector indexSelector = new IndexSelector(new CWorkspaceScope(), null, false, indexManager);
+ IIndex[] selectedIndexes = indexSelector.getIndexes();
+ SimpleLookupTable knownPaths = new SimpleLookupTable();
+ for (int i = 0, max = selectedIndexes.length; i < max; i++) {
+ String path = selectedIndexes[i].getIndexFile().getAbsolutePath();
+ knownPaths.put(path, path);
+ }
+ //Any index entries that are in the index state must have a corresponding
+ //path entry - if not they are removed from the saved indexes file
+ if (indexStates != null) {
+ Object[] indexNames = indexStates.keyTable;
+ for (int i = 0, l = indexNames.length; i < l; i++) {
+ String key = (String) indexNames[i];
+ if (key != null && !knownPaths.containsKey(key)) //here is an index that is in t
+ updateIndexState(key, null);
+ }
+ }
+
+ //Clean up the .metadata folder - if there are any files in the directory that
+ //are not associated to an index we delete them
+ File indexesDirectory = new File(getCCorePluginWorkingLocation().toOSString());
+ if (indexesDirectory.isDirectory()) {
+ File[] indexesFiles = indexesDirectory.listFiles();
+ if (indexesFiles != null) {
+ for (int i = 0, indexesFilesLength = indexesFiles.length; i < indexesFilesLength; i++) {
+ String fileName = indexesFiles[i].getAbsolutePath();
+ if (!knownPaths.containsKey(fileName) && fileName.toLowerCase().endsWith(".index")) { //$NON-NLS-1$
+ if (IndexManager.VERBOSE)
+ JobManager.verbose("Deleting index file " + indexesFiles[i]); //$NON-NLS-1$
+ indexesFiles[i].delete();
+ }
+ }
+ }
+ }
+
+
+ }
+
+
+
+ public String toString() {
+ StringBuffer buffer = new StringBuffer(10);
+ buffer.append(super.toString());
+ buffer.append("In-memory indexes:\n"); //$NON-NLS-1$
+ int count = 0;
+ for (Iterator iter = this.indexes.values().iterator(); iter.hasNext();) {
+ buffer.append(++count).append(" - ").append(iter.next().toString()).append('\n'); //$NON-NLS-1$
+ }
+ return buffer.toString();
+ }
+
+ private char[] readIndexState() {
+ try {
+ return org.eclipse.cdt.internal.core.Util.getFileCharContent(savedIndexNamesFile, null);
+ } catch (IOException ignored) {
+ if (IndexManager.VERBOSE)
+ JobManager.verbose("Failed to read saved index file names"); //$NON-NLS-1$
+ return new char[0];
+ }
+ }
+
+ private void updateIndexState(String indexName, Integer indexState) {
+ getIndexStates(); // ensure the states are initialized
+ if (indexState != null) {
+ if (indexState.equals(indexStates.get(indexName))) return; // not changed
+ indexStates.put(indexName, indexState);
+ } else {
+ if (!indexStates.containsKey(indexName)) return; // did not exist anyway
+ indexStates.removeKey(indexName);
+ }
+
+ BufferedWriter writer = null;
+ try {
+ writer = new BufferedWriter(new FileWriter(savedIndexNamesFile));
+ Object[] indexNames = indexStates.keyTable;
+ Object[] states = indexStates.valueTable;
+ for (int i = 0, l = states.length; i < l; i++) {
+ if (states[i] == SAVED_STATE) {
+ writer.write((String) indexNames[i]);
+ writer.write('\n');
+ }
+ }
+ } catch (IOException ignored) {
+ if (IndexManager.VERBOSE)
+ JobManager.verbose("Failed to write saved index file names"); //$NON-NLS-1$
+ } finally {
+ if (writer != null) {
+ try {
+ writer.close();
+ } catch (IOException e) {}
+ }
+ }
+ if (IndexManager.VERBOSE) {
+ String state = "?"; //$NON-NLS-1$
+ if (indexState == SAVED_STATE) state = "SAVED"; //$NON-NLS-1$
+ else if (indexState == UPDATING_STATE) state = "UPDATING"; //$NON-NLS-1$
+ else if (indexState == UNKNOWN_STATE) state = "UNKNOWN"; //$NON-NLS-1$
+ else if (indexState == REBUILDING_STATE) state = "REBUILDING"; //$NON-NLS-1$
+ JobManager.verbose("-> index state updated to: " + state + " for: "+indexName); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.index2.IIndexStorage#getIndexers()
+ */
+ public ICDTIndexer[] getIndexers() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.index2.IIndexStorage#getPathVariables()
+ */
+ public String[] getPathVariables() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.index2.IIndexStorage#resolvePathVariables()
+ */
+ public void resolvePathVariables() {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.index2.IIndexStorage#merge()
+ */
+ public void merge() {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.index2.IIndexStorage#canMergeWith(org.eclipse.cdt.core.index2.IIndexStorage)
+ */
+ public boolean canMergeWith(IIndexStorage storage) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+
+ public boolean getNeedToSave() {
+ return needToSave;
+ }
+ public void setNeedToSave(boolean needToSave) {
+ this.needToSave = needToSave;
+ }
+
+ public void jobWasCancelled(IPath path) {
+ Object o = this.indexes.get(path);
+ if (o instanceof IIndex) {
+ this.monitors.remove(o);
+ this.indexes.remove(path);
+ }
+ updateIndexState(computeIndexName(path), UNKNOWN_STATE);
+ }
+ public ReadWriteMonitor getIndexAccessMonitor() {
+ return indexAccessMonitor;
+ }
+}
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/CleanEncounteredHeaders.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/CleanEncounteredHeaders.java
index ee2b67d0a7..f6eab19626 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/CleanEncounteredHeaders.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/CleanEncounteredHeaders.java
@@ -4,9 +4,9 @@
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
-package org.eclipse.cdt.internal.core.search.indexing;
+package org.eclipse.cdt.internal.core.index.sourceindexer;
-import org.eclipse.cdt.internal.core.search.processing.IJob;
+import org.eclipse.cdt.internal.core.search.processing.IIndexJob;
import org.eclipse.core.runtime.IProgressMonitor;
/**
@@ -15,20 +15,18 @@ import org.eclipse.core.runtime.IProgressMonitor;
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
-public class CleanEncounteredHeaders implements IJob {
+public class CleanEncounteredHeaders implements IIndexJob {
- IndexManager manager = null;
+ SourceIndexer indexer = null;
- public CleanEncounteredHeaders(IndexManager manager){
- this.manager = manager;
+ public CleanEncounteredHeaders(SourceIndexer indexer){
+ this.indexer = indexer;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.search.processing.IJob#execute(org.eclipse.core.runtime.IProgressMonitor)
*/
public boolean execute(IProgressMonitor progress) {
-
- //Clean out the headers
- this.manager.resetEncounteredHeaders();
+ indexer.resetEncounteredHeaders();
return true;
}
/* (non-Javadoc)
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexAllProject.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/IndexAllProject.java
index 921978526f..d51415a3c1 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexAllProject.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/IndexAllProject.java
@@ -9,7 +9,7 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.cdt.internal.core.search.indexing;
+package org.eclipse.cdt.internal.core.index.sourceindexer;
import java.io.IOException;
@@ -22,6 +22,8 @@ import org.eclipse.cdt.internal.core.model.CModel;
import org.eclipse.cdt.internal.core.model.CModelManager;
import org.eclipse.cdt.internal.core.model.SourceRoot;
import org.eclipse.cdt.internal.core.search.SimpleLookupTable;
+import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
+import org.eclipse.cdt.internal.core.search.indexing.ReadWriteMonitor;
import org.eclipse.cdt.internal.core.search.processing.JobManager;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
@@ -31,8 +33,8 @@ import org.eclipse.core.runtime.IProgressMonitor;
public class IndexAllProject extends IndexRequest {
IProject project;
- public IndexAllProject(IProject project, IndexManager manager) {
- super(project.getFullPath(), manager);
+ public IndexAllProject(IProject project, SourceIndexer indexer) {
+ super(project.getFullPath(), indexer);
this.project = project;
}
@@ -50,10 +52,12 @@ public class IndexAllProject extends IndexRequest {
if (progressMonitor != null && progressMonitor.isCanceled()) return true;
if (!project.isAccessible()) return true; // nothing to do
-
- IIndex index = this.manager.getIndex(this.indexPath, true, /*reuse index file*/ true /*create if none*/);
+
+ String test = this.indexPath.toOSString();
+
+ IIndex index = indexer.getIndex(this.indexPath, true, /*reuse index file*/ true /*create if none*/);
if (index == null) return true;
- ReadWriteMonitor monitor = this.manager.getMonitorFor(index);
+ ReadWriteMonitor monitor = indexer.getMonitorFor(index);
if (monitor == null) return true; // index got deleted since acquired
try {
@@ -84,27 +88,27 @@ public class IndexAllProject extends IndexRequest {
ISourceEntry tempEntry = ((SourceRoot) sourceRoot[i]).getSourceEntry();
if ((i+1) != sourceRoot.length)
- this.manager.request(new AddFolderToIndex(sourceRoot[i].getPath(), project, tempEntry.fullExclusionPatternChars(), this.manager));
+ indexer.request(new AddFolderToIndex(sourceRoot[i].getPath(), project, tempEntry.fullExclusionPatternChars(), indexer));
else
- this.manager.request(new AddFolderToIndex(sourceRoot[i].getPath(), project, tempEntry.fullExclusionPatternChars(), this.manager,true));
+ indexer.request(new AddFolderToIndex(sourceRoot[i].getPath(), project, tempEntry.fullExclusionPatternChars(),indexer,true));
}
}
// request to save index when all cus have been indexed
- this.manager.request(new SaveIndex(this.indexPath, this.manager));
+ indexer.request(new SaveIndex(this.indexPath, indexer));
} catch (CoreException e) {
if (IndexManager.VERBOSE) {
JobManager.verbose("-> failed to index " + this.project + " because of the following exception:"); //$NON-NLS-1$ //$NON-NLS-2$
e.printStackTrace();
}
- this.manager.removeIndex(this.indexPath);
+ indexer.removeIndex(this.indexPath);
return false;
} catch (IOException e) {
if (IndexManager.VERBOSE) {
JobManager.verbose("-> failed to index " + this.project + " because of the following exception:"); //$NON-NLS-1$ //$NON-NLS-2$
e.printStackTrace();
}
- this.manager.removeIndex(this.indexPath);
+ indexer.removeIndex(this.indexPath);
return false;
} finally {
monitor.exitRead(); // free read lock
@@ -117,7 +121,7 @@ public class IndexAllProject extends IndexRequest {
}
protected Integer updatedIndexState() {
- return IndexManager.REBUILDING_STATE;
+ return CIndexStorage.REBUILDING_STATE;
}
public String toString() {
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexRequest.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/IndexRequest.java
index 2345b771ca..bd23e6e560 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexRequest.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/IndexRequest.java
@@ -9,24 +9,25 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.cdt.internal.core.search.indexing;
+package org.eclipse.cdt.internal.core.index.sourceindexer;
import java.io.IOException;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.internal.core.index.IIndex;
-import org.eclipse.cdt.internal.core.search.processing.IJob;
+import org.eclipse.cdt.internal.core.search.indexing.ReadWriteMonitor;
+import org.eclipse.cdt.internal.core.search.processing.IIndexJob;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
-public abstract class IndexRequest implements IJob {
+public abstract class IndexRequest implements IIndexJob {
protected boolean isCancelled = false;
- protected IPath indexPath;
- protected IndexManager manager;
-
- public IndexRequest(IPath indexPath, IndexManager manager) {
+ protected IPath indexPath = null;
+ protected SourceIndexer indexer = null;
+
+ public IndexRequest(IPath indexPath, SourceIndexer indexer) {
this.indexPath = indexPath;
- this.manager = manager;
+ this.indexer = indexer;
}
public boolean belongsTo(String projectName) {
@@ -34,18 +35,18 @@ public abstract class IndexRequest implements IJob {
}
public void cancel() {
- this.manager.jobFinishedNotification( this );
- this.manager.jobWasCancelled(this.indexPath);
+ this.indexer.jobFinishedNotification( this );
+ this.indexer.jobWasCancelled(this.indexPath);
this.isCancelled = true;
}
public boolean isReadyToRun() {
IProject project = CCorePlugin.getWorkspace().getRoot().getProject(indexPath.segment(0));
- if ( !project.isAccessible() || !this.manager.isIndexEnabled( project ) )
+ if ( !project.isAccessible() || !this.indexer.isIndexEnabled( project ) )
return false;
// tag the index as inconsistent
- this.manager.aboutToUpdateIndex(indexPath, updatedIndexState());
+ indexer.aboutToUpdateIndex(indexPath, updatedIndexState());
return true;
}
/*
@@ -57,7 +58,7 @@ public abstract class IndexRequest implements IJob {
try {
monitor.exitRead(); // free read lock
monitor.enterWrite(); // ask permission to write
- this.manager.saveIndex(index);
+ indexer.saveIndex(index);
} finally {
monitor.exitWriteEnterRead(); // finished writing and reacquire read permission
}
@@ -65,6 +66,10 @@ public abstract class IndexRequest implements IJob {
}
protected Integer updatedIndexState() {
- return IndexManager.UPDATING_STATE;
+ return CIndexStorage.UPDATING_STATE;
+ }
+
+ public IPath getIndexPath(){
+ return indexPath;
}
}
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/RemoveFolderFromIndex.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/RemoveFolderFromIndex.java
index 0c08b31e7b..7f97094517 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/RemoveFolderFromIndex.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/RemoveFolderFromIndex.java
@@ -9,26 +9,28 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.cdt.internal.core.search.indexing;
+package org.eclipse.cdt.internal.core.index.sourceindexer;
import java.io.IOException;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.index.IIndex;
import org.eclipse.cdt.internal.core.index.IQueryResult;
+import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
+import org.eclipse.cdt.internal.core.search.indexing.ReadWriteMonitor;
import org.eclipse.cdt.internal.core.search.processing.JobManager;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
-class RemoveFolderFromIndex extends IndexRequest {
+public class RemoveFolderFromIndex extends IndexRequest {
IPath folderPath;
char[][] exclusionPatterns;
IProject project;
- public RemoveFolderFromIndex(IPath folderPath, char[][] exclusionPatterns, IProject project, IndexManager manager) {
- super(project.getFullPath(), manager);
+ public RemoveFolderFromIndex(IPath folderPath, char[][] exclusionPatterns, IProject project, SourceIndexer indexer) {
+ super(project.getFullPath(), indexer);
this.folderPath = folderPath;
this.exclusionPatterns = exclusionPatterns;
this.project = project;
@@ -38,9 +40,9 @@ class RemoveFolderFromIndex extends IndexRequest {
if (progressMonitor != null && progressMonitor.isCanceled()) return true;
/* ensure no concurrent write access to index */
- IIndex index = manager.getIndex(this.indexPath, true, /*reuse index file*/ false /*create if none*/);
+ IIndex index = indexer.getIndex(this.indexPath, true, /*reuse index file*/ false /*create if none*/);
if (index == null) return true;
- ReadWriteMonitor monitor = manager.getMonitorFor(index);
+ ReadWriteMonitor monitor = indexer.getMonitorFor(index);
if (monitor == null) return true; // index got deleted since acquired
try {
@@ -50,7 +52,7 @@ class RemoveFolderFromIndex extends IndexRequest {
for (int i = 0, max = results == null ? 0 : results.length; i < max; i++) {
String documentPath = results[i].getPath();
if (this.exclusionPatterns == null || !Util.isExcluded(new Path(documentPath), this.exclusionPatterns)) {
- manager.remove(documentPath, this.indexPath); // write lock will be acquired by the remove operation
+ indexer.remove(documentPath, this.indexPath); // write lock will be acquired by the remove operation
}
}
} catch (IOException e) {
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/RemoveFromIndex.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/RemoveFromIndex.java
index e69d580e90..33d443cb74 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/RemoveFromIndex.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/RemoveFromIndex.java
@@ -9,20 +9,22 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.cdt.internal.core.search.indexing;
+package org.eclipse.cdt.internal.core.index.sourceindexer;
import java.io.IOException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.cdt.internal.core.index.IIndex;
+import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
+import org.eclipse.cdt.internal.core.search.indexing.ReadWriteMonitor;
import org.eclipse.cdt.internal.core.search.processing.JobManager;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
-class RemoveFromIndex extends IndexRequest {
+public class RemoveFromIndex extends IndexRequest {
String resourceName;
- public RemoveFromIndex(String resourceName, IPath indexPath, IndexManager manager) {
- super(indexPath, manager);
+ public RemoveFromIndex(String resourceName, IPath indexPath, SourceIndexer indexer) {
+ super(indexPath, indexer);
this.resourceName = resourceName;
}
@@ -31,9 +33,9 @@ class RemoveFromIndex extends IndexRequest {
if (progressMonitor != null && progressMonitor.isCanceled()) return true;
/* ensure no concurrent write access to index */
- IIndex index = manager.getIndex(this.indexPath, true, /*reuse index file*/ false /*create if none*/);
+ IIndex index = indexer.getIndex(this.indexPath, true, /*reuse index file*/ false /*create if none*/);
if (index == null) return true;
- ReadWriteMonitor monitor = manager.getMonitorFor(index);
+ ReadWriteMonitor monitor = indexer.getMonitorFor(index);
if (monitor == null) return true; // index got deleted since acquired
try {
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/SaveIndex.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SaveIndex.java
index 99e3bfa0d6..2e96e94fcb 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/SaveIndex.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SaveIndex.java
@@ -9,35 +9,37 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.cdt.internal.core.search.indexing;
+package org.eclipse.cdt.internal.core.index.sourceindexer;
import java.io.IOException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.cdt.internal.core.index.IIndex;
+import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
+import org.eclipse.cdt.internal.core.search.indexing.ReadWriteMonitor;
import org.eclipse.cdt.internal.core.search.processing.JobManager;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
/*
* Save the index of a project.
*/
public class SaveIndex extends IndexRequest {
- public SaveIndex(IPath indexPath, IndexManager manager) {
- super(indexPath, manager);
+ public SaveIndex(IPath indexPath, SourceIndexer indexer) {
+ super(indexPath, indexer);
}
public boolean execute(IProgressMonitor progressMonitor) {
if (progressMonitor != null && progressMonitor.isCanceled()) return true;
/* ensure no concurrent write access to index */
- IIndex index = this.manager.getIndex(this.indexPath, true /*reuse index file*/, false /*don't create if none*/);
+ IIndex index = indexer.getIndex(this.indexPath, true /*reuse index file*/, false /*don't create if none*/);
if (index == null) return true;
- ReadWriteMonitor monitor = this.manager.getMonitorFor(index);
+ ReadWriteMonitor monitor = indexer.getMonitorFor(index);
if (monitor == null) return true; // index got deleted since acquired
try {
monitor.enterWrite(); // ask permission to write
- this.manager.saveIndex(index);
+ indexer.saveIndex(index);
} catch (IOException e) {
if (IndexManager.VERBOSE) {
JobManager.verbose("-> failed to save index " + this.indexPath + " because of the following exception:"); //$NON-NLS-1$ //$NON-NLS-2$
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexer.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexer.java
new file mode 100644
index 0000000000..0e0ccbf8b0
--- /dev/null
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexer.java
@@ -0,0 +1,685 @@
+/**********************************************************************
+ * Copyright (c) 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.cdt.internal.core.index.sourceindexer;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.ICDescriptor;
+import org.eclipse.cdt.core.ICLogConstants;
+import org.eclipse.cdt.core.index.ICDTIndexer;
+import org.eclipse.cdt.core.index.IIndexChangeListener;
+import org.eclipse.cdt.core.index.IIndexStorage;
+import org.eclipse.cdt.core.index.IndexChangeEvent;
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.ICModelMarker;
+import org.eclipse.cdt.core.parser.util.ObjectSet;
+import org.eclipse.cdt.internal.core.Util;
+import org.eclipse.cdt.internal.core.index.IDocument;
+import org.eclipse.cdt.internal.core.index.IIndex;
+import org.eclipse.cdt.internal.core.index.IIndexerOutput;
+import org.eclipse.cdt.internal.core.index.impl.IndexDelta;
+import org.eclipse.cdt.internal.core.search.SimpleLookupTable;
+import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
+import org.eclipse.cdt.internal.core.search.indexing.ReadWriteMonitor;
+import org.eclipse.cdt.internal.core.search.processing.IIndexJob;
+import org.eclipse.cdt.internal.core.sourcedependency.UpdateDependency;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.ISafeRunnable;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * @author Bogdan Gheorghe
+ */
+public class SourceIndexer implements ICDTIndexer {
+
+ public static boolean VERBOSE = false;
+
+ //private IndexerModelListener indexModelListener = null;
+
+ /**
+ * Collection of listeners for indexer deltas
+ */
+ protected List indexChangeListeners = Collections.synchronizedList(new ArrayList());
+ public static final String INDEX_NOTIFICATION_NAME = Util.bind( "indexNotificationJob" ); //$NON-NLS-1$
+
+ public final static String INDEX_MODEL_ID = CCorePlugin.PLUGIN_ID + ".newindexmodel"; //$NON-NLS-1$
+ public final static String ACTIVATION = "enable"; //$NON-NLS-1$
+ public final static String PROBLEM_ACTIVATION = "problemEnable"; //$NON-NLS-1$
+ public final static QualifiedName activationKey = new QualifiedName(INDEX_MODEL_ID, ACTIVATION);
+ public final static QualifiedName problemsActivationKey = new QualifiedName( INDEX_MODEL_ID, PROBLEM_ACTIVATION );
+
+ public static final String INDEXER_ENABLED = "indexEnabled"; //$NON-NLS-1$
+ public static final String INDEXER_PROBLEMS_ENABLED = "indexerProblemsEnabled"; //$NON-NLS-1$
+ public static final String SOURCE_INDEXER = "cdt_source_indexer"; //$NON-NLS-1$
+ public static final String INDEXER_VALUE = "indexValue"; //$NON-NLS-1$
+ public static final String INDEXER_PROBLEMS_VALUE = "indexProblemsValue"; //$NON-NLS-1$
+
+ public static final int PREPROCESSOR_PROBLEMS_BIT = 1;
+ public static final int SEMANTIC_PROBLEMS_BIT = 1 << 1;
+ public static final int SYNTACTIC_PROBLEMS_BIT = 1 << 2;
+
+ private CIndexStorage indexStorage = null;
+ public ReadWriteMonitor storageMonitor = null;
+ private IndexManager indexManager = null;
+
+ private HashSet jobSet = null;
+
+ public SourceIndexer(){
+ this.indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager();
+ this.indexStorage = (CIndexStorage) indexManager.getIndexStorageForIndexer(this);
+ this.jobSet = new HashSet();
+ this.storageMonitor = new ReadWriteMonitor();
+ }
+
+ /**
+ * @return
+ */
+ private IIndexStorage getIndexStorage() {
+ return indexStorage;
+ }
+
+
+ public void addSource(IFile resource, IPath indexedContainers){
+ this.addSource(resource,indexedContainers, false);
+ }
+
+ /**
+ * Trigger addition of a resource to an index
+ * Note: the actual operation is performed in background
+ * @param checkEncounteredHeaders TODO
+ */
+ public void addSource(IFile resource, IPath indexedContainers, boolean checkEncounteredHeaders){
+
+ IProject project = resource.getProject();
+
+ boolean indexEnabled = false;
+ if (project != null)
+ indexEnabled = isIndexEnabled(project);
+ else
+ org.eclipse.cdt.internal.core.model.Util.log(null, "IndexManager addSource: File has no project associated : " + resource.getName(), ICLogConstants.CDT); //$NON-NLS-1$
+
+ if (CCorePlugin.getDefault() == null) return;
+
+ if (indexEnabled){
+ AddCompilationUnitToIndex job = new AddCompilationUnitToIndex(resource, indexedContainers, this, checkEncounteredHeaders);
+
+ //If we are in WAITING mode, we need to kick ourselves into enablement
+ if (!jobSet.add(resource.getLocation()) &&
+ indexManager.enabledState()==IndexManager.ENABLED)
+ return;
+
+
+ if (indexManager.awaitingJobsCount() < CIndexStorage.MAX_FILES_IN_MEMORY) {
+ // reduces the chance that the file is open later on, preventing it from being deleted
+ if (!job.initializeContents()) return;
+ }
+
+ this.indexManager.request(job);
+ }
+ }
+
+
+
+ public void updateDependencies(IResource resource){
+ if (CCorePlugin.getDefault() == null || !isIndexEnabled( resource.getProject() ) )
+ return;
+
+ UpdateDependency job = new UpdateDependency(resource, this);
+ indexManager.request(job);
+ }
+
+ /**
+ * Returns the index for a given project, according to the following algorithm:
+ * - if index is already in memory: answers this one back
+ * - if (reuseExistingFile) then read it and return this index and record it in memory
+ * - if (createIfMissing) then create a new empty index and record it in memory
+ *
+ * Warning: Does not check whether index is consistent (not being used)
+ */
+ public synchronized boolean haveEncounteredHeader(IPath projectPath, IPath filePath) {
+
+ if (!(indexStorage instanceof CIndexStorage))
+ return false;
+
+ SimpleLookupTable headerTable = ((CIndexStorage)indexStorage).getEncounteredHeaders();
+
+
+ // Path is already canonical per construction
+ ObjectSet headers = (ObjectSet) headerTable.get(projectPath);
+ if (headers == null) {
+ //First time for the project, must create a new ObjectSet
+ headers = new ObjectSet(4);
+ headerTable.put(projectPath, headers);
+ }
+
+ if (headers.containsKey(filePath.toOSString()))
+ return true;
+
+ headers.put(filePath.toOSString());
+
+ return false;
+ }
+
+
+
+ /**
+ * Trigger addition of the entire content of a project
+ * Note: the actual operation is performed in background
+ */
+ public void indexAll(IProject project) {
+ if (CCorePlugin.getDefault() == null) return;
+
+ //check to see if indexing isEnabled for this project
+ boolean indexEnabled = isIndexEnabled(project);
+
+ if (indexEnabled){
+ if( indexManager.enabledState() == IndexManager.WAITING ){
+ //if we are paused because the user cancelled a previous index, this is a good
+ //enough reason to restart
+ indexManager.enable();
+ }
+ // check if the same request is not already in the queue
+ IndexRequest request = new IndexAllProject(project, this);
+ for (int i = indexManager.getJobEnd(); i > indexManager.getJobStart(); i--) // NB: don't check job at jobStart, as it may have already started (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=32488)
+ if (request.equals(indexManager.getAwaitingJobAt(i))) return;
+ indexManager.request(request);
+ }
+ }
+
+
+
+
+
+ /**
+ * @param project
+ * @return
+ */
+ public boolean isIndexEnabled(IProject project) {
+ if( project == null || !project.exists() || !project.isOpen() )
+ return false;
+
+ Boolean indexValue = null;
+
+ try {
+ indexValue = (Boolean) project.getSessionProperty(activationKey);
+ } catch (CoreException e) {
+ }
+
+ if (indexValue != null)
+ return indexValue.booleanValue();
+
+ try {
+ //Load value for project
+ indexValue = loadIndexerEnabledFromCDescriptor(project);
+ if (indexValue != null){
+ project.setSessionProperty(SourceIndexer.activationKey, indexValue);
+ return indexValue.booleanValue();
+ }
+
+// TODO: Indexer Block Place holder for Managed Make - take out
+ indexValue = new Boolean(true);
+ project.setSessionProperty(SourceIndexer.activationKey, indexValue);
+ return indexValue.booleanValue();
+ } catch (CoreException e1) {
+ }
+
+ return false;
+ }
+
+
+
+ public int indexProblemsEnabled(IProject project) {
+ Integer value = null;
+
+ try {
+ value = (Integer) project.getSessionProperty(problemsActivationKey);
+ } catch (CoreException e) {
+ }
+
+ if (value != null)
+ return value.intValue();
+
+ try {
+ //Load value for project
+ value = loadIndexerProblemsEnabledFromCDescriptor(project);
+ if (value != null){
+ project.setSessionProperty(SourceIndexer.problemsActivationKey, value);
+ return value.intValue();
+ }
+
+ //TODO: Indexer Block Place holder for Managed Make - take out
+ value = new Integer(0);
+ project.setSessionProperty(SourceIndexer.problemsActivationKey, value);
+ return value.intValue();
+ } catch (CoreException e1) {
+ }
+
+ return 0;
+ }
+ /**
+ * Index the content of the given source folder.
+ */
+ public void indexSourceFolder(IProject project, IPath sourceFolder, final char[][] exclusionPattern) {
+ if( !isIndexEnabled( project ) )
+ return;
+ if (indexManager.getJobEnd() > indexManager.getJobStart()) {
+ // check if a job to index the project is not already in the queue
+ IndexRequest request = new IndexAllProject(project, this);
+ for (int i = indexManager.getJobEnd(); i > indexManager.getJobStart(); i--) // NB: don't check job at jobStart, as it may have already started (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=32488)
+ if (request.equals(indexManager.getAwaitingJobAt(i))) return;
+ }
+ this.request(new AddFolderToIndex(sourceFolder, project, exclusionPattern, this));
+ }
+
+ /**
+ * Trigger removal of a resource to an index
+ * Note: the actual operation is performed in background
+ */
+ public void remove(String resourceName, IPath indexedContainer){
+ IProject project = CCorePlugin.getWorkspace().getRoot().getProject(indexedContainer.toString());
+ if( isIndexEnabled( project ) )
+ request(new RemoveFromIndex(resourceName, indexedContainer, this));
+ }
+
+
+ /**
+ * Remove the content of the given source folder from the index.
+ */
+ public void removeSourceFolderFromIndex(IProject project, IPath sourceFolder, char[][] exclusionPatterns) {
+
+ if( !isIndexEnabled( project ) )
+ return;
+
+ if (indexManager.getJobEnd()> indexManager.getJobStart()) {
+ // check if a job to index the project is not already in the queue
+ IndexRequest request = new IndexAllProject(project, this);
+ for (int i = indexManager.getJobEnd(); i > indexManager.getJobStart(); i--) // NB: don't check job at jobStart, as it may have already started (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=32488)
+ if (request.equals(indexManager.getAwaitingJobAt(i))) return;
+ }
+
+ this.request(new RemoveFolderFromIndex(sourceFolder, exclusionPatterns, project, this));
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.internal.core.search.processing.JobManager#jobFinishedNotification(org.eclipse.cdt.internal.core.search.processing.IJob)
+ */
+ public void jobFinishedNotification(IIndexJob job) {
+ this.indexJobFinishedNotification(job);
+
+ }
+
+
+
+ private Boolean loadIndexerEnabledFromCDescriptor(IProject project) throws CoreException {
+ // Check if we have the property in the descriptor
+ // We pass false since we do not want to create the descriptor if it does not exists.
+ ICDescriptor descriptor = CCorePlugin.getDefault().getCProjectDescription(project, false);
+ Boolean strBool = null;
+ if (descriptor != null) {
+ Node child = descriptor.getProjectData(SOURCE_INDEXER).getFirstChild();
+
+ while (child != null) {
+ if (child.getNodeName().equals(INDEXER_ENABLED))
+ strBool = Boolean.valueOf(((Element)child).getAttribute(INDEXER_VALUE));
+
+
+ child = child.getNextSibling();
+ }
+ }
+
+ return strBool;
+ }
+ private Integer loadIndexerProblemsEnabledFromCDescriptor(IProject project) throws CoreException {
+ // we are only checking for the settings do not create the descriptor.
+ ICDescriptor descriptor = CCorePlugin.getDefault().getCProjectDescription(project, false);
+ Integer strInt = null;
+ if( descriptor != null ){
+ Node child = descriptor.getProjectData(SourceIndexer.SOURCE_INDEXER).getFirstChild();
+
+ while (child != null) {
+ if (child.getNodeName().equals(INDEXER_PROBLEMS_ENABLED)){
+ String val = ((Element)child).getAttribute(INDEXER_PROBLEMS_VALUE);
+ try{
+ strInt = Integer.valueOf( val );
+ } catch( NumberFormatException e ){
+ //some old projects might have a boolean stored, translate that into just preprocessors
+ Boolean bool = Boolean.valueOf( val );
+ if( bool.booleanValue() )
+ strInt = new Integer( SourceIndexer.PREPROCESSOR_PROBLEMS_BIT );
+ else
+ strInt = new Integer( 0 );
+ }
+ break;
+ }
+ child = child.getNextSibling();
+ }
+ }
+
+ return strInt;
+ }
+
+ static private class RemoveIndexMarkersJob extends Job{
+ private final IResource resource;
+ public RemoveIndexMarkersJob( IResource resource, String name ){
+ super( name );
+ this.resource = resource;
+ }
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ resource.deleteMarkers( ICModelMarker.INDEXER_MARKER, true, IResource.DEPTH_INFINITE );
+ } catch (CoreException e) {
+ return Status.CANCEL_STATUS;
+ }
+ return Status.OK_STATUS;
+ }
+
+ }
+
+ public void removeIndexerProblems( IResource resource){
+ String jobName = "remove markers"; //$NON-NLS-1$
+ RemoveIndexMarkersJob job = new RemoveIndexMarkersJob( resource, jobName );
+ job.setRule( resource );
+ job.setPriority( Job.DECORATE );
+ job.schedule();
+ }
+
+ public void addIndexChangeListener(IIndexChangeListener listener) {
+ synchronized(indexChangeListeners) {
+ if (!indexChangeListeners.contains(listener)) {
+ indexChangeListeners.add(listener);
+ }
+ }
+ }
+
+ public void removeIndexChangeListener(IIndexChangeListener listener) {
+ synchronized(indexChangeListeners) {
+ int i = indexChangeListeners.indexOf(listener);
+ if (i != -1) {
+ indexChangeListeners.remove(i);
+ }
+ }
+ }
+ /**
+ * @param indexDelta
+ */
+ public void notifyListeners(IndexDelta indexDelta) {
+ final IndexChangeEvent indexEvent = new IndexChangeEvent(indexDelta);
+ for (int i= 0; i < indexChangeListeners.size(); i++) {
+ IIndexChangeListener tempListener = null;
+ synchronized(indexChangeListeners){
+ tempListener = (IIndexChangeListener) indexChangeListeners.get(i);
+ }
+ final IIndexChangeListener listener = tempListener;
+ long start = -1;
+ if (VERBOSE) {
+ System.out.print("Listener #" + (i+1) + "=" + listener.toString());//$NON-NLS-1$//$NON-NLS-2$
+ start = System.currentTimeMillis();
+ }
+
+ // wrap callbacks with Safe runnable for subsequent listeners to be called when some are causing grief
+ Job job = new Job(INDEX_NOTIFICATION_NAME){
+ protected IStatus run(IProgressMonitor monitor) {
+ Platform.run(new ISafeRunnable() {
+ public void handleException(Throwable exception) {
+ CCorePlugin.log(exception);
+ }
+ public void run() throws Exception {
+ listener.indexChanged(indexEvent);
+ }
+ });
+
+ return Status.OK_STATUS;
+ }
+ };
+
+ job.schedule();
+ if (VERBOSE) {
+ System.out.println(" -> " + (System.currentTimeMillis()-start) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+ }
+
+ /**
+ * No more job awaiting.
+ */
+ public void notifyIdle(long idlingTime){
+ if (idlingTime > 1000 && ((CIndexStorage) indexStorage).getNeedToSave())
+ ((CIndexStorage) indexStorage).saveIndexes();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.index2.IIndexer#getIndexerFeatures()
+ */
+ public int getIndexerFeatures() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.index2.IIndexer#shouldIndex(org.eclipse.core.resources.IFile)
+ */
+ public boolean shouldIndex(IFile file) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.index2.IIndexer#index(org.eclipse.cdt.internal.core.index.IDocument, org.eclipse.cdt.internal.core.index.IIndexerOutput)
+ */
+ public void index(IDocument document, IIndexerOutput output) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.index2.IIndexer#addRequest(org.eclipse.cdt.core.model.ICElement, org.eclipse.core.resources.IResourceDelta, org.eclipse.core.resources.IResourceChangeEvent)
+ */
+ public void addRequest(ICElement element, IResourceDelta delta) {
+
+ switch (element.getElementType()) {
+ case ICElement.C_PROJECT :
+ this.indexAll(element.getCProject().getProject());
+ break;
+
+ case ICElement.C_CCONTAINER:
+ this.indexSourceFolder(element.getCProject().getProject(),element.getPath(),null);
+ break;
+
+ case ICElement.C_UNIT:
+ IFile file = (IFile) delta.getResource();
+ IProject filesProject = file.getProject();
+ this.addSource(file, filesProject.getFullPath());
+ break;
+ }
+
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.index2.IIndexer#removeRequest(org.eclipse.cdt.core.model.ICElement, org.eclipse.core.resources.IResourceDelta, org.eclipse.core.resources.IResourceChangeEvent)
+ */
+ public void removeRequest(ICElement element, IResourceDelta delta) {
+ switch (element.getElementType()) {
+ case ICElement.C_PROJECT :
+ IPath fullPath = element.getCProject().getProject().getFullPath();
+ if( delta.getKind() == IResourceDelta.CHANGED )
+ indexManager.discardJobs(fullPath.segment(0));
+ indexStorage.removeIndexFamily(fullPath);
+ // NB: Discarding index jobs belonging to this project was done during PRE_DELETE
+ break;
+ // NB: Update of index if project is opened, closed, or its c nature is added or removed
+ // is done in updateCurrentDeltaAndIndex
+
+ case ICElement.C_CCONTAINER:
+ this.removeSourceFolderFromIndex(element.getCProject().getProject(),element.getPath(),null);
+ break;
+
+ case ICElement.C_UNIT:
+ IFile file = (IFile) delta.getResource();
+ this.remove(file.getFullPath().toString(), file.getProject().getFullPath());
+ break;
+ }
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.index2.IIndexer#indexJobFinishedNotification(org.eclipse.cdt.internal.core.search.processing.IIndexJob)
+ */
+ public void indexJobFinishedNotification(IIndexJob job) {
+ ((CIndexStorage)indexStorage).setNeedToSave(true);
+
+ if (job instanceof AddCompilationUnitToIndex){
+ AddCompilationUnitToIndex tempJob = (AddCompilationUnitToIndex) job;
+ jobSet.remove(tempJob.getResource().getLocation());
+ }
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.index2.IIndexer#shutdown()
+ */
+ public void shutdown() {
+ indexStorage.shutdown();
+ //indexModelListener.shutdown();
+ }
+
+ /**
+ * Forward job request to Index Manager
+ * @param cleanHeaders
+ */
+ public void request(IIndexJob indexJob) {
+ this.indexManager.request(indexJob);
+ }
+
+ public ReadWriteMonitor getStorageMonitor() {
+ return storageMonitor;
+ }
+ /**
+ *
+ */
+ public void resetEncounteredHeaders() {
+ try{
+ storageMonitor.enterWrite();
+ indexStorage.resetEncounteredHeaders();
+ }
+ finally {
+ storageMonitor.exitWrite();
+ }
+ }
+
+ /**
+ * @param path
+ * @param reuseIndexFile
+ * @param createIfMissing
+ * @return
+ */
+ public synchronized IIndex getIndex(IPath path, boolean reuseExistingFile, boolean createIfMissing) {
+ IIndex index = null;
+ try{
+ storageMonitor.enterRead();
+ index = indexStorage.getIndex(path,reuseExistingFile, createIfMissing);
+ }
+ finally{
+ storageMonitor.exitRead();
+ }
+ return index;
+ }
+
+ /**
+ * @param index
+ * @return
+ */
+ public ReadWriteMonitor getMonitorFor(IIndex index) {
+ ReadWriteMonitor monitor = null;
+ try{
+ storageMonitor.enterRead();
+ monitor=indexStorage.getMonitorFor(index);
+ }
+ finally{
+ storageMonitor.exitRead();
+ }
+ return monitor;
+ }
+
+ /**
+ * @param path
+ */
+ public void removeIndex(IPath path) {
+ try{
+ storageMonitor.enterWrite();
+ indexStorage.removeIndex(path);
+ }
+ finally{
+ storageMonitor.exitWrite();
+ }
+
+ }
+
+ /**
+ * @param path
+ */
+ public void jobWasCancelled(IPath path) {
+ try{
+ storageMonitor.enterWrite();
+ indexStorage.jobWasCancelled(path);
+ }
+ finally{
+ storageMonitor.exitWrite();
+ }
+ }
+
+ /**
+ * @param index
+ */
+ public void saveIndex(IIndex index) throws IOException {
+ try{
+ storageMonitor.enterWrite();
+ indexStorage.saveIndex(index);
+ }
+ finally {
+ storageMonitor.exitWrite();
+ }
+
+ }
+
+ /**
+ * @param indexPath
+ * @param indexState
+ */
+ public void aboutToUpdateIndex(IPath indexPath, Integer indexState) {
+ try{
+ //storageMonitor.enterWrite();
+ indexStorage.aboutToUpdateIndex(indexPath, indexState);
+ }
+ finally {
+ //storageMonitor.exitWrite();
+ }
+ }
+}
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexerRequestor.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexerRequestor.java
index 864e9b5b5b..71c0d39b5f 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexerRequestor.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexerRequestor.java
@@ -9,7 +9,7 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.cdt.internal.core.search.indexing;
+package org.eclipse.cdt.internal.core.index.sourceindexer;
/**
* @author bgheorgh
@@ -31,7 +31,6 @@ import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.IProblem;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ParserMode;
-import org.eclipse.cdt.core.parser.ParserTimeOut;
import org.eclipse.cdt.core.parser.ParserUtil;
import org.eclipse.cdt.core.parser.ast.IASTASMDefinition;
import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
@@ -72,6 +71,9 @@ import org.eclipse.cdt.core.parser.ast.IASTVariableReference;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.index.impl.IFileDocument;
import org.eclipse.cdt.internal.core.index.impl.IndexedFile;
+import org.eclipse.cdt.internal.core.search.indexing.IIndexConstants;
+import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
+import org.eclipse.cdt.internal.core.search.indexing.IndexProblemHandler;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
@@ -94,7 +96,7 @@ import org.eclipse.core.runtime.jobs.Job;
*/
public class SourceIndexerRequestor implements ISourceElementRequestor, IIndexConstants {
- SourceIndexer indexer;
+ SourceIndexerRunner indexer;
IFile resourceFile;
char[] packageName;
@@ -109,7 +111,6 @@ public class SourceIndexerRequestor implements ISourceElementRequestor, IIndexCo
private Map problemsMap = null;
private IProgressMonitor pm = new NullProgressMonitor();
- private ParserTimeOut timeoutThread = null;
private static final String INDEXER_MARKER_ORIGINATOR = ICModelMarker.INDEXER_MARKER + ".originator"; //$NON-NLS-1$
private static final String INDEXER_MARKER_PREFIX = Util.bind("indexerMarker.prefix" ) + " "; //$NON-NLS-1$ //$NON-NLS-2$
@@ -118,11 +119,10 @@ public class SourceIndexerRequestor implements ISourceElementRequestor, IIndexCo
private ArrayList filesTraversed = null;
private IParser parser;
- public SourceIndexerRequestor(SourceIndexer indexer, IFile resourceFile, ParserTimeOut timeOut) {
+ public SourceIndexerRequestor(SourceIndexerRunner indexer, IFile resourceFile) {
super();
this.indexer = indexer;
this.resourceFile = resourceFile;
- this.timeoutThread = timeOut;
this.filesTraversed = new ArrayList(15);
this.filesTraversed.add(resourceFile.getLocation().toOSString());
}
@@ -236,7 +236,7 @@ public class SourceIndexerRequestor implements ISourceElementRequestor, IIndexCo
/* See if this file has been encountered before */
if (type.isHeader())
- CCorePlugin.getDefault().getCoreModel().getIndexManager().haveEncounteredHeader(resourceProject.getFullPath(),new Path(inclusion.getFullFileName()));
+ indexer.haveEncounteredHeader(resourceProject.getFullPath(),new Path(inclusion.getFullFileName()));
}
@@ -314,7 +314,7 @@ public class SourceIndexerRequestor implements ISourceElementRequestor, IIndexCo
//file number for the current file (if it has one). If the current file does not
//have a file number, we need to add it to the index.
IFile tempFile = CCorePlugin.getWorkspace().getRoot().getFileForLocation(new Path(include.getFullFileName()));
- String filePath = "";
+ String filePath = ""; //$NON-NLS-1$
if (tempFile != null){
//File is local to workspace
filePath = tempFile.getFullPath().toString();
@@ -578,56 +578,6 @@ public class SourceIndexerRequestor implements ISourceElementRequestor, IIndexCo
}
}
- public void setParser( IParser parser )
- {
- this.parser = parser;
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.internal.ui.text.contentassist.ITimeoutThreadOwner#setTimeout(int)
- */
- public void setTimeout(int timeout) {
- timeoutThread.setTimeout(timeout);
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.internal.ui.text.contentassist.ITimeoutThreadOwner#startTimer()
- */
- public void startTimer() {
- createProgressMonitor(parser);
- while (!timeoutThread.isReadyToRun()){
- try {
- Thread.sleep(20);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- timeoutThread.startTimer();
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.internal.ui.text.contentassist.ITimeoutThreadOwner#stopTimer()
- */
- public void stopTimer() {
- timeoutThread.stopTimer();
- pm.setCanceled(false);
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#parserTimeout()
- */
- public boolean parserTimeout() {
- if ((pm != null) && (pm.isCanceled()))
- return true;
- return false;
- }
- /*
- * Creates a new progress monitor with each start timer
- */
- private void createProgressMonitor( IParser parser ) {
- pm.setCanceled(false);
- timeoutThread.setParser(parser);
- }
-
-
public boolean areProblemMarkersEnabled(){
return problemMarkersEnabled != 0;
}
@@ -682,9 +632,9 @@ public class SourceIndexerRequestor implements ISourceElementRequestor, IIndexCo
if( problem.getSourceLineNumber() == -1 )
return false;
- boolean preprocessor = ( problemMarkersEnabled & IndexManager.PREPROCESSOR_PROBLEMS_BIT ) != 0;
- boolean semantics = ( problemMarkersEnabled & IndexManager.SEMANTIC_PROBLEMS_BIT ) != 0;
- boolean syntax = ( problemMarkersEnabled & IndexManager.SYNTACTIC_PROBLEMS_BIT ) != 0;
+ boolean preprocessor = ( problemMarkersEnabled & SourceIndexer.PREPROCESSOR_PROBLEMS_BIT ) != 0;
+ boolean semantics = ( problemMarkersEnabled & SourceIndexer.SEMANTIC_PROBLEMS_BIT ) != 0;
+ boolean syntax = ( problemMarkersEnabled & SourceIndexer.SYNTACTIC_PROBLEMS_BIT ) != 0;
if( problem.checkCategory( IProblem.PREPROCESSOR_RELATED ) || problem.checkCategory( IProblem.SCANNER_RELATED ) )
return preprocessor && problem.getID() != IProblem.PREPROCESSOR_CIRCULAR_INCLUSION;
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexer.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexerRunner.java
index 41eaff5f1e..6fe409b741 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexer.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexerRunner.java
@@ -9,7 +9,7 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.cdt.internal.core.search.indexing;
+package org.eclipse.cdt.internal.core.index.sourceindexer;
/**
* @author bgheorgh
@@ -27,12 +27,10 @@ import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
-import org.eclipse.cdt.core.parser.ParseError;
import org.eclipse.cdt.core.parser.ParserFactory;
import org.eclipse.cdt.core.parser.ParserFactoryError;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ParserMode;
-import org.eclipse.cdt.core.parser.ParserTimeOut;
import org.eclipse.cdt.core.parser.ParserUtil;
import org.eclipse.cdt.core.parser.ScannerInfo;
import org.eclipse.cdt.internal.core.index.IDocument;
@@ -40,6 +38,8 @@ import org.eclipse.cdt.internal.core.index.impl.IndexDelta;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
/**
* A SourceIndexer indexes source files using the parser. The following items are indexed:
@@ -52,36 +52,27 @@ import org.eclipse.core.runtime.CoreException;
* - Structs
* - Unions
*/
-public class SourceIndexer extends AbstractIndexer {
+public class SourceIndexerRunner extends AbstractIndexer {
- //TODO: Indexer, add additional file types
- //Header files: "h" , "hh", "hpp"
- //Use the CModelManager defined file types
- //public static final String[] FILE_TYPES= new String[] {"cpp","c", "cc", "cxx"}; //$NON-NLS-1$
-
- //protected DefaultProblemFactory problemFactory= new DefaultProblemFactory(Locale.getDefault());
- public static final String CDT_INDEXER_TIMEOUT= "CDT_INDEXER_TIMEOUT"; //$NON-NLS-1$
-
IFile resourceFile;
- ParserTimeOut timeOut = null;
+ private SourceIndexer indexer;
/**
* @param resource
* @param out
*/
- public SourceIndexer(IFile resource, ParserTimeOut timeOut) {
+ public SourceIndexerRunner(IFile resource, SourceIndexer indexer) {
+ this.indexer = indexer;
this.resourceFile = resource;
- this.timeOut = timeOut;
}
protected void indexFile(IDocument document) throws IOException {
// Add the name of the file to the index
output.addDocument(document);
- // Create a new Parser
- SourceIndexerRequestor requestor = new SourceIndexerRequestor(this, resourceFile, timeOut);
+ // Create a new Parser
+ SourceIndexerRequestor requestor = new SourceIndexerRequestor(this, resourceFile);
- IndexManager manager = CCorePlugin.getDefault().getCoreModel().getIndexManager();
- int problems = manager.indexProblemsEnabled( resourceFile.getProject() );
+ int problems = indexer.indexProblemsEnabled( resourceFile.getProject() );
requestor.setProblemMarkersEnabled( problems );
requestor.requestRemoveMarkers( resourceFile, null );
@@ -108,7 +99,6 @@ public class SourceIndexer extends AbstractIndexer {
parser = ParserFactory.createParser(
ParserFactory.createScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE, language, requestor, ParserUtil.getScannerLogService(), null ),
requestor, ParserMode.COMPLETE_PARSE, language, ParserUtil.getParserLogService() );
- requestor.setParser(parser);
} catch( ParserFactoryError pfe ){
} catch (CoreException e) {
} finally {
@@ -118,14 +108,6 @@ public class SourceIndexer extends AbstractIndexer {
}
try{
-
- // start timer
- String timeOut = CCorePlugin.getDefault().getPluginPreferences().getString(CDT_INDEXER_TIMEOUT);
- Integer timeOutValue = new Integer(timeOut);
- if (timeOutValue.intValue() > 0) {
- requestor.setTimeout(timeOutValue.intValue());
- requestor.startTimer();
- }
boolean retVal = parser.parse();
if (AbstractIndexer.VERBOSE){
@@ -140,23 +122,19 @@ public class SourceIndexer extends AbstractIndexer {
org.eclipse.cdt.internal.core.model.Util.log(null, "Out Of Memory error: " + vmErr.getMessage() + " on File: " + resourceFile.getName(), ICLogConstants.CDT); //$NON-NLS-1$ //$NON-NLS-2$
}
}
- catch (ParseError e){
- org.eclipse.cdt.internal.core.model.Util.log(null, "Parser Timeout on File: " + resourceFile.getName(), ICLogConstants.CDT); //$NON-NLS-1$ //$NON-NLS-2$
- }
catch ( Exception ex ){
if (ex instanceof IOException)
throw (IOException) ex;
}
finally{
- requestor.stopTimer();
//if the user disable problem reporting since we last checked, don't report the collected problems
- if( manager.indexProblemsEnabled( resourceFile.getProject() ) != 0 )
+ if( indexer.indexProblemsEnabled( resourceFile.getProject() ) != 0 )
requestor.reportProblems();
//Report events
ArrayList filesTrav = requestor.getFilesTraversed();
IndexDelta indexDelta = new IndexDelta(resourceFile.getProject(),filesTrav, IIndexDelta.INDEX_FINISHED_DELTA);
- CCorePlugin.getDefault().getCoreModel().getIndexManager().notifyListeners(indexDelta);
+ indexer.notifyListeners(indexDelta);
//Release all resources
parser=null;
currentProject = null;
@@ -165,16 +143,19 @@ public class SourceIndexer extends AbstractIndexer {
scanInfo=null;
}
}
- /**
- * Sets the document types the <code>IIndexer</code> handles.
- */
-
- public void setFileTypes(String[] fileTypes){}
+
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.search.indexing.AbstractIndexer#getResourceFile()
*/
public IFile getResourceFile() {
return resourceFile;
}
-
+
+ /**
+ * @param fullPath
+ * @param path
+ */
+ public boolean haveEncounteredHeader(IPath fullPath, Path path) {
+ return indexer.haveEncounteredHeader(fullPath, path);
+ }
}
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java
index f2fde62409..0ce829d9bf 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java
@@ -1,688 +1,233 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
+/**********************************************************************
+ * Copyright (c) 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-
+ * Contributors:
+ * IBM - Initial API and implementation
+ **********************************************************************/
package org.eclipse.cdt.internal.core.search.indexing;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.zip.CRC32;
+import java.util.Set;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICDescriptor;
-import org.eclipse.cdt.core.ICLogConstants;
-import org.eclipse.cdt.core.index.IIndexChangeListener;
-import org.eclipse.cdt.core.index.IndexChangeEvent;
-import org.eclipse.cdt.core.model.ICModelMarker;
-import org.eclipse.cdt.core.parser.ParserTimeOut;
-import org.eclipse.cdt.core.parser.util.ObjectSet;
-import org.eclipse.cdt.internal.core.CharOperation;
-import org.eclipse.cdt.internal.core.Util;
-import org.eclipse.cdt.internal.core.index.IIndex;
-import org.eclipse.cdt.internal.core.index.impl.Index;
-import org.eclipse.cdt.internal.core.index.impl.IndexDelta;
-import org.eclipse.cdt.internal.core.search.CWorkspaceScope;
-import org.eclipse.cdt.internal.core.search.IndexSelector;
-import org.eclipse.cdt.internal.core.search.SimpleLookupTable;
-import org.eclipse.cdt.internal.core.search.processing.IJob;
+import org.eclipse.cdt.core.index.ICDTIndexer;
+import org.eclipse.cdt.core.index.IIndexStorage;
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.internal.core.index.sourceindexer.CIndexStorage;
+import org.eclipse.cdt.internal.core.index.sourceindexer.IndexRequest;
+import org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer;
+import org.eclipse.cdt.internal.core.search.processing.IIndexJob;
import org.eclipse.cdt.internal.core.search.processing.JobManager;
-import org.eclipse.cdt.internal.core.sourcedependency.UpdateDependency;
-import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.ISafeRunnable;
-import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Preferences;
import org.eclipse.core.runtime.QualifiedName;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
-
-public class IndexManager extends JobManager implements IIndexConstants {
- /* number of file contents in memory */
- public static int MAX_FILES_IN_MEMORY = 0;
-
- public IWorkspace workspace;
- public SimpleLookupTable indexNames = new SimpleLookupTable();
- private Map indexes = new HashMap(5);
-
- /* read write monitors */
- private Map monitors = new HashMap(5);
-
- /* need to save ? */
- private boolean needToSave = false;
- private static final CRC32 checksumCalculator = new CRC32();
- private IPath cCorePluginLocation = null;
-
- /* can only replace a current state if its less than the new one */
- private SimpleLookupTable indexStates = null;
- private File savedIndexNamesFile =
- new File(getCCorePluginWorkingLocation().append("savedIndexNames.txt").toOSString()); //$NON-NLS-1$
+/**
+ * @author Bogdan Gheorghe
+ */
+public class IndexManager extends JobManager{
- private SimpleLookupTable encounteredHeaders = null;
+ public final static String INDEX_MODEL_ID = CCorePlugin.PLUGIN_ID + ".cdtindexers"; //$NON-NLS-1$
+ public final static String INDEXERID = "indexerID"; //$NON-NLS-1$
+ public final static QualifiedName indexerIDKey = new QualifiedName(INDEX_MODEL_ID, INDEXERID);
- public static Integer SAVED_STATE = new Integer(0);
- public static Integer UPDATING_STATE = new Integer(1);
- public static Integer UNKNOWN_STATE = new Integer(2);
- public static Integer REBUILDING_STATE = new Integer(3);
+ public static final String CDT_INDEXER = "cdt_indexer"; //$NON-NLS-1$
+ public static final String INDEXER_ID = "indexerID"; //$NON-NLS-1$
+ public static final String INDEXER_ID_VALUE = "indexerIDValue"; //$NON-NLS-1$
public static boolean VERBOSE = false;
- private ParserTimeOut timeoutThread = null;
-
- private IndexerModelListener indexModelListener = null;
-
- /**
- * Collection of listeners for indexer deltas
- */
- protected List indexChangeListeners = Collections.synchronizedList(new ArrayList());
- public static final String INDEX_NOTIFICATION_NAME = Util.bind( "indexNotificationJob" ); //$NON-NLS-1$
-
- public final static String INDEX_MODEL_ID = CCorePlugin.PLUGIN_ID + ".newindexmodel"; //$NON-NLS-1$
- public final static String ACTIVATION = "enable"; //$NON-NLS-1$
- public final static String PROBLEM_ACTIVATION = "problemEnable"; //$NON-NLS-1$
- public final static QualifiedName activationKey = new QualifiedName(INDEX_MODEL_ID, ACTIVATION);
- public final static QualifiedName problemsActivationKey = new QualifiedName( INDEX_MODEL_ID, PROBLEM_ACTIVATION );
-
- public static final String INDEXER_ENABLED = "indexEnabled"; //$NON-NLS-1$
- public static final String INDEXER_PROBLEMS_ENABLED = "indexerProblemsEnabled"; //$NON-NLS-1$
- public static final String CDT_INDEXER = "cdt_indexer"; //$NON-NLS-1$
- public static final String INDEXER_VALUE = "indexValue"; //$NON-NLS-1$
- public static final String INDEXER_PROBLEMS_VALUE = "indexProblemsValue"; //$NON-NLS-1$
-
- public static final int PREPROCESSOR_PROBLEMS_BIT = 1;
- public static final int SEMANTIC_PROBLEMS_BIT = 1 << 1;
- public static final int SYNTACTIC_PROBLEMS_BIT = 1 << 2;
-
- public synchronized void aboutToUpdateIndex(IPath path, Integer newIndexState) {
- // newIndexState is either UPDATING_STATE or REBUILDING_STATE
- // must tag the index as inconsistent, in case we exit before the update job is started
- String indexName = computeIndexName(path);
- Object state = getIndexStates().get(indexName);
- Integer currentIndexState = state == null ? UNKNOWN_STATE : (Integer) state;
- if (currentIndexState.equals(REBUILDING_STATE)) return; // already rebuilding the index
+ //Map of Contributed Indexers; keyed by project
+ private HashMap contributedIndexerMap = null;
+
+ //Map of Persisted Indexers; keyed by project
+ private HashMap indexerMap = null;
+
+ /**
+ * Create an indexer only on request
+ */
+ protected static class CDTIndexer {
- int compare = newIndexState.compareTo(currentIndexState);
- if (compare > 0) {
- // so UPDATING_STATE replaces SAVED_STATE and REBUILDING_STATE replaces everything
- updateIndexState(indexName, newIndexState);
- } else if (compare < 0 && this.indexes.get(path) == null) {
- // if already cached index then there is nothing more to do
- rebuildIndex(indexName, path);
- }
- }
- /**
- * Not at the moment...
- * @param resource
- * @param indexedContainer
- */
- /*
- public void addBinary(IFile resource, IPath indexedContainer){
- if (JavaCore.getPlugin() == null) return;
- AddClassFileToIndex job = new AddClassFileToIndex(resource, indexedContainer, this);
- if (this.awaitingJobsCount() < MAX_FILES_IN_MEMORY) {
- // reduces the chance that the file is open later on, preventing it from being deleted
- if (!job.initializeContents()) return;
- }
- request(job);
- }
- */
- public void addSource(IFile resource, IPath indexedContainers){
- this.addSource(resource,indexedContainers, false);
- }
-
+ IConfigurationElement element;
+ ICDTIndexer indexer;
+
+ public CDTIndexer(IConfigurationElement _element) {
+ element = _element;
+ }
+
+ public ICDTIndexer getIndexer() throws CoreException {
+ if (indexer == null) {
+ indexer = (ICDTIndexer) element.createExecutableExtension("class"); //$NON-NLS-1$
+ }
+ return indexer;
+ }
+
+ public String getName() {
+ return element.getAttribute("name"); //$NON-NLS-1$
+ }
+
+ }
+
+
/**
- * Trigger addition of a resource to an index
- * Note: the actual operation is performed in background
- * @param checkEncounteredHeaders TODO
+ * Flush current state
*/
- public void addSource(IFile resource, IPath indexedContainers, boolean checkEncounteredHeaders){
-
- IProject project = resource.getProject();
-
- boolean indexEnabled = false;
- if (project != null)
- indexEnabled = isIndexEnabled(project);
- else
- org.eclipse.cdt.internal.core.model.Util.log(null, "IndexManager addSource: File has no project associated : " + resource.getName(), ICLogConstants.CDT); //$NON-NLS-1$
-
- if (CCorePlugin.getDefault() == null) return;
+ public void reset() {
+ super.reset();
- if (indexEnabled){
- AddCompilationUnitToIndex job = new AddCompilationUnitToIndex(resource, indexedContainers, this, checkEncounteredHeaders);
-
- //If we are in WAITING mode, we need to kick ourselves into enablement
- if (!jobSet.add(job.resource.getLocation()) &&
- enabledState()==ENABLED)
- return;
-
-
- if (this.awaitingJobsCount() < MAX_FILES_IN_MEMORY) {
- // reduces the chance that the file is open later on, preventing it from being deleted
- if (!job.initializeContents()) return;
- }
-
- request(job);
- }
+ initializeIndexersMap();
+ this.indexerMap = new HashMap(5);
}
- public void updateDependencies(IResource resource){
- if (CCorePlugin.getDefault() == null || !isIndexEnabled( resource.getProject() ) )
- return;
-
- UpdateDependency job = new UpdateDependency(resource);
- request(job);
- }
-
- String computeIndexName(IPath path) {
- String name = (String) indexNames.get(path);
- if (name == null) {
- String pathString = path.toOSString();
- checksumCalculator.reset();
- checksumCalculator.update(pathString.getBytes());
- String fileName = Long.toString(checksumCalculator.getValue()) + ".index"; //$NON-NLS-1$
- if (IndexManager.VERBOSE)
- JobManager.verbose("-> index name for " + pathString + " is " + fileName); //$NON-NLS-1$ //$NON-NLS-2$
- name = getCCorePluginWorkingLocation().append(fileName).toOSString();
- indexNames.put(path, name);
- }
- return name;
- }
- /**
- * Returns the index for a given project, according to the following algorithm:
- * - if index is already in memory: answers this one back
- * - if (reuseExistingFile) then read it and return this index and record it in memory
- * - if (createIfMissing) then create a new empty index and record it in memory
- *
- * Warning: Does not check whether index is consistent (not being used)
- */
- public synchronized IIndex getIndex(IPath path, boolean reuseExistingFile, boolean createIfMissing) {
- // Path is already canonical per construction
- IIndex index = (IIndex) indexes.get(path);
- if (index == null) {
- String indexName = computeIndexName(path);
- Object state = getIndexStates().get(indexName);
- Integer currentIndexState = state == null ? UNKNOWN_STATE : (Integer) state;
- if (currentIndexState == UNKNOWN_STATE) {
- // should only be reachable for query jobs
- // IF you put an index in the cache, then AddJarFileToIndex fails because it thinks there is nothing to do
- rebuildIndex(indexName, path);
- return null;
- }
- // index isn't cached, consider reusing an existing index file
- if (reuseExistingFile) {
- File indexFile = new File(indexName);
- if (indexFile.exists()) { // check before creating index so as to avoid creating a new empty index if file is missing
- try {
- index = new Index(indexName, "Index for " + path.toOSString(), true /*reuse index file*/); //$NON-NLS-1$
- indexes.put(path, index);
- monitors.put(index, new ReadWriteMonitor());
- return index;
- } catch (IOException e) {
- // failed to read the existing file or its no longer compatible
- if (currentIndexState != REBUILDING_STATE) { // rebuild index if existing file is corrupt, unless the index is already being rebuilt
- if (IndexManager.VERBOSE)
- JobManager.verbose("-> cannot reuse existing index: "+indexName+" path: "+path.toOSString()); //$NON-NLS-1$ //$NON-NLS-2$
- rebuildIndex(indexName, path);
- return null;
- }
- index = null; // will fall thru to createIfMissing & create a empty index for the rebuild all job to populate
- }
- }
- if (currentIndexState == SAVED_STATE) { // rebuild index if existing file is missing
- rebuildIndex(indexName, path);
- return null;
- }
- }
- // index wasn't found on disk, consider creating an empty new one
- if (createIfMissing) {
- try {
- if (VERBOSE)
- JobManager.verbose("-> create empty index: "+indexName+" path: "+path.toOSString()); //$NON-NLS-1$ //$NON-NLS-2$
- index = new Index(indexName, "Index for " + path.toOSString(), false /*do not reuse index file*/); //$NON-NLS-1$
- indexes.put(path, index);
- monitors.put(index, new ReadWriteMonitor());
- return index;
- } catch (IOException e) {
- if (VERBOSE)
- JobManager.verbose("-> unable to create empty index: "+indexName+" path: "+path.toOSString()); //$NON-NLS-1$ //$NON-NLS-2$
- // The file could not be created. Possible reason: the project has been deleted.
- return null;
- }
- }
- }
- //System.out.println(" index name: " + path.toOSString() + " <----> " + index.getIndexFile().getName());
- return index;
- }
-
- /**
- * Returns the index for a given project, according to the following algorithm:
- * - if index is already in memory: answers this one back
- * - if (reuseExistingFile) then read it and return this index and record it in memory
- * - if (createIfMissing) then create a new empty index and record it in memory
- *
- * Warning: Does not check whether index is consistent (not being used)
- */
- public synchronized boolean haveEncounteredHeader(IPath projectPath, IPath filePath) {
-
- SimpleLookupTable headerTable = getEncounteredHeaders();
- // Path is already canonical per construction
- ObjectSet headers = (ObjectSet) headerTable.get(projectPath);
- if (headers == null) {
- //First time for the project, must create a new ObjectSet
- headers = new ObjectSet(4);
- headerTable.put(projectPath, headers);
- }
-
- if (headers.containsKey(filePath.toOSString()))
- return true;
-
- headers.put(filePath.toOSString());
-
- return false;
- }
+
- private SimpleLookupTable getIndexStates() {
- if (indexStates != null) return indexStates;
+ public synchronized String getIndexerID(IProject project) throws CoreException {
+ //See if there's already one associated with the resource for this session
+ String indexerID = (String) project.getSessionProperty(indexerIDKey);
- this.indexStates = new SimpleLookupTable();
- char[] savedIndexNames = readIndexState();
- if (savedIndexNames.length > 0) {
- char[][] names = CharOperation.splitOn('\n', savedIndexNames);
- for (int i = 0, l = names.length; i < l; i++) {
- char[] name = names[i];
- if (name.length > 0)
- this.indexStates.put(new String(name), SAVED_STATE);
- }
+ // Try to load one for the project
+ if (indexerID == null) {
+ indexerID = loadIndexerIDFromCDescriptor(project);
}
- return this.indexStates;
- }
- private SimpleLookupTable getEncounteredHeaders(){
-
- if (encounteredHeaders == null){
- this.encounteredHeaders = new SimpleLookupTable();
+ // There is nothing persisted for the session, or saved in a file so
+ // create a build info object
+ if (indexerID != null) {
+ project.setSessionProperty(indexerIDKey, indexerID);
+ }
+ else{
+ //Hmm, no persisted indexer value. Could be an old project - need to run project
+ //update code here
}
-
- return this.encounteredHeaders;
+ return indexerID;
}
/**
- * Resets the headers table
- */
- public void resetEncounteredHeaders() {
- this.encounteredHeaders = null;
- }
-
- private IPath getCCorePluginWorkingLocation() {
- if (this.cCorePluginLocation != null) return this.cCorePluginLocation;
-
- return this.cCorePluginLocation = CCorePlugin.getDefault().getStateLocation();
- }
- /**
- * Index access is controlled through a read-write monitor so as
- * to ensure there is no concurrent read and write operations
- * (only concurrent reading is allowed).
- */
- public ReadWriteMonitor getMonitorFor(IIndex index){
- return (ReadWriteMonitor) monitors.get(index);
- }
- /**
- * Trigger addition of the entire content of a project
- * Note: the actual operation is performed in background
- */
- public void indexAll(IProject project) {
- if (CCorePlugin.getDefault() == null) return;
-
- //check to see if indexing isEnabled for this project
- boolean indexEnabled = isIndexEnabled(project);
-
- if (indexEnabled){
- if( enabledState() == WAITING ){
- //if we are paused because the user cancelled a previous index, this is a good
- //enough reason to restart
- enable();
- }
- // check if the same request is not already in the queue
- IndexRequest request = new IndexAllProject(project, this);
- for (int i = this.jobEnd; i > this.jobStart; i--) // NB: don't check job at jobStart, as it may have already started (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=32488)
- if (request.equals(this.awaitingJobs[i])) return;
- this.request(request);
- }
- }
- /**
+ * Loads indexerID from .cdtproject file
* @param project
- * @return
+ * @param includes
+ * @param symbols
+ * @throws CoreException
*/
- public boolean isIndexEnabled(IProject project) {
- if( project == null || !project.exists() || !project.isOpen() )
- return false;
+ private String loadIndexerIDFromCDescriptor(IProject project) throws CoreException {
+ ICDescriptor descriptor = CCorePlugin.getDefault().getCProjectDescription(project, true);
- Boolean indexValue = null;
-
- try {
- indexValue = (Boolean) project.getSessionProperty(activationKey);
- } catch (CoreException e) {
- }
+ Node child = descriptor.getProjectData(CDT_INDEXER).getFirstChild();
- if (indexValue != null)
- return indexValue.booleanValue();
+ String indexerID = null;
- try {
- //Load value for project
- indexValue = loadIndexerEnabledFromCDescriptor(project);
- if (indexValue != null){
- project.setSessionProperty(IndexManager.activationKey, indexValue);
- return indexValue.booleanValue();
- }
+ while (child != null) {
+ if (child.getNodeName().equals(INDEXER_ID))
+ indexerID = ((Element)child).getAttribute(INDEXER_ID_VALUE);
-// TODO: Indexer Block Place holder for Managed Make - take out
- indexValue = new Boolean(true);
- project.setSessionProperty(IndexManager.activationKey, indexValue);
- return indexValue.booleanValue();
- } catch (CoreException e1) {
+ child = child.getNextSibling();
}
- return false;
+ return indexerID;
}
- public int indexProblemsEnabled(IProject project) {
- Integer value = null;
-
- try {
- value = (Integer) project.getSessionProperty(problemsActivationKey);
- } catch (CoreException e) {
- }
-
- if (value != null)
- return value.intValue();
-
- try {
- //Load value for project
- value = loadIndexerProblemsEnabledFromCDescriptor(project);
- if (value != null){
- project.setSessionProperty(IndexManager.problemsActivationKey, value);
- return value.intValue();
- }
-
- //TODO: Indexer Block Place holder for Managed Make - take out
- value = new Integer(0);
- project.setSessionProperty(IndexManager.problemsActivationKey, value);
- return value.intValue();
- } catch (CoreException e1) {
- }
-
- return 0;
- }
- /**
- * Index the content of the given source folder.
- */
- public void indexSourceFolder(IProject project, IPath sourceFolder, final char[][] exclusionPattern) {
- if( !isIndexEnabled( project ) )
- return;
- if (this.jobEnd > this.jobStart) {
- // check if a job to index the project is not already in the queue
- IndexRequest request = new IndexAllProject(project, this);
- for (int i = this.jobEnd; i > this.jobStart; i--) // NB: don't check job at jobStart, as it may have already started (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=32488)
- if (request.equals(this.awaitingJobs[i])) return;
- }
- this.request(new AddFolderToIndex(sourceFolder, project, exclusionPattern, this));
- }
- public void jobWasCancelled(IPath path) {
- Object o = this.indexes.get(path);
- if (o instanceof IIndex) {
- this.monitors.remove(o);
- this.indexes.remove(path);
- }
- updateIndexState(computeIndexName(path), UNKNOWN_STATE);
- }
- /**
- * Advance to the next available job, once the current one has been completed.
- * Note: clients awaiting until the job count is zero are still waiting at this point.
- */
- protected synchronized void moveToNextJob() {
- // remember that one job was executed, and we will need to save indexes at some point
- needToSave = true;
- super.moveToNextJob();
- }
- /**
- * No more job awaiting.
- */
- protected void notifyIdle(long idlingTime){
- if (idlingTime > 1000 && needToSave) saveIndexes();
- }
- /*
- * For debug purpose
- */
- public IIndex peekAtIndex(IPath path) {
- return (IIndex) indexes.get(path);
- }
+ /**
+ * Adds all the contributed Indexer Pages to a map
+ */
+ private void initializeIndexersMap() {
+
+ contributedIndexerMap = new HashMap(5);
+
+ IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, "CIndexer"); //$NON-NLS-1$
+ IConfigurationElement[] infos = extensionPoint.getConfigurationElements();
+ for (int i = 0; i < infos.length; i++) {
+ if (infos[i].getName().equals("indexer")) { //$NON-NLS-1$
+ String id = infos[i].getAttribute("id"); //$NON-NLS-1$
+ contributedIndexerMap.put(id, new CDTIndexer(infos[i]));
+ }
+ }
+ }
+
/**
- * Name of the background process
+ * Notify indexer which scheduled this job that the job has completed
+ *
*/
- public String processName(){
- return org.eclipse.cdt.internal.core.Util.bind("process.name"); //$NON-NLS-1$
+ protected synchronized void jobFinishedNotification(IIndexJob job) {
+ if (job instanceof IndexRequest ){
+ IndexRequest indexRequest = (IndexRequest) job;
+ IPath path = indexRequest.getIndexPath();
+ IProject project= ResourcesPlugin.getWorkspace().getRoot().getProject(path.toOSString());
+ ICDTIndexer indexer = getIndexerForProject(project);
+
+ if (indexer != null)
+ indexer.indexJobFinishedNotification(job);
+ }
}
-
- private void rebuildIndex(String indexName, IPath path) {
- Object target = org.eclipse.cdt.internal.core.Util.getTarget(ResourcesPlugin.getWorkspace().getRoot(), path, true);
- if (target == null) return;
- if (IndexManager.VERBOSE)
- JobManager.verbose("-> request to rebuild index: "+indexName+" path: "+path.toOSString()); //$NON-NLS-1$ //$NON-NLS-2$
- updateIndexState(indexName, REBUILDING_STATE);
- IndexRequest request = null;
- if (target instanceof IProject) {
- IProject p = (IProject) target;
- if( p.exists() && isIndexEnabled( p ) )
- request = new IndexAllProject(p, this);
- }
-
- if (request != null)
- request(request);
- }
- /**
- * Recreates the index for a given path, keeping the same read-write monitor.
- * Returns the new empty index or null if it didn't exist before.
- * Warning: Does not check whether index is consistent (not being used)
- */
- public synchronized IIndex recreateIndex(IPath path) {
- // only called to over write an existing cached index...
- try {
- IIndex index = (IIndex) this.indexes.get(path);
- ReadWriteMonitor monitor = (ReadWriteMonitor) this.monitors.remove(index);
- // Path is already canonical
- String indexPath = computeIndexName(path);
- if (IndexManager.VERBOSE)
- JobManager.verbose("-> recreating index: "+indexPath+" for path: "+path.toOSString()); //$NON-NLS-1$ //$NON-NLS-2$
- index = new Index(indexPath, "Index for " + path.toOSString(), false /*reuse index file*/); //$NON-NLS-1$
- indexes.put(path, index);
- monitors.put(index, monitor);
- return index;
- } catch (IOException e) {
- // The file could not be created. Possible reason: the project has been deleted.
- if (IndexManager.VERBOSE) {
- JobManager.verbose("-> failed to recreate index for path: "+path.toOSString()); //$NON-NLS-1$ //$NON-NLS-2$
- e.printStackTrace();
- }
- return null;
- }
- }
- /**
- * Trigger removal of a resource to an index
- * Note: the actual operation is performed in background
- */
- public void remove(String resourceName, IPath indexedContainer){
- IProject project = CCorePlugin.getWorkspace().getRoot().getProject(indexedContainer.toString());
- if( isIndexEnabled( project ) )
- request(new RemoveFromIndex(resourceName, indexedContainer, this));
- }
- /**
- * Removes the index for a given path.
- * This is a no-op if the index did not exist.
- */
- public synchronized void removeIndex(IPath path) {
- if (IndexManager.VERBOSE)
- JobManager.verbose("removing index " + path); //$NON-NLS-1$
- String indexName = computeIndexName(path);
- File indexFile = new File(indexName);
- if (indexFile.exists())
- indexFile.delete();
- Object o = this.indexes.get(path);
- if (o instanceof IIndex)
- this.monitors.remove(o);
- this.indexes.remove(path);
- updateIndexState(indexName, null);
- }
+
/**
- * Removes all indexes whose paths start with (or are equal to) the given path.
+ * @param project
+ * @param element
+ * @param delta
*/
- public synchronized void removeIndexFamily(IPath path) {
- // only finds cached index files... shutdown removes all non-cached index files
- ArrayList toRemove = null;
- Iterator iterator = this.indexes.keySet().iterator();
- while (iterator.hasNext()) {
- IPath indexPath = (IPath) iterator.next();
- if (path.isPrefixOf(indexPath)) {
- if (toRemove == null)
- toRemove = new ArrayList();
- toRemove.add(indexPath);
- }
+ public void addResourceEvent(IProject project, ICElement element, IResourceDelta delta) {
+ //Get indexer for this project
+ ICDTIndexer indexer = getIndexerForProject(project);
+
+ if (indexer != null)
+ indexer.addRequest(element, delta);
+ else{
+ //Maybe indexer hasn't been created for this project yet
+ //Scenarios:
+ //1) New Project created - UI has set env var telling which indexer to use
+ //2) Existing Project - the indexer has been persisted to file, need to load it up from CCorePlugin
+
}
- if (toRemove != null)
- for (int i = 0, length = toRemove.size(); i < length; i++)
- this.removeIndex((IPath) toRemove.get(i));
}
- /**
- * Remove the content of the given source folder from the index.
- */
- public void removeSourceFolderFromIndex(IProject project, IPath sourceFolder, char[][] exclusionPatterns) {
-
- if( !isIndexEnabled( project ) )
- return;
-
- if (this.jobEnd > this.jobStart) {
- // check if a job to index the project is not already in the queue
- IndexRequest request = new IndexAllProject(project, this);
- for (int i = this.jobEnd; i > this.jobStart; i--) // NB: don't check job at jobStart, as it may have already started (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=32488)
- if (request.equals(this.awaitingJobs[i])) return;
- }
- this.request(new RemoveFolderFromIndex(sourceFolder, exclusionPatterns, project, this));
- }
/**
- * Flush current state
+ * @param project
+ * @param element
+ * @param delta
*/
- public void reset() {
- super.reset();
- if (this.indexes != null) {
- this.indexes = new HashMap(5);
- this.monitors = new HashMap(5);
- this.indexStates = null;
- this.encounteredHeaders = null;
- }
-
- if (this.timeoutThread == null){
- this.timeoutThread = new ParserTimeOut("Indexer TimeOut Thread"); //$NON-NLS-1$
- this.timeoutThread.setThreadPriority(Thread.MAX_PRIORITY);
-
- Preferences prefs = CCorePlugin.getDefault().getPluginPreferences();
- prefs.setDefault(SourceIndexer.CDT_INDEXER_TIMEOUT,20000);
- }
+ public void removeResourceEvent(IProject project, ICElement element, IResourceDelta delta) {
+ //Get the indexer for this project
+ ICDTIndexer indexer = null;
+ indexer = (ICDTIndexer) indexerMap.get(project);
- this.indexNames = new SimpleLookupTable();
- this.cCorePluginLocation = null;
-
- indexModelListener = IndexerModelListener.getDefault();
-
+ if (indexer != null)
+ indexer.removeRequest(element, delta);
}
- public void saveIndex(IIndex index) throws IOException {
- // must have permission to write from the write monitor
- if (index.hasChanged()) {
- if (IndexManager.VERBOSE)
- JobManager.verbose("-> saving index " + index.getIndexFile()); //$NON-NLS-1$
- index.save();
- }
- String indexName = index.getIndexFile().getPath();
- if (this.jobEnd > this.jobStart) {
- Object indexPath = indexNames.keyForValue(indexName);
- if (indexPath != null) {
- for (int i = this.jobEnd; i > this.jobStart; i--) { // skip the current job
- IJob job = this.awaitingJobs[i];
- if (job instanceof IndexRequest)
- if (((IndexRequest) job).indexPath.equals(indexPath)) return;
- }
- }
- }
- updateIndexState(indexName, SAVED_STATE);
- }
+
/**
- * Commit all index memory changes to disk
+ * Name of the background process
*/
- public void saveIndexes() {
- // only save cached indexes... the rest were not modified
- ArrayList toSave = new ArrayList();
- synchronized(this) {
- for (Iterator iter = this.indexes.values().iterator(); iter.hasNext();) {
- Object o = iter.next();
- if (o instanceof IIndex)
- toSave.add(o);
- }
- }
-
- for (int i = 0, length = toSave.size(); i < length; i++) {
- IIndex index = (IIndex) toSave.get(i);
- ReadWriteMonitor monitor = getMonitorFor(index);
- if (monitor == null) continue; // index got deleted since acquired
- try {
- monitor.enterWrite();
- try {
- saveIndex(index);
- } catch(IOException e){
- if (IndexManager.VERBOSE) {
- JobManager.verbose("-> got the following exception while saving:"); //$NON-NLS-1$
- e.printStackTrace();
- }
- //Util.log(e);
- }
- } finally {
- monitor.exitWrite();
- }
- }
- needToSave = false;
+ public String processName(){
+ return org.eclipse.cdt.internal.core.Util.bind("process.name"); //$NON-NLS-1$
}
+
+
public void shutdown() {
- if (IndexManager.VERBOSE)
+ //Send shutdown messages to all indexers
+
+ /*if (IndexManager.VERBOSE)
JobManager.verbose("Shutdown"); //$NON-NLS-1$
//Get index entries for all projects in the workspace, store their absolute paths
IndexSelector indexSelector = new IndexSelector(new CWorkspaceScope(), null, false, this);
@@ -722,220 +267,116 @@ public class IndexManager extends JobManager implements IIndexConstants {
indexModelListener.shutdown();
- this.timeoutThread = null;
+ this.timeoutThread = null;*/
+
+ //Send shutdown notification to all indexers
+ if (indexerMap != null){
+ Set projects = indexerMap.keySet();
+ Iterator i = projects.iterator();
+ while (i.hasNext()){
+ IProject tempProject = (IProject) i.next();
+ ICDTIndexer indexer = (ICDTIndexer) indexerMap.get(tempProject);
+ if (indexer != null)
+ indexer.shutdown();
+ }
+ }
super.shutdown();
}
-
- public String toString() {
- StringBuffer buffer = new StringBuffer(10);
- buffer.append(super.toString());
- buffer.append("In-memory indexes:\n"); //$NON-NLS-1$
- int count = 0;
- for (Iterator iter = this.indexes.values().iterator(); iter.hasNext();) {
- buffer.append(++count).append(" - ").append(iter.next().toString()).append('\n'); //$NON-NLS-1$
- }
- return buffer.toString();
+
+ public IIndexStorage getIndexStorageForIndexer(ICDTIndexer indexer){
+ //For now we have only one index storage format that all indexers are to use
+ return new CIndexStorage(indexer);
}
-
- private char[] readIndexState() {
- try {
- return org.eclipse.cdt.internal.core.Util.getFileCharContent(savedIndexNamesFile, null);
- } catch (IOException ignored) {
- if (IndexManager.VERBOSE)
- JobManager.verbose("Failed to read saved index file names"); //$NON-NLS-1$
- return new char[0];
- }
+
+ public synchronized int getJobStart(){
+ return jobStart;
}
- private void updateIndexState(String indexName, Integer indexState) {
- getIndexStates(); // ensure the states are initialized
- if (indexState != null) {
- if (indexState.equals(indexStates.get(indexName))) return; // not changed
- indexStates.put(indexName, indexState);
- } else {
- if (!indexStates.containsKey(indexName)) return; // did not exist anyway
- indexStates.removeKey(indexName);
- }
-
- BufferedWriter writer = null;
- try {
- writer = new BufferedWriter(new FileWriter(savedIndexNamesFile));
- Object[] indexNames = indexStates.keyTable;
- Object[] states = indexStates.valueTable;
- for (int i = 0, l = states.length; i < l; i++) {
- if (states[i] == SAVED_STATE) {
- writer.write((String) indexNames[i]);
- writer.write('\n');
- }
- }
- } catch (IOException ignored) {
- if (IndexManager.VERBOSE)
- JobManager.verbose("Failed to write saved index file names"); //$NON-NLS-1$
- } finally {
- if (writer != null) {
- try {
- writer.close();
- } catch (IOException e) {}
- }
- }
- if (IndexManager.VERBOSE) {
- String state = "?"; //$NON-NLS-1$
- if (indexState == SAVED_STATE) state = "SAVED"; //$NON-NLS-1$
- else if (indexState == UPDATING_STATE) state = "UPDATING"; //$NON-NLS-1$
- else if (indexState == UNKNOWN_STATE) state = "UNKNOWN"; //$NON-NLS-1$
- else if (indexState == REBUILDING_STATE) state = "REBUILDING"; //$NON-NLS-1$
- JobManager.verbose("-> index state updated to: " + state + " for: "+indexName); //$NON-NLS-1$ //$NON-NLS-2$
- }
+ public synchronized int getJobEnd(){
+ return jobEnd;
}
+
/**
+ * Returns the job at position in the awaiting job queue
+ * @param position
* @return
*/
- public ParserTimeOut getTimeout() {
- // TODO Auto-generated method stub
- return this.timeoutThread ;
+ public synchronized IIndexJob getAwaitingJobAt(int position){
+ return this.awaitingJobs[position];
}
- /* (non-Javadoc)
- * @see org.eclipse.cdt.internal.core.search.processing.JobManager#jobFinishedNotification(org.eclipse.cdt.internal.core.search.processing.IJob)
+
+
+
+
+ /**
+ * Check to see if the indexer associated with this project
+ * requires dependency update notifications
+ * @param resource
+ * @param resource2
*/
- protected void jobFinishedNotification(IJob job) {
-
- if (job instanceof AddCompilationUnitToIndex){
- AddCompilationUnitToIndex tempJob = (AddCompilationUnitToIndex) job;
- jobSet.remove(tempJob.resource.getLocation());
- }
+ public void updateDependencies(IProject project, IResource resource) {
+ ICDTIndexer indexer = getIndexerForProject(project);
+ if (indexer instanceof SourceIndexer)
+ ((SourceIndexer) indexer).updateDependencies(resource);
+
}
- private Boolean loadIndexerEnabledFromCDescriptor(IProject project) throws CoreException {
- // Check if we have the property in the descriptor
- // We pass false since we do not want to create the descriptor if it does not exists.
- ICDescriptor descriptor = CCorePlugin.getDefault().getCProjectDescription(project, false);
- Boolean strBool = null;
- if (descriptor != null) {
- Node child = descriptor.getProjectData(CDT_INDEXER).getFirstChild();
+ public synchronized ICDTIndexer getIndexerForProject(IProject project){
- while (child != null) {
- if (child.getNodeName().equals(INDEXER_ENABLED))
- strBool = Boolean.valueOf(((Element)child).getAttribute(INDEXER_VALUE));
-
-
- child = child.getNextSibling();
- }
- }
+ ICDTIndexer indexer = null;
+ indexer = (ICDTIndexer) indexerMap.get(project);
- return strBool;
- }
- private Integer loadIndexerProblemsEnabledFromCDescriptor(IProject project) throws CoreException {
- // we are only checking for the settings do not create the descriptor.
- ICDescriptor descriptor = CCorePlugin.getDefault().getCProjectDescription(project, false);
- Integer strInt = null;
- if( descriptor != null ){
- Node child = descriptor.getProjectData(CDT_INDEXER).getFirstChild();
-
- while (child != null) {
- if (child.getNodeName().equals(INDEXER_PROBLEMS_ENABLED)){
- String val = ((Element)child).getAttribute(INDEXER_PROBLEMS_VALUE);
- try{
- strInt = Integer.valueOf( val );
- } catch( NumberFormatException e ){
- //some old projects might have a boolean stored, translate that into just preprocessors
- Boolean bool = Boolean.valueOf( val );
- if( bool.booleanValue() )
- strInt = new Integer( IndexManager.PREPROCESSOR_PROBLEMS_BIT );
- else
- strInt = new Integer( 0 );
- }
- break;
- }
- child = child.getNextSibling();
- }
- }
-
- return strInt;
- }
-
- static private class RemoveIndexMarkersJob extends Job{
- private final IResource resource;
- public RemoveIndexMarkersJob( IResource resource, String name ){
- super( name );
- this.resource = resource;
- }
- protected IStatus run(IProgressMonitor monitor) {
+ if (indexer == null){
+ String indexerID = null;
try {
- resource.deleteMarkers( ICModelMarker.INDEXER_MARKER, true, IResource.DEPTH_INFINITE );
- } catch (CoreException e) {
- return Status.CANCEL_STATUS;
- }
- return Status.OK_STATUS;
- }
-
- }
-
- public void removeIndexerProblems( IResource resource){
- String jobName = "remove markers"; //$NON-NLS-1$
- RemoveIndexMarkersJob job = new RemoveIndexMarkersJob( resource, jobName );
- job.setRule( resource );
- job.setPriority( Job.DECORATE );
- job.schedule();
- }
-
- public void addIndexChangeListener(IIndexChangeListener listener) {
- synchronized(indexChangeListeners) {
- if (!indexChangeListeners.contains(listener)) {
- indexChangeListeners.add(listener);
- }
- }
- }
-
- public void removeIndexChangeListener(IIndexChangeListener listener) {
- synchronized(indexChangeListeners) {
- int i = indexChangeListeners.indexOf(listener);
- if (i != -1) {
- indexChangeListeners.remove(i);
- }
- }
- }
- /**
- * @param indexDelta
- */
- public void notifyListeners(IndexDelta indexDelta) {
- final IndexChangeEvent indexEvent = new IndexChangeEvent(indexDelta);
- for (int i= 0; i < indexChangeListeners.size(); i++) {
- IIndexChangeListener tempListener = null;
- synchronized(indexChangeListeners){
- tempListener = (IIndexChangeListener) indexChangeListeners.get(i);
- }
- final IIndexChangeListener listener = tempListener;
- long start = -1;
- if (VERBOSE) {
- System.out.print("Listener #" + (i+1) + "=" + listener.toString());//$NON-NLS-1$//$NON-NLS-2$
- start = System.currentTimeMillis();
- }
-
- // wrap callbacks with Safe runnable for subsequent listeners to be called when some are causing grief
- Job job = new Job(INDEX_NOTIFICATION_NAME){
- protected IStatus run(IProgressMonitor monitor) {
- Platform.run(new ISafeRunnable() {
- public void handleException(Throwable exception) {
- CCorePlugin.log(exception);
- }
- public void run() throws Exception {
- listener.indexChanged(indexEvent);
- }
- });
-
- return Status.OK_STATUS;
- }
- };
-
- job.schedule();
- if (VERBOSE) {
- System.out.println(" -> " + (System.currentTimeMillis()-start) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$
- }
+ //Indexer has not been created yet for this session
+ //Check to see if the indexer has been set in a session property
+ indexerID = (String) project.getSessionProperty(indexerIDKey);
+ } catch (CoreException e) {}
+
+ if (indexerID == null){
+ try{
+ //Need to load the indexer from descriptor
+ indexerID = loadIndexerIDFromCDescriptor(project);
+ } catch (CoreException e){}
}
-
+
+ //Make sure that we have an indexer ID
+ if (indexerID == null)
+ return null;
+
+ //Create the indexer and store it
+ indexer = getIndexer(indexerID);
+ indexerMap.put(project,indexer);
+
}
-
+ return indexer;
+ }
+
+ protected ICDTIndexer getIndexer(String indexerId) {
+ CDTIndexer configElement = (CDTIndexer) contributedIndexerMap.get(indexerId);
+ if (configElement != null) {
+ try {
+ return configElement.getIndexer();
+ } catch (CoreException e) {}
+ }
+ return null;
+ }
+
+ protected void notifyIdle(long idlingTime) {
+ //Notify all indexers
+ if (indexerMap == null)
+ return;
+
+ Set mapKeys = indexerMap.keySet();
+ Iterator i = mapKeys.iterator();
+ while (i.hasNext()){
+ IProject tempProject = (IProject) i.next();
+ ICDTIndexer indexer = (ICDTIndexer) indexerMap.get(tempProject);
+ indexer.notifyIdle(idlingTime);
+ }
+ }
+
+
}
-
-
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexerModelListener.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexerModelListener.java
index 632552d792..6789b092ef 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexerModelListener.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexerModelListener.java
@@ -10,12 +10,14 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.search.indexing;
+import org.eclipse.cdt.core.index.ICDTIndexer;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ElementChangedEvent;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICElementDelta;
import org.eclipse.cdt.core.model.IElementChangedListener;
+import org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer;
import org.eclipse.cdt.internal.core.model.SourceRoot;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@@ -54,6 +56,13 @@ public class IndexerModelListener implements IElementChangedListener {
int kind= delta.getKind();
int flags= delta.getFlags();
ICElement element= delta.getElement();
+ IProject project = element.getCProject().getProject();
+ ICDTIndexer indexer = indexManager.getIndexerForProject(project);
+
+ if (!(indexer instanceof SourceIndexer))
+ return;
+
+ SourceIndexer sourceIndexer = (SourceIndexer) indexer;
switch(kind){
case ICElementDelta.CHANGED:
@@ -69,27 +78,27 @@ public class IndexerModelListener implements IElementChangedListener {
switch(tempResource.getType())
{
case IResource.FILE:
- indexManager.addSource((IFile) tempResource,tempResource.getProject().getFullPath());
+ sourceIndexer.addSource((IFile) tempResource,tempResource.getProject().getFullPath());
break;
case IResource.FOLDER:
tempRootElement = (SourceRoot) getElementSource(element);
if (tempRootElement != null){
IProject theProj = tempResource.getProject();
- indexManager.indexSourceFolder(theProj,tempResource.getFullPath(),tempRootElement.getSourceEntry().fullExclusionPatternChars());
+ sourceIndexer.indexSourceFolder(theProj,tempResource.getFullPath(),tempRootElement.getSourceEntry().fullExclusionPatternChars());
}
break;
case IResource.PROJECT:
- indexManager.indexAll(tempResource.getProject());
+ sourceIndexer.indexAll(tempResource.getProject());
break;
}
} else if( (flags & ICElementDelta.F_REMOVED_PATHENTRY_SOURCE) != 0 ){
IResource tempResource = element.getResource();
- IProject project = tempResource.getProject();
- if( indexManager.indexProblemsEnabled(project) != 0 ){
- indexManager.removeIndexerProblems( tempResource );
+ IProject tempProject = tempResource.getProject();
+ if( sourceIndexer.indexProblemsEnabled(tempProject) != 0 ){
+ sourceIndexer.removeIndexerProblems( tempResource );
}
}
break;
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java
index d64bf07334..fcbdc2174a 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java
@@ -40,6 +40,7 @@ import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
public class CoreModel {
@@ -986,4 +987,6 @@ public class CoreModel {
public IndexManager getIndexManager() {
return manager.getIndexManager();
}
+
+
}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java
index bb8b5c9c4c..823e2fbeb4 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java
@@ -1113,6 +1113,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
public IndexManager getIndexManager() {
return this.fDeltaProcessor.indexManager;
}
+
public void deleting(IProject project) {
// discard all indexing jobs for this project
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java
index 1b00bfabed..84d499fa56 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java
@@ -5,7 +5,6 @@ package org.eclipse.cdt.internal.core.model;
* All Rights Reserved.
*/
-
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.IArchive;
@@ -17,7 +16,6 @@ import org.eclipse.cdt.core.model.ICElementDelta;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ISourceRoot;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
-import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceDelta;
@@ -38,7 +36,7 @@ public class DeltaProcessor {
protected CElementDelta fCurrentDelta;
protected IndexManager indexManager = new IndexManager();
-
+
/* The C element that was last created (see createElement(IResource).
* This is used as a stack of C elements (using getParent() to pop it, and
* using the various get*(...) to push it. */
@@ -606,22 +604,8 @@ public class DeltaProcessor {
if (indexManager == null)
return;
-
- switch (element.getElementType()) {
- case ICElement.C_PROJECT :
- this.indexManager.indexAll(element.getCProject().getProject());
- break;
-
- case ICElement.C_CCONTAINER:
- indexManager.indexSourceFolder(element.getCProject().getProject(),element.getPath(),null);
- break;
-
- case ICElement.C_UNIT:
- IFile file = (IFile) delta.getResource();
- IProject filesProject = file.getProject();
- indexManager.addSource(file, filesProject.getFullPath());
- break;
- }
+
+ indexManager.addResourceEvent(element.getCProject().getProject(),element,delta);
}
@@ -630,40 +614,22 @@ public class DeltaProcessor {
if (indexManager == null)
return;
- switch (element.getElementType()) {
- case ICElement.C_PROJECT :
- IPath fullPath = element.getCProject().getProject().getFullPath();
- if( delta.getKind() == IResourceDelta.CHANGED )
- indexManager.discardJobs(fullPath.segment(0));
- indexManager.removeIndexFamily(fullPath);
- // NB: Discarding index jobs belonging to this project was done during PRE_DELETE
- break;
- // NB: Update of index if project is opened, closed, or its c nature is added or removed
- // is done in updateCurrentDeltaAndIndex
-
- case ICElement.C_CCONTAINER:
- indexManager.removeSourceFolderFromIndex(element.getCProject().getProject(),element.getPath(),null);
- break;
-
- case ICElement.C_UNIT:
- IFile file = (IFile) delta.getResource();
- indexManager.remove(file.getFullPath().toString(), file.getProject().getFullPath());
- break;
- }
+ indexManager.removeResourceEvent(element.getCProject().getProject(),element,delta);
}
-
+
private void updateDependencies(ICElement element){
IResource resource = element.getResource();
if (resource == null)
return;
+ IProject project = resource.getProject();
String filename = resource.getName();
- if (CoreModel.isValidHeaderUnitName(resource.getProject(), filename)) {
- indexManager.updateDependencies(resource);
+ if (CoreModel.isValidHeaderUnitName(project, filename)) {
+ indexManager.updateDependencies(project, resource);
}
}
diff --git a/core/org.eclipse.cdt.core/plugin.xml b/core/org.eclipse.cdt.core/plugin.xml
index a799c9cef0..b370be95a0 100644
--- a/core/org.eclipse.cdt.core/plugin.xml
+++ b/core/org.eclipse.cdt.core/plugin.xml
@@ -61,7 +61,7 @@
<!-- =================================================================================== -->
<extension-point id="PathEntryContainerInitializer" name="%PathEntryContainerInitializer" schema="schema/PathEntryContainerInitializer.exsd"/>
<extension-point id="CodeFormatter" name="%CodeFormatter.name" schema="schema/CodeFormatter.exsd"/>
-
+ <extension-point id="CIndexer" name="C/C++ Indexer" schema="schema/CIndexer.exsd"/>
<!-- =================================================================================== -->
<!-- Define the list of the Binary Parser provided by the CDT -->
<!-- =================================================================================== -->
@@ -527,5 +527,20 @@
<extension point="org.eclipse.core.runtime.preferences">
<initializer class="org.eclipse.cdt.internal.core.CCorePreferenceInitializer"/>
</extension>
+ <extension
+ point="org.eclipse.cdt.core.CIndexer">
+ <indexer
+ indexStorageID="org.eclipse.cdt.core.cindexstorage"
+ class="org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer"
+ name="Original C/C++ Indexer"
+ id="org.eclipse.cdt.core.originalsourceindexer">
+ </indexer>
+ </extension>
+ <extension
+ point="org.eclipse.core.runtime.applications">
+ <application>
+ <run class="org.eclipse.cdt.core.index2.IndexRunner"/>
+ </application>
+ </extension>
</plugin>
diff --git a/core/org.eclipse.cdt.core/schema/CIndexer.exsd b/core/org.eclipse.cdt.core/schema/CIndexer.exsd
new file mode 100644
index 0000000000..f5ea1e0a22
--- /dev/null
+++ b/core/org.eclipse.cdt.core/schema/CIndexer.exsd
@@ -0,0 +1,119 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.cdt.core">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.cdt.core" id="CDTIndexer" name="CDT Indexer"/>
+ </appInfo>
+ <documentation>
+ This extension point is used to contribute a new Indexer to the CDT. This indexer can choose to receive event notification from the index manager.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <complexType>
+ <sequence>
+ <element ref="indexer"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="indexer">
+ <complexType>
+ <sequence>
+ <element ref="indexer" minOccurs="1" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="id" type="string" use="required">
+ <annotation>
+ <documentation>
+ a unique name for this indexer
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string" use="required">
+ <annotation>
+ <documentation>
+ a name that will be used for this indexer in the UI
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+ the class that implements &lt;code&gt;org.eclipse.cdt.core.index2.IIndexer&lt;/code&gt;
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java" basedOn="org.eclipse.cdt.core.index2.IIndexer"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ CDT 3.0
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiInfo"/>
+ </appInfo>
+ <documentation>
+ Plug-ins that want to extend this extension point must implement &lt;samp&gt;org.eclipse.cdt.core.index.IIndexer&lt;/samp&gt; interface.
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/core/org.eclipse.cdt.core/search/ChangeLog b/core/org.eclipse.cdt.core/search/ChangeLog
index 0bc129690a..9aadc6a28b 100644
--- a/core/org.eclipse.cdt.core/search/ChangeLog
+++ b/core/org.eclipse.cdt.core/search/ChangeLog
@@ -1,3 +1,6 @@
+2005-03-12 Bogdan Gheorghe
+ Updated search to work with new index framework
+
2004-11-02 Bogdan Gheorghe
Partial Fix for 74427: Indexer needs to store more info
diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/ICSearchConstants.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/ICSearchConstants.java
index 7ea7302bae..0e21a5419d 100644
--- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/ICSearchConstants.java
+++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/ICSearchConstants.java
@@ -187,17 +187,17 @@ public interface ICSearchConstants {
* has not finished indexing the workspace. Results will more likely
* not contain all the matches.
*/
- int FORCE_IMMEDIATE_SEARCH = IJob.ForceImmediate;
+ int FORCE_IMMEDIATE_SEARCH = IIndexJob.ForceImmediate;
/**
* The search operation throws an <code>org.eclipse.core.runtime.OperationCanceledException</code>
* if the underlying indexer has not finished indexing the workspace.
*/
- int CANCEL_IF_NOT_READY_TO_SEARCH = IJob.CancelIfNotReady;
+ int CANCEL_IF_NOT_READY_TO_SEARCH = IIndexJob.CancelIfNotReady;
/**
* The search operation waits for the underlying indexer to finish indexing
* the workspace before starting the search.
*/
- int WAIT_UNTIL_READY_TO_SEARCH = IJob.WaitUntilReady;
+ int WAIT_UNTIL_READY_TO_SEARCH = IIndexJob.WaitUntilReady;
public static final String EXTERNAL_SEARCH_LINK_PREFIX = "cdtlnk"; //$NON-NLS-1$
diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/IndexSelector.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/IndexSelector.java
index f7ec5b0f30..5f2dfe9b4f 100644
--- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/IndexSelector.java
+++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/IndexSelector.java
@@ -12,11 +12,13 @@ package org.eclipse.cdt.internal.core.search;
import java.util.ArrayList;
+import org.eclipse.cdt.core.index.ICDTIndexer;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.internal.core.index.IIndex;
+import org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
@@ -89,7 +91,17 @@ public class IndexSelector {
int count = 0;
for (int i = 0; i < length; i++){
// may trigger some index recreation work
- IIndex index = indexManager.getIndex(indexKeys[i], true /*reuse index file*/, false /*do not create if none*/);
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ ICDTIndexer indexer = indexManager.getIndexerForProject( root.getProject(indexKeys[i].toOSString()));
+
+ IIndex index = null;
+
+ if (indexer != null){
+ if (indexer instanceof SourceIndexer){
+ SourceIndexer sourceIndexer = (SourceIndexer) indexer;
+ index =sourceIndexer.getIndex(indexKeys[i], true /*reuse index file*/, false /*do not create if none*/);
+ }
+ }
if (index != null) indexes[count++] = index; // only consider indexes which are ready yet
}
if (count != length) {
diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/PatternSearchJob.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/PatternSearchJob.java
index 06e2f30126..d199fbeacc 100644
--- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/PatternSearchJob.java
+++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/PatternSearchJob.java
@@ -15,19 +15,22 @@ package org.eclipse.cdt.internal.core.search;
import java.io.IOException;
+import org.eclipse.cdt.core.index.ICDTIndexer;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.internal.core.index.IIndex;
+import org.eclipse.cdt.internal.core.index.impl.Index;
+import org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.cdt.internal.core.search.indexing.ReadWriteMonitor;
import org.eclipse.cdt.internal.core.search.matching.CSearchPattern;
-import org.eclipse.cdt.internal.core.search.processing.IJob;
+import org.eclipse.cdt.internal.core.search.processing.IIndexJob;
import org.eclipse.cdt.internal.core.search.processing.JobManager;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
-public class PatternSearchJob implements IJob {
+public class PatternSearchJob implements IIndexJob {
protected CSearchPattern pattern;
@@ -129,7 +132,17 @@ public class PatternSearchJob implements IJob {
if (index == null)
return COMPLETE;
- ReadWriteMonitor monitor = indexManager.getMonitorFor(index);
+
+ if (!(index instanceof Index))
+ return FAILED;
+
+ ICDTIndexer indexer =((Index) index).getIndexer();
+
+ if (!(indexer instanceof SourceIndexer))
+ return FAILED;
+
+ SourceIndexer sourceIndexer = (SourceIndexer) indexer;
+ ReadWriteMonitor monitor = sourceIndexer.getMonitorFor(index);
if (monitor == null)
return COMPLETE; // index got deleted since acquired
try {
@@ -140,7 +153,7 @@ public class PatternSearchJob implements IJob {
try {
monitor.exitRead(); // free read lock
monitor.enterWrite(); // ask permission to write
- this.indexManager.saveIndex(index);
+ sourceIndexer.saveIndex(index);
} catch (IOException e) {
return FAILED;
} finally {
diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/ClassDeclarationPattern.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/ClassDeclarationPattern.java
index 3ac6bd002c..702f782a29 100644
--- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/ClassDeclarationPattern.java
+++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/ClassDeclarationPattern.java
@@ -28,8 +28,8 @@ import org.eclipse.cdt.internal.core.CharOperation;
import org.eclipse.cdt.internal.core.index.IEntryResult;
import org.eclipse.cdt.internal.core.index.impl.IndexInput;
import org.eclipse.cdt.internal.core.index.impl.IndexedFile;
+import org.eclipse.cdt.internal.core.index.sourceindexer.AbstractIndexer;
import org.eclipse.cdt.internal.core.search.IIndexSearchRequestor;
-import org.eclipse.cdt.internal.core.search.indexing.AbstractIndexer;
/**
diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/DerivedTypesPattern.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/DerivedTypesPattern.java
index 00997a2ce5..44701f8352 100644
--- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/DerivedTypesPattern.java
+++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/DerivedTypesPattern.java
@@ -23,7 +23,7 @@ import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
import org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
-import org.eclipse.cdt.internal.core.search.indexing.AbstractIndexer;
+import org.eclipse.cdt.internal.core.index.sourceindexer.AbstractIndexer;
/**
* @author bgheorgh
diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FieldDeclarationPattern.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FieldDeclarationPattern.java
index c19e1b6fc6..c4a79d2270 100644
--- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FieldDeclarationPattern.java
+++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FieldDeclarationPattern.java
@@ -29,8 +29,8 @@ import org.eclipse.cdt.internal.core.CharOperation;
import org.eclipse.cdt.internal.core.index.IEntryResult;
import org.eclipse.cdt.internal.core.index.impl.IndexInput;
import org.eclipse.cdt.internal.core.index.impl.IndexedFile;
+import org.eclipse.cdt.internal.core.index.sourceindexer.AbstractIndexer;
import org.eclipse.cdt.internal.core.search.IIndexSearchRequestor;
-import org.eclipse.cdt.internal.core.search.indexing.AbstractIndexer;
/**
diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FriendPattern.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FriendPattern.java
index bf1255bd06..d7d001a87d 100644
--- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FriendPattern.java
+++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FriendPattern.java
@@ -22,7 +22,7 @@ import java.util.Iterator;
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier;
-import org.eclipse.cdt.internal.core.search.indexing.AbstractIndexer;
+import org.eclipse.cdt.internal.core.index.sourceindexer.AbstractIndexer;
/**
* @author bgheorgh
diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/IncludePattern.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/IncludePattern.java
index a349775931..7392a9f5af 100644
--- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/IncludePattern.java
+++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/IncludePattern.java
@@ -19,8 +19,8 @@ import org.eclipse.cdt.internal.core.CharOperation;
import org.eclipse.cdt.internal.core.index.IEntryResult;
import org.eclipse.cdt.internal.core.index.impl.IndexInput;
import org.eclipse.cdt.internal.core.index.impl.IndexedFile;
+import org.eclipse.cdt.internal.core.index.sourceindexer.AbstractIndexer;
import org.eclipse.cdt.internal.core.search.IIndexSearchRequestor;
-import org.eclipse.cdt.internal.core.search.indexing.AbstractIndexer;
/**
* @author bgheorgh
diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MacroDeclarationPattern.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MacroDeclarationPattern.java
index 22b4f15434..3db3806e9f 100644
--- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MacroDeclarationPattern.java
+++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MacroDeclarationPattern.java
@@ -23,8 +23,8 @@ import org.eclipse.cdt.internal.core.CharOperation;
import org.eclipse.cdt.internal.core.index.IEntryResult;
import org.eclipse.cdt.internal.core.index.impl.IndexInput;
import org.eclipse.cdt.internal.core.index.impl.IndexedFile;
+import org.eclipse.cdt.internal.core.index.sourceindexer.AbstractIndexer;
import org.eclipse.cdt.internal.core.search.IIndexSearchRequestor;
-import org.eclipse.cdt.internal.core.search.indexing.AbstractIndexer;
/**
* @author aniefer
diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MethodDeclarationPattern.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MethodDeclarationPattern.java
index 36143ab15a..9b2e331ff9 100644
--- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MethodDeclarationPattern.java
+++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MethodDeclarationPattern.java
@@ -25,8 +25,8 @@ import org.eclipse.cdt.internal.core.CharOperation;
import org.eclipse.cdt.internal.core.index.IEntryResult;
import org.eclipse.cdt.internal.core.index.impl.IndexInput;
import org.eclipse.cdt.internal.core.index.impl.IndexedFile;
+import org.eclipse.cdt.internal.core.index.sourceindexer.AbstractIndexer;
import org.eclipse.cdt.internal.core.search.IIndexSearchRequestor;
-import org.eclipse.cdt.internal.core.search.indexing.AbstractIndexer;
/**
* @author aniefer
diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/NamespaceDeclarationPattern.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/NamespaceDeclarationPattern.java
index f8abbf1c50..5c0225e491 100644
--- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/NamespaceDeclarationPattern.java
+++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/NamespaceDeclarationPattern.java
@@ -22,8 +22,8 @@ import org.eclipse.cdt.internal.core.CharOperation;
import org.eclipse.cdt.internal.core.index.IEntryResult;
import org.eclipse.cdt.internal.core.index.impl.IndexInput;
import org.eclipse.cdt.internal.core.index.impl.IndexedFile;
+import org.eclipse.cdt.internal.core.index.sourceindexer.AbstractIndexer;
import org.eclipse.cdt.internal.core.search.IIndexSearchRequestor;
-import org.eclipse.cdt.internal.core.search.indexing.AbstractIndexer;
/**
* @author aniefer
diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/processing/IJob.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/processing/IIndexJob.java
index b516970179..411610efda 100644
--- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/processing/IJob.java
+++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/processing/IIndexJob.java
@@ -13,12 +13,9 @@
*/
package org.eclipse.cdt.internal.core.search.processing;
-/**
- * @author bgheorgh
- */
import org.eclipse.core.runtime.IProgressMonitor;
-public interface IJob {
+public interface IIndexJob {
/* Waiting policies */
int ForceImmediate = 1;
@@ -30,20 +27,20 @@ public interface IJob {
boolean COMPLETE = true;
/**
- * True if job belongs to the passed in jobFamily
+ * True if index job belongs to the passed in jobFamily
*/
public boolean belongsTo(String jobFamily);
/**
- * Asks this job to cancel its execution. The cancellation
+ * Asks this index job to cancel its execution. The cancellation
* can take an undertermined amount of time.
*/
public void cancel();
/**
- * Execute the current job, answer whether it was successful.
+ * Execute the current index job, answer whether it was successful.
*/
public boolean execute(IProgressMonitor progress);
/**
- * Answer whether the job is ready to run.
+ * Answer whether the index job is ready to run.
*/
public boolean isReadyToRun();
diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/processing/JobManager.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/processing/JobManager.java
index b2a6109a8e..1ac23d5883 100644
--- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/processing/JobManager.java
+++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/processing/JobManager.java
@@ -13,11 +13,9 @@
*/
package org.eclipse.cdt.internal.core.search.processing;
-import java.util.HashSet;
-
import org.eclipse.cdt.core.ICLogConstants;
import org.eclipse.cdt.internal.core.Util;
-import org.eclipse.cdt.internal.core.search.indexing.IndexRequest;
+import org.eclipse.cdt.internal.core.index.sourceindexer.IndexRequest;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
@@ -27,7 +25,7 @@ import org.eclipse.core.runtime.SubProgressMonitor;
public abstract class JobManager implements Runnable {
/* queue of jobs to execute */
- protected IJob[] awaitingJobs = new IJob[10];
+ protected IIndexJob[] awaitingJobs = new IIndexJob[10];
protected int jobStart = 0;
protected int jobEnd = -1;
protected boolean executing = false;
@@ -47,8 +45,6 @@ public abstract class JobManager implements Runnable {
private int awaitingClients = 0;
- protected HashSet jobSet;
-
protected IndexingJob indexJob = null;
static private final IStatus OK_STATUS = new Status( IStatus.OK, "org.eclipse.cdt.core", IStatus.OK, "", null ); //$NON-NLS-1$//$NON-NLS-2$
@@ -87,7 +83,7 @@ public abstract class JobManager implements Runnable {
* Answers the first job in the queue, or null if there is no job available
* Until the job has completed, the job manager will keep answering the same job.
*/
- public synchronized IJob currentJob() {
+ public synchronized IIndexJob currentJob() {
if ( enabled != ENABLED )
return null;
@@ -114,7 +110,7 @@ public abstract class JobManager implements Runnable {
int oldEnabledState = 0;
try {
- IJob currentJob;
+ IIndexJob currentJob;
// cancel current job if it belongs to the given family
synchronized(this){
currentJob = this.currentJob();
@@ -208,7 +204,7 @@ public abstract class JobManager implements Runnable {
}
if( indexJob != null ){
String progressString = null;
- IJob job = currentJob();
+ IIndexJob job = currentJob();
if( job instanceof IndexRequest ){
progressString = " ("; //$NON-NLS-1$
progressString += job.toString();
@@ -241,23 +237,23 @@ public abstract class JobManager implements Runnable {
*
*/
public boolean performConcurrentJob(
- IJob searchJob,
+ IIndexJob searchJob,
int waitingPolicy,
IProgressMonitor progress,
- IJob jobToIgnore) {
+ IIndexJob jobToIgnore) {
if (VERBOSE)
JobManager.verbose("STARTING concurrent job - " + searchJob); //$NON-NLS-1$
if (!searchJob.isReadyToRun()) {
if (VERBOSE)
JobManager.verbose("ABORTED concurrent job - " + searchJob); //$NON-NLS-1$
- return IJob.FAILED;
+ return IIndexJob.FAILED;
}
int concurrentJobWork = 100;
if (progress != null)
progress.beginTask("", concurrentJobWork); //$NON-NLS-1$
- boolean status = IJob.FAILED;
+ boolean status = IIndexJob.FAILED;
if (awaitingJobsCount() > 0) {
if( enabledState() == WAITING ){
//the indexer is paused, resume now that we have been asked for something
@@ -268,7 +264,7 @@ public abstract class JobManager implements Runnable {
attemptPolicy = false;
switch (waitingPolicy) {
- case IJob.ForceImmediate :
+ case IIndexJob.ForceImmediate :
if (VERBOSE)
JobManager.verbose("-> NOT READY - forcing immediate - " + searchJob);//$NON-NLS-1$
boolean wasEnabled = ( enabledState() == ENABLED );
@@ -284,7 +280,7 @@ public abstract class JobManager implements Runnable {
JobManager.verbose("FINISHED concurrent job - " + searchJob); //$NON-NLS-1$
return status;
- case IJob.CancelIfNotReady :
+ case IIndexJob.CancelIfNotReady :
if (VERBOSE)
JobManager.verbose("-> NOT READY - cancelling - " + searchJob); //$NON-NLS-1$
if (progress != null) progress.setCanceled(true);
@@ -292,10 +288,10 @@ public abstract class JobManager implements Runnable {
JobManager.verbose("CANCELED concurrent job - " + searchJob); //$NON-NLS-1$
throw new OperationCanceledException();
- case IJob.WaitUntilReady :
+ case IIndexJob.WaitUntilReady :
int awaitingWork;
- IJob previousJob = null;
- IJob currentJob;
+ IIndexJob previousJob = null;
+ IIndexJob currentJob;
IProgressMonitor subProgress = null;
int totalWork = this.awaitingJobsCount();
if (progress != null && totalWork > 0) {
@@ -333,7 +329,7 @@ public abstract class JobManager implements Runnable {
if( enabledState() == WAITING ){
//user canceled the index we are waiting on, force immediate
- waitingPolicy = IJob.ForceImmediate;
+ waitingPolicy = IIndexJob.ForceImmediate;
attemptPolicy = true;
continue policy;
}
@@ -372,7 +368,7 @@ public abstract class JobManager implements Runnable {
* @param jobToIgnore
* @return
*/
- private boolean jobShouldBeIgnored(IJob jobToIgnore) {
+ private boolean jobShouldBeIgnored(IIndexJob jobToIgnore) {
if (jobToIgnore == null)
return false;
@@ -384,7 +380,7 @@ public abstract class JobManager implements Runnable {
public abstract String processName();
- public synchronized void request(IJob job) {
+ public synchronized void request(IIndexJob job) {
if (!job.isReadyToRun()) {
if (VERBOSE)
JobManager.verbose("ABORTED request of background job - " + job); //$NON-NLS-1$
@@ -398,7 +394,7 @@ public abstract class JobManager implements Runnable {
System.arraycopy(
awaitingJobs,
jobStart,
- (awaitingJobs = new IJob[size * 2]),
+ (awaitingJobs = new IIndexJob[size * 2]),
0,
jobEnd);
jobStart = 0;
@@ -435,11 +431,10 @@ public abstract class JobManager implements Runnable {
thread = new Thread(this, this.processName());
thread.setDaemon(true);
// less prioritary by default, priority is raised if clients are actively waiting on it
- thread.setPriority(Thread.NORM_PRIORITY-1);
+ thread.setPriority(Thread.MIN_PRIORITY);
thread.start();
}
- jobSet = new HashSet();
}
/**
@@ -452,7 +447,7 @@ public abstract class JobManager implements Runnable {
try {
while (this.thread != null) {
try {
- IJob job;
+ IIndexJob job;
if ((job = currentJob()) == null) {
if (idlingStart < 0)
idlingStart = System.currentTimeMillis();
@@ -548,6 +543,6 @@ public abstract class JobManager implements Runnable {
return buffer.toString();
}
- protected abstract void jobFinishedNotification(IJob job);
+ protected abstract void jobFinishedNotification(IIndexJob job);
}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java
index 76ee1d7a10..cb15ae8ed0 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java
@@ -31,13 +31,13 @@ import org.eclipse.cdt.core.search.SearchEngine;
import org.eclipse.cdt.internal.core.CDTLogWriter;
import org.eclipse.cdt.internal.core.CDescriptorManager;
import org.eclipse.cdt.internal.core.PathEntryVariableManager;
+import org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexerRunner;
import org.eclipse.cdt.internal.core.model.BufferManager;
import org.eclipse.cdt.internal.core.model.CModelManager;
import org.eclipse.cdt.internal.core.model.DeltaProcessor;
import org.eclipse.cdt.internal.core.model.IBufferFactory;
import org.eclipse.cdt.internal.core.model.Util;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
-import org.eclipse.cdt.internal.core.search.indexing.SourceIndexer;
import org.eclipse.cdt.internal.core.search.matching.MatchLocator;
import org.eclipse.cdt.internal.core.search.processing.JobManager;
import org.eclipse.core.resources.IProject;
@@ -889,7 +889,7 @@ public class CCorePlugin extends Plugin {
} //$NON-NLS-1$
option = Platform.getDebugOption(INDEXER);
- if(option != null) SourceIndexer.VERBOSE = option.equalsIgnoreCase("true") ; //$NON-NLS-1$
+ if(option != null) SourceIndexerRunner.VERBOSE = option.equalsIgnoreCase("true") ; //$NON-NLS-1$
option = Platform.getDebugOption(SEARCH);
if(option != null) SearchEngine.VERBOSE = option.equalsIgnoreCase("true") ; //$NON-NLS-1$
diff --git a/core/org.eclipse.cdt.ui.tests/ChangeLog b/core/org.eclipse.cdt.ui.tests/ChangeLog
index 923bda4516..30736fd805 100644
--- a/core/org.eclipse.cdt.ui.tests/ChangeLog
+++ b/core/org.eclipse.cdt.ui.tests/ChangeLog
@@ -1,3 +1,6 @@
+2005-03-13 Bogdan Gheorghe
+ Updated references to IndexManager to reflect new indexing framework.
+
2005-02-03 Tanya Wolff
Fixed some content assist regression tests.
Added Regression tests (content assist, refactoring) to automated suite for nightly builds
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist/CompletionProposalsBaseTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist/CompletionProposalsBaseTest.java
index a176868945..10de097a7a 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist/CompletionProposalsBaseTest.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist/CompletionProposalsBaseTest.java
@@ -100,8 +100,7 @@ public abstract class CompletionProposalsBaseTest extends TestCase{
}
// use the new indexer
- IndexManager indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager();
- indexManager.reset();
+ //IndexManager indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager();
}
private static void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException {
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist/ContentAssistTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist/ContentAssistTests.java
index a0589aeec2..86d0a7638b 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist/ContentAssistTests.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist/ContentAssistTests.java
@@ -30,7 +30,7 @@ import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.core.testplugin.FileManager;
-import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
+import org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer;
import org.eclipse.cdt.internal.ui.CHelpProviderManager;
import org.eclipse.cdt.internal.ui.text.CHelpBookDescriptor;
import org.eclipse.cdt.internal.ui.text.contentassist.CCompletionProcessor;
@@ -65,7 +65,7 @@ public class ContentAssistTests extends TestCase {
cPrj = CProjectHelper.createCCProject("ContentAssistTestProject", "bin"); //$NON-NLS-1$ //$NON-NLS-2$
project = cPrj.getProject();
- project.setSessionProperty(IndexManager.activationKey,new Boolean(false));
+ project.setSessionProperty(SourceIndexer.activationKey,new Boolean(false));
} catch ( CoreException e ) {
/*boo*/
}
diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog
index af8dcee828..eaa454fa9c 100644
--- a/core/org.eclipse.cdt.ui/ChangeLog
+++ b/core/org.eclipse.cdt.ui/ChangeLog
@@ -1,3 +1,14 @@
+2005-03-13 Bogdan Gheorghe
+ New UI items to support index framework
+
+ * src/org/eclipse/cdt/internal/ui/CPluginResources
+ * src/org/eclipse/cdt/ui/CUIPreferenceInitializer.java
+ * src/org/eclipse/cdt/internal/ui/dialogs/IndexerBlock.java
+ * src/org/eclipse/cdt/internal/ui/dialogs/IndexerOptionPropertyPage.java
+ * src/org/eclipse/cdt/internal/ui/dialogs/SourceIndexerBlock.java
+ * src/org/eclipse/cdt/ui/index/AbstractIndexerPage
+ * plugin.xml
+
2005-03-12 Alain Magloire
Plan item 79518: for PathEntry variable manager. Enable.
* src/org/eclipse/cdt/internal/ui/preferences/PathEntryVariablesGroup.java
diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml
index c5d881d266..27fe7fe1e8 100644
--- a/core/org.eclipse.cdt.ui/plugin.xml
+++ b/core/org.eclipse.cdt.ui/plugin.xml
@@ -44,6 +44,7 @@
<!-- Purpose: Provide a perspective specific text hovering for CEditor files -->
<!-- =========================================================================== -->
<extension-point id="textHovers" name="%textHoversName"/>
+ <extension-point id="IndexerPage" name="Indexer Page" schema="schema/IndexerPage.exsd"/>
<extension-point id="completionContributors" name="%completionContributors" schema="schema/completionContributors.exsd"/>
<extension
@@ -617,11 +618,6 @@
id="org.eclipse.cdt.ui.preferences.CFileTypesPreferences">
</page>
<page
- class="org.eclipse.cdt.internal.ui.preferences.CSearchPreferencePage"
- category="org.eclipse.cdt.ui.preferences.CPluginPreferencePage"
- name="%CDTSearch.name"
- id="org.eclipse.cdt.ui.preferences.CSearchPreferencePage"/>
- <page
name="%appearancePrefName"
category="org.eclipse.cdt.ui.preferences.CPluginPreferencePage"
class="org.eclipse.cdt.internal.ui.preferences.AppearancePreferencePage"
@@ -1324,13 +1320,20 @@
file="templates/default-templates.xml">
</include>
</extension>
-
<extension
+ point="org.eclipse.cdt.ui.IndexerPage">
+ <indexerUI
+ class="org.eclipse.cdt.ui.dialogs.SourceIndexerBlock"
+ indexerID="org.eclipse.cdt.core.originalsourceindexer"
+ name="Original C/C++ Indexer"
+ id="org.eclipse.cdt.ui.originalSourceIndexerUI"/>
+ </extension>
+ <extension
point="org.eclipse.cdt.ui.completionContributors">
<contributor
class="org.eclipse.cdt.internal.ui.text.contentassist.DOMCompletionContributor"
id="DOM"
priority="1"/>
- </extension>
-
+ </extension>
+
</plugin>
diff --git a/core/org.eclipse.cdt.ui/schema/IndexerPage.exsd b/core/org.eclipse.cdt.ui/schema/IndexerPage.exsd
new file mode 100644
index 0000000000..aef18ad547
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/schema/IndexerPage.exsd
@@ -0,0 +1,123 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.cdt.ui">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.cdt.ui" id="IndexerPage" name="Indexer Page"/>
+ </appInfo>
+ <documentation>
+ [Enter description of this extension point.]
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <complexType>
+ <sequence>
+ <element ref="indexerUI" minOccurs="1" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="indexerUI">
+ <complexType>
+ <attribute name="id" type="string" use="required">
+ <annotation>
+ <documentation>
+ a unique id for this indexer page
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string" use="required">
+ <annotation>
+ <documentation>
+ a UI name for this page to be used in the UI
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="indexerID" type="string" use="required">
+ <annotation>
+ <documentation>
+ the unique id of the indexer that this UI is associated with
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+ the class that implements &lt;code&gt;org.eclipse.cdt.ui.index2.AbstractIndexerPage&lt;/code&gt;
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiInfo"/>
+ </appInfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties
index 523fb57359..71df494f40 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties
@@ -38,8 +38,9 @@ ErrorParserBlock.desc=Set the error parsers for this project
BinaryParserBlock.label=Binary Parser
BinaryParserBlock.desc=Set required binary parser for this project
-IndexerBlock.label=C/C++ Indexer
-IndexerBlock.desc=C/C++ Indexer setting for this project.
+BaseIndexerBlock.label=C/C++ Indexer
+BaseIndexerBlock.desc=C/C++ Indexer setting for this project.
+BaseIndexerBlock.comboLabel=Available indexers
ReferenceBlock.label= Projects
ReferenceBlock.desc= Referenced C/C++ Projects
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CSearchPreferencePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CSearchPreferencePage.java
deleted file mode 100644
index d54801e3a4..0000000000
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CSearchPreferencePage.java
+++ /dev/null
@@ -1,191 +0,0 @@
-/**********************************************************************
-Copyright (c) 2002, 2004 IBM Rational Software and others.
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Common Public License v1.0
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/cpl-v10.html
-
-Contributors:
- IBM Rational Software - Initial Contribution
-**********************************************************************/
-
-package org.eclipse.cdt.internal.ui.preferences;
-
-import java.util.ArrayList;
-
-import org.eclipse.cdt.core.CCorePlugin;
-import org.eclipse.cdt.internal.core.search.indexing.SourceIndexer;
-import org.eclipse.cdt.internal.ui.search.CSearchPage;
-import org.eclipse.cdt.ui.CUIPlugin;
-import org.eclipse.cdt.utils.ui.controls.ControlFactory;
-import org.eclipse.core.runtime.Preferences;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.preference.PreferencePage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPreferencePage;
-
-public class CSearchPreferencePage extends PreferencePage
- implements
- IWorkbenchPreferencePage {
-
- private Combo fExternLinks;
- private Button fExternEnabled;
-
- protected OverlayPreferenceStore fOverlayStore;
- private Text fTextControl;
-
- private static final String TIMEOUT_VALUE = "20000"; //$NON-NLS-1$
-
- public CSearchPreferencePage(){
- setPreferenceStore(CUIPlugin.getDefault().getPreferenceStore());
- fOverlayStore = createOverlayStore();
- }
-
- private OverlayPreferenceStore createOverlayStore() {
- ArrayList overlayKeys = new ArrayList();
- overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, CSearchPage.EXTERNALMATCH_ENABLED));
- overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.INT, CSearchPage.EXTERNALMATCH_VISIBLE));
- overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, SourceIndexer.CDT_INDEXER_TIMEOUT));
-
- OverlayPreferenceStore.OverlayKey[] keys = new OverlayPreferenceStore.OverlayKey[overlayKeys.size()];
- overlayKeys.toArray(keys);
- return new OverlayPreferenceStore(getPreferenceStore(), keys);
- }
-
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
- */
- protected Control createContents(Composite parent) {
- fOverlayStore.load();
- fOverlayStore.start();
-
- initializeDialogUnits(parent);
-
- Composite result= new Composite(parent, SWT.NONE);
- GridLayout layout= new GridLayout();
- layout.marginHeight= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
- layout.marginWidth= 0;
- layout.verticalSpacing= convertVerticalDLUsToPixels(10);
- layout.horizontalSpacing= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
- result.setLayout(layout);
-
- Group indexerTimeoutGroup= new Group(result, SWT.NONE);
- indexerTimeoutGroup.setLayout(new GridLayout());
- indexerTimeoutGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- indexerTimeoutGroup.setText(PreferencesMessages.getString("CSearchPreferences.IndexerTimeout.IndexerTimeoutGroup")); //$NON-NLS-1$
-
- fTextControl = (Text) addTextField( indexerTimeoutGroup, PreferencesMessages.getString("CSearchPreferences.IndexerTimeout.Timeout"),"TimeOut",6,0,true); //$NON-NLS-1$ //$NON-NLS-2$
-
- initialize();
-
- return result;
-
- }
-
- private void initialize(){
- fTextControl.setText(fOverlayStore.getString(SourceIndexer.CDT_INDEXER_TIMEOUT));
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
- */
- public void init(IWorkbench workbench) {
- // TODO Auto-generated method stub
- }
-
- /**
- * Creates a button with the given label and sets the default
- * configuration data.
- */
- private Combo createComboBox( Composite parent, String label, String[] items, String selection )
- {
- ControlFactory.createLabel( parent, label );
- Combo combo = ControlFactory.createSelectCombo( parent, items, selection );
- combo.setLayoutData( new GridData() );
- return combo;
- }
- /**
- * Creates a button with the given label and sets the default
- * configuration data.
- */
- private Button createCheckButton( Composite parent, String label )
- {
- Button button = new Button( parent, SWT.CHECK | SWT.LEFT );
- button.setText( label );
- // FieldEditor GridData
- GridData data = new GridData();
- button.setLayoutData( data );
- return button;
- }
-
- private Control addTextField(Composite composite, String label, String key, int textLimit, int indentation, boolean isNumber) {
-
- Label labelControl = new Label(composite, SWT.NONE);
- labelControl.setText(label);
- GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
- gd.horizontalIndent = indentation;
- labelControl.setLayoutData(gd);
-
- Text textControl = new Text(composite, SWT.BORDER | SWT.SINGLE);
- gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
- gd.widthHint = convertWidthInCharsToPixels(textLimit + 1);
- textControl.setLayoutData(gd);
- textControl.setTextLimit(textLimit);
-
- return textControl;
- }
-
- /*
- * @see IPreferencePage#performOk()
- */
- public boolean performOk() {
-
- String timeOut = fTextControl.getText();
- try {
- // Check the string number
- Integer.parseInt(timeOut);
- } catch (NumberFormatException ex){
- timeOut = TIMEOUT_VALUE;
- }
-
- fOverlayStore.setValue(SourceIndexer.CDT_INDEXER_TIMEOUT, timeOut);
- fOverlayStore.propagate();
-
-// Store IProblem Marker value in CCorePlugin Preferences
- Preferences prefs = CCorePlugin.getDefault().getPluginPreferences();
-
- prefs.setValue(SourceIndexer.CDT_INDEXER_TIMEOUT,timeOut);
- CCorePlugin.getDefault().savePluginPreferences();
-
- return true;
- }
-
- /**
- * @param store
- */
- public static void initDefaults(IPreferenceStore store) {
- store.setDefault(SourceIndexer.CDT_INDEXER_TIMEOUT,TIMEOUT_VALUE);
- }
-
- /*
- * @see PreferencePage#performDefaults()
- */
- protected void performDefaults() {
- fOverlayStore.loadDefaults();
- initialize();
- super.performDefaults();
- }
-
-}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/WorkInProgressPreferencePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/WorkInProgressPreferencePage.java
deleted file mode 100644
index d26db4fb86..0000000000
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/WorkInProgressPreferencePage.java
+++ /dev/null
@@ -1,210 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-/*
- * Created on Mar 30, 2004
- *
- * TODO To change the template for this generated file go to
- * Window - Preferences - Java - Code Generation - Code and Comments
- */
-package org.eclipse.cdt.internal.ui.preferences;
-
-import java.util.ArrayList;
-
-import org.eclipse.cdt.core.CCorePlugin;
-import org.eclipse.cdt.core.browser.AllTypesCache;
-import org.eclipse.cdt.internal.core.search.indexing.SourceIndexer;
-import org.eclipse.cdt.internal.ui.search.CSearchPage;
-import org.eclipse.cdt.ui.CUIPlugin;
-import org.eclipse.cdt.utils.ui.controls.ControlFactory;
-import org.eclipse.core.runtime.Preferences;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.preference.PreferencePage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPreferencePage;
-
-/**
- * @author bgheorgh
- *
- * TODO To change the template for this generated type comment go to
- * Window - Preferences - Java - Code Generation - Code and Comments
- */
-public class WorkInProgressPreferencePage extends PreferencePage
- implements
- IWorkbenchPreferencePage {
-
- private Button fBackgroundTypeCacheEnabled;
- protected OverlayPreferenceStore fOverlayStore;
-
- public WorkInProgressPreferencePage(){
- setPreferenceStore(CUIPlugin.getDefault().getPreferenceStore());
- fOverlayStore = createOverlayStore();
- }
-
- private OverlayPreferenceStore createOverlayStore() {
- ArrayList overlayKeys = new ArrayList();
- overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, CSearchPage.EXTERNALMATCH_ENABLED));
- overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.INT, CSearchPage.EXTERNALMATCH_VISIBLE));
- overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, SourceIndexer.CDT_INDEXER_TIMEOUT));
- overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AllTypesCache.ENABLE_BACKGROUND_TYPE_CACHE));
-
- OverlayPreferenceStore.OverlayKey[] keys = new OverlayPreferenceStore.OverlayKey[overlayKeys.size()];
- overlayKeys.toArray(keys);
- return new OverlayPreferenceStore(getPreferenceStore(), keys);
- }
-
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
- */
- protected Control createContents(Composite parent) {
- fOverlayStore.load();
- fOverlayStore.start();
-
- initializeDialogUnits(parent);
-
- Composite result= new Composite(parent, SWT.NONE);
- GridLayout layout= new GridLayout();
- layout.marginHeight= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
- layout.marginWidth= 0;
- layout.verticalSpacing= convertVerticalDLUsToPixels(10);
- layout.horizontalSpacing= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
- result.setLayout(layout);
-
- Group backgroundTypeCacheGroup= new Group(result, SWT.NONE);
- backgroundTypeCacheGroup.setLayout(new GridLayout());
- backgroundTypeCacheGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- backgroundTypeCacheGroup.setText("Open Type"); //$NON-NLS-1$
-
- fBackgroundTypeCacheEnabled = createCheckButton(backgroundTypeCacheGroup, "Cache types in background"); //$NON-NLS-1$
- fBackgroundTypeCacheEnabled.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- }
- public void widgetSelected(SelectionEvent e) {
- Button button = (Button) e.widget;
- fOverlayStore.setValue(AllTypesCache.ENABLE_BACKGROUND_TYPE_CACHE, button.getSelection());
- }
- });
-
- Group editorCorrectionGroup= new Group(result, SWT.NONE);
- editorCorrectionGroup.setLayout(new GridLayout());
- editorCorrectionGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- editorCorrectionGroup.setText("Editor"); //$NON-NLS-1$
-
- initialize();
-
- return result;
-
- }
-
- private void initialize(){
- fBackgroundTypeCacheEnabled.setSelection(fOverlayStore.getBoolean(AllTypesCache.ENABLE_BACKGROUND_TYPE_CACHE));
-
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
- */
- public void init(IWorkbench workbench) {
- // TODO Auto-generated method stub
- }
-
- /**
- * Creates a button with the given label and sets the default
- * configuration data.
- */
- private Combo createComboBox( Composite parent, String label, String[] items, String selection )
- {
- ControlFactory.createLabel( parent, label );
- Combo combo = ControlFactory.createSelectCombo( parent, items, selection );
- combo.setLayoutData( new GridData() );
- return combo;
- }
- /**
- * Creates a button with the given label and sets the default
- * configuration data.
- */
- private Button createCheckButton( Composite parent, String label )
- {
- Button button = new Button( parent, SWT.CHECK | SWT.LEFT );
- button.setText( label );
- // FieldEditor GridData
- GridData data = new GridData();
- button.setLayoutData( data );
- return button;
- }
-
- private Control addTextField(Composite composite, String label, String key, int textLimit, int indentation, boolean isNumber) {
-
- Label labelControl = new Label(composite, SWT.NONE);
- labelControl.setText(label);
- GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
- gd.horizontalIndent = indentation;
- labelControl.setLayoutData(gd);
-
- Text textControl = new Text(composite, SWT.BORDER | SWT.SINGLE);
- gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
- gd.widthHint = convertWidthInCharsToPixels(textLimit + 1);
- textControl.setLayoutData(gd);
- textControl.setTextLimit(textLimit);
-
- return textControl;
- }
- /*
- * @see IPreferencePage#performOk()
- */
- public boolean performOk() {
-
- fOverlayStore.propagate();
-
-// Store IProblem Marker value in CCorePlugin Preferences
- Preferences prefs = CCorePlugin.getDefault().getPluginPreferences();
-
- prefs.setValue(AllTypesCache.ENABLE_BACKGROUND_TYPE_CACHE, fOverlayStore.getString(AllTypesCache.ENABLE_BACKGROUND_TYPE_CACHE));
- CCorePlugin.getDefault().savePluginPreferences();
-
- return true;
- }
-
- /**
- * @param store
- */
- public static void initDefaults(IPreferenceStore store) {
- store.setDefault(AllTypesCache.ENABLE_BACKGROUND_TYPE_CACHE, false);
- Preferences prefs = CCorePlugin.getDefault().getPluginPreferences();
-
- if (prefs != null){
- prefs.setValue(AllTypesCache.ENABLE_BACKGROUND_TYPE_CACHE, store.getString(AllTypesCache.ENABLE_BACKGROUND_TYPE_CACHE));
- CCorePlugin.getDefault().savePluginPreferences();
- }
- }
-
- /*
- * @see PreferencePage#performDefaults()
- */
- protected void performDefaults() {
- fOverlayStore.loadDefaults();
- initialize();
- super.performDefaults();
- }
-}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPreferenceInitializer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPreferenceInitializer.java
index 1574644a46..56d0955359 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPreferenceInitializer.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPreferenceInitializer.java
@@ -14,9 +14,7 @@ import org.eclipse.cdt.internal.ui.cview.CView;
import org.eclipse.cdt.internal.ui.preferences.BuildConsolePreferencePage;
import org.eclipse.cdt.internal.ui.preferences.CEditorPreferencePage;
import org.eclipse.cdt.internal.ui.preferences.CPluginPreferencePage;
-import org.eclipse.cdt.internal.ui.preferences.CSearchPreferencePage;
import org.eclipse.cdt.internal.ui.preferences.CodeAssistPreferencePage;
-import org.eclipse.cdt.internal.ui.preferences.WorkInProgressPreferencePage;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.editors.text.EditorsUI;
@@ -38,8 +36,6 @@ public class CUIPreferenceInitializer extends AbstractPreferenceInitializer {
PreferenceConstants.initializeDefaultValues(store);
CPluginPreferencePage.initDefaults(store);
BuildConsolePreferencePage.initDefaults(store);
- WorkInProgressPreferencePage.initDefaults(store);
- CSearchPreferencePage.initDefaults(store);
CView.initDefaults(store);
CEditorPreferencePage.initDefaults(store);
CodeAssistPreferencePage.initDefaults(store);
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerBlock.java
index e914b86706..c1c23a2f6c 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerBlock.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerBlock.java
@@ -1,80 +1,443 @@
-/*******************************************************************************
- * Copyright (c) 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v0.5
+/**********************************************************************
+ * Copyright (c) 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v05.html
+ * http://www.eclipse.org/legal/cpl-v10.html
*
- * Contributors:
- * IBM Corp. - Rational Software - initial implementation
- ******************************************************************************/
-
+ * Contributors:
+ * IBM - Initial API and implementation
+ **********************************************************************/
package org.eclipse.cdt.ui.dialogs;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.ICDescriptor;
+import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.cdt.ui.index.AbstractIndexerPage;
+import org.eclipse.cdt.utils.ui.controls.ControlFactory;
+import org.eclipse.cdt.utils.ui.controls.TabFolderLayout;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.swt.SWT;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+/**
+ * @author Bogdan Gheorghe
+ */
+
+/**
+ * This <code>IndexerBlock2</code> is used in the <code>MakeProjectWizardOptionPage</code> and
+ * the <code>NewManagedProjectOptionPage</code> to display the indexer options during the creation of
+ * a new project.
+ */
public class IndexerBlock extends AbstractCOptionPage {
+
+ public final static String INDEX_UI_ID = CUIPlugin.PLUGIN_ID + ".cdtindexers"; //$NON-NLS-1$
+ public final static String INDEXERUIID = "indexerUIID"; //$NON-NLS-1$
+ public final static QualifiedName indexerUIIDKey = new QualifiedName(INDEX_UI_ID, INDEXERUIID);
+
+ public static final String INDEXER_UI = "indexerUI"; //$NON-NLS-1$
+ public static final String INDEXER_UI_VALUE = "indexerUIValue"; //$NON-NLS-1$
+
+ private static final String INDEXER_LABEL = CUIPlugin.getResourceString("BaseIndexerBlock.label" ); //$NON-NLS-1$
+ private static final String INDEXER_DESCRIPTION = CUIPlugin.getResourceString("BaseIndexerBlock.desc"); //$NON-NLS-1$
+ private static final String INDEXER_COMBO_LABEL = CUIPlugin.getResourceString("BaseIndexerBlock.comboLabel"); //$NON-NLS-1$
+
- private IndexerOptionDialogPage optionPage;
+ private Combo indexersComboBox;
+ private HashMap indexerPageMap;
+ private String selectedIndexerId = null;
+ private Composite parentComposite;
+ private ICOptionPage currentPage;
+
+
+ public IndexerBlock(){
+ super(INDEXER_LABEL);
+ setDescription(INDEXER_DESCRIPTION);
+ initializeIndexerPageMap();
+ }
+
+ /**
+ * Create a profile page only on request
+ */
+ protected static class IndexerPageConfiguration {
+ ICOptionPage page;
+ IConfigurationElement element;
- private static final String INDEXER_LABEL = "IndexerBlock.label"; //$NON-NLS-1$
- private static final String INDEXER_DESC = "IndexerBlock.desc"; //$NON-NLS-1$
-
- public IndexerBlock(){
- super(CUIPlugin.getResourceString(INDEXER_LABEL));
- setDescription(CUIPlugin.getResourceString(INDEXER_DESC));
- optionPage = new IndexerOptionDialogPage();
+ public IndexerPageConfiguration(IConfigurationElement _element) {
+ element = _element;
+ }
+
+ public ICOptionPage getPage() throws CoreException {
+ if (page == null) {
+ page = (ICOptionPage) element.createExecutableExtension("class"); //$NON-NLS-1$
+ }
+ return page;
+ }
+ public String getName() {
+ return element.getAttribute("name"); //$NON-NLS-1$
+ }
+ public String getIndexerID(){
+ return element.getAttribute("indexerID"); //$NON-NLS-1$
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
+ */
+ public void createControl(Composite parent) {
+
+
+ Composite composite = ControlFactory.createComposite(parent, 1);
+ Font font = parent.getFont();
+ GridLayout layout= ((GridLayout)composite.getLayout());
+ layout.marginHeight= 0;
+ layout.marginWidth= 0;
+ layout.verticalSpacing= 0;
+ layout.horizontalSpacing= GridData.FILL_HORIZONTAL;
+ composite.setFont(font);
+ setControl(composite);
+
+
+ // create a composite for general scanner config discovery options
+ Composite scComp = ControlFactory.createComposite(composite, 1);
+ ((GridLayout)scComp.getLayout()).marginHeight = 0;
+ ((GridLayout)scComp.getLayout()).marginTop = 5;
+ scComp.setFont(font);
+
+ // Create a group for discovered indexer's UI
+ if (createIndexerControls(scComp)) {
+ // create a composite for discovery profile options
+ Composite indexPageComposite = ControlFactory.createComposite(composite, 1);
+ indexPageComposite.setFont(font);
+ GridData gd = (GridData) indexPageComposite.getLayoutData();
+ gd.grabExcessHorizontalSpace = true;
+ // gd.grabExcessVerticalSpace = true;
+ gd.horizontalAlignment = GridData.FILL;
+ gd.verticalAlignment = GridData.FILL;
+ indexPageComposite.setLayout(new TabFolderLayout());
+ // Must set the composite parent to super class.
+ parentComposite = indexPageComposite;
+
+ setPage();
+
+ }
+ parent.layout(true);
+ }
+
+
+
+ /**
+ *
+ */
+ private void setPage() {
+
+ String profileId = getCurrentIndexPageId();
+
+ //If no indexer has been selected, return
+ if (profileId == null)
+ return;
+
+ ICOptionPage page = getIndexerPage(profileId);
+ if (page != null) {
+ if (page.getControl() == null) {
+ page.setContainer(getContainer());
+ page.createControl(parentComposite);
+ parentComposite.layout(true);
+ parentComposite.pack(true);
+ } else {
+ page.setVisible(false);
+ }
+ page.setVisible(true);
+ }
+ setCurrentPage(page);
+ }
+
+
+ /**
+ * @param page
+ */
+ private void setCurrentPage(ICOptionPage page) {
+ currentPage = page;
}
+
+
+
+ protected String getCurrentIndexPageId() {
+ String selectedIndexPageName = getSelectedIndexerID();
+
+ if (selectedIndexPageName == null)
+ return null;
+
+ String selectedIndexPageId = getIndexerPageId(selectedIndexPageName);
+ return selectedIndexPageId;
+ }
+ /**
+ * @param scComp
+ * @param numberOfColumns
+ * @return
+ */
+ private boolean createIndexerControls(Composite parent) {
+ //TODO: Put in some logic to deal with old CDT project: upgrade old projects
+ //to use the Classic CDT Indexer
+
+ Group group= ControlFactory.createGroup(parent,INDEXER_COMBO_LABEL,2);
+
+ // Add discovered indexers combo box
+ indexersComboBox = ControlFactory.createSelectCombo(group,"", ""); //$NON-NLS-1$ //$NON-NLS-2$
+
+ //Add combo box listener
+ indexersComboBox.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ setPage();
+ }
+ });
+ //Add button
+ ControlFactory.createPushButton(group,"Info ...");
+
+ // fill the combobox and set the initial value
+ for (Iterator items = getIndexerPageIdList().iterator(); items.hasNext();) {
+ String profileId = (String)items.next();
+ String pageName = getIndexerPageName(profileId);
+ if (pageName != null) {
+ indexersComboBox.add(pageName);
+ }
+ }
+
+ return true;
+ }
+
+
+
+
+ /**
+ * Adds all the contributed Indexer Pages to a map
+ */
+ private void initializeIndexerPageMap() {
+ indexerPageMap = new HashMap(5);
+
+ IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(CUIPlugin.getPluginId(), "IndexerPage"); //$NON-NLS-1$
+ IConfigurationElement[] infos = extensionPoint.getConfigurationElements();
+ for (int i = 0; i < infos.length; i++) {
+ if (infos[i].getName().equals("indexerUI")) { //$NON-NLS-1$
+ String id = infos[i].getAttribute("id"); //$NON-NLS-1$
+ indexerPageMap.put(id, new IndexerPageConfiguration(infos[i]));
+ }
+ }
+ }
+
+
+ /**
+ * Returns the contributed Indexer Pages as a list
+ */
+ protected List getIndexerPageIdList() {
+ return new ArrayList(indexerPageMap.keySet());
+ }
+
+ /**
+ * Returns the page name for the given id
+ * @param profileId
+ * @return String
+ */
+ protected String getIndexerPageName(String indexerPageId) {
+ IndexerPageConfiguration configElement =
+ (IndexerPageConfiguration) indexerPageMap.get(indexerPageId);
+ if (configElement != null) {
+ return configElement.getName();
+ }
+ return null;
+ }
+ /**
+ * Returns the indexer page id for the give name
+ * @param indexerPageName
+ * @return String
+ */
+ protected String getIndexerPageId(String indexerPageName) {
+ for (Iterator I = indexerPageMap.keySet().iterator(); I.hasNext();) {
+ String indexerPageId = (String) I.next();
+ String tempPageName = getIndexerPageName(indexerPageId);
+ if (indexerPageName.equals(tempPageName)) {
+ return indexerPageId;
+ }
+ }
+ return null;
+ }
+
+ protected ICOptionPage getIndexerPage(String indexerPageId) {
+ IndexerPageConfiguration configElement =
+ (IndexerPageConfiguration) indexerPageMap.get(indexerPageId);
+ if (configElement != null) {
+ try {
+ return configElement.getPage();
+ } catch (CoreException e) {
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns the indexer id for the given name
+ * @param profileId
+ * @return String
+ */
+ protected String getIndexerIdName(String indexerPageId) {
+ IndexerPageConfiguration configElement =
+ (IndexerPageConfiguration) indexerPageMap.get(indexerPageId);
+ if (configElement != null) {
+ return configElement.getIndexerID();
+ }
+ return null;
+ }
+
+ public void performApply(IProgressMonitor monitor) throws CoreException {
+ IProject newProject = null;
+ newProject = getContainer().getProject();
- /* (non-Javadoc)
- * @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performApply(org.eclipse.core.runtime.IProgressMonitor)
+ persistIndexerSettings(newProject, monitor);
+ }
+
+ /**
+ * Persists BasicIndexerBlock settings to disk and allows current indexer page to persist settings
+ * This is needed since we need to pass in the project if we are trying to save changes made to the
+ * property page.
+ */
+ public void persistIndexerSettings(IProject project, IProgressMonitor monitor) throws CoreException{
+
+ persistIndexerValues(project);
+
+ //Give the chosen indexer a chance to persist its values
+ if (currentPage != null){
+ currentPage.performApply(monitor);
+ }
+ }
+
+ public void performDefaults() {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * @return
*/
- public void performApply(IProgressMonitor monitor) throws CoreException {
+ public boolean isIndexEnabled() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ //Storage section
+
+ public void persistIndexerValues(IProject project){
+ ICDescriptor descriptor = null;
+ Element rootElement = null;
IProject newProject = null;
- newProject = getContainer().getProject();
- optionPage.persistIndexerValues(newProject);
+ //Get the currently selected indexer from the UI
+ String indexerName = getSelectedIndexerID();
+ //If no indexer has been selected, return
+ if (indexerName == null)
+ return;
- boolean indexProject = optionPage.getIndexerValue();
+ //Match up the selected indexer in the UI to a corresponding
+ //contributed Indexer Page ID
+ String indexerPageID = getIndexerPageId(indexerName);
- if (indexProject && newProject != null)
- CCorePlugin.getDefault().getCoreModel().getIndexManager().indexAll(newProject);
-
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performDefaults()
- */
- public void performDefaults() {
- // TODO Auto-generated method stub
+ if (indexerPageID == null)
+ return;
+
+ //Get the id of the indexer that goes along with this UI page - this gets persisted
+ String indexerID = getIndexerIdName(indexerPageID);
+
+ try {
+ newProject = project;
+ descriptor = CCorePlugin.getDefault().getCProjectDescription(newProject, true);
+ rootElement = descriptor.getProjectData(IndexManager.CDT_INDEXER);
+
+ // Clear out all current children
+ Node child = rootElement.getFirstChild();
+ while (child != null) {
+ rootElement.removeChild(child);
+ child = rootElement.getFirstChild();
+ }
+ Document doc = rootElement.getOwnerDocument();
+
+ saveIndexerInfo(indexerID, indexerPageID, rootElement, doc);
+
+ descriptor.saveProjectData();
+
+ //Update project session property
+
+ project.setSessionProperty(IndexManager.indexerIDKey, indexerID);
+ project.setSessionProperty(indexerUIIDKey, indexerPageID);
+
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
+
+ /**
+ * @param oldIndexerID
+ * @param project
*/
- public void createControl(Composite parent) {
- Composite result = new Composite(parent, SWT.NONE);
- result.setLayout(new GridLayout());
- result.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ public void setIndexerID(String oldIndexerID, IProject project) {
+ //Get the corresponding text for the given indexer id
+ selectedIndexerId = getIndexerPageName(oldIndexerID);
- optionPage.createControl(result);
- optionPage.setIndexerValue(true);
+ //Set the appropriate indexer in the combo box
+ indexersComboBox.setText(selectedIndexerId);
+ //Load the appropriate page
+ setPage();
+ //Give the contributed page a chance to initialize
+ if (currentPage instanceof AbstractIndexerPage){
+ ((AbstractIndexerPage) currentPage).initialize(project);
+ }
+ }
+
+
+ private static void saveIndexerInfo (String indexerID, String indexerUIID, Element rootElement, Document doc ) {
- setControl(result);
+ //Save the indexer id
+ Element indexerIDElement = doc.createElement(IndexManager.INDEXER_ID);
+ indexerIDElement.setAttribute(IndexManager.INDEXER_ID_VALUE,indexerID);
+ rootElement.appendChild(indexerIDElement);
-
+ //Save the indexer UI id
+ Element indexerUIIDElement = doc.createElement(INDEXER_UI);
+ indexerUIIDElement.setAttribute(INDEXER_UI_VALUE,indexerUIID);
+ rootElement.appendChild(indexerUIIDElement);
}
- public boolean isIndexEnabled(){
- return optionPage.getIndexerValue();
+ public String getSelectedIndexerID(){
+ String indexerID = null;
+
+ int selIndex = indexersComboBox.getSelectionIndex();
+
+ //If no indexer has been selected return
+ if (selIndex != -1)
+ indexerID = indexersComboBox.getItem(selIndex);
+
+ return indexerID;
}
-
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerOptionDialogPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerOptionDialogPage.java
deleted file mode 100644
index ef2afe8d30..0000000000
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerOptionDialogPage.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v0.5
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v05.html
- *
- * Contributors:
- * IBM Corp. - Rational Software - initial implementation
- ******************************************************************************/
-
-package org.eclipse.cdt.ui.dialogs;
-
-import org.eclipse.cdt.core.CCorePlugin;
-import org.eclipse.cdt.core.ICDescriptor;
-import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
-import org.eclipse.cdt.internal.ui.CUIMessages;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jface.dialogs.DialogPage;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.swt.SWT;
-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.Group;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-
-public class IndexerOptionDialogPage extends DialogPage {
-
- private static final String ENABLE_PREPROCESSOR_PROBLEMS = CUIMessages.getString( "IndexerOptions.enablePreprocessor" ); //$NON-NLS-1$
- private static final String ENABLE_SEMANTIC_PROBLEMS = CUIMessages.getString( "IndexerOptions.enableSemantic" ); //$NON-NLS-1$
- private static final String ENABLE_SYNTACTIC_PROBLEMS = CUIMessages.getString( "IndexerOptions.enableSyntactic" ); //$NON-NLS-1$
- private static final String ENABLE_INDEXING = CUIMessages.getString( "IndexerOptions.enableIndexing" ); //$NON-NLS-1$
- private static final String INDEXER = CUIMessages.getString("IndexerOptions.indexer" ); //$NON-NLS-1$
- private static final String INDEXER_PROBLEMS = CUIMessages.getString("IndexerOptions.problemReporting" ); //$NON-NLS-1$
-
- private Button indexerEnabled;
- private Button preprocessorProblemsEnabled;
- private Button syntacticProblemsEnabled;
- private Button semanticProblemsEnabled;
-
- public IndexerOptionDialogPage(){
- super();
- }
- /* (non-Javadoc)
- * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
- */
- public void createControl(Composite parent) {
- Composite result= new Composite(parent, SWT.NONE);
- GridLayout layout= new GridLayout();
- layout.marginHeight= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
- layout.marginWidth= 0;
- layout.verticalSpacing= convertVerticalDLUsToPixels(10);
- layout.horizontalSpacing= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
- result.setLayout(layout);
-
- Group group= new Group(result, SWT.NONE);
- group.setLayout(new GridLayout());
- group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- group.setText( INDEXER );
-
- indexerEnabled = createCheckButton(group, ENABLE_INDEXING );
-
- Group problemsGroup = new Group(result, SWT.NONE );
- problemsGroup.setLayout(new GridLayout());
- problemsGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- problemsGroup.setText( INDEXER_PROBLEMS );
-
- preprocessorProblemsEnabled = createCheckButton( problemsGroup, ENABLE_PREPROCESSOR_PROBLEMS );
- semanticProblemsEnabled = createCheckButton( problemsGroup, ENABLE_SEMANTIC_PROBLEMS );
- //uncomment when we want to report syntax problems
- syntacticProblemsEnabled = createCheckButton( problemsGroup, ENABLE_SYNTACTIC_PROBLEMS );
- setControl(result);
- }
-
- /**
- * Creates a button with the given label and sets the default
- * configuration data.
- */
- private Button createCheckButton( Composite parent, String label )
- {
- Button button = new Button( parent, SWT.CHECK | SWT.LEFT );
- button.setText( label );
- // FieldEditor GridData
- GridData data = new GridData();
- button.setLayoutData( data );
- return button;
- }
-
- public void setIndexerValue(boolean value){
- indexerEnabled.setSelection(value);
- }
-
- public void setIndexerProblemValues( int value ){
- preprocessorProblemsEnabled.setSelection( (value & IndexManager.PREPROCESSOR_PROBLEMS_BIT) != 0 );
- if( syntacticProblemsEnabled != null )
- syntacticProblemsEnabled.setSelection( (value & IndexManager.SYNTACTIC_PROBLEMS_BIT) != 0 );
- semanticProblemsEnabled.setSelection( (value & IndexManager.SEMANTIC_PROBLEMS_BIT) != 0 );
- }
-
- public boolean getIndexerValue(){
- return indexerEnabled.getSelection();
- }
-
- public int getIndexerProblemsValues(){
- int result = 0;
- result |= preprocessorProblemsEnabled.getSelection() ? IndexManager.PREPROCESSOR_PROBLEMS_BIT : 0;
- if( syntacticProblemsEnabled != null )
- result |= syntacticProblemsEnabled.getSelection() ? IndexManager.SYNTACTIC_PROBLEMS_BIT : 0;
- result |= semanticProblemsEnabled.getSelection() ? IndexManager.SEMANTIC_PROBLEMS_BIT : 0;
- return result;
- }
-
- public void persistIndexerValues(IProject project){
- ICDescriptor descriptor = null;
- Element rootElement = null;
- IProject newProject = null;
-
- try {
- newProject = project;
- descriptor = CCorePlugin.getDefault().getCProjectDescription(newProject, true);
- rootElement = descriptor.getProjectData(IndexManager.CDT_INDEXER);
-
- // Clear out all current children
- Node child = rootElement.getFirstChild();
- while (child != null) {
- rootElement.removeChild(child);
- child = rootElement.getFirstChild();
- }
- Document doc = rootElement.getOwnerDocument();
-
- boolean indexProject = getIndexerValue();
- int problemValues = getIndexerProblemsValues();
-
- saveIndexerEnabled(indexProject, rootElement, doc);
- saveIndexerProblemsEnabled( problemValues, rootElement, doc );
-
- descriptor.saveProjectData();
-
- //Update project session property
-
- project.setSessionProperty(IndexManager.activationKey,new Boolean(indexProject));
- project.setSessionProperty(IndexManager.problemsActivationKey, new Integer( problemValues ));
-
- } catch (CoreException e) {
- e.printStackTrace();
- }
- }
-
- private static void saveIndexerEnabled (boolean indexerEnabled, Element rootElement, Document doc ) {
-
- Element indexEnabled = doc.createElement(IndexManager.INDEXER_ENABLED);
- Boolean tempValue= new Boolean(indexerEnabled);
-
- indexEnabled.setAttribute(IndexManager.INDEXER_VALUE,tempValue.toString());
- rootElement.appendChild(indexEnabled);
-
- }
- private static void saveIndexerProblemsEnabled ( int problemValues, Element rootElement, Document doc ) {
-
- Element enabled = doc.createElement(IndexManager.INDEXER_PROBLEMS_ENABLED);
- Integer tempValue= new Integer( problemValues );
-
- enabled.setAttribute(IndexManager.INDEXER_PROBLEMS_VALUE, tempValue.toString());
- rootElement.appendChild(enabled);
- }
-}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerOptionPropertyPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerOptionPropertyPage.java
index f715051fa9..b485707f04 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerOptionPropertyPage.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerOptionPropertyPage.java
@@ -17,6 +17,7 @@ import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
@@ -29,14 +30,16 @@ import org.w3c.dom.Node;
public class IndexerOptionPropertyPage extends PropertyPage {
- private IndexerOptionDialogPage optionPage;
- private boolean oldIndexerValue;
- private int oldIndexerProblemsValue;
+
+
+ private IndexerBlock optionPage;
+ private String oldIndexerID;
+
private boolean requestedIndexAll;
-
+
public IndexerOptionPropertyPage(){
super();
- optionPage = new IndexerOptionDialogPage();
+ optionPage = new IndexerBlock();
requestedIndexAll = false;
}
/* (non-Javadoc)
@@ -63,43 +66,43 @@ public class IndexerOptionPropertyPage extends PropertyPage {
IProject project = getProject();
try {
- oldIndexerValue = getIndexerEnabled(project);
- oldIndexerProblemsValue = getIndexerProblemsEnabled( project );
+ oldIndexerID = getIndexerID(project);
+
} catch (CoreException e) {
e.printStackTrace();
}
- optionPage.setIndexerValue(oldIndexerValue);
- optionPage.setIndexerProblemValues( oldIndexerProblemsValue );
+ optionPage.setIndexerID(oldIndexerID, project);
}
/*
* @see IPreferencePage#performOk()
*/
public boolean performOk() {
-
- boolean newIndexerValue = optionPage.getIndexerValue();
- int newIndexerProblemsValue = optionPage.getIndexerProblemsValues();
+
+ /* String newIndexerID = optionPage.getSelectedIndexerID();
+
+ boolean indexerIDChanged = false;
- boolean indexChanged = (oldIndexerValue != newIndexerValue);
- boolean problemsChanged = (oldIndexerProblemsValue != newIndexerProblemsValue );
+ if (newIndexerID != null){
+ indexerIDChanged = !(oldIndexerID.equals(newIndexerID));
+ }
+ else if (oldIndexerID != null){
+ //newIndexerID is null, oldIndexerID wasn't null
+ indexerIDChanged = true;
+ }
+
+ if ( indexerIDChanged ){
+ //persist new values
+ IProject tempProject = getProject();
+ optionPage.persistIndexerValues(tempProject);
+ }*/
- if ( indexChanged || problemsChanged){
- //persist new values
- IProject tempProject = getProject();
- optionPage.persistIndexerValues(tempProject);
+ IProject tempProject = getProject();
+ try {
+ optionPage.persistIndexerSettings(tempProject, new NullProgressMonitor());
+ } catch (CoreException e) {}
- if( problemsChanged && newIndexerProblemsValue == 0)
- CCorePlugin.getDefault().getCoreModel().getIndexManager().removeIndexerProblems(tempProject);
-
- //if indexer is now on send a index all request
- if( indexChanged && newIndexerValue && !requestedIndexAll ) {
- CCorePlugin.getDefault().getCoreModel().getIndexManager().indexAll(tempProject);
- requestedIndexAll = true;
- } else if( indexChanged && !newIndexerValue ) {
- CCorePlugin.getDefault().getCoreModel().getIndexManager().discardJobs( tempProject.getName() );
- }
- }
return true;
}
@@ -112,104 +115,51 @@ public class IndexerOptionPropertyPage extends PropertyPage {
return project;
}
- public boolean getIndexerEnabled(IProject project) throws CoreException {
- // See if there's already one associated with the resource for this
- // session
- Boolean indexValue = (Boolean) project.getSessionProperty(IndexManager.activationKey);
+ public String getIndexerID(IProject project) throws CoreException {
+ //See if there's already one associated with the resource for this session
+ String indexerID = (String) project.getSessionProperty(IndexerBlock.indexerUIIDKey);
+ if (indexerID != null)
+ return indexerID;
+
// Try to load one for the project
- if (indexValue == null) {
- indexValue = loadIndexerEnabledFromCDescriptor(project);
- }
-
+ indexerID = loadIndexerIDFromCDescriptor(project);
+
// There is nothing persisted for the session, or saved in a file so
// create a build info object
- if (indexValue != null) {
- project.setSessionProperty(IndexManager.activationKey, indexValue);
+ if (indexerID != null) {
+ project.setSessionProperty(IndexerBlock.indexerUIIDKey, indexerID);
}
else{
- //Hmm, no persisted indexer value. Could be an old project - set to true and persist
- indexValue = new Boolean(true);
- optionPage.setIndexerValue(true);
- optionPage.persistIndexerValues(project);
+ //Hmm, no persisted indexer value. Could be an old project - need to run project
+ //update code here
}
- return indexValue.booleanValue();
+ return indexerID;
}
-
- public int getIndexerProblemsEnabled( IProject project ) throws CoreException
- {
- // See if there's already one associated with the resource for this session
- Integer value = (Integer) project.getSessionProperty( IndexManager.problemsActivationKey );
- // Try to load one for the project
- if (value == null) {
- value = loadIndexerProblemsEnabledFromCDescriptor(project);
- }
-
- // There is nothing persisted for the session, or saved in a file so
- // create a build info object
- if (value != null) {
- project.setSessionProperty(IndexManager.problemsActivationKey, value);
- } else {
- //Hmm, no persisted indexer value. Could be an old project - set all to false and persist
- value = new Integer( 0 );
- optionPage.setIndexerProblemValues( 0 );
- optionPage.persistIndexerValues(project);
- }
-
- return value.intValue();
- }
/**
- * Loads dis from .cdtproject file
+ * Loads indexerID from .cdtproject file
* @param project
* @param includes
* @param symbols
* @throws CoreException
*/
- private Boolean loadIndexerEnabledFromCDescriptor(IProject project) throws CoreException {
+ private String loadIndexerIDFromCDescriptor(IProject project) throws CoreException {
ICDescriptor descriptor = CCorePlugin.getDefault().getCProjectDescription(project, true);
Node child = descriptor.getProjectData(IndexManager.CDT_INDEXER).getFirstChild();
- Boolean strBool = null;
-
- while (child != null) {
- if (child.getNodeName().equals(IndexManager.INDEXER_ENABLED))
- strBool = Boolean.valueOf(((Element)child).getAttribute(IndexManager.INDEXER_VALUE));
-
-
- child = child.getNextSibling();
- }
- return strBool;
- }
-
- private Integer loadIndexerProblemsEnabledFromCDescriptor( IProject project ) throws CoreException
- {
- ICDescriptor descriptor = CCorePlugin.getDefault().getCProjectDescription(project, true);
-
- Node child = descriptor.getProjectData(IndexManager.CDT_INDEXER).getFirstChild();
- Integer strInt = null;
+ String indexerID = ""; //$NON-NLS-1$
while (child != null) {
- if (child.getNodeName().equals(IndexManager.INDEXER_PROBLEMS_ENABLED)) {
- String val = ((Element)child).getAttribute(IndexManager.INDEXER_PROBLEMS_VALUE);
- try{
- strInt = Integer.valueOf( val );
- } catch( NumberFormatException e ){
- //some old projects might have a boolean stored, translate that into just preprocessors
- Boolean bool = Boolean.valueOf( val );
- if( bool.booleanValue() )
- strInt = new Integer( IndexManager.PREPROCESSOR_PROBLEMS_BIT );
- else
- strInt = new Integer( 0 );
- }
- break;
- }
+ if (child.getNodeName().equals(IndexerBlock.INDEXER_UI))
+ indexerID = ((Element)child).getAttribute(IndexerBlock.INDEXER_UI_VALUE);
child = child.getNextSibling();
}
- return strInt;
+
+ return indexerID;
}
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/SourceIndexerBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/SourceIndexerBlock.java
new file mode 100644
index 0000000000..8c6b932cd8
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/SourceIndexerBlock.java
@@ -0,0 +1,301 @@
+/*******************************************************************************
+ * Copyright (c) 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * IBM Corp. - Rational Software - initial implementation
+ ******************************************************************************/
+
+package org.eclipse.cdt.ui.dialogs;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.ICDescriptor;
+import org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer;
+import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
+import org.eclipse.cdt.internal.ui.CUIMessages;
+import org.eclipse.cdt.ui.index.AbstractIndexerPage;
+import org.eclipse.cdt.utils.ui.controls.ControlFactory;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+
+public class SourceIndexerBlock extends AbstractIndexerPage {
+
+ private static final String ENABLE_PREPROCESSOR_PROBLEMS = CUIMessages.getString( "IndexerOptions.enablePreprocessor" ); //$NON-NLS-1$
+ private static final String ENABLE_SEMANTIC_PROBLEMS = CUIMessages.getString( "IndexerOptions.enableSemantic" ); //$NON-NLS-1$
+ private static final String ENABLE_SYNTACTIC_PROBLEMS = CUIMessages.getString( "IndexerOptions.enableSyntactic" ); //$NON-NLS-1$
+ private static final String ENABLE_INDEXING = CUIMessages.getString( "IndexerOptions.enableIndexing" ); //$NON-NLS-1$
+ private static final String INDEXER = CUIMessages.getString("IndexerOptions.indexer" ); //$NON-NLS-1$
+ private static final String INDEXER_PROBLEMS = CUIMessages.getString("IndexerOptions.problemReporting" ); //$NON-NLS-1$
+
+ private Button indexerEnabled;
+ private Button preprocessorProblemsEnabled;
+ private Button syntacticProblemsEnabled;
+ private Button semanticProblemsEnabled;
+
+ private boolean oldIndexerValue;
+ private int oldIndexerProblemsValue;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performApply(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public void performApply(IProgressMonitor monitor) throws CoreException {
+
+ IProject newProject = null;
+ newProject = getContainer().getProject();
+
+ this.persistIndexerValues(newProject);
+
+ boolean indexProject = getIndexerValue();
+
+ //if (indexProject && newProject != null)
+ //SourceIndexer.indexAll()
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performDefaults()
+ */
+ public void performDefaults() {
+ // TODO Auto-generated method stub
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
+ */
+ public void createControl(Composite parent) {
+
+ Composite page = ControlFactory.createComposite(parent, 1);
+
+ Group group = ControlFactory.createGroup(page,INDEXER,1);
+
+ GridData gd = (GridData) group.getLayoutData();
+ gd.grabExcessHorizontalSpace = true;
+ gd.horizontalAlignment = GridData.FILL;
+
+
+ indexerEnabled = ControlFactory.createCheckBox(group, ENABLE_INDEXING );
+
+
+ Group problemsGroup = ControlFactory.createGroup(page,INDEXER_PROBLEMS,1);
+
+ GridData gd2 = (GridData) problemsGroup.getLayoutData();
+ gd2.grabExcessHorizontalSpace = true;
+ gd2.horizontalAlignment = GridData.FILL;
+
+
+ preprocessorProblemsEnabled = ControlFactory.createCheckBox( problemsGroup, ENABLE_PREPROCESSOR_PROBLEMS );
+ semanticProblemsEnabled = ControlFactory.createCheckBox( problemsGroup, ENABLE_SEMANTIC_PROBLEMS );
+ //uncomment when we want to report syntax problems
+ syntacticProblemsEnabled = ControlFactory.createCheckBox( problemsGroup, ENABLE_SYNTACTIC_PROBLEMS );
+ setControl(page);
+
+ }
+
+ public void persistIndexerValues(IProject project){
+ ICDescriptor descriptor = null;
+ Element rootElement = null;
+ IProject newProject = null;
+
+ try {
+ newProject = project;
+ descriptor = CCorePlugin.getDefault().getCProjectDescription(newProject, true);
+ rootElement = descriptor.getProjectData(SourceIndexer.SOURCE_INDEXER);
+
+ // Clear out all current children
+ Node child = rootElement.getFirstChild();
+ while (child != null) {
+ rootElement.removeChild(child);
+ child = rootElement.getFirstChild();
+ }
+ Document doc = rootElement.getOwnerDocument();
+
+ boolean indexProject = getIndexerValue();
+ int problemValues = getIndexerProblemsValues();
+
+ saveIndexerEnabled(indexProject, rootElement, doc);
+ saveIndexerProblemsEnabled( problemValues, rootElement, doc );
+
+ descriptor.saveProjectData();
+
+ //Update project session property
+
+ project.setSessionProperty(SourceIndexer.activationKey,new Boolean(indexProject));
+ project.setSessionProperty(SourceIndexer.problemsActivationKey, new Integer( problemValues ));
+
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+
+
+ public boolean getIndexerValue(){
+ return indexerEnabled.getSelection();
+ }
+
+ public int getIndexerProblemsValues(){
+ int result = 0;
+ result |= preprocessorProblemsEnabled.getSelection() ? SourceIndexer.PREPROCESSOR_PROBLEMS_BIT : 0;
+ if( syntacticProblemsEnabled != null )
+ result |= syntacticProblemsEnabled.getSelection() ? SourceIndexer.SYNTACTIC_PROBLEMS_BIT : 0;
+ result |= semanticProblemsEnabled.getSelection() ? SourceIndexer.SEMANTIC_PROBLEMS_BIT : 0;
+ return result;
+ }
+
+ private static void saveIndexerEnabled (boolean indexerEnabled, Element rootElement, Document doc ) {
+
+ Element indexEnabled = doc.createElement(SourceIndexer.INDEXER_ENABLED);
+ Boolean tempValue= new Boolean(indexerEnabled);
+
+ indexEnabled.setAttribute(SourceIndexer.INDEXER_VALUE,tempValue.toString());
+ rootElement.appendChild(indexEnabled);
+
+ }
+ private static void saveIndexerProblemsEnabled ( int problemValues, Element rootElement, Document doc ) {
+
+ Element enabled = doc.createElement(SourceIndexer.INDEXER_PROBLEMS_ENABLED);
+ Integer tempValue= new Integer( problemValues );
+
+ enabled.setAttribute(SourceIndexer.INDEXER_PROBLEMS_VALUE, tempValue.toString());
+ rootElement.appendChild(enabled);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.ui.index2.AbstractIndexerPage#initialize(org.eclipse.core.resources.IProject)
+ */
+ public void initialize(IProject project) {
+
+ try {
+ oldIndexerValue = getIndexerEnabled(project);
+ oldIndexerProblemsValue = getIndexerProblemsEnabled( project );
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+
+ //Set the index enabled checkbox
+ setIndexerValue(oldIndexerValue);
+
+ //Set the IProblem checkboxes
+ setIndexerProblemValues(oldIndexerProblemsValue);
+ }
+
+ public boolean getIndexerEnabled(IProject project) throws CoreException {
+ // See if there's already one associated with the resource for this
+ // session
+ Boolean indexValue = (Boolean) project.getSessionProperty(SourceIndexer.activationKey);
+
+ // Try to load one for the project
+ if (indexValue == null) {
+ indexValue = loadIndexerEnabledFromCDescriptor(project);
+ }
+
+ // There is nothing persisted for the session, or saved in a file so
+ // create a build info object
+ if (indexValue != null) {
+ project.setSessionProperty(SourceIndexer.activationKey, indexValue);
+ }
+ else{
+ //Hmm, no persisted indexer value. Could be an old project - set to true and persist
+ indexValue = new Boolean(true);
+ setIndexerValue(true);
+ persistIndexerValues(project);
+ }
+
+ return indexValue.booleanValue();
+ }
+
+ public int getIndexerProblemsEnabled( IProject project ) throws CoreException
+ {
+ // See if there's already one associated with the resource for this session
+ Integer value = (Integer) project.getSessionProperty( SourceIndexer.problemsActivationKey );
+
+ // Try to load one for the project
+ if (value == null) {
+ value = loadIndexerProblemsEnabledFromCDescriptor(project);
+ }
+
+ // There is nothing persisted for the session, or saved in a file so
+ // create a build info object
+ if (value != null) {
+ project.setSessionProperty(SourceIndexer.problemsActivationKey, value);
+ } else {
+ //Hmm, no persisted indexer value. Could be an old project - set all to false and persist
+ value = new Integer( 0 );
+ setIndexerProblemValues( 0 );
+ persistIndexerValues(project);
+ }
+
+ return value.intValue();
+ }
+
+ public void setIndexerValue(boolean value){
+ indexerEnabled.setSelection(value);
+ }
+
+ public void setIndexerProblemValues( int value ){
+ preprocessorProblemsEnabled.setSelection( (value & SourceIndexer.PREPROCESSOR_PROBLEMS_BIT) != 0 );
+ if( syntacticProblemsEnabled != null )
+ syntacticProblemsEnabled.setSelection( (value & SourceIndexer.SYNTACTIC_PROBLEMS_BIT) != 0 );
+ semanticProblemsEnabled.setSelection( (value & SourceIndexer.SEMANTIC_PROBLEMS_BIT) != 0 );
+ }
+
+ /**
+ * Loads dis from .cdtproject file
+ * @param project
+ * @param includes
+ * @param symbols
+ * @throws CoreException
+ */
+ private Boolean loadIndexerEnabledFromCDescriptor(IProject project) throws CoreException {
+ ICDescriptor descriptor = CCorePlugin.getDefault().getCProjectDescription(project, true);
+
+ Node child = descriptor.getProjectData(SourceIndexer.SOURCE_INDEXER).getFirstChild();
+ Boolean strBool = null;
+
+ while (child != null) {
+ if (child.getNodeName().equals(SourceIndexer.INDEXER_ENABLED))
+ strBool = Boolean.valueOf(((Element)child).getAttribute(SourceIndexer.INDEXER_VALUE));
+
+
+ child = child.getNextSibling();
+ }
+
+ return strBool;
+ }
+
+ private Integer loadIndexerProblemsEnabledFromCDescriptor( IProject project ) throws CoreException
+ {
+ ICDescriptor descriptor = CCorePlugin.getDefault().getCProjectDescription(project, true);
+
+ Node child = descriptor.getProjectData(SourceIndexer.SOURCE_INDEXER).getFirstChild();
+ Integer strInt = null;
+
+ while (child != null) {
+ if (child.getNodeName().equals(SourceIndexer.INDEXER_PROBLEMS_ENABLED)) {
+ String val = ((Element)child).getAttribute(SourceIndexer.INDEXER_PROBLEMS_VALUE);
+ try{
+ strInt = Integer.valueOf( val );
+ } catch( NumberFormatException e ){
+ //some old projects might have a boolean stored, translate that into just preprocessors
+ Boolean bool = Boolean.valueOf( val );
+ if( bool.booleanValue() )
+ strInt = new Integer( SourceIndexer.PREPROCESSOR_PROBLEMS_BIT );
+ else
+ strInt = new Integer( 0 );
+ }
+ break;
+ }
+
+ child = child.getNextSibling();
+ }
+ return strInt;
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/index/AbstractIndexerPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/index/AbstractIndexerPage.java
new file mode 100644
index 0000000000..02b5f34983
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/index/AbstractIndexerPage.java
@@ -0,0 +1,32 @@
+/**********************************************************************
+ * Copyright (c) 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.cdt.ui.index;
+
+import org.eclipse.cdt.ui.dialogs.AbstractCOptionPage;
+import org.eclipse.core.resources.IProject;
+
+/**
+ * @author Bogdan Gheorghe
+ */
+public abstract class AbstractIndexerPage extends AbstractCOptionPage {
+
+
+ protected AbstractIndexerPage() {
+ super();
+ }
+
+ /**
+ * Called by BaseIndexerBlock to give the indexer page a chance to load its state from store
+ * @param currentProject - the project that this page is being created for
+ */
+ abstract public void initialize(IProject currentProject);
+
+}

Back to the top