Skip to content

Commit e720333

Browse files
committed
[Omit needless words] Only move "lonely of" arguments back to the base name.
If the first argument label would end up as "of" following splitting and pruning, move that "of" onto the base name.
1 parent 643725f commit e720333

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

lib/Basic/StringExtras.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -873,10 +873,6 @@ static bool shouldPlacePrepositionOnArgLabel(StringRef beforePreposition,
873873
afterPreposition == "Z")
874874
return false;
875875

876-
// The preposition "of" binds tightly to the left word.
877-
if (camel_case::sameWordIgnoreFirstCase(preposition, "of"))
878-
return false;
879-
880876
return true;
881877
}
882878

@@ -1147,9 +1143,12 @@ bool swift::omitNeedlessWords(StringRef &baseName,
11471143
}
11481144

11491145
// If needed, split the base name.
1146+
bool didSplitBaseName = false;
11501147
if (!argNames.empty() &&
1151-
splitBaseName(baseName, argNames[0], paramTypes[0], firstParamName))
1148+
splitBaseName(baseName, argNames[0], paramTypes[0], firstParamName)) {
1149+
didSplitBaseName = true;
11521150
anyChanges = true;
1151+
}
11531152

11541153
// Omit needless words based on parameter types.
11551154
for (unsigned i = 0, n = argNames.size(); i != n; ++i) {
@@ -1182,5 +1181,16 @@ bool swift::omitNeedlessWords(StringRef &baseName,
11821181
}
11831182
}
11841183

1184+
// Place a "lonely of" on the base name, rather than having it as
1185+
// the first argument label.
1186+
if (didSplitBaseName &&
1187+
camel_case::sameWordIgnoreFirstCase(argNames[0], "of")) {
1188+
SmallString<16> newBaseName;
1189+
newBaseName += baseName;
1190+
newBaseName += "Of";
1191+
baseName = scratch.copyString(newBaseName);
1192+
argNames[0] = StringRef();
1193+
}
1194+
11851195
return lowercaseAcronymsForReturn();
11861196
}

test/IDE/print_omit_needless_words.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@
279279

280280
// "Of" associates left.
281281
// CHECK-OMIT-NEEDLESS-WORDS: func typeOf(_: String)
282-
// CHECK-OMIT-NEEDLESS-WORDS: func typeOf(namedString _: String)
282+
// CHECK-OMIT-NEEDLESS-WORDS: func type(ofNamedString _: String)
283283

284284
// Look for preposition prior to "of".
285285
// CHECK-OMIT-NEEDLESS-WORDS: func append(contentsOf _: String)

0 commit comments

Comments
 (0)