| 90 | namespace { |
| 91 | |
| 92 | QString includeArgumentForFile(const QString& includefile, const Path::List& includePaths, |
| 93 | const Path& source) |
| 94 | { |
| 95 | const auto sourceFolder = source.parent(); |
| 96 | const Path canonicalFile(QFileInfo(includefile).canonicalFilePath()); |
| 97 | |
| 98 | QString shortestDirective; |
| 99 | bool isRelative = false; |
| 100 | |
| 101 | // we can include the file directly |
| 102 | if (sourceFolder == canonicalFile.parent()) { |
| 103 | shortestDirective = canonicalFile.lastPathSegment(); |
| 104 | isRelative = true; |
| 105 | } else { |
| 106 | // find the include directive with the shortest length |
| 107 | for (const auto& includePath : includePaths) { |
| 108 | QString relative = includePath.relativePath(canonicalFile); |
| 109 | if (relative.startsWith(QLatin1String("./"))) { |
| 110 | relative.remove(0, 2); |
| 111 | } |
| 112 | |
| 113 | if (shortestDirective.isEmpty() || relative.length() < shortestDirective.length()) { |
| 114 | shortestDirective = relative; |
| 115 | isRelative = (includePath == sourceFolder); |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | // Item not found in include path? |
| 121 | if (shortestDirective.isEmpty()) { |
| 122 | return {}; |
| 123 | } |
| 124 | |
| 125 | if (isRelative) { |
| 126 | return QLatin1Char('\"') + shortestDirective + QLatin1Char('\"'); |
| 127 | } |
| 128 | return QLatin1Char('<') + shortestDirective + QLatin1Char('>'); |
| 129 | } |
| 130 | |
| 131 | QString includeDirectiveArgumentFromPath(const Path& file, |
| 132 | const DeclarationPointer& declaration) |
no test coverage detected