clang-tools 6.0.0

UsingInserter.h
Go to the documentation of this file.
1 //===---------- UsingInserter.h - clang-tidy ----------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_USINGINSERTER_H
11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_USINGINSERTER_H
12
13 #include "clang/AST/Decl.h"
14 #include "clang/AST/Stmt.h"
15 #include "clang/Basic/Diagnostic.h"
16 #include "clang/Basic/SourceManager.h"
17 #include <set>
18
19 namespace clang {
20 namespace tidy {
21 namespace utils {
22
23 // UsingInserter adds using declarations for |QualifiedName| to the surrounding
24 // function.
25 // This allows using a shorter name without clobbering other scopes.
26 class UsingInserter {
27 public:
28 UsingInserter(const SourceManager &SourceMgr);
29
30 // Creates a \p using declaration fixit. Returns ``llvm::None`` on error
31 // or if the using declaration already exists.
32 llvm::Optional<FixItHint>
33 createUsingDeclaration(ASTContext &Context, const Stmt &Statement,
34 llvm::StringRef QualifiedName);
35
36 // Returns the unqualified version of the name if there is an
37 // appropriate using declaration and the qualified name otherwise.
38 llvm::StringRef getShortName(ASTContext &Context, const Stmt &Statement,
39 llvm::StringRef QualifiedName);
40
41 private:
42 typedef std::pair<const FunctionDecl *, std::string> NameInFunction;
43 const SourceManager &SourceMgr;
44 std::set<NameInFunction> AddedUsing;
45 };
46
47 } // namespace utils
48 } // namespace tidy
49 } // namespace clang
50 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_USINGINSERTER_H
clang::tidy::utils::UsingInserter::UsingInserter
UsingInserter(const SourceManager &SourceMgr)
Definition: UsingInserter.cpp:30
clang::tidy::utils::UsingInserter
Definition: UsingInserter.h:26
clang::tidy::utils::UsingInserter::createUsingDeclaration
llvm::Optional< FixItHint > createUsingDeclaration(ASTContext &Context, const Stmt &Statement, llvm::StringRef QualifiedName)
Definition: UsingInserter.cpp:33
clang
Definition: AndroidTidyModule.cpp:28
clang::tidy::utils::UsingInserter::getShortName
llvm::StringRef getShortName(ASTContext &Context, const Stmt &Statement, llvm::StringRef QualifiedName)
Definition: UsingInserter.cpp:78