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 f850b5328ac..85c411f85ee 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 @@ -87,16 +87,16 @@ public class InclusionTests extends PreprocessorTestsBase { IFolder f0 = importFolder(".framework"); importFolder("f1.framework"); importFolder("f1"); - importFolder("f1/f2.framework"); + importFolder("f1.framework/f2"); importFolder("f3"); IFile base = importFile("base.cpp", content); importFile(".framework/one.h", "1"); importFile("f1.framework/two.h", "2"); - importFile("f1/f2.framework/three.h", "3"); + importFile("f1.framework/f2/three.h", "3"); String[] path = { - f0.getLocation().removeLastSegments(1) + "/__framework__.framework/__filename__" + f0.getLocation().removeLastSegments(1) + "/__framework__.framework/__header__" }; IScannerInfo scannerInfo = new ExtendedScannerInfo(Collections.EMPTY_MAP, path, new String[]{}, null); CodeReader reader= new CodeReader(base.getLocation().toString()); @@ -104,7 +104,7 @@ public class InclusionTests extends PreprocessorTestsBase { // first file is not picked up (no framework) validateInteger("2"); - // third file is not picked up (framework must be a single folder) + validateInteger("3"); validateEOF(); } @@ -210,8 +210,8 @@ public class InclusionTests extends PreprocessorTestsBase { CodeReader reader= new CodeReader(base.getLocation().toString()); ParserLanguage lang[]= {ParserLanguage.C, ParserLanguage.CPP}; - for (int i = 0; i < lang.length; i++) { - initializeScanner(reader, lang[i], ParserMode.COMPLETE_PARSE, new ScannerInfo()); + for (ParserLanguage element : lang) { + initializeScanner(reader, element, ParserMode.COMPLETE_PARSE, new ScannerInfo()); validateToken(IToken.t_int); validateIdentifier("var"); validateToken(IToken.tASSIGN); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScannerInfo.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScannerInfo.java index e26adbfffc1..294c2d4fdfe 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScannerInfo.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScannerInfo.java @@ -30,15 +30,15 @@ public interface IScannerInfo { /** * Returns an array of paths that are searched when processing an include directive. * see {@link IExtendedScannerInfo#getLocalIncludePath()} - * + *

* In order to handle framework includes used on Apple Computers you can make use of - * the two variables: '__framework__' and '__filename__'. - *
E.g.: /System/Library/Frameworks/__framework__.framework/Headers/__filename__, - * /System/Library/Frameworks/__framework__.framework/PrivateHeaders/__filename__ + * the two variables: '__framework__' and '__header__'. + *
E.g.: /System/Library/Frameworks/__framework__.framework/Headers/__header__, + * /System/Library/Frameworks/__framework__.framework/PrivateHeaders/__header__ * would handle the framework search for '/System/Library/Frameworks' - * - * The variables are handled only, if a search path element makes use of both of the variables. - * Such a search path element is not used for directives that are not of the form 'folder/name'. + *
The variables are handled only, if a search path element makes use of both of the variables. + * The __framework__ variable will receive the first segment of the include, the __header__ variable + * the rest. Such a search path element is not used for directives with a single segment (e.g. 'header.h') */ public String[] getIncludePaths(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/IncludeSearchPathElement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/IncludeSearchPathElement.java index cec6e849536..3c9acd4c6a2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/IncludeSearchPathElement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/IncludeSearchPathElement.java @@ -18,7 +18,7 @@ import java.io.File; final class IncludeSearchPathElement { private static final boolean NON_SLASH_SEPARATOR = File.separatorChar != '/'; public static final String FRAMEWORK_VAR = "__framework__"; //$NON-NLS-1$ - public static final String FILE_VAR = "__filename__"; //$NON-NLS-1$ + public static final String FILE_VAR = "__header__"; //$NON-NLS-1$ private final String fPath; @@ -42,39 +42,35 @@ final class IncludeSearchPathElement { public String getLocation(String includeDirective) { if (fIsFrameworkDirectory) { - int lastSep = lastSeparator(includeDirective); - if (lastSep < 0) { + int firstSep = firstSeparator(includeDirective); + if (firstSep < 1) { return null; } - String framework = includeDirective.substring(0, lastSep); - if (lastSeparator(framework) != -1 || framework.length() == 0) { - return null; - } - - String file= includeDirective.substring(lastSep+1); + String framework = includeDirective.substring(0, firstSep); + String file= includeDirective.substring(firstSep+1); if (file.length() == 0) return null; StringBuilder buf= new StringBuilder(fPath); - replaceAll(buf, FRAMEWORK_VAR, framework); - replaceAll(buf, FILE_VAR, file); + replace(buf, FRAMEWORK_VAR, framework); + replace(buf, FILE_VAR, file); return ScannerUtility.reconcilePath(buf.toString()); } return ScannerUtility.createReconciledPath(fPath, includeDirective); } - private int lastSeparator(String path) { - int lastSep= path.lastIndexOf('/'); + private int firstSeparator(String path) { + int firstSep= path.indexOf('/'); if (NON_SLASH_SEPARATOR) { - lastSep= Math.max(lastSep, path.lastIndexOf(File.separatorChar)); + firstSep= Math.max(firstSep, path.indexOf(File.separatorChar)); } - return lastSep; + return firstSep; } - private void replaceAll(StringBuilder buf, String find, final String replace) { - for (int idx= buf.indexOf(find); idx > 0; idx= buf.indexOf(find, idx)) { + private void replace(StringBuilder buf, String find, final String replace) { + int idx= buf.indexOf(find); + if (idx >= 0) { buf.replace(idx, idx+find.length(), replace); - idx+= replace.length(); } } } \ No newline at end of file