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

Side by Side Diff: tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp

Issue 2569783002: When prepending "Get" to accessors, consider inheritance chain. (Closed)
Patch Set: Added test for non-virtual method scenario. 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // Changes Blink-style names to Chrome-style names. Currently transforms: 5 // Changes Blink-style names to Chrome-style names. Currently transforms:
6 // fields: 6 // fields:
7 // int m_operationCount => int operation_count_ 7 // int m_operationCount => int operation_count_
8 // variables (including parameters): 8 // variables (including parameters):
9 // int mySuperVariable => int my_super_variable 9 // int mySuperVariable => int my_super_variable
10 // constants: 10 // constants:
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 } 341 }
342 342
343 bool GetNameForDecl(const clang::FunctionDecl& decl, 343 bool GetNameForDecl(const clang::FunctionDecl& decl,
344 clang::ASTContext& context, 344 clang::ASTContext& context,
345 std::string& name) { 345 std::string& name) {
346 name = decl.getName().str(); 346 name = decl.getName().str();
347 name[0] = clang::toUppercase(name[0]); 347 name[0] = clang::toUppercase(name[0]);
348 348
349 // Given 349 // Given
350 // class Foo {}; 350 // class Foo {};
351 // class DerivedFoo : class Foo;
351 // using Bar = Foo; 352 // using Bar = Foo;
352 // Bar f1(); // <- |Bar| would be matched by hasString("Bar") below. 353 // Bar f1(); // <- |Bar| would be matched by hasString("Bar") below.
353 // Bar f2(); // <- |Bar| would be matched by hasName("Foo") below. 354 // Bar f2(); // <- |Bar| would be matched by hasName("Foo") below.
355 // DerivedFoo f3(); // <- |DerivedFoo| matched by isDerivedFrom(...) below.
354 // |type_with_same_name_as_function| matcher matches Bar and Foo return types. 356 // |type_with_same_name_as_function| matcher matches Bar and Foo return types.
355 auto type_with_same_name_as_function = qualType(anyOf( 357 auto type_with_same_name_as_function = qualType(anyOf(
356 hasString(name), // hasString matches the type as spelled (Bar above). 358 // hasString matches the type as spelled (Bar above).
357 hasDeclaration(namedDecl(hasName(name))))); // hasDeclaration matches 359 hasString(name),
358 // resolved type (Foo above). 360 // hasDeclaration matches resolved type (Foo or DerivedFoo above).
361 hasDeclaration(namedDecl(hasName(name))),
362 hasDeclaration(cxxRecordDecl(isDerivedFrom(namedDecl(hasName(name)))))));
363
359 // |type_containing_same_name_as_function| matcher will match all of the 364 // |type_containing_same_name_as_function| matcher will match all of the
360 // return types below: 365 // return types below:
361 // - Foo foo() // Direct application of |type_with_same_name_as_function|. 366 // - Foo foo() // Direct application of |type_with_same_name_as_function|.
362 // - Foo* foo() // |hasDescendant| traverses references/pointers. 367 // - Foo* foo() // |hasDescendant| traverses references/pointers.
363 // - RefPtr<Foo> foo() // |hasDescendant| traverses template arguments. 368 // - RefPtr<Foo> foo() // |hasDescendant| traverses template arguments.
364 auto type_containing_same_name_as_function = 369 auto type_containing_same_name_as_function =
365 qualType(anyOf(type_with_same_name_as_function, 370 qualType(anyOf(type_with_same_name_as_function,
366 hasDescendant(type_with_same_name_as_function))); 371 hasDescendant(type_with_same_name_as_function)));
367 // https://crbug.com/582312: Prepend "Get" if method name conflicts with 372 // https://crbug.com/582312: Prepend "Get" if method name conflicts with
368 // return type. 373 // return type.
(...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after
1260 for (const auto& r : replacements) { 1265 for (const auto& r : replacements) {
1261 std::string replacement_text = r.getReplacementText().str(); 1266 std::string replacement_text = r.getReplacementText().str();
1262 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); 1267 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0');
1263 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() 1268 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset()
1264 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; 1269 << ":::" << r.getLength() << ":::" << replacement_text << "\n";
1265 } 1270 }
1266 llvm::outs() << "==== END EDITS ====\n"; 1271 llvm::outs() << "==== END EDITS ====\n";
1267 1272
1268 return 0; 1273 return 0;
1269 } 1274 }
OLDNEW
« 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