blob: c8a28a0ee61563c788f14c4ccf249c6fc2d2f74a [file] [log] [blame]
Felix Bergeradfdc142016-03-05 21:17:58 +00001//===--- FixItHintUtils.cpp - 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#include "FixItHintUtils.h"
11#include "LexerUtils.h"
12#include "clang/AST/ASTContext.h"
13
14namespace clang {
15namespace tidy {
16namespace utils {
17namespace create_fix_it {
18
19FixItHint changeVarDeclToReference(const VarDecl &Var, ASTContext &Context) {
20 SourceLocation AmpLocation = Var.getLocation();
21 auto Token = lexer_utils::getPreviousNonCommentToken(Context, AmpLocation);
22 if (!Token.is(tok::unknown))
23 AmpLocation = Lexer::getLocForEndOfToken(Token.getLocation(), 0,
24 Context.getSourceManager(),
25 Context.getLangOpts());
26 return FixItHint::CreateInsertion(AmpLocation, "&");
27}
28
29FixItHint changeVarDeclToConst(const VarDecl &Var) {
30 return FixItHint::CreateInsertion(Var.getTypeSpecStartLoc(), "const ");
31}
32
33} // namespace create_fix_it
34} // namespace utils
35} // namespace tidy
36} // namespace clang