From c5cb633aab75ae83d4b3db0e1fe41e8ed68d2ab8 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Thu, 10 Sep 2015 00:03:11 +0000 Subject: [PATCH] Omit needless words: don't produce parameters with the argument label "with". When dropping the redundant type information from a parameter name would leave us with "with", instead drop the "with" and lowercase the rest of the parameter name. It's still redundant information, but it's less bad than simply "with". Swift SVN r31835 --- lib/Basic/StringExtras.cpp | 20 ++++++++++++++++--- test/IDE/print_omit_needless_words.swift | 7 +++++-- .../usr/include/Foundation.h | 4 ++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/lib/Basic/StringExtras.cpp b/lib/Basic/StringExtras.cpp index 270788623c3..9e63c4b8891 100644 --- a/lib/Basic/StringExtras.cpp +++ b/lib/Basic/StringExtras.cpp @@ -559,7 +559,20 @@ StringRef swift::omitNeedlessWords(StringRef name, OmissionTypeName typeName, break; } - SWIFT_FALLTHROUGH; + // If removing the type information would leave us with a + // parameter named "with", lowercase the type information and + // keep that instead. + if ((role == NameRole::FirstParameter || + role == NameRole::SubsequentParameter) && + *nameWordRevIter == "with" && + std::next(nameWordRevIter) == nameWordRevIterEnd) { + name = toLowercaseWord( + name.substr(nameWordRevIter.base().getPosition()), + scratch); + break; + } + + SWIFT_FALLTHROUGH; case PartOfSpeech::Verb: case PartOfSpeech::Gerund: @@ -574,6 +587,7 @@ StringRef swift::omitNeedlessWords(StringRef name, OmissionTypeName typeName, } break; } + } else if (role == NameRole::Property) { // For a property, check whether type information is at the beginning. name = omitNeedlessWordsForResultType(name, typeName, true, scratch); @@ -583,11 +597,11 @@ StringRef swift::omitNeedlessWords(StringRef name, OmissionTypeName typeName, if (name == "get" || name == "set") return origName; - // If we ended up with a keyword for a property name or base name, - // do nothing. switch (role) { case NameRole::BaseName: case NameRole::Property: + // If we ended up with a keyword for a property name or base name, + // do nothing. if (isKeyword(name)) return origName; break; diff --git a/test/IDE/print_omit_needless_words.swift b/test/IDE/print_omit_needless_words.swift index 10fbdba7873..1ac070b0bf9 100644 --- a/test/IDE/print_omit_needless_words.swift +++ b/test/IDE/print_omit_needless_words.swift @@ -24,8 +24,11 @@ // Note: SEL -> "Selector" // CHECK-FOUNDATION: func makeObjectsPerform(aSelector: Selector) -// Note: id -> "Object", leaving "with" -// CHECK-FOUNDATION: func makeObjectsPerform(aSelector: Selector, with anObject: AnyObject?) +// Note: "with" parameters drop the "with". +// CHECK-FOUNDATION: func makeObjectsPerform(aSelector: Selector, object anObject: AnyObject?) + +// Note: id -> "Object". +// CHECK-FOUNDATION: func indexOf(object: AnyObject) -> Int // Note: Class -> "Class" // CHECK-OBJECTIVEC: func isKindOf(aClass: AnyClass) -> Bool diff --git a/test/Inputs/clang-importer-sdk/usr/include/Foundation.h b/test/Inputs/clang-importer-sdk/usr/include/Foundation.h index af80c1670b2..c0ee986b11e 100644 --- a/test/Inputs/clang-importer-sdk/usr/include/Foundation.h +++ b/test/Inputs/clang-importer-sdk/usr/include/Foundation.h @@ -98,6 +98,10 @@ __attribute__((availability(ios,introduced=8.0))) - (void)makeObjectsPerformSelector:(nonnull SEL)aSelector withObject:(nullable ObjectType)anObject; @end +@interface NSArray (AddingObject) +- (NSInteger)indexOfObject:(nonnull id)object; +@end + @interface DummyClass : NSObject - (nonnull id)objectAtIndexedSubscript:(NSUInteger)idx; - description;