diff options
author | Markus Schorn | 2008-12-19 13:11:47 +0000 |
---|---|---|
committer | Markus Schorn | 2008-12-19 13:11:47 +0000 |
commit | 85b3cba682fada798da05c589d08e26c63cda0f3 (patch) | |
tree | 166bccf96d550f709d755c3b875d1e799bbc6412 | |
parent | b8f0202b73ec302bdb8a833e54b18c865657a63c (diff) | |
download | org.eclipse.cdt-CDT_4_0_branch.tar.gz org.eclipse.cdt-CDT_4_0_branch.tar.xz org.eclipse.cdt-CDT_4_0_branch.zip |
Includes pointing to directories instead of files, bug 243682.CDT_4_0_branch
4 files changed, 71 insertions, 15 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java index 29646c57b9d..e85364bef4f 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2008 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -1079,4 +1079,29 @@ public class IndexBugsTests extends BaseTestCase { } } } + + // #include "dir" + // #include "header.h" + public void testIncludsionOfFolders_Bug243682() throws Exception { + String contents= getContentsForTest(1)[0].toString(); + final IIndexManager indexManager = CCorePlugin.getIndexManager(); + TestScannerProvider.sIncludes= new String[]{fCProject.getProject().getLocation().toString() + "/f1"}; + + IFile sol= TestSourceReader.createFile(fCProject.getProject(), "f1/header.h", ""); + TestSourceReader.createFile(fCProject.getProject(), "dir/dummy.h", ""); + TestSourceReader.createFile(fCProject.getProject(), "header.h/dummy.h", ""); + IFile f1= TestSourceReader.createFile(fCProject.getProject(), "source1.cpp", contents); + indexManager.reindex(fCProject); + waitForIndexer(); + fIndex.acquireReadLock(); + try { + IIndexFile f= fIndex.getFile(IndexLocationFactory.getWorkspaceIFL(f1)); + IIndexInclude[] is= f.getIncludes(); + assertFalse(is[0].isResolved()); + assertTrue(is[1].isResolved()); + assertEquals(sol.getFullPath().toString(), is[1].getIncludesLocation().getFullPath()); + } finally { + fIndex.releaseReadLock(); + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/IncludeFileResolutionCache.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/IncludeFileResolutionCache.java index dada76d87da..4b746ef4f77 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/IncludeFileResolutionCache.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/IncludeFileResolutionCache.java @@ -14,6 +14,7 @@ import java.io.File; import java.lang.ref.Reference; import java.lang.ref.SoftReference; import java.util.Arrays; +import java.util.BitSet; import java.util.HashMap; import java.util.Map; @@ -24,10 +25,18 @@ import java.util.Map; * @since 5.0 */ public final class IncludeFileResolutionCache { - private static final String[] EMPTY_STRING_ARRAY= {}; + private static final Content EMPTY_STRING_ARRAY= new Content(new String[0]); private static final boolean CASE_INSENSITIVE = new File("a").equals(new File("A")); //$NON-NLS-1$ //$NON-NLS-2$ private static boolean BYPASS_CACHE= Boolean.getBoolean("CDT_INDEXER_BYPASS_FILE_EXISTS_CACHE"); //$NON-NLS-1$ + private static class Content { + public Content(String[] names) { + fNames= names; + fIsFile= new BitSet(names.length*2); + } + public String[] fNames; + public BitSet fIsFile; + } private Reference fExistsCache= null; public IncludeFileResolutionCache() { @@ -37,7 +46,7 @@ public final class IncludeFileResolutionCache { public boolean exists(String path) { File file= new File(path); if (BYPASS_CACHE) { - return file.exists(); + return file.isFile(); } String parent= file.getParent(); @@ -45,23 +54,40 @@ public final class IncludeFileResolutionCache { if (CASE_INSENSITIVE) name= name.toUpperCase(); - String[] avail= (String[]) getExistsCache().get(parent); + Content avail= (Content) getExistsCache().get(parent); if (avail == null) { - avail= new File(parent).list(); - if (avail == null || avail.length == 0) { + String[] files= new File(parent).list(); + if (files == null || files.length == 0) { avail= EMPTY_STRING_ARRAY; } else { if (CASE_INSENSITIVE) { - for (int i = 0; i < avail.length; i++) { - avail[i]= avail[i].toUpperCase(); + for (int i = 0; i < files.length; i++) { + files[i]= files[i].toUpperCase(); } } - Arrays.sort(avail); + Arrays.sort(files); + avail= new Content(files); } getExistsCache().put(parent, avail); } - return Arrays.binarySearch(avail, name) >= 0; + int idx= Arrays.binarySearch(avail.fNames, name); + if (idx < 0) + return false; + idx *= 2; + + final BitSet isFileBitset = avail.fIsFile; + if (isFileBitset.get(idx)) + return true; + if (isFileBitset.get(idx+1)) + return false; + + if (file.isFile()) { + isFileBitset.set(idx); + return true; + } + isFileBitset.set(idx+1); + return false; } private Map getExistsCache() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/Checksums.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/Checksums.java index 56b4c551c8a..561ae9bb929 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/Checksums.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/Checksums.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2008 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -118,7 +118,7 @@ public class Checksums { IPath location= file.getLocation(); if (location != null) { File f= location.toFile(); - if (f.exists()) { + if (f.isFile()) { try { byte[] checksum= computeChecksum(md, f); putChecksum(result, file, checksum); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/TeamPDOMImportOperation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/TeamPDOMImportOperation.java index 75a7614a9ae..308683cebf0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/TeamPDOMImportOperation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/TeamPDOMImportOperation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2008 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -302,9 +302,14 @@ public class TeamPDOMImportOperation implements IWorkspaceRunnable { IPath location= tu.getLocation(); if (location != null) { try { - byte[] checksum= Checksums.computeChecksum(md, location.toFile()); - if (!Arrays.equals(checksum, cs.fChecksum)) { + final File file = location.toFile(); + if (!file.isFile()) { i.remove(); + } else { + byte[] checksum= Checksums.computeChecksum(md, file); + if (!Arrays.equals(checksum, cs.fChecksum)) { + i.remove(); + } } } catch (IOException e) { |