|
clang 24.0.0git
|
Generates replacements for inserting or deleting #include directives in a file. More...
#include "clang/Tooling/Inclusions/HeaderIncludes.h"
Classes | |
| struct | HeaderToInsert |
| Represents a single header directive to be inserted in a batch operation. More... | |
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 | insert (llvm::ArrayRef< HeaderToInsert > Headers) const |
| Inserts a batch of headers into the code, sorting and grouping them according to IncludeStyle and returning the replacements. | |
| 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 55 of file HeaderIncludes.h.
| clang::tooling::HeaderIncludes::HeaderIncludes | ( | llvm::StringRef | FileName, |
| llvm::StringRef | Code, | ||
| const IncludeStyle & | Style ) |
Definition at line 377 of file HeaderIncludes.cpp.
References false, clang::for(), clang::if(), clang::tooling::Import, clang::tooling::Include, IncludeRegex, INT_MAX, and clang::Line.
| tooling::Replacements clang::tooling::HeaderIncludes::insert | ( | llvm::ArrayRef< HeaderToInsert > | Headers | ) | const |
Inserts a batch of headers into the code, sorting and grouping them according to IncludeStyle and returning the replacements.
Definition at line 533 of file HeaderIncludes.cpp.
References clang::tooling::HeaderIncludes::HeaderToInsert::Directive, clang::tooling::HeaderIncludes::HeaderToInsert::Header, insert(), clang::tooling::HeaderIncludes::HeaderToInsert::IsAngled, clang::Result, and clang::Text.
| 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 453 of file HeaderIncludes.cpp.
References clang::tooling::Import, clang::tooling::Include, and Open.
Referenced by insert().
| 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 591 of file HeaderIncludes.cpp.
References clang::Result.
|
static |
Definition at line 122 of file HeaderIncludes.h.
Referenced by HeaderIncludes(), and clang::format::sortCppIncludes().