[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / clang-tools-extra / clangd / refactor / InsertionPoint.h
blob401a384928e11bafb57bfc503df8f6f88934d93f
1 //===--- InsertionPoint.h - Where should we add new code? --------*- C++-*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_REFACTOR_INSERTIONPOINT_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_REFACTOR_INSERTIONPOINT_H
12 #include "clang/AST/DeclCXX.h"
13 #include "clang/Basic/Specifiers.h"
14 #include "clang/Tooling/Core/Replacement.h"
16 namespace clang {
17 namespace clangd {
19 // An anchor describes where to insert code into a decl sequence.
21 // It allows inserting above or below a block of decls matching some criterion.
22 // For example, "insert after existing constructors".
23 struct Anchor {
24 // A predicate describing which decls are considered part of a block.
25 // Match need not handle TemplateDecls, which are unwrapped before matching.
26 std::function<bool(const Decl *)> Match;
27 // Whether the insertion point should be before or after the matching block.
28 enum Dir { Above, Below } Direction = Below;
31 // Returns the point to insert a declaration according to Anchors.
32 // Anchors are tried in order. For each, the first matching location is chosen.
33 SourceLocation insertionPoint(const DeclContext &Ctx,
34 llvm::ArrayRef<Anchor> Anchors);
36 // Returns an edit inserting Code inside Ctx.
37 // Location is chosen according to Anchors, falling back to the end of Ctx.
38 // Fails if the chosen insertion point is in a different file than Ctx itself.
39 llvm::Expected<tooling::Replacement> insertDecl(llvm::StringRef Code,
40 const DeclContext &Ctx,
41 llvm::ArrayRef<Anchor> Anchors);
43 // Variant for C++ classes that ensures the right access control.
44 SourceLocation insertionPoint(const CXXRecordDecl &InClass,
45 std::vector<Anchor> Anchors,
46 AccessSpecifier Protection);
48 // Variant for C++ classes that ensures the right access control.
49 // May insert a new access specifier if needed.
50 llvm::Expected<tooling::Replacement> insertDecl(llvm::StringRef Code,
51 const CXXRecordDecl &InClass,
52 std::vector<Anchor> Anchors,
53 AccessSpecifier Protection);
55 } // namespace clangd
56 } // namespace clang
58 #endif