clang 20.0.0git
|
Generates replacements for inserting or deleting #include directives in a file. More...
#include "clang/Tooling/Inclusions/HeaderIncludes.h"
Public Member Functions | |
HeaderIncludes (llvm::StringRef FileName, llvm::StringRef Code, const IncludeStyle &Style) | |
std::optional< tooling::Replacement > | insert (llvm::StringRef Header, bool IsAngled, IncludeDirective Directive) const |
Inserts an #include or #import directive of Header into the code. | |
tooling::Replacements | remove (llvm::StringRef Header, bool IsAngled) const |
Removes all existing #includes and #imports of Header quoted with <> if IsAngled is true or "" if IsAngled is false. | |
Static Public Attributes | |
static const llvm::Regex | IncludeRegex |
Generates replacements for inserting or deleting #include directives in a file.
Definition at line 52 of file HeaderIncludes.h.
clang::tooling::HeaderIncludes::HeaderIncludes | ( | llvm::StringRef | FileName, |
llvm::StringRef | Code, | ||
const IncludeStyle & | Style | ||
) |
Definition at line 281 of file HeaderIncludes.cpp.
References Category, E, clang::tooling::Import, clang::tooling::Include, IncludeRegex, INT_MAX, and clang::Line.
std::optional< tooling::Replacement > clang::tooling::HeaderIncludes::insert | ( | llvm::StringRef | Header, |
bool | IsAngled, | ||
IncludeDirective | Directive | ||
) | const |
Inserts an #include or #import directive of Header
into the code.
If IsAngled
is true, Header
will be quoted with <> in the directive; otherwise, it will be quoted with "".
When searching for points to insert new header, this ignores #include's after the #include block(s) in the beginning of a file to avoid inserting headers into code sections where new #include's should not be added by default. These code sections include:
Returns a replacement that inserts the new header into a suitable #include block of the same category. This respects the order of the existing #includes in the block; if the existing #includes are not already sorted, this will simply insert the #include in front of the first #include of the same category in the code that should be sorted after IncludeName
. If IncludeName
already exists (with exactly the same spelling), this returns std::nullopt.
Definition at line 356 of file HeaderIncludes.cpp.
References clang::FileName, clang::tooling::IncludeCategoryManager::getIncludePriority(), clang::tooling::Include, Iter, and Priority.
tooling::Replacements clang::tooling::HeaderIncludes::remove | ( | llvm::StringRef | Header, |
bool | IsAngled | ||
) | const |
Removes all existing #includes and #imports of Header
quoted with <> if IsAngled
is true or "" if IsAngled
is false.
This doesn't resolve the header file path; it only deletes #includes and #imports with exactly the same spelling.
Definition at line 401 of file HeaderIncludes.cpp.
References clang::FileName, Iter, and clang::Result.
|
static |
Definition at line 87 of file HeaderIncludes.h.
Referenced by HeaderIncludes(), and clang::format::sortCppIncludes().