Omit needless words: strip result type info from both sides of a zero-argument method.

This takes an highly-redundant API name like NSBezierPath's

  func bezierPathByReversingPath() -> NSBezierPath

and turns it into

  func reversing() -> NSBezierPath

Also, handle 'instancetype' properly when omitting words matching the
result type from the front of the base name.

Swift SVN r32119
This commit is contained in:
Doug Gregor
2015-09-21 19:46:12 +00:00
parent 81850079ac
commit 8e6d7665ce
5 changed files with 20 additions and 9 deletions

View File

@@ -619,6 +619,8 @@ bool swift::omitNeedlessWords(StringRef &baseName,
ArrayRef<OmissionTypeName> paramTypes,
bool returnsSelf,
StringScratchSpace &scratch) {
bool anyChanges = false;
// For zero-parameter methods that return 'Self' or a result type
// that matches the declaration context, omit needless words from
// the base name.
@@ -632,16 +634,15 @@ bool swift::omitNeedlessWords(StringRef &baseName,
StringRef oldBaseName = baseName;
baseName = omitNeedlessWords(baseName, typeName, NameRole::Property,
scratch);
return baseName != oldBaseName;
if (baseName != oldBaseName)
anyChanges = true;
}
return false;
}
// Omit needless words in the base name based on the result type.
bool anyChanges = false;
StringRef newBaseName
= omitNeedlessWordsForResultType(baseName, resultType,
= omitNeedlessWordsForResultType(baseName,
returnsSelf ? contextType : resultType,
resultTypeMatchesContext, scratch);
if (newBaseName != baseName) {
baseName = newBaseName;