MCPcopy Create free account
hub / github.com/KDE/kdevelop / includeArgumentForFile

Function includeArgumentForFile

plugins/clang/codegen/clangclasshelper.cpp:92–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90namespace {
91
92QString 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
131QString includeDirectiveArgumentFromPath(const Path& file,
132 const DeclarationPointer& declaration)

Callers 1

Calls 7

lastPathSegmentMethod · 0.80
relativePathMethod · 0.80
QFileInfoClass · 0.50
parentMethod · 0.45
removeMethod · 0.45
isEmptyMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected