Clang Project

clang_source_code/lib/Tooling/FixIt.cpp
1//===--- FixIt.cpp - FixIt Hint utilities -----------------------*- 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//===----------------------------------------------------------------------===//
8//
9// This file contains implementations of utitilies to ease source code rewriting
10// by providing helper functions related to FixItHint.
11//
12//===----------------------------------------------------------------------===//
13#include "clang/Tooling/FixIt.h"
14#include "clang/Lex/Lexer.h"
15
16namespace clang {
17namespace tooling {
18namespace fixit {
19
20namespace internal {
21StringRef getText(CharSourceRange Rangeconst ASTContext &Context) {
22  return Lexer::getSourceText(RangeContext.getSourceManager(),
23                              Context.getLangOpts());
24}
25
26CharSourceRange maybeExtendRange(CharSourceRange Rangetok::TokenKind Next,
27                                 ASTContext &Context) {
28  Optional<TokenTok = Lexer::findNextToken(
29      Range.getEnd(), Context.getSourceManager(), Context.getLangOpts());
30  if (!Tok || !Tok->is(Next))
31    return Range;
32  return CharSourceRange::getTokenRange(Range.getBegin(), Tok->getLocation());
33}
34// namespace internal
35
36// end namespace fixit
37// end namespace tooling
38// end namespace clang
39