Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Unified Diff: tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp

Issue 2589923002: Add a hardcoded list of methods that need a "Get" prefix. (Closed)
Patch Set: Rebasing... Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/clang/rewrite_to_chrome_style/tests/methods-expected.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 d308f5e1e046cf87995fe7c529d68ed28058f9df..e142dc2639c45afd7f2c4de72e8e0d8feb3899b8 100644
--- a/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
+++ b/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
@@ -330,6 +330,70 @@ AST_MATCHER_P(clang::QualType, hasString, std::string, ExpectedString) {
return ExpectedString == Node.getAsString();
}
+bool ShouldPrefixFunctionName(const std::string& old_method_name) {
+ // Methods that are named similarily to a type - they should be prefixed
+ // with a "get" prefix.
+ static const char* kConflictingMethods[] = {
+ "animationWorklet",
+ "audioWorklet",
+ "binaryType",
+ "blob",
+ "channelCountMode",
+ "color",
+ "counterDirectives",
+ "document",
+ "emptyChromeClient",
+ "emptyEditorClient",
+ "emptySpellCheckerClient",
+ "entryType",
+ "error",
+ "fileUtilities",
+ "font",
+ "iconURL",
+ "inputMethodController",
+ "inputType",
+ "layout",
+ "layoutBlock",
+ "layoutSize",
+ "length",
+ "lineCap",
+ "lineJoin",
+ "matchedProperties",
+ "name",
+ "navigationType",
+ "node",
+ "outcome",
+ "pagePopup",
+ "paintWorklet",
+ "path",
+ "processingInstruction",
+ "readyState",
+ "screenInfo",
+ "scrollAnimator",
+ "settings",
+ "signalingState",
+ "state",
+ "string",
+ "text",
+ "textAlign",
+ "textBaseline",
+ "theme",
+ "timing",
+ "topLevelBlameContext",
+ "widget",
+ };
+ for (const auto& conflicting_method : kConflictingMethods) {
+ if (old_method_name == conflicting_method)
+ return true;
+ }
+
+ return false;
+}
+
+AST_MATCHER(clang::FunctionDecl, shouldPrefixFunctionName) {
+ return ShouldPrefixFunctionName(Node.getName().str());
+}
+
bool GetNameForDecl(const clang::FunctionDecl& decl,
clang::ASTContext& context,
std::string& name) {
@@ -349,7 +413,8 @@ bool GetNameForDecl(const clang::FunctionDecl& decl,
hasString(name),
// hasDeclaration matches resolved type (Foo or DerivedFoo above).
hasDeclaration(namedDecl(hasName(name))),
- hasDeclaration(cxxRecordDecl(isDerivedFrom(namedDecl(hasName(name)))))));
+ hasDeclaration(
+ cxxRecordDecl(isDerivedFrom(namedDecl(hasName(name)))))));
// |type_containing_same_name_as_function| matcher will match all of the
// return types below:
@@ -361,8 +426,9 @@ bool GetNameForDecl(const clang::FunctionDecl& decl,
hasDescendant(type_with_same_name_as_function)));
// https://crbug.com/582312: Prepend "Get" if method name conflicts with
// return type.
- auto conflict_matcher =
- functionDecl(returns(type_containing_same_name_as_function));
+ auto conflict_matcher = functionDecl(anyOf(
+ returns(type_containing_same_name_as_function),
+ shouldPrefixFunctionName()));
if (IsMatching(conflict_matcher, decl, context))
name = "Get" + name;
@@ -819,6 +885,8 @@ class UnresolvedRewriterBase : public RewriterBase<TargetNode> {
!IsBlacklistedMethodName(old_name)) {
new_name = old_name;
new_name[0] = clang::toUppercase(old_name[0]);
+ if (ShouldPrefixFunctionName(old_name))
+ new_name = "Get" + new_name;
return true;
}
« no previous file with comments | « no previous file | tools/clang/rewrite_to_chrome_style/tests/methods-expected.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698