1 //===--- SourceCode.cpp - Source code manipulation routines -----*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file provides functions that simplify extraction of source code.
11 //===----------------------------------------------------------------------===//
12 #include "clang/Tooling/Refactoring/SourceCode.h"
13 #include "clang/Lex/Lexer.h"
15 using namespace clang;
17 StringRef clang::tooling::getText(CharSourceRange Range,
18 const ASTContext &Context) {
19 return Lexer::getSourceText(Range, Context.getSourceManager(),
20 Context.getLangOpts());
23 CharSourceRange clang::tooling::maybeExtendRange(CharSourceRange Range,
25 ASTContext &Context) {
26 Optional<Token> Tok = Lexer::findNextToken(
27 Range.getEnd(), Context.getSourceManager(), Context.getLangOpts());
28 if (!Tok || !Tok->is(Next))
30 return CharSourceRange::getTokenRange(Range.getBegin(), Tok->getLocation());