clang  10.0.0svn
Classes | Public Member Functions | List of all members
clang::tooling::HeaderIncludes Class Reference

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)
 
llvm::Optional< tooling::Replacementinsert (llvm::StringRef Header, bool IsAngled) const
 Inserts an #include directive of Header into the code. More...
 
tooling::Replacements remove (llvm::StringRef Header, bool IsAngled) const
 Removes all existing #includes of Header quoted with <> if IsAngled is true or "" if IsAngled is false. More...
 

Detailed Description

Generates replacements for inserting or deleting #include directives in a file.

Definition at line 50 of file HeaderIncludes.h.

Constructor & Destructor Documentation

◆ HeaderIncludes()

clang::tooling::HeaderIncludes::HeaderIncludes ( llvm::StringRef  FileName,
llvm::StringRef  Code,
const IncludeStyle Style 
)

Member Function Documentation

◆ insert()

llvm::Optional< tooling::Replacement > clang::tooling::HeaderIncludes::insert ( llvm::StringRef  Header,
bool  IsAngled 
) const

Inserts an #include 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:

  • 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 IncludeName. If IncludeName already exists (with exactly the same spelling), this returns None.

Definition at line 292 of file HeaderIncludes.cpp.

References clang::tooling::IncludeCategoryManager::getIncludePriority(), clang::tooling::None, and clang::tooling::Quoted.

◆ remove()

tooling::Replacements clang::tooling::HeaderIncludes::remove ( llvm::StringRef  Header,
bool  IsAngled 
) const

Removes all existing #includes 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 with exactly the same spelling.

Definition at line 331 of file HeaderIncludes.cpp.

References clang::tooling::Replacements::add(), clang::Error, and toString().

Referenced by clang::format::formatReplacements().


The documentation for this class was generated from the following files: