Commit Graph

137 Commits

Author SHA1 Message Date
Doug Gregor
24cede9543 [Omit needless words] Treat "Mask" as a skippable type suffix.
Fixes rdar://problem/23751733.
2016-02-22 11:39:20 -08:00
Doug Gregor
bc18e4521b [Omit needless words] After "by", recognize gerunds more liberally. 2016-02-12 16:40:10 -08:00
Doug Gregor
0e46850a66 [Omit needless words] "ObjectValue" in the name matches "Object" in the type.
Fixes rdar://problem/24618946.
2016-02-12 12:41:40 -08:00
Doug Gregor
a87782e414 [Omit needless words] Handle "extended prepositions" like "compatible with".
Also, be more careful not to produce base names that are keywords.
2016-02-12 10:33:59 -08:00
Doug Gregor
90af7e60e7 [Omit needless words] "Of" associates left except when determining properties of the result. 2016-02-11 16:44:05 -08:00
Doug Gregor
e720333032 [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.
2016-02-11 16:44:05 -08:00
Doug Gregor
643725f75a [Omit needless words] The preposition "of" binds to the word preceding it. 2016-02-11 16:44:05 -08:00
Doug Gregor
a024fe0115 [Omit needless words] Split at a preposition before "of", if one exists.
This helps for cases such as "appendWithContentsOfFoo", where
"contentsOf" or "contentsOfFoo" is a better argument label than "foo"
or "ofFoo".
2016-02-11 16:44:05 -08:00
Doug Gregor
850e0e2fc3 [Omit needless words] Skip over verbs and gerunds when looking for a preposition. 2016-02-11 16:44:04 -08:00
Doug Gregor
720d67faf4 [Omit needless words] Split out find-last-preposition. NFC 2016-02-11 16:44:04 -08:00
Doug Gregor
55b406a20d [Omit needless words] Stop preventing argument labels named "for", "with", or other vacuous words.
Fixes rdar://problem/23752046.
2016-02-11 16:44:04 -08:00
practicalswift
7d67f58e1f [gardening] Fix recently introduced typo: "prposition" → "preposition" 2016-02-11 19:12:49 +01:00
Doug Gregor
050b324593 [Omit needless words] Split before last preposition in most cases.
Splitting *before* the last preposition tends to keep the
prepositional phrase together. Only leave the preposition on the base
name in rare cases where we would end up with weird argument labels
(e.g., prefer "moveTo(x:y:)" to "move(toX:y:)").

Also, refine our heuristics for when we can remove the preposition
entirely.
2016-02-10 14:20:44 -08:00
Doug Gregor
0533f6158d [Omit needless words] Move a paired preposition into the first argument label.
If the second argument label starts with a preposition for a split
selector, move the preposition into the first argument label. For
example:

-  func transitionFrom(fromViewController: NSViewController, to
toViewController: NSViewController, options:
NSViewControllerTransitionOptions = [], completionHandler completion:
(() -> Void)? = nil)
+  func transition(from fromViewController: NSViewController, to
toViewController: NSViewController, options:
NSViewControllerTransitionOptions = [], completionHandler completion:
(() -> Void)? = nil)
2016-02-08 22:41:16 -08:00
Doug Gregor
8a3a2958e7 [Omit needless words] Improve our handling of plural acronyms. 2016-02-08 22:41:16 -08:00
Doug Gregor
32b0c8c4a8 [Omit needless words] "No" conflicts after "With". 2016-02-08 22:41:15 -08:00
Doug Gregor
d03d831e1e [Omit needless words] Drop split preposition if the first parameter is defaulted. 2016-02-08 16:23:27 -08:00
Doug Gregor
c04a67ae4c [Omit needless words] Don't split setters, "action-like" methods.
Suggested by Brent Royal-Gordon.
2016-02-07 21:40:10 -08:00
Doug Gregor
e05cf6e018 [Omit needless words] Split first selector piece into base name/first argument label. 2016-02-05 23:03:36 -08:00
Doug Gregor
bd8fc9614e [Omit needless words] Match type/name words ignoring case 2016-02-05 22:27:45 -08:00
Doug Gregor
1dec2f1f34 [Clang importer] After stripping a prefix, lowercase initialisms as well. 2016-02-03 16:11:59 -08:00
Doug Gregor
b9955404c8 [Clang importer] Lowercase plural initialisms correctly.
URLs -> urls rather than urLs.
2016-01-27 16:38:11 -08:00
Doug Gregor
769b41e240 [Omit needless words] Prune redundant "self" type following a verb in the base name.
This allows us to prune UIViewController's
"dismissViewControllerAnimated" to "dismissAnimated", eliminating
unnecessary redundancy.
2016-01-19 10:34:23 -08:00
Doug Gregor
e380184cf3 [Omit needless words] Don't strip just "Error". 2016-01-18 22:06:42 -08:00
Doug Gregor
4d2480086e [Omit needless words] Use the getter name for BOOL properties.
Rather than employ complicated heuristics to determine when to add
"is" to the name of a Booleam property, just trust the name of the
getter.
2016-01-05 10:43:32 -08:00
Doug Gregor
bfba3a7968 [Omit needless words] Fix lowercasing of initialisms ending with a non-letter.
Lowercases "UTF8String" to "utf8String" rather than "utF8String".
2016-01-04 16:45:31 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Doug Gregor
c8dd8d0661 Implement SE-0001: Allow (most) keywords as argument labels.
Allow all keywords except for parameter introducers (var/let/inout) to
be argument labels when declaring or calling a
function/initializer/subscript, e.g., this

  func touchesMatching(phase: NSTouchPhase, `in` view: NSView?) -> Set<NSTouch>

can now be expressed as

  func touchesMatching(phase: NSTouchPhase, in view: NSView?) -> Set<NSTouch>

and the call goes from

  event.touchesMatching(phase, `in`: view)

to

  event.touchesMatching(phase, in: view)

Fixes [SR-344](https://bugs.swift.org/browse/SR-344) /
rdar://problem/22415674.
2015-12-22 16:18:28 -08:00
Doug Gregor
1e432568bc Clang importer: Swift 2 lowercased subsequent argument names coming from Objective-C selectors. Mimic this. 2015-12-03 11:50:43 -08:00
Doug Gregor
2ea58f93b0 Clang importer: handle CF type renaming in importFullName.
Ensures that the Swift lookup tables get transformed name for imported
CF types, including original name (which is still
available). Otherwise, this is an NFC refactoring that gets the last
of the naming tricks into importFullName.
2015-12-03 11:50:43 -08:00
Doug Gregor
106bf80152 Omit needless words: don't prune "properties" of the context from the base name.
The properties of a context indicate those things that are considered
"contained within" the context (among other things). This helps us
avoid producing overly-generic names when we identify a redundancy in
the base name. For example, NSView contains the following:

  var gestureRecognizers: [NSGestureRecognizer]
  func addGestureRecognizer(gestureRecognizer: NSGestureRecognizer)
  func removeGestureRecognizer(gestureRecognizer: NSGestureRecognizer)

Normally, omit-needless-words would prune the two method names down to
"add" and "remove", respectively, because they restate type
information. However, this pruning is not ideal, because a view isn't
primarily a collection of gesture recognizers.

Use the presence of the property "gestureRecognizers" to indicate that
we should not strip "gestureRecognizer" or "gestureRecognizers" from
the base names of methods within that class (or its subclasses).

Note that there is more work to do here to properly deal with API
evolution: a newly-added property shouldn't have any effect on
existing APIs. We should use availability information here, and only
consider properties introduced no later than the entity under
consideration.
2015-11-16 15:27:38 -08:00
Doug Gregor
8a044152da Omit needless words: lowercase the initial words of all names, including acroynums.
Cocoa's naming guidelines use lowercase initial words for selector
pieces and property names except when the first word is an
acronym. Force the first word of all imported APIs to be lowercase,
including acronyms.

Swift SVN r32719
2015-10-16 06:28:03 +00:00
Doug Gregor
f8b246980a Omit needless words: drop "with" from the beginning of first argument labels.
For example, copy(withZone:) becomes copy(zone:).

Swift SVN r32708
2015-10-15 18:53:51 +00:00
Doug Gregor
382746cd0d Omit needless words: stop splitting first selector pieces for Boolean parameters.
Swift SVN r32692
2015-10-14 23:29:20 +00:00
Xi Ge
1138a9cd27 Suppress warnings, NFC
Swift SVN r32662
2015-10-13 20:00:02 +00:00
Doug Gregor
2dcc3afd34 Omit needless words: never reduce a name down to "using", "for", or
"with"

Treat these prepositions as vacuous names, so we never reduce any
parameter name down to one of them. If that would happen, leave the
entire parameter name alone. This makes our transformation a bit more conservative.

Swift SVN r32460
2015-10-06 07:40:34 +00:00
Doug Gregor
7778790a68 Omit needless words: prepend "is" to Boolean property names.
Prepend       "is" to        Boolean property names (e.g., "empty" becomes
"isEmpty") unless the property name strongly indicates its Boolean
nature or we're   likely to ruin the name. Therefore, the  presence of
one of the following in  the property name will suppress   this
transformation:

* An auxiliary verb, such as "is", "has", "may", "should", or "will".

* A word ending in "s", indicating either a plural (for which
  prepending "is" would be incorrect) or a verb in the continuous
  tense (which indicates its Boolean nature, e.g., "translates" in
  "translatesCoordinates").

Swift SVN r32458
2015-10-06 07:03:17 +00:00
Doug Gregor
bf55d2712e Omit needless words: add some more verbs found in Cocoa.
Add adjust, alter, animate, capture, center, collapse, define, dim,
echo, enable, export, import, localize, maintain, notify, preload,
require, retain, resize, reuse, suppress, translate, traverse,
<re>verb and auto<verb>.

Swift SVN r32457
2015-10-06 07:03:09 +00:00
Doug Gregor
44e34850ae Omit needless words: give initial Boolean parameters argument labels.
When the first parameter of a function has Boolean type, try to create
an argument label for it. We start with the (normally non-API)
parameter name as the argument label, then try to match that against
the end of the base name of the method to eliminate redundancy. Add a
little magic, and here are some diffs:

    -  func openUntitledDocumentAndDisplay(_: Bool) throws -> NSDocument
    +  func openUntitledDocument(display _: Bool) throws -> NSDocument

    -  func fontMenu(_: Bool) -> NSMenu?
    -  func fontPanel(_: Bool) -> NSFontPanel?
    +  func fontMenu(create _: Bool) -> NSMenu?
    +  func fontPanel(create _: Bool) -> NSFontPanel?

    -  func lockFocusFlipped(_: Bool)
    +  func lockFocus(flipped _: Bool)

    -  func rectForSearchTextWhenCentered(_: Bool) -> NSRect
    +  func rectForSearchText(whenCentered _: Bool) -> NSRect

    -  func dismissPreviewAnimated(_: Bool)
    -  func dismissMenuAnimated(_: Bool)
    +  func dismissPreview(animated _: Bool)
    +  func dismissMenu(animated _: Bool)

Swift SVN r32392
2015-10-01 23:34:21 +00:00
Doug Gregor
cf7cc554cd Omit needless words: make _t a skippable type suffix.
Swift SVN r32384
2015-10-01 22:37:43 +00:00
Doug Gregor
2d5d3d240c Omit needless words: use the actual mapped names for builtin C types.
This provides better fidelity between omit-needless-words acting on
Clang types vs. acting on Swift types.

Swift SVN r32383
2015-10-01 22:37:40 +00:00
Doug Gregor
65b7666298 Omit needless words: stop introducing "body" for usingBlock/withBlock.
The special rule of introducing "body" isn't helping readability. We
might want to have a special rule around closure (or, especially,
trailing closure) parameters, but this is not it.

Swift SVN r32166
2015-09-22 22:37:53 +00:00
Doug Gregor
9b008714a5 Omit needless words: make "Type" a skippable suffix.
"Type" shows up in type names from time to time, but tends to be
omitted from selector pieces in such cases. This lets us skip that
suffix, fixing, e.g.,

  -  func changeCountTokenForSaveOperation(_: NSSaveOperationType) -> AnyObject
  +  func changeCountTokenFor(_: NSSaveOperationType) -> AnyObject

Swift SVN r32165
2015-09-22 22:37:48 +00:00
Doug Gregor
c2aee8429d Omit needless words: drop "with" and "using" leading subsequent parameters.
Beyond the first parameter, the "with" or "using" at the beginning of
an argument label is needless, because one does not read the base name
of the method as if it distributed to the parameters. Some examples:

-  func setProperty(_: String, withValue: AnyObject? = nil)
+  func setProperty(_: String, value: AnyObject? = nil)

-  func hitTest(_: NSRect, withImageDestinationRect: NSRect, context:
   NSGraphicsContext? = nil, hints: [String : AnyObject]? = nil,
   flipped: Bool) -> Bool
+  func hitTest(_: NSRect, imageDestinationRect: NSRect, context:
   NSGraphicsContext? = nil, hints: [String : AnyObject]? = nil,
   flipped: Bool) -> Bool

-  func track(_: NSRulerMarker, withMouseEvent: NSEvent) -> Bool
+  func track(_: NSRulerMarker, mouseEvent: NSEvent) -> Bool

Swift SVN r32141
2015-09-22 00:46:53 +00:00
Doug Gregor
158a2b1ad5 Omit needless words: remove the Ref/Ptr type-stripping rule.
Instead, when mapping a Clang type to its name for omission purposes,
map CF types to their appropriate names. This more directly mirrors
what will happen on the Swift side, but is otherwise NFC.

Swift SVN r32140
2015-09-22 00:35:10 +00:00
Doug Gregor
7d6babd53a Omit needless words NFC: factor out options for OmissionTypeName.
Swift SVN r32139
2015-09-22 00:35:07 +00:00
Doug Gregor
a75c28dee1 Omit needless words: split first selector after omitting needless words.
It's a cleaner rule to specify that we omit needless words from the
base name of a method and *then* split it for default arguments. This
tweak actually caught a small number of cases where we weren't
splitting properly, but should have.

Swift SVN r32133
2015-09-21 23:18:35 +00:00
Doug Gregor
f3b20a4412 Omit needless words: strip context type from the name prefix consistently.
When the context type of a declaraton matches the result type,
strip off redundant type information at the beginning of the
declaration name if it is followed by a preposition. This covers the
class of transformations on performs on a class that produce a value
of the same type as that class, e.g., NSURL's "URLWithHTTPS" or
NSString's "stringByAppendingString".

When that preposition is the magical "By" and is followed by a gerund,
strip the "By" as well. Note that this is slightly more conservative
now for methods, which previously stripped based on the result type
(always). For example, in NSCalendar:

-  func adding(_: NSDateComponents, to: NSDate, options:
   NSCalendarOptions = [])
 -> NSDate?
+  func dateByAdding(_: NSDateComponents, to: NSDate, options:
   NSCalendarOptions
 = []) -> NSDate?

but it's more general for properties, e.g.,

-  @NSCopying var bezierPathByFlattening: NSBezierPath { get }
-  @NSCopying var bezierPathByReversing: NSBezierPath { get }
+  @NSCopying var byFlattening: NSBezierPath { get }
+  @NSCopying var reversing: NSBezierPath { get }

The important part is that the rules are more uniform and the code is
more regularly structured: we strip this leading type information when
it's redundant with the context and result type, regardless of whether
we have a property or a method, and the "By" rule is no longer special
in that regard.

Swift SVN r32129
2015-09-21 22:52:14 +00:00
Doug Gregor
8e6d7665ce Omit needless words: strip result type info from both sides of a zero-argument method.
This takes an highly-redundant API name like NSBezierPath's

  func bezierPathByReversingPath() -> NSBezierPath

and turns it into

  func reversing() -> NSBezierPath

Also, handle 'instancetype' properly when omitting words matching the
result type from the front of the base name.

Swift SVN r32119
2015-09-21 19:46:12 +00:00
Doug Gregor
627a1820b8 Omit needless words: split the base name when the first parameter is defaulted.
Split the base name at the last preposition, but *only* when the first
parameter is defaulted, because defaulted arguments might not show up
at the call site and the longer base name can feel odd in such
cases. With this, stop avoiding the argument label "with": it's fine
when we have actual context at the call site, and the "with: nil" case
no longer happens now that we're defaulting nil.

Swift SVN r32098
2015-09-20 05:16:46 +00:00