Skip to content

Commit 643725f

Browse files
committed
[Omit needless words] The preposition "of" binds to the word preceding it.
1 parent a024fe0 commit 643725f

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

lib/Basic/StringExtras.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -830,10 +830,6 @@ static bool wordConflictsBeforePreposition(StringRef word,
830830
camel_case::sameWordIgnoreFirstCase(word, "compatible"))
831831
return true;
832832

833-
if (camel_case::sameWordIgnoreFirstCase(preposition, "of") &&
834-
camel_case::sameWordIgnoreFirstCase(word, "kind"))
835-
return true;
836-
837833
return false;
838834
}
839835

@@ -877,6 +873,10 @@ static bool shouldPlacePrepositionOnArgLabel(StringRef beforePreposition,
877873
afterPreposition == "Z")
878874
return false;
879875

876+
// The preposition "of" binds tightly to the left word.
877+
if (camel_case::sameWordIgnoreFirstCase(preposition, "of"))
878+
return false;
879+
880880
return true;
881881
}
882882

test/IDE/Inputs/custom-modules/OmitNeedlessWords.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@
1111
-(void)saveToURL:(nonnull NSURL *)url forSaveOperation:(NSInteger)operation;
1212
-(void)indexWithItemNamed:(nonnull NSString *)name;
1313
-(void)methodAndReturnError:(NSError **)error;
14+
-(nullable Class)typeOfString:(nonnull NSString *)string;
15+
-(nullable Class)typeOfNamedString:(nonnull NSString *)string;
1416
-(void)appendWithContentsOfString:(nonnull NSString *)string;
1517
@end

test/IDE/print_omit_needless_words.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
// CHECK-FOUNDATION: func makeObjectsPerform(_: Selector, with: AnyObject?, with: AnyObject?)
3636

3737
// Note: id -> "Object".
38-
// CHECK-FOUNDATION: func index(of _: AnyObject) -> Int
38+
// CHECK-FOUNDATION: func indexOf(_: AnyObject) -> Int
3939

4040
// Note: Class -> "Class"
4141
// CHECK-OBJECTIVEC: func isKindOf(aClass: AnyClass) -> Bool
@@ -277,6 +277,10 @@
277277
// CHECK-OMIT-NEEDLESS-WORDS: func index(withItemNamed _: String)
278278
// CHECK-OMIT-NEEDLESS-WORDS: func methodAndReturnError(_: AutoreleasingUnsafeMutablePointer<Error?>)
279279

280+
// "Of" associates left.
281+
// CHECK-OMIT-NEEDLESS-WORDS: func typeOf(_: String)
282+
// CHECK-OMIT-NEEDLESS-WORDS: func typeOf(namedString _: String)
283+
280284
// Look for preposition prior to "of".
281285
// CHECK-OMIT-NEEDLESS-WORDS: func append(contentsOf _: String)
282286

0 commit comments

Comments
 (0)