mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-01 06:05:24 +02:00
Fix for Bug 78414: IProblem count increased through indexing header files stand-alone
This commit is contained in:
parent
4f1af97e09
commit
44e45fb15f
11 changed files with 242 additions and 65 deletions
|
@ -20,9 +20,6 @@ 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;
|
||||
|
@ -100,7 +97,7 @@ import org.eclipse.core.runtime.Platform;
|
|||
if (indexFile.exists())
|
||||
indexFile.delete();
|
||||
|
||||
testProject.setSessionProperty(IndexManager.activationKey,new Boolean(true));
|
||||
testProject.setSessionProperty(IndexManager.activationKey,new Boolean(false));
|
||||
|
||||
if (testProject==null)
|
||||
fail("Unable to create project");
|
||||
|
@ -164,7 +161,8 @@ import org.eclipse.core.runtime.Platform;
|
|||
|
||||
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"};
|
||||
|
@ -218,19 +216,22 @@ import org.eclipse.core.runtime.Platform;
|
|||
|
||||
public void testDepTable() throws Exception{
|
||||
//Add a file to the project
|
||||
|
||||
IFile depTest2C = importFile("DepTest2.cpp","resources/dependency/DepTest2.cpp");
|
||||
IFile depTestC = importFile("DepTest.cpp","resources/dependency/DepTest.cpp");
|
||||
IFile cH = importFile("c.h","resources/dependency/c.h");
|
||||
IFile aH = importFile("a.h","resources/dependency/a.h");
|
||||
IFile Inc1H = importFile("Inc1.h","resources/dependency/Inc1.h");
|
||||
IFile dH = importFile("d.h","resources/dependency/d.h");
|
||||
IFile depTestH = importFile("DepTest.h","resources/dependency/DepTest.h");
|
||||
IFile depTest2H = importFile("DepTest2.h","resources/dependency/DepTest2.h");
|
||||
IFile depTest2C = importFile("DepTest2.cpp","resources/dependency/DepTest2.cpp");
|
||||
IFile depTestC = importFile("DepTest.cpp","resources/dependency/DepTest.cpp");
|
||||
|
||||
testProject.setSessionProperty(IndexManager.activationKey,new Boolean(true));
|
||||
|
||||
PathCollector pathCollector = new PathCollector();
|
||||
getTableRefs(dH, pathCollector);
|
||||
|
||||
String[] dHModel = {IPath.SEPARATOR + "DepTestProject" + IPath.SEPARATOR + "DepTest2.cpp", IPath.SEPARATOR + "DepTestProject" + IPath.SEPARATOR + "DepTest.cpp", IPath.SEPARATOR + "DepTestProject" + IPath.SEPARATOR + "DepTest2.h"};
|
||||
String[] dHModel = {IPath.SEPARATOR + "DepTestProject" + IPath.SEPARATOR + "DepTest2.cpp", IPath.SEPARATOR + "DepTestProject" + IPath.SEPARATOR + "DepTest.cpp"};
|
||||
String[] iPath = pathCollector.getPaths();
|
||||
|
||||
if (dHModel.length != iPath.length)
|
||||
|
@ -247,7 +248,7 @@ import org.eclipse.core.runtime.Platform;
|
|||
pathCollector = new PathCollector();
|
||||
getTableRefs(Inc1H, pathCollector);
|
||||
|
||||
String[] Inc1HModel = {IPath.SEPARATOR + "DepTestProject" + IPath.SEPARATOR + "DepTest.cpp",IPath.SEPARATOR + "DepTestProject" + IPath.SEPARATOR + "DepTest.h"};
|
||||
String[] Inc1HModel = {IPath.SEPARATOR + "DepTestProject" + IPath.SEPARATOR + "DepTest.cpp"};
|
||||
iPath = pathCollector.getPaths();
|
||||
|
||||
if (Inc1HModel.length != iPath.length)
|
||||
|
@ -272,6 +273,8 @@ 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));
|
||||
|
||||
String[] beforeModel = {Path.SEPARATOR + "DepTestProject" + IPath.SEPARATOR + "DepTest.cpp"};
|
||||
|
||||
PathCollector pathCollector = new PathCollector();
|
||||
|
@ -292,7 +295,7 @@ import org.eclipse.core.runtime.Platform;
|
|||
getTableRefs(Inc1H, pathCollector);
|
||||
|
||||
iPath = pathCollector.getPaths();
|
||||
String[] inc1Model = {Path.SEPARATOR + "DepTestProject" + IPath.SEPARATOR + "DepTest.cpp",Path.SEPARATOR + "DepTestProject" + IPath.SEPARATOR + "DepTest.h"};
|
||||
String[] inc1Model = {Path.SEPARATOR + "DepTestProject" + IPath.SEPARATOR + "DepTest.cpp"};
|
||||
compareArrays(iPath,inc1Model);
|
||||
|
||||
pathCollector = new PathCollector();
|
||||
|
@ -307,7 +310,7 @@ import org.eclipse.core.runtime.Platform;
|
|||
|
||||
iPath = pathCollector.getPaths();
|
||||
|
||||
String[] cHModel = {Path.SEPARATOR + "DepTestProject" + Path.SEPARATOR + "Inc1.h", Path.SEPARATOR + "DepTestProject" + Path.SEPARATOR + "DepTest.cpp", Path.SEPARATOR + "DepTestProject" + Path.SEPARATOR + "a.h", Path.SEPARATOR + "DepTestProject" + Path.SEPARATOR + "DepTest.h"};
|
||||
String[] cHModel = {Path.SEPARATOR + "DepTestProject" + Path.SEPARATOR + "DepTest.cpp"};
|
||||
compareArrays(iPath,cHModel);
|
||||
|
||||
editCode(depTestC,"#include \"DepTest.h\"","//#include \"DepTest.h\"");
|
||||
|
@ -334,7 +337,7 @@ import org.eclipse.core.runtime.Platform;
|
|||
|
||||
iPath = pathCollector.getPaths();
|
||||
|
||||
if (iPath.length != 1)
|
||||
if (iPath.length != 0)
|
||||
fail("Number of included files differs from model");
|
||||
|
||||
pathCollector = new PathCollector();
|
||||
|
@ -342,7 +345,7 @@ import org.eclipse.core.runtime.Platform;
|
|||
|
||||
iPath = pathCollector.getPaths();
|
||||
|
||||
if (iPath.length != 1)
|
||||
if (iPath.length != 0)
|
||||
fail("Number of included files differs from model");
|
||||
|
||||
|
||||
|
@ -351,7 +354,7 @@ import org.eclipse.core.runtime.Platform;
|
|||
|
||||
iPath = pathCollector.getPaths();
|
||||
|
||||
if (iPath.length != 3)
|
||||
if (iPath.length != 0)
|
||||
fail("Number of included files differs from model");
|
||||
|
||||
}
|
||||
|
@ -367,6 +370,8 @@ 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));
|
||||
|
||||
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"};
|
||||
|
@ -434,6 +439,8 @@ 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));
|
||||
|
||||
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"};
|
||||
|
@ -500,10 +507,13 @@ import org.eclipse.core.runtime.Platform;
|
|||
IFile aH = importFile("a.h","resources/dependency/a.h");
|
||||
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));
|
||||
|
||||
|
||||
String[] beforeModel = {Path.SEPARATOR + "DepTestProject" + IPath.SEPARATOR + "DepTest3.cpp"};
|
||||
String[] cHModel = {Path.SEPARATOR + "DepTestProject" + IPath.SEPARATOR + "DepTest3.cpp", IPath.SEPARATOR + "DepTestProject" + IPath.SEPARATOR + "a.h", IPath.SEPARATOR + "DepTestProject" + IPath.SEPARATOR + "DepTest3.h"};
|
||||
String[] aHModel = {Path.SEPARATOR + "DepTestProject" + Path.SEPARATOR + "DepTest3.cpp", Path.SEPARATOR + "DepTestProject" + Path.SEPARATOR + "DepTest3.h"};
|
||||
String[] cHModel = {Path.SEPARATOR + "DepTestProject" + IPath.SEPARATOR + "DepTest3.cpp"};
|
||||
String[] aHModel = {Path.SEPARATOR + "DepTestProject" + Path.SEPARATOR + "DepTest3.cpp"};
|
||||
PathCollector pathCollector = new PathCollector();
|
||||
getTableRefs(depTest3H, pathCollector);
|
||||
|
||||
|
@ -570,6 +580,8 @@ 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));
|
||||
|
||||
ICSearchPattern pattern = SearchEngine.createSearchPattern( "Z", ICSearchConstants.TYPE, ICSearchConstants.DECLARATIONS, true );
|
||||
|
||||
search(workspace,pattern,scope,resultCollector);
|
||||
|
|
|
@ -14,7 +14,9 @@
|
|||
package org.eclipse.cdt.core.search.tests;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.search.BasicSearchResultCollector;
|
||||
|
@ -27,7 +29,6 @@ import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
|
|||
import org.eclipse.cdt.testplugin.CProjectHelper;
|
||||
import org.eclipse.cdt.testplugin.CTestPlugin;
|
||||
import org.eclipse.cdt.testplugin.FileManager;
|
||||
import org.eclipse.core.internal.resources.ResourceException;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
|
@ -44,30 +45,28 @@ import org.eclipse.core.runtime.Path;
|
|||
*/
|
||||
public class BaseSearchTest extends TestCase implements ICSearchConstants {
|
||||
|
||||
ICSearchScope scope;
|
||||
IFile file;
|
||||
IProject testProject;
|
||||
NullProgressMonitor monitor;
|
||||
IWorkspace workspace;
|
||||
BasicSearchResultCollector resultCollector;
|
||||
SearchEngine searchEngine;
|
||||
FileManager fileManager;
|
||||
|
||||
public BaseSearchTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
static protected ICSearchScope scope;
|
||||
static protected IFile file;
|
||||
static protected IProject testProject;
|
||||
static protected NullProgressMonitor monitor;
|
||||
static protected IWorkspace workspace;
|
||||
static protected BasicSearchResultCollector resultCollector;
|
||||
static protected SearchEngine searchEngine;
|
||||
static protected FileManager fileManager;
|
||||
{
|
||||
|
||||
(CCorePlugin.getDefault().getCoreModel().getIndexManager()).reset();
|
||||
monitor = new NullProgressMonitor();
|
||||
|
||||
workspace = ResourcesPlugin.getWorkspace();
|
||||
|
||||
//Create temp project
|
||||
testProject = createProject("SearchTestProject");
|
||||
try {
|
||||
//Create temp project
|
||||
testProject = createProject("SearchTestProject");
|
||||
testProject.setSessionProperty(IndexManager.activationKey,new Boolean(true));
|
||||
} catch (CoreException e) {}
|
||||
|
||||
|
||||
testProject.setSessionProperty(IndexManager.activationKey,new Boolean(true));
|
||||
|
||||
if (testProject == null)
|
||||
fail("Unable to create project");
|
||||
|
@ -75,10 +74,16 @@ public class BaseSearchTest extends TestCase implements ICSearchConstants {
|
|||
//Create file manager
|
||||
fileManager = new FileManager();
|
||||
|
||||
//Add a file to the project
|
||||
//importFile("mail.cpp", "resources/indexer/mail.cpp");
|
||||
importFile("classDecl.cpp", "resources/search/classDecl.cpp");
|
||||
importFile("include.h", "resources/search/include.h");
|
||||
try {
|
||||
//Add a file to the project
|
||||
//importFile("mail.cpp", "resources/indexer/mail.cpp");
|
||||
importFile("classDecl.cpp", "resources/search/classDecl.cpp");
|
||||
importFile("include.h", "resources/search/include.h");
|
||||
} catch (Exception e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
scope = SearchEngine.createWorkspaceScope();
|
||||
|
||||
|
@ -87,20 +92,17 @@ public class BaseSearchTest extends TestCase implements ICSearchConstants {
|
|||
searchEngine = new SearchEngine();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public BaseSearchTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
protected void tearDown() {
|
||||
try {
|
||||
super.tearDown();
|
||||
} catch (Exception e1) {
|
||||
}
|
||||
//Delete project
|
||||
if (testProject.exists()){
|
||||
try {
|
||||
fileManager.closeAllFiles();
|
||||
testProject.delete(true,monitor);
|
||||
} catch (ResourceException e) {
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IProject createProject(String projectName) throws CoreException {
|
||||
|
|
|
@ -1,3 +1,16 @@
|
|||
2004-11-12 Bogdan Gheorghe
|
||||
Fix for Bug 78414: IProblem count increased through indexing header files stand-alone
|
||||
|
||||
* index/org/eclipse/cdt/internal/core/search/indexing/IndexAllProject.java
|
||||
* index/org/eclipse/cdt/internal/core/search/indexing/AddCompilationUnitToIndex.java
|
||||
* index/org/eclipse/cdt/internal/core/search/indexing/AddFileToIndex.java
|
||||
* index/org/eclipse/cdt/internal/core/search/indexing/AddFolderToIndex.java
|
||||
* index/org/eclipse/cdt/internal/core/search/indexing/CleanEncounteredHeaders.java
|
||||
* index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java
|
||||
* index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexerRequestor.java
|
||||
|
||||
* parser/org/eclipse/cdt/internal/core/parser/problem/Problem.java
|
||||
|
||||
2004-11-02 Bogdan Gheorghe
|
||||
Fixed a bug in the index merge.
|
||||
|
||||
|
|
|
@ -21,8 +21,8 @@ import org.eclipse.core.runtime.IPath;
|
|||
public class AddCompilationUnitToIndex extends AddFileToIndex {
|
||||
char[] contents;
|
||||
|
||||
public AddCompilationUnitToIndex(IFile resource, IPath indexedContainer, IndexManager manager) {
|
||||
super(resource, indexedContainer, manager);
|
||||
public AddCompilationUnitToIndex(IFile resource, IPath indexedContainer, IndexManager manager, boolean checkEncounteredHeaders) {
|
||||
super(resource, indexedContainer, manager, checkEncounteredHeaders);
|
||||
}
|
||||
protected boolean indexDocument(IIndex index) throws IOException {
|
||||
if (!initializeContents()) return false;
|
||||
|
|
|
@ -12,26 +12,43 @@ package org.eclipse.cdt.internal.core.search.indexing;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
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.processing.JobManager;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
||||
public abstract class AddFileToIndex extends IndexRequest {
|
||||
IFile resource;
|
||||
|
||||
private boolean checkEncounteredHeaders;
|
||||
|
||||
public AddFileToIndex(IFile resource, IPath indexPath, IndexManager manager) {
|
||||
public AddFileToIndex(IFile resource, IPath indexPath, IndexManager manager, boolean checkEncounteredHeaders) {
|
||||
super(indexPath, manager);
|
||||
this.resource = resource;
|
||||
this.checkEncounteredHeaders = checkEncounteredHeaders;
|
||||
}
|
||||
|
||||
public AddFileToIndex(IFile resource, IPath indexPath, IndexManager manager) {
|
||||
this(resource,indexPath,manager,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 */
|
||||
ICFileType type = CCorePlugin.getDefault().getFileType(resourceProject,resource.getName());
|
||||
|
||||
/* See if this file has been encountered before */
|
||||
if (type.isHeader() &&
|
||||
manager.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*/);
|
||||
if (index == null) return true;
|
||||
|
|
|
@ -34,7 +34,8 @@ class AddFolderToIndex extends IndexRequest {
|
|||
char[][] exclusionPattern;
|
||||
ArrayList sourceFilesToIndex;
|
||||
ArrayList headerFilesToIndex;
|
||||
|
||||
boolean cleanEncouteredHeaders;
|
||||
|
||||
public AddFolderToIndex(IPath folderPath, IProject project, char[][] exclusionPattern, IndexManager manager) {
|
||||
super(project.getFullPath(), manager);
|
||||
this.folderPath = folderPath;
|
||||
|
@ -42,6 +43,17 @@ class AddFolderToIndex extends IndexRequest {
|
|||
this.exclusionPattern = exclusionPattern;
|
||||
this.sourceFilesToIndex = new ArrayList();
|
||||
this.headerFilesToIndex = new ArrayList();
|
||||
this.cleanEncouteredHeaders = false;
|
||||
}
|
||||
|
||||
public AddFolderToIndex(IPath folderPath, IProject project, char[][] exclusionPattern, IndexManager manager, boolean cleanEncounteredHeaders) {
|
||||
super(project.getFullPath(), manager);
|
||||
this.folderPath = folderPath;
|
||||
this.project = project;
|
||||
this.exclusionPattern = exclusionPattern;
|
||||
this.sourceFilesToIndex = new ArrayList();
|
||||
this.headerFilesToIndex = new ArrayList();
|
||||
this.cleanEncouteredHeaders = cleanEncounteredHeaders;
|
||||
}
|
||||
|
||||
public boolean execute(IProgressMonitor progressMonitor) {
|
||||
|
@ -102,12 +114,15 @@ 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);
|
||||
this.manager.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);
|
||||
|
||||
this.manager.addSource((IFile)headerFilesToIndex.get(i), this.indexPath, true);
|
||||
|
||||
if (cleanEncouteredHeaders){
|
||||
CleanEncounteredHeaders cleanHeaders = new CleanEncounteredHeaders(this.manager);
|
||||
this.manager.request(cleanHeaders);
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Created on Aug 19, 2004
|
||||
*
|
||||
* 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;
|
||||
|
||||
import org.eclipse.cdt.internal.core.search.processing.IJob;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
||||
/**
|
||||
* @author bgheorgh
|
||||
*
|
||||
* TODO To change the template for this generated type comment go to
|
||||
* Window - Preferences - Java - Code Style - Code Templates
|
||||
*/
|
||||
public class CleanEncounteredHeaders implements IJob {
|
||||
|
||||
IndexManager manager = null;
|
||||
|
||||
public CleanEncounteredHeaders(IndexManager manager){
|
||||
this.manager = manager;
|
||||
}
|
||||
/* (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();
|
||||
return true;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.search.processing.IJob#belongsTo(java.lang.String)
|
||||
*/
|
||||
public boolean belongsTo(String jobFamily) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.search.processing.IJob#cancel()
|
||||
*/
|
||||
public void cancel() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.search.processing.IJob#isReadyToRun()
|
||||
*/
|
||||
public boolean isReadyToRun() {
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -82,7 +82,11 @@ public class IndexAllProject extends IndexRequest {
|
|||
for (int i=0;i<sourceRoot.length;i++){
|
||||
if (sourceRoot[i] instanceof SourceRoot){
|
||||
ISourceEntry tempEntry = ((SourceRoot) sourceRoot[i]).getSourceEntry();
|
||||
this.manager.request(new AddFolderToIndex(sourceRoot[i].getPath(), project, tempEntry.fullExclusionPatternChars(), this.manager));
|
||||
|
||||
if ((i+1) != sourceRoot.length)
|
||||
this.manager.request(new AddFolderToIndex(sourceRoot[i].getPath(), project, tempEntry.fullExclusionPatternChars(), this.manager));
|
||||
else
|
||||
this.manager.request(new AddFolderToIndex(sourceRoot[i].getPath(), project, tempEntry.fullExclusionPatternChars(), this.manager,true));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ 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;
|
||||
|
@ -81,6 +82,8 @@ public class IndexManager extends JobManager implements IIndexConstants {
|
|||
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);
|
||||
|
@ -147,12 +150,16 @@ public class IndexManager extends JobManager implements IIndexConstants {
|
|||
request(job);
|
||||
}
|
||||
*/
|
||||
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){
|
||||
public void addSource(IFile resource, IPath indexedContainers, boolean checkEncounteredHeaders){
|
||||
|
||||
IProject project = resource.getProject();
|
||||
|
||||
|
@ -165,7 +172,7 @@ public class IndexManager extends JobManager implements IIndexConstants {
|
|||
if (CCorePlugin.getDefault() == null) return;
|
||||
|
||||
if (indexEnabled){
|
||||
AddCompilationUnitToIndex job = new AddCompilationUnitToIndex(resource, indexedContainers, this);
|
||||
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()) &&
|
||||
|
@ -272,6 +279,32 @@ public class IndexManager extends JobManager implements IIndexConstants {
|
|||
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;
|
||||
|
@ -289,6 +322,23 @@ public class IndexManager extends JobManager implements IIndexConstants {
|
|||
return this.indexStates;
|
||||
}
|
||||
|
||||
private 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;
|
||||
|
||||
|
@ -557,6 +607,7 @@ public class IndexManager extends JobManager implements IIndexConstants {
|
|||
this.indexes = new HashMap(5);
|
||||
this.monitors = new HashMap(5);
|
||||
this.indexStates = null;
|
||||
this.encounteredHeaders = null;
|
||||
}
|
||||
|
||||
if (this.timeoutThread == null){
|
||||
|
|
|
@ -234,6 +234,9 @@ public class SourceIndexerRequestor implements ISourceElementRequestor, IIndexCo
|
|||
ICFileType type = CCorePlugin.getDefault().getFileType(resourceProject,
|
||||
inclusion.getFullFileName());
|
||||
|
||||
/* See if this file has been encountered before */
|
||||
if (type.isHeader())
|
||||
CCorePlugin.getDefault().getCoreModel().getIndexManager().haveEncounteredHeader(resourceProject.getFullPath(),new Path(inclusion.getFullFileName()));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -248,7 +248,11 @@ public class Problem implements IProblem {
|
|||
msg = MessageFormat.format( msg, new Object [] { new String(arg) } );
|
||||
}
|
||||
|
||||
Object [] args = { msg, new String( originatingFileName ), new Integer( lineNumber ) };
|
||||
Object [] args = null;
|
||||
if (originatingFileName != null)
|
||||
args = new Object []{ msg, new String( originatingFileName ), new Integer( lineNumber ) };
|
||||
else
|
||||
args = new Object []{ msg, new String(""), new Integer( lineNumber ) };
|
||||
|
||||
message = ParserMessages.getFormattedString( PROBLEM_PATTERN, args );
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue