1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 
5 #include "NoUsingNamespaceMozillaJavaChecker.h"
6 #include "CustomMatchers.h"
7 
registerMatchers(MatchFinder * AstMatcher)8 void NoUsingNamespaceMozillaJavaChecker::registerMatchers(
9     MatchFinder *AstMatcher) {
10   AstMatcher->addMatcher(
11       usingDirectiveDecl(isUsingNamespaceMozillaJava()).bind("directive"),
12       this);
13 }
14 
check(const MatchFinder::MatchResult & Result)15 void NoUsingNamespaceMozillaJavaChecker::check(
16     const MatchFinder::MatchResult &Result) {
17   const UsingDirectiveDecl *Directive =
18       Result.Nodes.getNodeAs<UsingDirectiveDecl>("directive");
19   const NamespaceDecl *Namespace = Directive->getNominatedNamespace();
20 
21   diag(Directive->getUsingLoc(), "using namespace %0 is forbidden",
22        DiagnosticIDs::Error)
23       << Namespace->getQualifiedNameAsString();
24 }
25