mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Omit needless words] Don't split setters, "action-like" methods.
Suggested by Brent Royal-Gordon.
This commit is contained in:
committed by
Slava Pestov
parent
30217cb7b4
commit
c04a67ae4c
@@ -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 ¶mType,
|
||||
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.
|
||||
|
||||
@@ -4,4 +4,6 @@
|
||||
-(void)jumpToUrl:(nonnull NSURL *)url;
|
||||
-(BOOL)objectIsCompatibleWithObject:(nonnull id)other;
|
||||
-(void)insetByX:(NSInteger)x y:(NSInteger)y;
|
||||
-(void)setIndirectlyToValue:(nonnull id)object;
|
||||
-(void)jumpToTop:(nonnull id)sender;
|
||||
@end
|
||||
|
||||
@@ -255,6 +255,8 @@
|
||||
// CHECK-OMIT-NEEDLESS-WORDS: func jumpTo(_: URL)
|
||||
// CHECK-OMIT-NEEDLESS-WORDS: func objectIsCompatibleWith(_: AnyObject) -> Bool
|
||||
// CHECK-OMIT-NEEDLESS-WORDS: func insetBy(x _: Int, y: Int)
|
||||
// CHECK-OMIT-NEEDLESS-WORDS: func setIndirectlyToValue(_: AnyObject)
|
||||
// CHECK-OMIT-NEEDLESS-WORDS: func jumpToTop(_: AnyObject)
|
||||
|
||||
// Don't drop the 'error'.
|
||||
// CHECK-ERRORS: func tryAndReturnError(_: ()) throws
|
||||
|
||||
Reference in New Issue
Block a user