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

Don't include directories, bug 243682.

This commit is contained in:
Markus Schorn 2008-10-07 14:52:24 +00:00
parent 4f6ab7cd2e
commit 9bccca7417
6 changed files with 75 additions and 26 deletions

View file

@ -1399,4 +1399,28 @@ public class IndexBugsTests extends BaseTestCase {
fIndex.releaseReadLock();
}
}
// #include "dir"
// #include "header.h"
public void testIncludsionOfFolders_Bug243682() throws Exception {
String contents= getContentsForTest(1)[0];
final IIndexManager indexManager = CCorePlugin.getIndexManager();
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(ILinkage.CPP_LINKAGE_ID, IndexLocationFactory.getWorkspaceIFL(f1));
IIndexInclude[] is= f.getIncludes();
assertFalse(is[0].isResolved());
assertTrue(is[1].isResolvedByHeuristics());
assertEquals(sol.getFullPath().toString(), is[1].getIncludesLocation().getFullPath());
} finally {
fIndex.releaseReadLock();
}
}
}

View file

@ -34,7 +34,7 @@ public class StandaloneIndexerFallbackReaderFactory implements ICodeReaderFactor
public CodeReader createCodeReaderForInclusion(String path) {
try {
if (!new File(path).exists())
if (!new File(path).isFile())
return null;
return new CodeReader(path);
} catch (IOException e) {
@ -44,7 +44,7 @@ public class StandaloneIndexerFallbackReaderFactory implements ICodeReaderFactor
public CodeReader createCodeReaderForTranslationUnit(String path) {
try {
if (!new File(path).exists())
if (!new File(path).isFile())
return null;
return new CodeReader(path);
} catch (IOException e) {

View file

@ -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
@ -82,7 +82,7 @@ public class StandaloneIndexerInputAdapter extends IndexerInputAdapter {
@Override
public boolean doesIncludeFileExist(String includePath) {
return new File(includePath).exists();
return new File(includePath).isFile();
}
@Override
@ -95,7 +95,7 @@ public class StandaloneIndexerInputAdapter extends IndexerInputAdapter {
} catch (IOException e) {
// use the original
}
//Standalone indexing stores the absolute paths of files being indexed
//Stand-alone indexing stores the absolute paths of files being indexed
result = new IndexFileLocation(URIUtil.toURI(includePath),includePath);
fIflCache.put(includePath, result);
}

View file

@ -23,8 +23,7 @@ public class InternalParserUtil extends ParserFactory {
public static CodeReader createFileReader(String finalPath) {
File includeFile = new File(finalPath);
if (includeFile.exists() && includeFile.isFile())
{
if (includeFile.isFile()) {
try {
//use the canonical path so that in case of non-case-sensitive OSs
//the CodeReader always has the same name as the file on disk with

View file

@ -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,20 +25,28 @@ import java.util.Map;
* @since 5.0
*/
public final class FileExistsCache {
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 Reference<Map<String,String[]>> fCache= null;
private static class Content {
public Content(String[] names) {
fNames= names;
fIsFile= new BitSet(names.length*2);
}
public String[] fNames;
public BitSet fIsFile;
}
private Reference<Map<String,Content>> fCache= null;
public FileExistsCache() {
fCache= new SoftReference<Map<String,String[]>>(new HashMap<String, String[]>()); // before running out of memory the entire map will be thrown away.
fCache= new SoftReference<Map<String,Content>>(new HashMap<String, Content>()); // before running out of memory the entire map will be thrown away.
}
public boolean exists(String path) {
public boolean isFile(String path) {
File file= new File(path);
if (BYPASS_CACHE) {
return file.exists();
return file.isFile();
}
String parent= file.getParent();
@ -45,30 +54,47 @@ public final class FileExistsCache {
if (CASE_INSENSITIVE)
name= name.toUpperCase();
String[] avail= getExistsCache().get(parent);
Content avail= 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<String, String[]> getExistsCache() {
Map<String, String[]> cache= fCache.get();
private Map<String, Content> getExistsCache() {
Map<String, Content> cache= fCache.get();
if (cache == null) {
cache= new HashMap<String, String[]>();
fCache= new SoftReference<Map<String, String[]>>(cache); // before running out of memory the entire map will be thrown away.
cache= new HashMap<String, Content>();
fCache= new SoftReference<Map<String, Content>>(cache); // before running out of memory the entire map will be thrown away.
}
return cache;
}

View file

@ -81,7 +81,7 @@ public class ProjectIndexerInputAdapter extends IndexerInputAdapter {
if (fIflCache == null) {
return doResolveASTPath(includePath);
}
if (!fExistsCache.exists(includePath)) {
if (!fExistsCache.isFile(includePath)) {
return null;
}
IIndexFileLocation result= fIflCache.get(includePath);
@ -108,9 +108,9 @@ public class ProjectIndexerInputAdapter extends IndexerInputAdapter {
@Override
public boolean doesIncludeFileExist(String includePath) {
if (fExistsCache != null) {
return fExistsCache.exists(includePath);
return fExistsCache.isFile(includePath);
}
return new File(includePath).exists();
return new File(includePath).isFile();
}
@Override