clang-tools
22.0.0git
llvm-project
clang-tools-extra
clang-tidy
abseil
NoNamespaceCheck.cpp
Go to the documentation of this file.
1
//===----------------------------------------------------------------------===//
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
#include "
NoNamespaceCheck.h
"
10
#include "
AbseilMatcher.h
"
11
#include "clang/ASTMatchers/ASTMatchFinder.h"
12
13
using namespace
clang::ast_matchers
;
14
15
namespace
clang::tidy::abseil
{
16
17
void
NoNamespaceCheck::registerMatchers
(MatchFinder *Finder) {
18
Finder->addMatcher(namespaceDecl(hasName(
"::absl"
), unless(isInAbseilFile()))
19
.bind(
"abslNamespace"
),
20
this
);
21
}
22
23
void
NoNamespaceCheck::check
(
const
MatchFinder::MatchResult &Result) {
24
const
auto
*AbslNamespaceDecl =
25
Result.Nodes.getNodeAs<NamespaceDecl>(
"abslNamespace"
);
26
27
diag(AbslNamespaceDecl->getLocation(),
28
"namespace 'absl' is reserved for implementation of the Abseil library "
29
"and should not be opened in user code"
);
30
}
31
32
}
// namespace clang::tidy::abseil
AbseilMatcher.h
NoNamespaceCheck.h
clang::tidy::abseil::NoNamespaceCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
Definition
NoNamespaceCheck.cpp:23
clang::tidy::abseil::NoNamespaceCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Definition
NoNamespaceCheck.cpp:17
clang::ast_matchers
Definition
AbseilMatcher.h:13
clang::tidy::abseil
Definition
AbseilTidyModule.cpp:33
Generated on
for clang-tools by
1.14.0