Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Schorn2008-12-19 13:11:47 +0000
committerMarkus Schorn2008-12-19 13:11:47 +0000
commit85b3cba682fada798da05c589d08e26c63cda0f3 (patch)
tree166bccf96d550f709d755c3b875d1e799bbc6412
parentb8f0202b73ec302bdb8a833e54b18c865657a63c (diff)
downloadorg.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
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java27
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/IncludeFileResolutionCache.java44
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/Checksums.java4
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/TeamPDOMImportOperation.java11
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 29646c57b9..e85364bef4 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 dada76d87d..4b746ef4f7 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 56b4c551c8..561ae9bb92 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 75a7614a9a..308683cebf 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) {

Back to the top