Omit needless words: remove arguments that match the default arguments.

For cases where the Clang importer provides a defaulted argument,
e.g., "[]" for option sets and "nil" for optionals, remove the
corresponding arguments at any call sites that simply specify "[]" or
"nil". Such arguments are basically noise, and tend to harm
readability when there are low-content argument labels like "with:" or
"for".

Some examples from Lister:

  self.updateUserActivity(AppConfiguration.UserActivity.watch,
                          userInfo: userInfo, webpageURL: nil)

becomes

  self.updateUserActivity(AppConfiguration.UserActivity.watch,
                          userInfo: userInfo)

and

  contentView.hitTest(tapLocation, with: nil)

becomes

  contentView.hitTest(tapLocation)

and

  document.closeWithCompletionHandler(nil)

becomes simply

  document.close()

and a whole pile of optional "completion handler" arguments go away.

Swift SVN r31978
This commit is contained in:
Doug Gregor
2015-09-15 22:45:50 +00:00
parent dc820315ba
commit 838759d155
9 changed files with 341 additions and 44 deletions

View File

@@ -444,8 +444,9 @@ StringRef swift::omitNeedlessWords(StringRef name, OmissionTypeName typeName,
if ((role == NameRole::FirstParameter ||
role == NameRole::SubsequentParameter) &&
(name == "usingBlock" || name == "withBlock") &&
typeName.Name == "Block")
typeName.Name == "Block") {
return "body";
}
// Get the camel-case words in the name and type name.
auto nameWords = camel_case::getWords(name);