From f03642cfb3f2673e96610756dd0e36269fb34aa2 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Sun, 30 Mar 2008 23:52:09 +0000 Subject: [PATCH] Fixed bug 224817. --- .../parser/tests/scanner/InclusionTests.java | 25 +++++++++++-------- .../core/parser/scanner/CPreprocessor.java | 17 ++++++------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/InclusionTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/InclusionTests.java index 6c3b2c3f5f3..df9f50669b6 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/InclusionTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/InclusionTests.java @@ -8,6 +8,7 @@ * Contributors: * IBM - Initial API and implementation * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.scanner; @@ -77,24 +78,26 @@ public class InclusionTests extends PreprocessorTestsBase { } public void testIncludeNext() throws Exception { - String baseFile = "int zero; \n#include \"foo.h\""; //$NON-NLS-1$ - String i1Next = "int one; \n#include_next "; //$NON-NLS-1$ - String i2Next = "int two; \n#include_next \"foo.h\""; //$NON-NLS-1$ + String baseFile = "int zero; \n#include \"bar/foo.h\""; //$NON-NLS-1$ + String i1Next = "int one; \n#include_next "; //$NON-NLS-1$ + String i2Next = "int two; \n#include_next \"bar/foo.h\""; //$NON-NLS-1$ String i3Next = "int three; \n"; //$NON-NLS-1$ - - - IFile base = importFile( "base.cpp", baseFile ); //$NON-NLS-1$ - importFile( "foo.h", i1Next ); //$NON-NLS-1$ + + IFolder barf = importFolder("bar"); //$NON-NLS-1$ IFolder twof = importFolder("two"); //$NON-NLS-1$ + IFolder twobarf = importFolder("two/bar"); //$NON-NLS-1$ IFolder threef = importFolder("three"); //$NON-NLS-1$ - importFile( "two/foo.h", i2Next ); //$NON-NLS-1$ - importFile( "three/foo.h", i3Next ); //$NON-NLS-1$ + IFolder threebarf = importFolder("three/bar"); //$NON-NLS-1$ + IFile base = importFile("base.cpp", baseFile); //$NON-NLS-1$ + importFile("bar/foo.h", i1Next); //$NON-NLS-1$ + importFile("two/bar/foo.h", i2Next); //$NON-NLS-1$ + importFile("three/bar/foo.h", i3Next); //$NON-NLS-1$ String [] path = new String[2]; path[0] = twof.getLocation().toOSString(); path[1] = threef.getLocation().toOSString(); - IScannerInfo scannerInfo = new ExtendedScannerInfo( Collections.EMPTY_MAP, path, new String[]{}, null ); + IScannerInfo scannerInfo = new ExtendedScannerInfo(Collections.EMPTY_MAP, path, new String[]{}, null); CodeReader reader= new CodeReader(base.getLocation().toString()); initializeScanner(reader, ParserLanguage.C, ParserMode.COMPLETE_PARSE, scannerInfo); @@ -116,7 +119,7 @@ public class InclusionTests extends PreprocessorTestsBase { validateEOF(); } - + public void testIncludePathOrdering() throws Exception { // create directory structure: diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java index 68dcaa76f49..66ceb42ca42 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java @@ -9,11 +9,11 @@ * IBM - Initial API and implementation * Anton Leherbauer (Wind River Systems) * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.parser.scanner; import java.io.File; -import java.io.IOException; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -757,14 +757,13 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { } private int findIncludePos(String[] paths, File currentDirectory) { - for (int i = 0; i < paths.length; ++i) - try { - String path = new File(paths[i]).getCanonicalPath(); - String parent = currentDirectory.getCanonicalPath(); - if (path.equals(parent)) - return i; - } catch (IOException e) { - } + for (int i = 0; i < paths.length; ++i) { + File pathDir = new File(paths[i]); + for (File dir = currentDirectory; dir != null; dir = dir.getParentFile()) { + if (dir.equals(pathDir)) + return i; + } + } return -1; }