Commit Graph

35 Commits

Author SHA1 Message Date
Michael Ilseman
32faa62502 [Import as member] Lower case initialisms 2016-03-09 14:26:43 -08:00
Michael Ilseman
d38f190acb [Clang importer] Basic import-as-member inference system
Introduces import-as-member (IAM) inferene system, to automatically
infer details that would otherwise have to be manually specified with
the swift_name attribute.

Basic functionality present, though there are some issues with
properties at the moment. No hooks, options, or tests yet, stay tuned.
2016-03-06 23:54:56 -08:00
Chris Lattner
b2fabdadcc move diagnoseArgumentLabelError to CSDiags.cpp now that it is the only client. 2016-02-12 17:33:22 -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
1dec2f1f34 [Clang importer] After stripping a prefix, lowercase initialisms as well. 2016-02-03 16:11:59 -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
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
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
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
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
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
7d6babd53a Omit needless words NFC: factor out options for OmissionTypeName.
Swift SVN r32139
2015-09-22 00:35:07 +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
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
Doug Gregor
406e7c6e48 Omit needless words: generalize the scratch space for strings.
NFC for now, but we'll need to handle multiple strings soon.

Swift SVN r31834
2015-09-10 00:03:09 +00:00
Doug Gregor
7960ca1619 Omit needless words: strip out prefixes that are redundant with the result type.
When the prefix of a method/property name is restating the result
type, followed by "By" and then a gerund, drop everything up to the
gerund. For example:

  func stringByAppendingString(string: String) -> String

becomes

  func appending(string: String) -> String

Swift SVN r31683
2015-09-04 00:07:38 +00:00
Doug Gregor
86eb26a88c Factor out the matching of type names at the beginning of a name. NFC
Swift SVN r31682
2015-09-04 00:07:27 +00:00
Doug Gregor
c439f0f5f0 Omit needless words: remove plural forms of element names when the type is a collection.
When the type name we're looking at is a collection of some element
type, also try to match the plural form of the element type name. For
example:

-  func deselectItemsAtIndexPaths(_: Set<NSIndexPath>)
+  func deselectItemsAt(_: Set<NSIndexPath>)

Swift SVN r31666
2015-09-03 17:06:50 +00:00
Doug Gregor
c3497fb378 Omit needless words: allow removal of words following a gerund.
Identify gerunds by stripping off the "ing" and looking for a
verb. This lets us transform, e.g., "stringByAppendingString" to
"stringByAppending", since "append" is a verb.

Swift SVN r31660
2015-09-03 05:44:20 +00:00
Doug Gregor
8ce50fbd76 Omit needless words: only omit words when they are preceded by a verb or preposition.
The presence of a verb or preposition prior to the redundant part
provides a firm linguistic split that lets the actual argument fill in
for the reader. For other parts of speech (adjectives, especially)
it's awkward to transition from "reading part of the name" to "reading
the argument". This eliminates a significant number of bad omissions,
e.g., "setTextColor()" -> "setText()", and generally makes the
transformation more conservative.

Swift SVN r31656
2015-09-03 05:04:11 +00:00
Doug Gregor
6e1b8323f7 Revert "Omit needless words: don't drop the first parameter name for failability initializers."
This reverts commit r31431. This isn't a good heuristic.

Swift SVN r31449
2015-08-25 14:36:04 +00:00
Doug Gregor
8ac10845b6 Omit needless words: don't drop the first parameter name for failability initializers.
Swift SVN r31431
2015-08-24 18:26:27 +00:00
Doug Gregor
c02cd1a424 Factor omit-needless-words logic out of the Clang importer.
Sink the actual logic for omitting needless words way down into
Basic, so we can re-use it elsewhere. Tie the Clang importer into that
logic, mapping Clang types down to strings appropriately. NFC

Swift SVN r31233
2015-08-13 23:39:29 +00:00
Doug Gregor
2c909b4d36 Remove Objective-C selector splitting options.
We're not going this way.

Swift SVN r27717
2015-04-25 03:59:00 +00:00
John McCall
e880aac1e0 Add a convenience routine for searching for a complete
word within a camelCase identifier.

Basically StringRef::find but requiring the next character
to not be lowercase.

Swift SVN r17658
2014-05-08 00:51:25 +00:00
Doug Gregor
4996efbfba Implement support for making "with" implicit on the first argument of an initializer.
When importing an Objective-C init method or factory method into an
initializer, if the first camelCase word of the first argument name
starts with "with", drop the "with". This means that

  -initWithRed:green:blue:alpha:

will get imported into Swift as

  init(red:green:blue:alpha:)

as will

  +colorWithRed:green:blue:alpha:

This is <rdar://problem/16795899>, hidden behind the
-implicit-objc-with flag.

Swift SVN r17271
2014-05-02 21:13:04 +00:00
Doug Gregor
8324dc92e1 Introduce and use camel_case::appendSentenceCase().
Swift SVN r17260
2014-05-02 17:43:00 +00:00
Doug Gregor
9d7f0b6211 Rework the selector-splitting heuristics.
This makes a number of changes to the selector-splitting
heuristics. Specifically:

  - Eliminate last-word splitting, and with it the notion of
    multi-words. We only split at prepositions now.
  - Introduce the notion of "linking verbs" such as "will" or
    "should"; when these show up, we refuse to split a selector, which
    helps with delegates.
  - Eliminate the special case for "get" and "set". It wasn't
    helping.
  




Swift SVN r16265
2014-04-12 20:32:16 +00:00
Doug Gregor
5d20720e87 Some more camelCase string utilities.
Swift SVN r16053
2014-04-08 15:13:18 +00:00
Doug Gregor
49387beb25 Selector splitting: don't split selectors in the middle of whitelisted "multi-words".
Swift SVN r16016
2014-04-07 19:17:23 +00:00
Doug Gregor
12d0eeb324 Move more of the Clang importer's camelCase logic to the new utilities.
Swift SVN r15843
2014-04-02 23:06:22 +00:00
Doug Gregor
925097a8b0 Add utilities for lower- and sentence-casing camelCase strings.
Swift SVN r15815
2014-04-02 18:29:50 +00:00
Doug Gregor
d6a173fead Add some utilities for working with camelCase names.
Swift SVN r15802
2014-04-02 15:18:32 +00:00