[Omit needless words] Don't split setters, "action-like" methods.

Suggested by Brent Royal-Gordon.
This commit is contained in:
Doug Gregor
2016-02-06 23:52:11 -08:00
committed by Slava Pestov
parent 30217cb7b4
commit c04a67ae4c
3 changed files with 17 additions and 1 deletions

View File

@@ -920,6 +920,7 @@ static bool splitBaseNameAfterLastPreposition(StringRef &baseName,
/// Split the base name, if it makes sense.
static bool splitBaseName(StringRef &baseName, StringRef &argName,
const OmissionTypeName &paramType,
StringRef paramName,
StringScratchSpace &scratch) {
// If there is already an argument label, do nothing.
if (!argName.empty()) return false;
@@ -932,6 +933,16 @@ static bool splitBaseName(StringRef &baseName, StringRef &argName,
return true;
}
// Don't split anything that starts with "set".
if (camel_case::getFirstWord(baseName) == "set")
return false;
// Don't split a method that looks like an action (with a "sender"
// of type AnyObject).
if (paramName == "sender" &&
camel_case::getLastWord(paramType.Name) == "Object")
return false;
// Try splitting after the last preposition.
if (splitBaseNameAfterLastPreposition(baseName, argName, paramType, scratch))
return true;
@@ -1013,7 +1024,8 @@ bool swift::omitNeedlessWords(StringRef &baseName,
// If needed, split the base name.
if (!argNames.empty() &&
splitBaseName(baseName, argNames[0], paramTypes[0], scratch))
splitBaseName(baseName, argNames[0], paramTypes[0], firstParamName,
scratch))
anyChanges = true;
// Omit needless words based on parameter types.