mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 08:55:25 +02:00
Bug 283080: Updating headers in non-src folders.
This commit is contained in:
parent
658dc0af75
commit
5a013d6320
10 changed files with 73 additions and 34 deletions
|
@ -81,6 +81,7 @@ import org.eclipse.cdt.core.testplugin.TestScannerProvider;
|
|||
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
||||
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
import org.eclipse.cdt.internal.core.pdom.CModelListener;
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
|
@ -624,6 +625,7 @@ public class IndexBugsTests extends BaseTestCase {
|
|||
// // header.h
|
||||
// enum E {A,B,C};
|
||||
public void test171834() throws Exception {
|
||||
CModelListener.sSuppressUpdateOfLastRecentlyUsed= false;
|
||||
waitForIndexer();
|
||||
|
||||
ICProject cproject = CProjectHelper.createCCProject("seq1", "bin", IPDOMManager.ID_FAST_INDEXER);
|
||||
|
|
|
@ -49,6 +49,7 @@ import org.eclipse.cdt.core.index.IndexFilter;
|
|||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
|
||||
import org.eclipse.cdt.internal.core.pdom.CModelListener;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
|
@ -908,6 +909,7 @@ public class IndexUpdateTests extends IndexTestBase {
|
|||
// globalVar= 1;
|
||||
// }
|
||||
public void testChangingSourceBeforeHeader_Bug171834() throws Exception {
|
||||
CModelListener.sSuppressUpdateOfLastRecentlyUsed= false;
|
||||
setupHeader(2, true);
|
||||
setupFile(0, true);
|
||||
IBinding binding;
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.eclipse.cdt.core.testplugin.ResourceHelper;
|
|||
import org.eclipse.cdt.core.testplugin.TestScannerProvider;
|
||||
import org.eclipse.cdt.internal.core.CCoreInternals;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase;
|
||||
import org.eclipse.cdt.internal.core.pdom.CModelListener;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOMManager;
|
||||
import org.eclipse.core.resources.IResourceStatus;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -64,6 +65,7 @@ public class BaseTestCase extends TestCase {
|
|||
protected void setUp() throws Exception {
|
||||
CPPASTNameBase.sAllowRecursionBindings= false;
|
||||
CPPASTNameBase.sAllowNameComputation= false;
|
||||
CModelListener.sSuppressUpdateOfLastRecentlyUsed= true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -53,6 +53,7 @@ import org.eclipse.cdt.internal.core.index.IndexBasedFileContentProvider;
|
|||
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContentProvider;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.StreamHasher;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
|
||||
import org.eclipse.cdt.internal.core.pdom.indexer.PotentialTranslationUnit;
|
||||
import org.eclipse.cdt.utils.EFSExtensionManager;
|
||||
import org.eclipse.core.runtime.Assert;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -71,7 +72,6 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
protected static enum UnusedHeaderStrategy {
|
||||
skip, useDefaultLanguage, useAlternateLanguage, useBoth
|
||||
}
|
||||
|
||||
private static final int MAX_ERRORS = 500;
|
||||
|
||||
private static class FileKey {
|
||||
|
@ -384,31 +384,33 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
if (ifl == null)
|
||||
continue;
|
||||
|
||||
final boolean isSourceUnit= fResolver.isSourceUnit(tu);
|
||||
final boolean isExcludedSource= isSourceUnit && !fIndexFilesWithoutConfiguration && !fResolver.isFileBuildConfigured(tu);
|
||||
final IIndexFragmentFile[] indexFiles= fIndex.getWritableFiles(ifl);
|
||||
|
||||
if ((isSourceUnit && !isExcludedSource) || fIndexHeadersWithoutContext != UnusedHeaderStrategy.skip) {
|
||||
// headers or sources required with a specific linkage
|
||||
AbstractLanguage[] langs= fResolver.getLanguages(tu, fIndexHeadersWithoutContext == UnusedHeaderStrategy.useBoth);
|
||||
for (AbstractLanguage lang : langs) {
|
||||
int linkageID = lang.getLinkageID();
|
||||
IIndexFragmentFile ifile= getFile(linkageID, indexFiles);
|
||||
if (ifile == null || !ifile.hasContent()) {
|
||||
store(tu, linkageID, isSourceUnit, files);
|
||||
requestUpdate(linkageID, ifl, null);
|
||||
count++;
|
||||
} else {
|
||||
takeFile(ifile, indexFiles);
|
||||
boolean update= false;
|
||||
if (checkConfig) {
|
||||
update= isSourceUnit ? isSourceUnitConfigChange(tu, ifile) : isHeaderConfigChange(tu, ifile);
|
||||
}
|
||||
update= update || force || isModified(checkTimestamps, checkFileContentsHash, ifl, tu, ifile);
|
||||
if (update) {
|
||||
requestUpdate(linkageID, ifl, ifile);
|
||||
if (!(tu instanceof PotentialTranslationUnit)) {
|
||||
final boolean isSourceUnit= fResolver.isSourceUnit(tu);
|
||||
final boolean isExcludedSource= isSourceUnit && !fIndexFilesWithoutConfiguration && !fResolver.isFileBuildConfigured(tu);
|
||||
|
||||
if ((isSourceUnit && !isExcludedSource) || fIndexHeadersWithoutContext != UnusedHeaderStrategy.skip) {
|
||||
// headers or sources required with a specific linkage
|
||||
AbstractLanguage[] langs= fResolver.getLanguages(tu, fIndexHeadersWithoutContext == UnusedHeaderStrategy.useBoth);
|
||||
for (AbstractLanguage lang : langs) {
|
||||
int linkageID = lang.getLinkageID();
|
||||
IIndexFragmentFile ifile= getFile(linkageID, indexFiles);
|
||||
if (ifile == null || !ifile.hasContent()) {
|
||||
store(tu, linkageID, isSourceUnit, files);
|
||||
requestUpdate(linkageID, ifl, null);
|
||||
count++;
|
||||
} else {
|
||||
takeFile(ifile, indexFiles);
|
||||
boolean update= false;
|
||||
if (checkConfig) {
|
||||
update= isSourceUnit ? isSourceUnitConfigChange(tu, ifile) : isHeaderConfigChange(tu, ifile);
|
||||
}
|
||||
update= update || force || isModified(checkTimestamps, checkFileContentsHash, ifl, tu, ifile);
|
||||
if (update) {
|
||||
requestUpdate(linkageID, ifl, ifile);
|
||||
store(tu, linkageID, isSourceUnit, files);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -729,7 +731,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
private void parseFile(Object tu, int linkageID, IIndexFileLocation ifl, IScannerInfo scanInfo,
|
||||
boolean inContext, IProgressMonitor pm) throws CoreException, InterruptedException {
|
||||
IPath path= getPathForLabel(ifl);
|
||||
AbstractLanguage[] langs= fResolver.getLanguages(tu, fIndexHeadersWithoutContext == UnusedHeaderStrategy.useBoth);
|
||||
AbstractLanguage[] langs= fResolver.getLanguages(tu, true);
|
||||
AbstractLanguage lang= null;
|
||||
for (AbstractLanguage lang2 : langs) {
|
||||
if (lang2.getLinkageID() == linkageID) {
|
||||
|
|
|
@ -35,6 +35,9 @@ import org.eclipse.core.runtime.CoreException;
|
|||
public class CModelListener implements IElementChangedListener, IResourceChangeListener {
|
||||
private static final int UPDATE_LR_CHANGED_FILES_COUNT = 5;
|
||||
|
||||
// For testing purposes, only.
|
||||
public static boolean sSuppressUpdateOfLastRecentlyUsed = false;
|
||||
|
||||
private PDOMManager fManager;
|
||||
private LinkedHashMap<ITranslationUnit, ITranslationUnit> fLRUs= new LinkedHashMap<ITranslationUnit, ITranslationUnit>(UPDATE_LR_CHANGED_FILES_COUNT, 0.75f, true) {
|
||||
@Override
|
||||
|
@ -57,7 +60,9 @@ public class CModelListener implements IElementChangedListener, IResourceChangeL
|
|||
processDelta(event.getDelta(), changeMap);
|
||||
|
||||
// bug 171834 update last recently changed sources
|
||||
addLastRecentlyUsed(changeMap);
|
||||
if (!sSuppressUpdateOfLastRecentlyUsed) {
|
||||
addLastRecentlyUsed(changeMap);
|
||||
}
|
||||
|
||||
for (Map.Entry<ICProject, DeltaAnalyzer> entry : changeMap.entrySet()) {
|
||||
ICProject cproject = entry.getKey();
|
||||
|
|
|
@ -43,7 +43,8 @@ public class DeltaAnalyzer {
|
|||
private void processDelta(ICElementDelta delta, Set<IResource> handled) throws CoreException {
|
||||
final int flags = delta.getFlags();
|
||||
|
||||
if ((flags & ICElementDelta.F_CHILDREN) != 0) {
|
||||
final boolean hasChildren = (flags & ICElementDelta.F_CHILDREN) != 0;
|
||||
if (hasChildren) {
|
||||
for (ICElementDelta child : delta.getAffectedChildren()) {
|
||||
processDelta(child, handled);
|
||||
}
|
||||
|
@ -78,8 +79,18 @@ public class DeltaAnalyzer {
|
|||
break;
|
||||
}
|
||||
|
||||
final IResourceDelta[] rDeltas= delta.getResourceDeltas();
|
||||
if (rDeltas != null && !sSuppressPotentialTUs) {
|
||||
if (!sSuppressPotentialTUs) {
|
||||
// If the cmodel delta does not have children, also look at the children of the
|
||||
// resource delta.
|
||||
final boolean checkChildren = !hasChildren;
|
||||
final IResourceDelta[] rDeltas= delta.getResourceDeltas();
|
||||
processResourceDelta(rDeltas, element, handled, checkChildren);
|
||||
}
|
||||
}
|
||||
|
||||
public void processResourceDelta(final IResourceDelta[] rDeltas, final ICElement element,
|
||||
Set<IResource> handled, boolean checkChildren) {
|
||||
if (rDeltas != null) {
|
||||
for (IResourceDelta rd: rDeltas) {
|
||||
final int rdkind = rd.getKind();
|
||||
if (rdkind != IResourceDelta.ADDED) {
|
||||
|
@ -97,6 +108,9 @@ public class DeltaAnalyzer {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (rdkind == IResourceDelta.CHANGED && checkChildren) {
|
||||
processResourceDelta(rd.getAffectedChildren(), element, handled, checkChildren);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -172,11 +172,20 @@ public class ProjectIndexerInputAdapter extends IndexerInputAdapter {
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public AbstractLanguage[] getLanguages(Object tuo, boolean bothForHeaders) {
|
||||
if (tuo instanceof PotentialTranslationUnit)
|
||||
if (tuo instanceof PotentialTranslationUnit) {
|
||||
if (fLangC != null) {
|
||||
if (fLangCpp != null) {
|
||||
return new AbstractLanguage[] {fLangC, fLangCpp};
|
||||
}
|
||||
return new AbstractLanguage[] {fLangC};
|
||||
}
|
||||
if (fLangCpp != null) {
|
||||
return new AbstractLanguage[] {fLangCpp};
|
||||
}
|
||||
return NO_LANGUAGE;
|
||||
}
|
||||
|
||||
ITranslationUnit tu= (ITranslationUnit) tuo;
|
||||
try {
|
||||
|
|
|
@ -342,6 +342,9 @@ public class BaseUITestCase extends BaseTestCase {
|
|||
for (int millis=0; millis < 5000; millis= millis==0 ? 1 : millis*2) {
|
||||
runEventQueue(millis);
|
||||
TreeItem root= tree.getItem(i0);
|
||||
if (!root.getExpanded()) {
|
||||
expandTreeItem(root);
|
||||
}
|
||||
ex= null;
|
||||
try {
|
||||
TreeItem firstItem= root.getItem(0);
|
||||
|
|
|
@ -949,8 +949,8 @@ public class CompletionTests extends AbstractContentAssistTest {
|
|||
public void testExternC_bug191315() throws Exception {
|
||||
StringBuffer[] content= getContentsForTest(3);
|
||||
createFile(fProject, "header191315.h", content[0].toString());
|
||||
createFile(fProject, "source191315.c", content[0].toString());
|
||||
createFile(fProject, "source191315.cpp", content[0].toString());
|
||||
createFile(fProject, "source191315.c", content[1].toString());
|
||||
createFile(fProject, "source191315.cpp", content[1].toString());
|
||||
IFile dfile= createFile(fProject, "header191315.h", content[0].toString());
|
||||
TestSourceReader.waitUntilFileIsIndexed(CCorePlugin.getIndexManager().getIndex(fCProject), dfile, 8000);
|
||||
final String[] expected= {
|
||||
|
|
|
@ -310,8 +310,8 @@ public class CompletionTests_PlainC extends AbstractContentAssistTest {
|
|||
public void testExternC_bug191315() throws Exception {
|
||||
StringBuffer[] content= getContentsForTest(3);
|
||||
createFile(fProject, "header191315.h", content[0].toString());
|
||||
createFile(fProject, "source191315.c", content[0].toString());
|
||||
createFile(fProject, "source191315.cpp", content[0].toString());
|
||||
createFile(fProject, "source191315.c", content[1].toString());
|
||||
createFile(fProject, "source191315.cpp", content[1].toString());
|
||||
IFile dfile= createFile(fProject, "header191315.h", content[0].toString());
|
||||
TestSourceReader.waitUntilFileIsIndexed(CCorePlugin.getIndexManager().getIndex(fCProject), dfile, 8000);
|
||||
final String[] expected= {
|
||||
|
|
Loading…
Add table
Reference in a new issue