1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Simpler and more robust implementation of PDOMManager.joinIndexer

method.
This commit is contained in:
Sergey Prigogin 2012-08-19 17:16:10 -07:00
parent 379cc8e8e1
commit ffe717ed93
7 changed files with 124 additions and 130 deletions

View file

@ -108,7 +108,7 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.jobs.Job;
public class IndexBugsTests extends BaseTestCase { public class IndexBugsTests extends BaseTestCase {
private static final int INDEX_WAIT_TIME = 800000; //XXX private static final int INDEXER_TIMEOUT_SEC = 20;
private ICProject fCProject; private ICProject fCProject;
protected IIndex fIndex; protected IIndex fIndex;
@ -305,13 +305,13 @@ public class IndexBugsTests extends BaseTestCase {
private void waitForIndexer() throws InterruptedException { private void waitForIndexer() throws InterruptedException {
final IIndexManager indexManager = CCorePlugin.getIndexManager(); final IIndexManager indexManager = CCorePlugin.getIndexManager();
assertTrue(indexManager.joinIndexer(INDEX_WAIT_TIME, npm())); assertTrue(indexManager.joinIndexer(INDEXER_TIMEOUT_SEC * 1000, npm()));
long waitms= 1; long waitms= 1;
while (waitms < 2000 && indexManager.isIndexerSetupPostponed(fCProject)) { while (waitms < 2000 && indexManager.isIndexerSetupPostponed(fCProject)) {
Thread.sleep(waitms); Thread.sleep(waitms);
waitms *= 2; waitms *= 2;
} }
assertTrue(indexManager.joinIndexer(INDEX_WAIT_TIME, npm())); assertTrue(indexManager.joinIndexer(INDEXER_TIMEOUT_SEC * 1000, npm()));
} }
protected Pattern[] getPattern(String qname) { protected Pattern[] getPattern(String qname) {
@ -385,7 +385,7 @@ public class IndexBugsTests extends BaseTestCase {
String[] content= getContentsForTest(2); String[] content= getContentsForTest(2);
IFile file= createFile(getProject(), "header.h", content[0]); IFile file= createFile(getProject(), "header.h", content[0]);
waitUntilFileIsIndexed(file, INDEX_WAIT_TIME); waitUntilFileIsIndexed(file, INDEXER_TIMEOUT_SEC * 1000);
IIndex index= CCorePlugin.getIndexManager().getIndex(fCProject); IIndex index= CCorePlugin.getIndexManager().getIndex(fCProject);
index.acquireReadLock(); index.acquireReadLock();
@ -399,7 +399,7 @@ public class IndexBugsTests extends BaseTestCase {
} }
file= createFile(getProject(), "header.h", content[1]); file= createFile(getProject(), "header.h", content[1]);
waitUntilFileIsIndexed(file, INDEX_WAIT_TIME); waitUntilFileIsIndexed(file, INDEXER_TIMEOUT_SEC * 1000);
index= CCorePlugin.getIndexManager().getIndex(fCProject); index= CCorePlugin.getIndexManager().getIndex(fCProject);
index.acquireReadLock(); index.acquireReadLock();
@ -425,10 +425,10 @@ public class IndexBugsTests extends BaseTestCase {
content.append("unsigned int arrayDataSize = sizeof(arrayData);\n"); content.append("unsigned int arrayDataSize = sizeof(arrayData);\n");
int indexOfDecl = content.indexOf(varName); int indexOfDecl = content.indexOf(varName);
assertTrue(CCorePlugin.getIndexManager().joinIndexer(INDEX_WAIT_TIME, npm())); assertTrue(CCorePlugin.getIndexManager().joinIndexer(INDEXER_TIMEOUT_SEC * 1000, npm()));
IFile file= createFile(getProject(), fileName, content.toString()); IFile file= createFile(getProject(), fileName, content.toString());
// must be done in a reasonable amount of time // must be done in a reasonable amount of time
waitUntilFileIsIndexed(file, INDEX_WAIT_TIME); waitUntilFileIsIndexed(file, INDEXER_TIMEOUT_SEC * 1000);
fIndex.acquireReadLock(); fIndex.acquireReadLock();
try { try {
IIndexBinding[] bindings= fIndex.findBindings(getPattern("arrayDataSize"), true, IndexFilter.ALL, npm()); IIndexBinding[] bindings= fIndex.findBindings(getPattern("arrayDataSize"), true, IndexFilter.ALL, npm());
@ -451,7 +451,7 @@ public class IndexBugsTests extends BaseTestCase {
String content= getContentsForTest(1)[0]; String content= getContentsForTest(1)[0];
IFile file= TestSourceReader.createFile(fCProject.getProject(), "test156671.cpp", content); IFile file= TestSourceReader.createFile(fCProject.getProject(), "test156671.cpp", content);
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME); TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEXER_TIMEOUT_SEC * 1000);
fIndex.acquireReadLock(); fIndex.acquireReadLock();
try { try {
@ -469,7 +469,7 @@ public class IndexBugsTests extends BaseTestCase {
TestScannerProvider.sIncludes= new String[]{include.getLocation().removeLastSegments(1).toString()}; TestScannerProvider.sIncludes= new String[]{include.getLocation().removeLastSegments(1).toString()};
TestScannerProvider.sIncludeFiles= new String[]{include.getName()}; TestScannerProvider.sIncludeFiles= new String[]{include.getName()};
IFile file= TestSourceReader.createFile(fCProject.getProject(), "test160281_1.cpp", ""); IFile file= TestSourceReader.createFile(fCProject.getProject(), "test160281_1.cpp", "");
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME); TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEXER_TIMEOUT_SEC * 1000);
fIndex.acquireReadLock(); fIndex.acquireReadLock();
try { try {
@ -493,7 +493,7 @@ public class IndexBugsTests extends BaseTestCase {
TestScannerProvider.sIncludes= new String[]{include.getLocation().removeLastSegments(1).toString()}; TestScannerProvider.sIncludes= new String[]{include.getLocation().removeLastSegments(1).toString()};
TestScannerProvider.sMacroFiles= new String[]{include.getName()}; TestScannerProvider.sMacroFiles= new String[]{include.getName()};
IFile file= TestSourceReader.createFile(fCProject.getProject(), "test160281_2.cpp", "int X;"); IFile file= TestSourceReader.createFile(fCProject.getProject(), "test160281_2.cpp", "int X;");
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME); TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEXER_TIMEOUT_SEC * 1000);
fIndex.acquireReadLock(); fIndex.acquireReadLock();
try { try {
@ -528,7 +528,7 @@ public class IndexBugsTests extends BaseTestCase {
int indexOfDecl = content.indexOf(funcName); int indexOfDecl = content.indexOf(funcName);
int indexOfDef = content.indexOf(funcName, indexOfDecl+1); int indexOfDef = content.indexOf(funcName, indexOfDecl+1);
IFile file= createFile(getProject(), fileName, content); IFile file= createFile(getProject(), fileName, content);
waitUntilFileIsIndexed(file, INDEX_WAIT_TIME); waitUntilFileIsIndexed(file, INDEXER_TIMEOUT_SEC * 1000);
// make sure the ast is correct // make sure the ast is correct
ITranslationUnit tu= (ITranslationUnit) fCProject.findElement(new Path(fileName)); ITranslationUnit tu= (ITranslationUnit) fCProject.findElement(new Path(fileName));
@ -569,7 +569,7 @@ public class IndexBugsTests extends BaseTestCase {
IFile include= TestSourceReader.createFile(fCProject.getProject(), "test164360.h", ""); IFile include= TestSourceReader.createFile(fCProject.getProject(), "test164360.h", "");
TestScannerProvider.sIncludeFiles= new String[] { include.getLocation().toOSString() }; TestScannerProvider.sIncludeFiles= new String[] { include.getLocation().toOSString() };
IFile file= TestSourceReader.createFile(fCProject.getProject(), "test164360.cpp", ""); IFile file= TestSourceReader.createFile(fCProject.getProject(), "test164360.cpp", "");
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME); TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEXER_TIMEOUT_SEC * 1000);
fIndex.acquireReadLock(); fIndex.acquireReadLock();
try { try {
@ -592,7 +592,7 @@ public class IndexBugsTests extends BaseTestCase {
IFile include= TestSourceReader.createFile(fCProject.getProject(), "test164360.h", ""); IFile include= TestSourceReader.createFile(fCProject.getProject(), "test164360.h", "");
TestScannerProvider.sMacroFiles= new String[]{include.getLocation().toOSString()}; TestScannerProvider.sMacroFiles= new String[]{include.getLocation().toOSString()};
IFile file= TestSourceReader.createFile(fCProject.getProject(), "test164360.cpp", ""); IFile file= TestSourceReader.createFile(fCProject.getProject(), "test164360.cpp", "");
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME); TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEXER_TIMEOUT_SEC * 1000);
fIndex.acquireReadLock(); fIndex.acquireReadLock();
try { try {
@ -618,7 +618,7 @@ public class IndexBugsTests extends BaseTestCase {
String content= getContentsForTest(1)[0]; String content= getContentsForTest(1)[0];
IFile file= TestSourceReader.createFile(fCProject.getProject(), "test164500.cpp", content); IFile file= TestSourceReader.createFile(fCProject.getProject(), "test164500.cpp", content);
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME); TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEXER_TIMEOUT_SEC * 1000);
fIndex.acquireReadLock(); fIndex.acquireReadLock();
try { try {
@ -655,7 +655,7 @@ public class IndexBugsTests extends BaseTestCase {
String[] testData = getContentsForTest(3); String[] testData = getContentsForTest(3);
IFile header= TestSourceReader.createFile(cproject.getProject(), "header.h", testData[0]); IFile header= TestSourceReader.createFile(cproject.getProject(), "header.h", testData[0]);
IFile referer= TestSourceReader.createFile(cproject.getProject(), "content.cpp", testData[1]); IFile referer= TestSourceReader.createFile(cproject.getProject(), "content.cpp", testData[1]);
TestSourceReader.waitUntilFileIsIndexed(index, referer, INDEX_WAIT_TIME); TestSourceReader.waitUntilFileIsIndexed(index, referer, INDEXER_TIMEOUT_SEC * 1000);
index.acquireReadLock(); index.acquireReadLock();
try { try {
@ -670,7 +670,7 @@ public class IndexBugsTests extends BaseTestCase {
InputStream in = new ByteArrayInputStream(testData[2].getBytes()); InputStream in = new ByteArrayInputStream(testData[2].getBytes());
header.setContents(in, IResource.FORCE, null); header.setContents(in, IResource.FORCE, null);
TestSourceReader.waitUntilFileIsIndexed(index, header, INDEX_WAIT_TIME); TestSourceReader.waitUntilFileIsIndexed(index, header, INDEXER_TIMEOUT_SEC * 1000);
index.acquireReadLock(); index.acquireReadLock();
try { try {
@ -695,7 +695,7 @@ public class IndexBugsTests extends BaseTestCase {
String content= getContentsForTest(1)[0]; String content= getContentsForTest(1)[0];
IFile file= TestSourceReader.createFile(fCProject.getProject(), "test172454.c", content); IFile file= TestSourceReader.createFile(fCProject.getProject(), "test172454.c", content);
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME); TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEXER_TIMEOUT_SEC * 1000);
fIndex.acquireReadLock(); fIndex.acquireReadLock();
try { try {
@ -728,7 +728,7 @@ public class IndexBugsTests extends BaseTestCase {
String content= getContentsForTest(1)[0]; String content= getContentsForTest(1)[0];
IFile file= TestSourceReader.createFile(fCProject.getProject(), "test172454.cpp", content); IFile file= TestSourceReader.createFile(fCProject.getProject(), "test172454.cpp", content);
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME); TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEXER_TIMEOUT_SEC * 1000);
fIndex.acquireReadLock(); fIndex.acquireReadLock();
try { try {
@ -762,7 +762,7 @@ public class IndexBugsTests extends BaseTestCase {
String content= getContentsForTest(1)[0]; String content= getContentsForTest(1)[0];
IFile file= TestSourceReader.createFile(fCProject.getProject(), "test173997.cpp", content); IFile file= TestSourceReader.createFile(fCProject.getProject(), "test173997.cpp", content);
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME); TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEXER_TIMEOUT_SEC * 1000);
fIndex.acquireReadLock(); fIndex.acquireReadLock();
try { try {
@ -781,7 +781,7 @@ public class IndexBugsTests extends BaseTestCase {
long timestamp= file.getLocalTimeStamp(); long timestamp= file.getLocalTimeStamp();
content= "int UPDATED20070213;\n" + content.replaceFirst("int", "float"); content= "int UPDATED20070213;\n" + content.replaceFirst("int", "float");
file= TestSourceReader.createFile(fCProject.getProject(), "test173997.cpp", content); file= TestSourceReader.createFile(fCProject.getProject(), "test173997.cpp", content);
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME); TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEXER_TIMEOUT_SEC * 1000);
fIndex.acquireReadLock(); fIndex.acquireReadLock();
try { try {
@ -814,7 +814,7 @@ public class IndexBugsTests extends BaseTestCase {
String[] content= getContentsForTest(2); String[] content= getContentsForTest(2);
IFile file= createFile(getProject(), "header.h", content[0]); IFile file= createFile(getProject(), "header.h", content[0]);
waitUntilFileIsIndexed(file, INDEX_WAIT_TIME); waitUntilFileIsIndexed(file, INDEXER_TIMEOUT_SEC * 1000);
IIndex index= CCorePlugin.getIndexManager().getIndex(fCProject); IIndex index= CCorePlugin.getIndexManager().getIndex(fCProject);
index.acquireReadLock(); index.acquireReadLock();
@ -829,7 +829,7 @@ public class IndexBugsTests extends BaseTestCase {
} }
file= createFile(getProject(), "header.h", content[1]); file= createFile(getProject(), "header.h", content[1]);
waitUntilFileIsIndexed(file, INDEX_WAIT_TIME); waitUntilFileIsIndexed(file, INDEXER_TIMEOUT_SEC * 1000);
index= CCorePlugin.getIndexManager().getIndex(fCProject); index= CCorePlugin.getIndexManager().getIndex(fCProject);
index.acquireReadLock(); index.acquireReadLock();
@ -971,7 +971,7 @@ public class IndexBugsTests extends BaseTestCase {
IIndex index = CCorePlugin.getIndexManager().getIndex(cproject); IIndex index = CCorePlugin.getIndexManager().getIndex(cproject);
String content= getContentsForTest(1)[0]; String content= getContentsForTest(1)[0];
IFile file= TestSourceReader.createFile(cproject.getProject(), "content.cpp", content); IFile file= TestSourceReader.createFile(cproject.getProject(), "content.cpp", content);
TestSourceReader.waitUntilFileIsIndexed(index, file, INDEX_WAIT_TIME); TestSourceReader.waitUntilFileIsIndexed(index, file, INDEXER_TIMEOUT_SEC * 1000);
CProjectHelper.delete(cproject); CProjectHelper.delete(cproject);
cproject = CProjectHelper.createCCProject(pname, "bin", IPDOMManager.ID_FAST_INDEXER); cproject = CProjectHelper.createCCProject(pname, "bin", IPDOMManager.ID_FAST_INDEXER);
@ -997,7 +997,7 @@ public class IndexBugsTests extends BaseTestCase {
IIndex index = CCorePlugin.getIndexManager().getIndex(cproject); IIndex index = CCorePlugin.getIndexManager().getIndex(cproject);
String content= getContentsForTest(1)[0]; String content= getContentsForTest(1)[0];
IFile file= TestSourceReader.createFile(cproject.getProject(), "content.cpp", content); IFile file= TestSourceReader.createFile(cproject.getProject(), "content.cpp", content);
TestSourceReader.waitUntilFileIsIndexed(index, file, INDEX_WAIT_TIME); TestSourceReader.waitUntilFileIsIndexed(index, file, INDEXER_TIMEOUT_SEC * 1000);
// move the project to a random new location // move the project to a random new location
File newLocation = CProjectHelper.freshDir(); File newLocation = CProjectHelper.freshDir();
@ -1030,7 +1030,7 @@ public class IndexBugsTests extends BaseTestCase {
String content= getContentsForTest(1)[0]; String content= getContentsForTest(1)[0];
IFile file= TestSourceReader.createFile(fCProject.getProject(), "testFBWP.cpp", content); IFile file= TestSourceReader.createFile(fCProject.getProject(), "testFBWP.cpp", content);
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME); TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEXER_TIMEOUT_SEC * 1000);
fIndex.acquireReadLock(); fIndex.acquireReadLock();
try { try {
@ -1063,7 +1063,7 @@ public class IndexBugsTests extends BaseTestCase {
String content= getContentsForTest(1)[0]; String content= getContentsForTest(1)[0];
IFile file= TestSourceReader.createFile(fCProject.getProject(), "testFilterFindBindingsFQCharArray.cpp", content); IFile file= TestSourceReader.createFile(fCProject.getProject(), "testFilterFindBindingsFQCharArray.cpp", content);
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME); TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEXER_TIMEOUT_SEC * 1000);
fIndex.acquireReadLock(); fIndex.acquireReadLock();
try { try {
@ -1186,7 +1186,7 @@ public class IndexBugsTests extends BaseTestCase {
String[] contents= getContentsForTest(2); String[] contents= getContentsForTest(2);
final IIndexManager indexManager = CCorePlugin.getIndexManager(); final IIndexManager indexManager = CCorePlugin.getIndexManager();
IFile f1= TestSourceReader.createFile(fCProject.getProject(), "header.h", contents[0]); IFile f1= TestSourceReader.createFile(fCProject.getProject(), "header.h", contents[0]);
waitUntilFileIsIndexed(f1, INDEX_WAIT_TIME); waitUntilFileIsIndexed(f1, INDEXER_TIMEOUT_SEC * 1000);
IFile f2= TestSourceReader.createFile(fCProject.getProject(), "src.cpp", contents[1]); IFile f2= TestSourceReader.createFile(fCProject.getProject(), "src.cpp", contents[1]);
waitForIndexer(); waitForIndexer();
@ -1212,7 +1212,7 @@ public class IndexBugsTests extends BaseTestCase {
String[] contents= getContentsForTest(2); String[] contents= getContentsForTest(2);
final IIndexManager indexManager = CCorePlugin.getIndexManager(); final IIndexManager indexManager = CCorePlugin.getIndexManager();
IFile f1= TestSourceReader.createFile(fCProject.getProject(), "header.h", contents[0]); IFile f1= TestSourceReader.createFile(fCProject.getProject(), "header.h", contents[0]);
waitUntilFileIsIndexed(f1, INDEX_WAIT_TIME); waitUntilFileIsIndexed(f1, INDEXER_TIMEOUT_SEC * 1000);
IFile f2= TestSourceReader.createFile(fCProject.getProject(), "src.cpp", contents[1]); IFile f2= TestSourceReader.createFile(fCProject.getProject(), "src.cpp", contents[1]);
waitForIndexer(); waitForIndexer();
@ -2303,7 +2303,7 @@ public class IndexBugsTests extends BaseTestCase {
} }
s= TestSourceReader.createFile(src, "source.cpp", "#include \"../h/a.h\""); s= TestSourceReader.createFile(src, "source.cpp", "#include \"../h/a.h\"");
waitUntilFileIsIndexed(s, INDEX_WAIT_TIME); waitUntilFileIsIndexed(s, INDEXER_TIMEOUT_SEC * 1000);
index.acquireReadLock(); index.acquireReadLock();
try { try {
r = index.findBindings("version2".toCharArray(), IndexFilter.ALL_DECLARED, null); r = index.findBindings("version2".toCharArray(), IndexFilter.ALL_DECLARED, null);
@ -2313,7 +2313,7 @@ public class IndexBugsTests extends BaseTestCase {
} }
s= TestSourceReader.createFile(h, "a.h", "int version3;"); s= TestSourceReader.createFile(h, "a.h", "int version3;");
waitUntilFileIsIndexed(s, INDEX_WAIT_TIME); waitUntilFileIsIndexed(s, INDEXER_TIMEOUT_SEC * 1000);
index.acquireReadLock(); index.acquireReadLock();
try { try {
r = index.findBindings("version2".toCharArray(), IndexFilter.ALL_DECLARED, null); r = index.findBindings("version2".toCharArray(), IndexFilter.ALL_DECLARED, null);

View file

@ -29,6 +29,7 @@ import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexFile; import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IndexLocationFactory; import org.eclipse.cdt.core.index.IndexLocationFactory;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
@ -315,18 +316,21 @@ public class TestSourceReader {
* @since 4.0 * @since 4.0
*/ */
public static void waitUntilFileIsIndexed(IIndex index, IFile file, int maxmillis) throws Exception { public static void waitUntilFileIsIndexed(IIndex index, IFile file, int maxmillis) throws Exception {
long fileTimestamp = file.getLocalTimeStamp();
IIndexFileLocation indexFileLocation = IndexLocationFactory.getWorkspaceIFL(file);
long endTime= System.currentTimeMillis() + maxmillis; long endTime= System.currentTimeMillis() + maxmillis;
int timeLeft= maxmillis; int timeLeft= maxmillis;
while (timeLeft >= 0) { while (timeLeft >= 0) {
Assert.assertTrue(CCorePlugin.getIndexManager().joinIndexer(timeLeft, new NullProgressMonitor())); Assert.assertTrue(CCorePlugin.getIndexManager().joinIndexer(timeLeft, new NullProgressMonitor()));
index.acquireReadLock(); index.acquireReadLock();
try { try {
IIndexFile[] files= index.getFiles(ILinkage.CPP_LINKAGE_ID, IndexLocationFactory.getWorkspaceIFL(file)); IIndexFile[] files= index.getFiles(ILinkage.CPP_LINKAGE_ID, indexFileLocation);
if (files.length > 0 && areAllFilesNotOlderThan(files, file.getLocalTimeStamp())) { if (files.length > 0 && areAllFilesNotOlderThan(files, fileTimestamp)) {
return; return;
} }
files= index.getFiles(ILinkage.C_LINKAGE_ID, IndexLocationFactory.getWorkspaceIFL(file)); files= index.getFiles(ILinkage.C_LINKAGE_ID, indexFileLocation);
if (files.length > 0 && areAllFilesNotOlderThan(files, file.getLocalTimeStamp())) { if (files.length > 0 && areAllFilesNotOlderThan(files, fileTimestamp)) {
return; return;
} }
} finally { } finally {

View file

@ -100,7 +100,9 @@ import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.QualifiedName; import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.SafeRunner; import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener; import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent; import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
import org.eclipse.core.runtime.preferences.IPreferencesService; import org.eclipse.core.runtime.preferences.IPreferencesService;
@ -1088,52 +1090,42 @@ public class PDOMManager implements IWritableIndexManager, IListener {
@Override @Override
public boolean joinIndexer(final int waitMaxMillis, final IProgressMonitor monitor) { public boolean joinIndexer(final int waitMaxMillis, final IProgressMonitor monitor) {
assert monitor != null; assert monitor != null;
long startMillis = System.currentTimeMillis(); long deadline = waitMaxMillis == FOREVER ? Long.MAX_VALUE : System.currentTimeMillis() + waitMaxMillis;
// Unfortunately, IJobManager.join() doesn't take a timeout. So, we create a watchdog thread to final boolean[] idleCondition = { false };
// interrupt the call if the indexer job doesn't complete in the alloted time JobChangeAdapter listener = new JobChangeAdapter() {
Thread th= null; @Override
if (waitMaxMillis != FOREVER) { public void done(IJobChangeEvent event) {
final Thread callingThread= Thread.currentThread(); synchronized (idleCondition) {
th= new Thread() { Job[] jobs = Job.getJobManager().find(PDOMManager.this);
@Override if (jobs.length == 0 || jobs.length == 1 && event.getJob() == jobs[0]) {
public void run() { idleCondition[0] = true;
idleCondition.notifyAll();
}
}
}
};
Job.getJobManager().addJobChangeListener(listener);
try {
if (Job.getJobManager().find(this).length == 0) {
return true;
}
synchronized (idleCondition) {
while (!idleCondition[0]) {
try { try {
Thread.sleep(waitMaxMillis); if (monitor.isCanceled())
monitor.setCanceled(true); return false;
callingThread.interrupt(); long t = System.currentTimeMillis();
if (t >= deadline)
return false;
idleCondition.wait(Math.min(100, deadline - t));
} catch (InterruptedException e) { } catch (InterruptedException e) {
} }
} }
};
th.setDaemon(true);
th.start();
}
try {
try {
Job.getJobManager().join(this, monitor);
return true; return true;
} catch (OperationCanceledException e) {
} catch (InterruptedException e) {
} }
// When the indexer job is interrupted, the join() above will throw an exception and that can
// happen slightly before the JobManager updates its job collection. Wait for it.
while (Job.getJobManager().find(this).length != 0) {
if (System.currentTimeMillis() - startMillis > waitMaxMillis) {
return false;
}
try {
Thread.sleep(50);
} catch (InterruptedException e) {
}
}
return true;
} finally { } finally {
// Make sure we don't leave the watchdog thread running Job.getJobManager().removeJobChangeListener(listener);
if (th != null) {
th.interrupt();
}
} }
} }

View file

@ -56,7 +56,7 @@ import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContext;
* Common base for refactoring tests. * Common base for refactoring tests.
*/ */
public abstract class RefactoringTestBase extends BaseTestCase { public abstract class RefactoringTestBase extends BaseTestCase {
private static final int INDEXER_TIMEOUT_SEC = 360; private static final int INDEXER_TIMEOUT_SEC = 300;
protected static final NullProgressMonitor NULL_PROGRESS_MONITOR = new NullProgressMonitor(); protected static final NullProgressMonitor NULL_PROGRESS_MONITOR = new NullProgressMonitor();
/** Allows empty files to be created during test setup. */ /** Allows empty files to be created during test setup. */

View file

@ -47,10 +47,12 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.testplugin.FileManager; import org.eclipse.cdt.core.testplugin.FileManager;
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
import org.eclipse.cdt.ui.testplugin.EditorTestHelper; import org.eclipse.cdt.ui.testplugin.EditorTestHelper;
import org.eclipse.cdt.ui.tests.BaseUITestCase; import org.eclipse.cdt.ui.tests.BaseUITestCase;
@ -68,6 +70,7 @@ import org.eclipse.cdt.internal.ui.search.actions.OpenDeclarationsAction;
* @author dsteffle * @author dsteffle
*/ */
public class BaseSelectionTestsIndexer extends BaseUITestCase { public class BaseSelectionTestsIndexer extends BaseUITestCase {
protected static final int INDEXER_TIMEOUT_SEC = 20;
protected ICProject fCProject; protected ICProject fCProject;
static FileManager fileManager = new FileManager(); static FileManager fileManager = new FileManager();
IProgressMonitor monitor = new NullProgressMonitor(); IProgressMonitor monitor = new NullProgressMonitor();
@ -91,6 +94,10 @@ public class BaseSelectionTestsIndexer extends BaseUITestCase {
assertTrue(CCorePlugin.getIndexManager().joinIndexer(maxSec * 1000, new NullProgressMonitor())); assertTrue(CCorePlugin.getIndexManager().joinIndexer(maxSec * 1000, new NullProgressMonitor()));
} }
protected void waitUntilFileIsIndexed(IIndex index, IFile file) throws Exception {
TestSourceReader.waitUntilFileIsIndexed(index, file, INDEXER_TIMEOUT_SEC * 1000);
}
protected String getMessage(IStatus status) { protected String getMessage(IStatus status) {
StringBuffer message = new StringBuffer("["); //$NON-NLS-1$ StringBuffer message = new StringBuffer("["); //$NON-NLS-1$
message.append(status.getMessage()); message.append(status.getMessage());

View file

@ -37,8 +37,6 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
* Test Ctrl-F3/F3 with the DOM Indexer for a C++ project. * Test Ctrl-F3/F3 with the DOM Indexer for a C++ project.
*/ */
public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsIndexer { public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsIndexer {
private static final int MAX_WAIT_TIME = 8000;
protected String sourceIndexerID; protected String sourceIndexerID;
protected IIndex index; protected IIndex index;
@ -87,10 +85,6 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
assertEquals(loc.getNodeLength(), name.length()); assertEquals(loc.getNodeLength(), name.length());
} }
protected void waitUntilFileIsIndexed(IIndex index, IFile file, int maxmillis) throws Exception {
TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
}
// // header // // header
// class Point{ // class Point{
// public: // public:
@ -124,7 +118,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("test93281.h", hcode); IFile hfile = importFile("test93281.h", hcode);
IFile file = importFile("test93281.cpp", scode); IFile file = importFile("test93281.cpp", scode);
waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); waitUntilFileIsIndexed(index, file);
int offset = scode.indexOf("p2->operator") + 6; int offset = scode.indexOf("p2->operator") + 6;
IASTNode node = testF3(file, offset); IASTNode node = testF3(file, offset);
@ -166,7 +160,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("test.h", hcode); IFile hfile = importFile("test.h", hcode);
IFile file = importFile("test.cpp", scode); IFile file = importFile("test.cpp", scode);
waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); waitUntilFileIsIndexed(index, file);
int hoffset= hcode.indexOf("testTemplate"); int hoffset= hcode.indexOf("testTemplate");
int soffset = scode.indexOf("testTemplate"); int soffset = scode.indexOf("testTemplate");
@ -192,7 +186,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("test.h", hcode); IFile hfile = importFile("test.h", hcode);
IFile file = importFile("test.cpp", scode); IFile file = importFile("test.cpp", scode);
waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); waitUntilFileIsIndexed(index, file);
int hoffset= hcode.indexOf("assign"); int hoffset= hcode.indexOf("assign");
int soffset = scode.indexOf("assign"); int soffset = scode.indexOf("assign");
@ -223,7 +217,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("basicDefinition.h", hcode); IFile hfile = importFile("basicDefinition.h", hcode);
IFile file = importFile("testBasicDefinition.cpp", scode); IFile file = importFile("testBasicDefinition.cpp", scode);
waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); waitUntilFileIsIndexed(index, file);
int hoffset= hcode.indexOf("MyInt"); int hoffset= hcode.indexOf("MyInt");
int soffset = scode.indexOf("MyInt"); int soffset = scode.indexOf("MyInt");
@ -304,7 +298,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("testBasicTemplateInstance.h", hcode); IFile hfile = importFile("testBasicTemplateInstance.h", hcode);
IFile file = importFile("testBasicTemplateInstance.cpp", scode); IFile file = importFile("testBasicTemplateInstance.cpp", scode);
waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); waitUntilFileIsIndexed(index, file);
int hoffset= hcode.indexOf("AAA"); int hoffset= hcode.indexOf("AAA");
int soffset = scode.indexOf("AAA<int>"); int soffset = scode.indexOf("AAA<int>");
@ -338,7 +332,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("testBug86829A.h", hcode); IFile hfile = importFile("testBug86829A.h", hcode);
IFile file = importFile("testBug86829A.cpp", scode); IFile file = importFile("testBug86829A.cpp", scode);
waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); waitUntilFileIsIndexed(index, file);
int offset = scode.indexOf("X(2)"); int offset = scode.indexOf("X(2)");
int doffset= hcode.indexOf("X(int)"); int doffset= hcode.indexOf("X(int)");
@ -370,7 +364,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("testBug86829B.h", hcode); IFile hfile = importFile("testBug86829B.h", hcode);
IFile file = importFile("testBug86829B.cpp", scode); IFile file = importFile("testBug86829B.cpp", scode);
waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); waitUntilFileIsIndexed(index, file);
int offset = scode.indexOf("X(a)"); int offset = scode.indexOf("X(a)");
int doffset = hcode.indexOf("X()"); int doffset = hcode.indexOf("X()");
@ -413,7 +407,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("testCPPSpecDeclsDefs.h", hcode); IFile hfile = importFile("testCPPSpecDeclsDefs.h", hcode);
IFile file = importFile("testCPPSpecDeclsDefs.cpp", scode); IFile file = importFile("testCPPSpecDeclsDefs.cpp", scode);
waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); waitUntilFileIsIndexed(index, file);
int offset0= hcode.indexOf("a;"); int offset0= hcode.indexOf("a;");
int offset1= scode.indexOf("a;"); int offset1= scode.indexOf("a;");
@ -564,7 +558,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("testBug168533.h", hcode); IFile hfile = importFile("testBug168533.h", hcode);
IFile file = importFile("testBug168533.cpp", scode); IFile file = importFile("testBug168533.cpp", scode);
waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); waitUntilFileIsIndexed(index, file);
int offset0= hcode.indexOf("d;"); int offset0= hcode.indexOf("d;");
int offset1= scode.indexOf("d;"); int offset1= scode.indexOf("d;");
@ -600,7 +594,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("testBug95225.h", hcode); IFile hfile = importFile("testBug95225.h", hcode);
IFile file = importFile("testBug95225.cpp", scode); IFile file = importFile("testBug95225.cpp", scode);
waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); waitUntilFileIsIndexed(index, file);
IASTNode decl; IASTNode decl;
int offset0, offset1; int offset0, offset1;
@ -642,7 +636,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("testBug95202.h", hcode); IFile hfile = importFile("testBug95202.h", hcode);
IFile file = importFile("testBug95202.cpp", scode); IFile file = importFile("testBug95202.cpp", scode);
waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); waitUntilFileIsIndexed(index, file);
IASTNode decl; IASTNode decl;
int offset0, offset1; int offset0, offset1;
@ -666,7 +660,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("testBug101287.h", hcode); IFile hfile = importFile("testBug101287.h", hcode);
IFile file = importFile("testBug101287.cpp", scode); IFile file = importFile("testBug101287.cpp", scode);
waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); waitUntilFileIsIndexed(index, file);
IASTNode decl; IASTNode decl;
int offset0, offset1; int offset0, offset1;
@ -692,7 +686,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("testBug102258.h", hcode); IFile hfile = importFile("testBug102258.h", hcode);
IFile file = importFile("testBug102258.cpp", scode); IFile file = importFile("testBug102258.cpp", scode);
waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); waitUntilFileIsIndexed(index, file);
IASTNode decl; IASTNode decl;
int offset0, offset1; int offset0, offset1;
@ -720,7 +714,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("testBug103323.h", hcode); IFile hfile = importFile("testBug103323.h", hcode);
IFile file = importFile("testBug103323.cpp", scode); IFile file = importFile("testBug103323.cpp", scode);
waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); waitUntilFileIsIndexed(index, file);
IASTNode decl; IASTNode decl;
int offset0, offset1; int offset0, offset1;
@ -750,7 +744,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("testBug78354.h", hcode); IFile hfile = importFile("testBug78354.h", hcode);
IFile file = importFile("testBug78354.cpp", scode); IFile file = importFile("testBug78354.cpp", scode);
waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); waitUntilFileIsIndexed(index, file);
IASTNode decl; IASTNode decl;
int offset0, offset1; int offset0, offset1;
@ -781,7 +775,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFileWithLink("testBug103697.h", hcode); IFile hfile = importFileWithLink("testBug103697.h", hcode);
IFile file = importFileWithLink("testBug103697.cpp", scode); IFile file = importFileWithLink("testBug103697.cpp", scode);
waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); waitUntilFileIsIndexed(index, file);
IASTNode decl; IASTNode decl;
int offset0, offset1; int offset0, offset1;
@ -808,7 +802,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("testBug108202.h", hcode); IFile hfile = importFile("testBug108202.h", hcode);
IFile file = importFile("testBug108202.cpp", scode); IFile file = importFile("testBug108202.cpp", scode);
waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); waitUntilFileIsIndexed(index, file);
IASTNode decl; IASTNode decl;
int offset0, offset1; int offset0, offset1;
@ -840,7 +834,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
IFile hcppfile = importFile("cpp.h", hcppcode); IFile hcppfile = importFile("cpp.h", hcppcode);
IFile cppfile = importFile("cpp.cpp", cppcode); IFile cppfile = importFile("cpp.cpp", cppcode);
CCorePlugin.getIndexManager().reindex(fCProject); CCorePlugin.getIndexManager().reindex(fCProject);
waitForIndex(MAX_WAIT_TIME); waitForIndex(INDEXER_TIMEOUT_SEC * 1000);
IASTNode decl; IASTNode decl;
int offset0, offset1; int offset0, offset1;
@ -875,7 +869,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("testBug190730.h", hcode); IFile hfile = importFile("testBug190730.h", hcode);
IFile file = importFile("testBug190730.cpp", scode); IFile file = importFile("testBug190730.cpp", scode);
waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); waitUntilFileIsIndexed(index, file);
IASTNode decl; IASTNode decl;
int offset0, offset1; int offset0, offset1;
@ -901,7 +895,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("testBug190730_2.h", hcode); IFile hfile = importFile("testBug190730_2.h", hcode);
IFile file = importFile("testBug190730_2.cpp", scode); IFile file = importFile("testBug190730_2.cpp", scode);
waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); waitUntilFileIsIndexed(index, file);
IASTNode decl; IASTNode decl;
int offset0, offset1; int offset0, offset1;
@ -929,7 +923,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("macrodef.h", hcode); IFile hfile = importFile("macrodef.h", hcode);
IFile file = importFile("macronavi.cpp", scode); IFile file = importFile("macronavi.cpp", scode);
waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); waitUntilFileIsIndexed(index, file);
IASTNode decl; IASTNode decl;
int offset0, offset1; int offset0, offset1;
@ -964,7 +958,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("macrodef.h", hcode); IFile hfile = importFile("macrodef.h", hcode);
IFile file = importFile("macronavi.cpp", scode); IFile file = importFile("macronavi.cpp", scode);
waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); waitUntilFileIsIndexed(index, file);
IASTNode decl; IASTNode decl;
int offset0, offset1; int offset0, offset1;
@ -993,7 +987,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("testUndef_312399.h", hcode); IFile hfile = importFile("testUndef_312399.h", hcode);
IFile file = importFile("testUndef_312399.cpp", scode); IFile file = importFile("testUndef_312399.cpp", scode);
waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); waitUntilFileIsIndexed(index, file);
IASTNode target = testF3(file, scode.indexOf("MYMACRO")); IASTNode target = testF3(file, scode.indexOf("MYMACRO"));
assertTrue(target instanceof IASTName); assertTrue(target instanceof IASTName);
@ -1011,7 +1005,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("aheader.h", hcode); IFile hfile = importFile("aheader.h", hcode);
IFile file = importFile("includenavi.cpp", scode); IFile file = importFile("includenavi.cpp", scode);
waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); waitUntilFileIsIndexed(index, file);
IASTNode decl; IASTNode decl;
int offset0, offset1; int offset0, offset1;
@ -1037,7 +1031,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile cfile = importFile("s.c", ccode); IFile cfile = importFile("s.c", ccode);
IFile cppfile = importFile("s.cpp", scode); IFile cppfile = importFile("s.cpp", scode);
waitUntilFileIsIndexed(index, cppfile, MAX_WAIT_TIME); waitUntilFileIsIndexed(index, cppfile);
IASTNode decl; IASTNode decl;
int offset1, offset2; int offset1, offset2;
@ -1075,7 +1069,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile cfile = importFile("s.c", ccode); IFile cfile = importFile("s.c", ccode);
IFile cppfile = importFile("s.cpp", scode); IFile cppfile = importFile("s.cpp", scode);
waitUntilFileIsIndexed(index, cppfile, MAX_WAIT_TIME); waitUntilFileIsIndexed(index, cppfile);
IASTNode decl; IASTNode decl;
int offset1, offset2; int offset1, offset2;
@ -1108,7 +1102,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
StringBuilder[] buffers= getContents(1); StringBuilder[] buffers= getContents(1);
String code= buffers[0].toString(); String code= buffers[0].toString();
IFile file = importFile("s.cpp", code); IFile file = importFile("s.cpp", code);
waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); waitUntilFileIsIndexed(index, file);
IASTNode decl; IASTNode decl;
int offset1, offset2; int offset1, offset2;
@ -1139,7 +1133,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
StringBuilder[] buffers= getContents(1); StringBuilder[] buffers= getContents(1);
String code= buffers[0].toString(); String code= buffers[0].toString();
IFile file = importFile("in.cpp", code); IFile file = importFile("in.cpp", code);
waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); waitUntilFileIsIndexed(index, file);
int offset1 = code.indexOf("operator +"); int offset1 = code.indexOf("operator +");
int offset2 = code.indexOf("+ x;"); int offset2 = code.indexOf("+ x;");
@ -1180,7 +1174,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("test.h", hcode); IFile hfile = importFile("test.h", hcode);
IFile file = importFile("test.cpp", scode); IFile file = importFile("test.cpp", scode);
waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); waitUntilFileIsIndexed(index, file);
int hoffset= hcode.indexOf("operator+"); int hoffset= hcode.indexOf("operator+");
int soffset = scode.indexOf("+"); int soffset = scode.indexOf("+");
@ -1199,7 +1193,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
public void testBug305487() throws Exception { public void testBug305487() throws Exception {
String code = getAboveComment(); String code = getAboveComment();
IFile file = importFile("testBug305487.cpp", code); IFile file = importFile("testBug305487.cpp", code);
waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); waitUntilFileIsIndexed(index, file);
int offset= code.indexOf("test(0)"); int offset= code.indexOf("test(0)");
IASTNode def = testF3(file, offset + 1); IASTNode def = testF3(file, offset + 1);
@ -1226,7 +1220,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("testImplicitConstructorCall_248855.h", hcode); IFile hfile = importFile("testImplicitConstructorCall_248855.h", hcode);
IFile file = importFile("testImplicitConstructorCall_248855.cpp", scode); IFile file = importFile("testImplicitConstructorCall_248855.cpp", scode);
waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); waitUntilFileIsIndexed(index, file);
IASTNode target = testF3(file, scode.indexOf("a1")); IASTNode target = testF3(file, scode.indexOf("a1"));
assertTrue(target instanceof IASTName); assertTrue(target instanceof IASTName);
@ -1264,7 +1258,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("test.h", hcode); IFile hfile = importFile("test.h", hcode);
IFile file = importFile("test.cpp", scode); IFile file = importFile("test.cpp", scode);
waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); waitUntilFileIsIndexed(index, file);
int hoffset= hcode.indexOf("func"); int hoffset= hcode.indexOf("func");
int offset = scode.indexOf("func()"); int offset = scode.indexOf("func()");

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui.tests.text.selection; package org.eclipse.cdt.ui.tests.text.selection;
@ -33,9 +33,6 @@ import org.eclipse.cdt.ui.testplugin.CTestPlugin;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexer { public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexer {
private static final int MAX_WAIT_TIME = 8000;
private String sourceIndexerID; private String sourceIndexerID;
private IIndex index; private IIndex index;
@ -99,7 +96,7 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("basicDefinition.h", hcode); IFile hfile = importFile("basicDefinition.h", hcode);
IFile file = importFile("testBasicDefinition.c", scode); IFile file = importFile("testBasicDefinition.c", scode);
TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); TestSourceReader.waitUntilFileIsIndexed(index, file, INDEXER_TIMEOUT_SEC * 1000);
int hoffset= hcode.indexOf("MyInt"); int hoffset= hcode.indexOf("MyInt");
int soffset = scode.indexOf("MyInt"); int soffset = scode.indexOf("MyInt");
@ -181,7 +178,7 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("testCPPSpecDeclsDefs.h", hcode); IFile hfile = importFile("testCPPSpecDeclsDefs.h", hcode);
IFile file = importFile("testCPPSpecDeclsDefs.c", scode); IFile file = importFile("testCPPSpecDeclsDefs.c", scode);
TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); TestSourceReader.waitUntilFileIsIndexed(index, file, INDEXER_TIMEOUT_SEC * 1000);
int offset0= hcode.indexOf("a;"); int offset0= hcode.indexOf("a;");
int offset1= scode.indexOf("a;"); int offset1= scode.indexOf("a;");
@ -293,7 +290,7 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("testBug101287.h", hcode); IFile hfile = importFile("testBug101287.h", hcode);
IFile file = importFile("testBug101287.c", scode); IFile file = importFile("testBug101287.c", scode);
TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); TestSourceReader.waitUntilFileIsIndexed(index, file, INDEXER_TIMEOUT_SEC * 1000);
IASTNode decl; IASTNode decl;
int offset0, offset1; int offset0, offset1;
@ -317,7 +314,7 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFileWithLink("testBug103697.h", hcode); IFile hfile = importFileWithLink("testBug103697.h", hcode);
IFile file = importFileWithLink("testBug103697.c", scode); IFile file = importFileWithLink("testBug103697.c", scode);
TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); TestSourceReader.waitUntilFileIsIndexed(index, file, INDEXER_TIMEOUT_SEC * 1000);
IASTNode decl; IASTNode decl;
int offset0, offset1; int offset0, offset1;
@ -345,7 +342,7 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("testBug78354.h", hcode); IFile hfile = importFile("testBug78354.h", hcode);
IFile file = importFile("testBug78354.c", scode); IFile file = importFile("testBug78354.c", scode);
TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); TestSourceReader.waitUntilFileIsIndexed(index, file, INDEXER_TIMEOUT_SEC * 1000);
IASTNode decl; IASTNode decl;
int offset0, offset1; int offset0, offset1;
@ -378,7 +375,7 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("testBug190730.h", hcode); IFile hfile = importFile("testBug190730.h", hcode);
IFile file = importFile("testBug190730.c", scode); IFile file = importFile("testBug190730.c", scode);
TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); TestSourceReader.waitUntilFileIsIndexed(index, file, INDEXER_TIMEOUT_SEC * 1000);
IASTNode decl; IASTNode decl;
int offset0, offset1; int offset0, offset1;
@ -404,7 +401,7 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("testBug190730_2.h", hcode); IFile hfile = importFile("testBug190730_2.h", hcode);
IFile file = importFile("testBug190730_2.c", scode); IFile file = importFile("testBug190730_2.c", scode);
TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); TestSourceReader.waitUntilFileIsIndexed(index, file, INDEXER_TIMEOUT_SEC * 1000);
IASTNode decl; IASTNode decl;
int offset0, offset1; int offset0, offset1;
@ -432,7 +429,7 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("macrodef.h", hcode); IFile hfile = importFile("macrodef.h", hcode);
IFile file = importFile("macronavi.c", scode); IFile file = importFile("macronavi.c", scode);
TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); TestSourceReader.waitUntilFileIsIndexed(index, file, INDEXER_TIMEOUT_SEC * 1000);
IASTNode decl; IASTNode decl;
int offset0, offset1; int offset0, offset1;
@ -465,7 +462,7 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("macrodef.h", hcode); IFile hfile = importFile("macrodef.h", hcode);
IFile file = importFile("macronavi.c", scode); IFile file = importFile("macronavi.c", scode);
TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); TestSourceReader.waitUntilFileIsIndexed(index, file, INDEXER_TIMEOUT_SEC * 1000);
IASTNode decl; IASTNode decl;
int offset0, offset1; int offset0, offset1;
@ -489,7 +486,7 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("aheader.h", hcode); IFile hfile = importFile("aheader.h", hcode);
IFile file = importFile("includenavi.c", scode); IFile file = importFile("includenavi.c", scode);
TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); TestSourceReader.waitUntilFileIsIndexed(index, file, INDEXER_TIMEOUT_SEC * 1000);
IASTNode decl; IASTNode decl;
int offset0, offset1; int offset0, offset1;
@ -509,7 +506,7 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe
String scode= buffers[1].toString(); String scode= buffers[1].toString();
IFile hfile = importFile("aheader.h", hcode); IFile hfile = importFile("aheader.h", hcode);
IFile file = importFile("source.c", scode); IFile file = importFile("source.c", scode);
TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); TestSourceReader.waitUntilFileIsIndexed(index, file, INDEXER_TIMEOUT_SEC * 1000);
IASTNode decl; IASTNode decl;
int offset0, offset1; int offset0, offset1;
@ -539,7 +536,7 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe
IFile hfile = importFile("aheader.h", hcode); IFile hfile = importFile("aheader.h", hcode);
IFile file = importFile("source.c", code); IFile file = importFile("source.c", code);
int offset= code.indexOf("myFunc(0)"); int offset= code.indexOf("myFunc(0)");
TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); TestSourceReader.waitUntilFileIsIndexed(index, file, INDEXER_TIMEOUT_SEC * 1000);
IASTNode decl= testF3(file, offset); IASTNode decl= testF3(file, offset);
assertTrue(decl instanceof IASTName); assertTrue(decl instanceof IASTName);
@ -555,8 +552,8 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe
IFile file = importFile("source.c", code); IFile file = importFile("source.c", code);
int offset= code.indexOf("__LINE__"); int offset= code.indexOf("__LINE__");
TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); TestSourceReader.waitUntilFileIsIndexed(index, file, INDEXER_TIMEOUT_SEC * 1000);
// just make sure that no NPE is thrown. // Just make sure that no NPE is thrown.
testF3(file, offset); testF3(file, offset);
} }
} }