[Omit needless words] Retain "with" after splitting more regularly.

The verb-based heuristic was unpredictable and not clearly
better. Back off to something more obvious.
This commit is contained in:
Doug Gregor
2016-02-29 12:57:58 -08:00
parent b890e4c29f
commit 87f1d577a3
2 changed files with 12 additions and 31 deletions

View File

@@ -950,38 +950,19 @@ static bool isVacuousPreposition(StringRef beforePreposition,
!camel_case::sameWordIgnoreFirstCase(preposition, "using"))
return false;
// If the preposition is "with", check for special cases.
if (camel_case::sameWordIgnoreFirstCase(preposition, "with")) {
// Some words following the preposition indicate that "with" is
// not vacuous.
auto following = camel_case::getFirstWord(afterPreposition);
if (camel_case::sameWordIgnoreFirstCase(following, "coder") ||
camel_case::sameWordIgnoreFirstCase(following, "zone"))
// If the preposition is "with" followed by "zone", never consider
// it vacuous.
if (camel_case::sameWordIgnoreFirstCase(preposition, "with") &&
camel_case::sameWordIgnoreFirstCase(
camel_case::getFirstWord(afterPreposition), "zone"))
return false;
// If the last word of the argument label looks like a past
// participle (ends in "-ed"), the preposition is not vacuous.
auto lastWord = camel_case::getLastWord(afterPreposition);
if (lastWord.endswith("ed"))
return false;
if (camel_case::sameWordIgnoreFirstCase(following, "delegate") ||
camel_case::sameWordIgnoreFirstCase(following, "frame"))
return true;
}
// If the parameter has a default argument, it's vacuous.
if (paramType.hasDefaultArgument()) return true;
// If the parameter is of function type, it's vacuous.
if (paramType.isFunction()) return true;
// If the first word of the name is a verb, the preposition is
// likely vacuous.
if (getPartOfSpeech(camel_case::getFirstWord(beforePreposition))
== PartOfSpeech::Verb)
return true;
return false;
}

View File

@@ -138,10 +138,10 @@
// CHECK-FOUNDATION: func enumerateObjectsRandomly(_: ((AnyObject!, Int, UnsafeMutablePointer<ObjCBool>) -> Void)? = nil)
// Note: id<Proto> treated as "Proto".
// CHECK-FOUNDATION: func doSomething(_: Copying)
// CHECK-FOUNDATION: func doSomething(with _: Copying)
// Note: NSObject<Proto> treated as "Proto".
// CHECK-FOUNDATION: func doSomethingElse(_: protocol<Copying, ObjectProtocol>)
// CHECK-FOUNDATION: func doSomethingElse(with _: protocol<Copying, ObjectProtocol>)
// Note: Function type -> "Function".
// CHECK-FOUNDATION: func sort(_: @convention(c) (AnyObject, AnyObject) -> Int)
@@ -150,7 +150,7 @@
// CHECK-FOUNDATION: func remove(_: [AnyObject])
// Note: Skipping "Type" suffix.
// CHECK-FOUNDATION: func doSomething(_: UnderlyingType)
// CHECK-FOUNDATION: func doSomething(with _: UnderlyingType)
// Don't introduce default arguments for lone parameters to setters.
// CHECK-FOUNDATION: func setDefaultEnumerationOptions(_: EnumerationOptions)
@@ -284,7 +284,7 @@
// CHECK-OMIT-NEEDLESS-WORDS: func type(ofTypeNamed _: String)
// Look for preposition prior to "of".
// CHECK-OMIT-NEEDLESS-WORDS: func append(contentsOf _: String)
// CHECK-OMIT-NEEDLESS-WORDS: func append(withContentsOf _: String)
// Leave subscripts alone
// CHECK-OMIT-NEEDLESS-WORDS: subscript(_: UInt) -> AnyObject { get }
@@ -298,10 +298,10 @@
// CHECK-OMIT-NEEDLESS-WORDS: func slobbering(_: String) -> OmitNeedlessWords
// Elements of C array types
// CHECK-OMIT-NEEDLESS-WORDS: func drawPolygon(_: UnsafePointer<Point>, count: Int)
// CHECK-OMIT-NEEDLESS-WORDS: func drawPolygon(with _: UnsafePointer<Point>, count: Int)
// Typedef ending in "Array".
// CHECK-OMIT-NEEDLESS-WORDS: func drawFilledPolygon(_: PointArray, count: Int)
// CHECK-OMIT-NEEDLESS-WORDS: func drawFilledPolygon(with _: PointArray, count: Int)
// Non-parameterized Objective-C class ending in "Array".
// CHECK-OMIT-NEEDLESS-WORDS: func draw(_: SEGreebieArray)