Chromium Code Reviews| Index: tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp |
| diff --git a/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp b/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp |
| index 600adeb807171fb69775d72155cf35aa883edac9..da3945dd1af6d22dd196cf5e98d40837ca3f10c7 100644 |
| --- a/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp |
| +++ b/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp |
| @@ -290,6 +290,10 @@ bool IsProbablyConst(const clang::VarDecl& decl, |
| return initializer->isEvaluatable(context); |
| } |
| +AST_MATCHER_P(clang::QualType, hasString, std::string, ExpectedString) { |
| + return ExpectedString == Node.getAsString(); |
| +} |
| + |
| bool GetNameForDecl(const clang::FunctionDecl& decl, |
| clang::ASTContext& context, |
| std::string& name) { |
| @@ -297,9 +301,14 @@ bool GetNameForDecl(const clang::FunctionDecl& decl, |
| name[0] = clang::toUppercase(name[0]); |
| // https://crbug.com/582312: Prepend "Get" if method name conflicts with type. |
| - const clang::IdentifierInfo* return_type = |
| - decl.getReturnType().getBaseTypeIdentifier(); |
| - if (return_type && return_type->getName() == name) |
| + auto type_with_same_name_as_function = qualType( |
| + anyOf(hasDeclaration(namedDecl(hasName(name))), hasString(name))); |
|
Łukasz Anforowicz
2016/09/07 23:14:28
Without |hasString| we wouldn't properly handle th
danakj
2016/09/08 23:30:40
Can you leave a comment here saying that hasName()
Łukasz Anforowicz
2016/09/09 00:20:35
Done.
|
| + auto type_containing_same_name_as_function = |
| + qualType(anyOf(type_with_same_name_as_function, |
| + hasDescendant(type_with_same_name_as_function))); |
|
Łukasz Anforowicz
2016/09/07 23:14:28
|hasDescendant| helps catch the RefPtr<SameNameAsF
|
| + auto conflict_matcher = |
| + functionDecl(returns(type_containing_same_name_as_function)); |
| + if (!match(conflict_matcher, decl, context).empty()) |
| name = "Get" + name; |
| return true; |