class HeaderIncludes
Declaration
class HeaderIncludes { /* full declaration omitted */ };
Description
Generates replacements for inserting or deleting #include directives in a file.
Declared at: clang/include/clang/Tooling/Inclusions/HeaderIncludes.h:49
Member Variables
- private std::string FileName
- private std::string Code
- private llvm::StringMap<std::list<Include>> ExistingIncludes
- private std::unordered_map< int, llvm::SmallVector<const Include*, 8>> IncludesByPriority
- Map from priorities of #include categories to all #includes in the same category. This is used to find #includes of the same category when inserting new #includes. #includes in the same categories are sorted in in the order they appear in the source file. See comment for "FormatStyle::IncludeCategories" for details about include priorities.
- private int FirstIncludeOffset
- private unsigned int MinInsertOffset
- private unsigned int MaxInsertOffset
- private clang::tooling::IncludeCategoryManager Categories
- private std::unordered_map<int, int> CategoryEndOffsets
- private std::set<int> Priorities
- private llvm::Regex IncludeRegex
Method Overview
- public HeaderIncludes(llvm::StringRef FileName, llvm::StringRef Code, const clang::tooling::IncludeStyle & Style)
- private void addExistingInclude(clang::tooling::HeaderIncludes::Include IncludeToAdd, unsigned int NextLineOffset)
- public llvm::Optional<tooling::Replacement> insert(llvm::StringRef Header, bool IsAngled) const
- public tooling::Replacements remove(llvm::StringRef Header, bool IsAngled) const
Methods
¶HeaderIncludes(
llvm::StringRef FileName,
llvm::StringRef Code,
const clang::tooling::IncludeStyle& Style)
HeaderIncludes(
llvm::StringRef FileName,
llvm::StringRef Code,
const clang::tooling::IncludeStyle& Style)
Declared at: clang/include/clang/Tooling/Inclusions/HeaderIncludes.h:51
Parameters
- llvm::StringRef FileName
- llvm::StringRef Code
- const clang::tooling::IncludeStyle& Style
¶void addExistingInclude(
clang::tooling::HeaderIncludes::Include
IncludeToAdd,
unsigned int NextLineOffset)
void addExistingInclude(
clang::tooling::HeaderIncludes::Include
IncludeToAdd,
unsigned int NextLineOffset)
Declared at: clang/include/clang/Tooling/Inclusions/HeaderIncludes.h:93
Parameters
- clang::tooling::HeaderIncludes::Include IncludeToAdd
- unsigned int NextLineOffset
¶llvm::Optional<tooling::Replacement> insert(
llvm::StringRef Header,
bool IsAngled) const
llvm::Optional<tooling::Replacement> insert(
llvm::StringRef Header,
bool IsAngled) const
Description
Inserts an #include directive of \p Header into the code. If \p IsAngled is true, \p 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: - raw string literals (containing #include). - #if blocks. - Special #include's among declarations (e.g. functions). 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 \p IncludeName. If\p IncludeName already exists (with exactly the same spelling), this returns None.
Declared at: clang/include/clang/Tooling/Inclusions/HeaderIncludes.h:73
Parameters
- llvm::StringRef Header
- bool IsAngled
¶tooling::Replacements remove(
llvm::StringRef Header,
bool IsAngled) const
tooling::Replacements remove(
llvm::StringRef Header,
bool IsAngled) const
Description
Removes all existing #includes of \p Header quoted with < > if \p IsAngled is true or "" if \p IsAngled is false. This doesn't resolve the header file path; it only deletes #includes with exactly the same spelling.
Declared at: clang/include/clang/Tooling/Inclusions/HeaderIncludes.h:80
Parameters
- llvm::StringRef Header
- bool IsAngled