diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/BaseScanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/BaseScanner.java index 163b060f315..69717b91ff7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/BaseScanner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/BaseScanner.java @@ -2839,6 +2839,23 @@ abstract class BaseScanner implements IScanner { } CodeReader reader = null; + // filename is an absolute path or it is a Linux absolute path on a windows machine + if (new File(filename).isAbsolute() || filename.startsWith("/")) { //$NON-NLS-1$ + reader = createReader( EMPTY_STRING, filename ); + if (reader != null) { + pushContext(reader.buffer, new InclusionData(reader, + createInclusionConstruct(fileNameArray, + reader.filename, local, startOffset, + startingLine, nameOffset, + nameEndOffset, nameLine, endOffset, + endLine, false))); + return; + } + handleProblem(IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND, startOffset, + fileNameArray); + return; + } + File currentDirectory = null; if (local || include_next) { // if the include is eclosed in quotes OR we are in an include_next @@ -2893,23 +2910,6 @@ abstract class BaseScanner implements IScanner { } } } - - // if not found by this point, and the inclusion is local, try just the - // path as is (bug 91086) - - if( local && !include_next ) - { - reader = createReader( EMPTY_STRING, filename ); - if (reader != null) { - pushContext(reader.buffer, new InclusionData(reader, - createInclusionConstruct(fileNameArray, - reader.filename, local, startOffset, - startingLine, nameOffset, - nameEndOffset, nameLine, endOffset, - endLine, false))); - return; - } - } handleProblem(IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND, startOffset, fileNameArray); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerUtility.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerUtility.java index 0e89348d56a..bb31c564a41 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerUtility.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerUtility.java @@ -84,7 +84,9 @@ public class ScannerUtility { if( ! path.equals( "" )) //$NON-NLS-1$ { newPathBuffer.append( new File(path).getPath() ); - newPathBuffer.append( File.separatorChar ); + + if (fileName.length() > 0 && fileName.toCharArray()[0] != File.separatorChar) + newPathBuffer.append( File.separatorChar ); } newPathBuffer.append( fileName ); //remove ".." and "." segments diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/parser/CodeReaderCache.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/parser/CodeReaderCache.java index 8030d75f3b8..c902946ce58 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/parser/CodeReaderCache.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/parser/CodeReaderCache.java @@ -9,6 +9,8 @@ package org.eclipse.cdt.core.parser; +import java.io.File; + import org.eclipse.cdt.internal.core.parser.ast.EmptyIterator; import org.eclipse.cdt.internal.core.util.ILRUCacheable; import org.eclipse.cdt.internal.core.util.LRUCache; @@ -137,6 +139,11 @@ public class CodeReaderCache implements ICodeReaderCache { // not in the cache if (ret == null) { + // for efficiency: check File.exists before ParserUtil#createReader() + // bug 100947 fix: don't want to attempt to create a code reader if there is no file for the key + if (!(new File(key).exists())) + return null; + ret = ParserUtil.createReader(key, EmptyIterator.EMPTY_ITERATOR); if (cache.getSpaceLimit() > 0)