[clang][ExtractAPI] Fix declaration fragments for ObjC methods
authorZixu Wang <zixu_wang@apple.com>
Wed, 6 Apr 2022 21:53:52 +0000 (14:53 -0700)
committerZixu Wang <zixu_wang@apple.com>
Thu, 7 Apr 2022 17:22:41 +0000 (10:22 -0700)
Objective-C methods selector parts should be considered as identifiers.

Depends on D123259

Differential Revision: https://reviews.llvm.org/D123261

clang/lib/ExtractAPI/DeclarationFragments.cpp
clang/test/ExtractAPI/objc_category.m
clang/test/ExtractAPI/objc_interface.m

index a569ff9..75d360a 100644 (file)
@@ -593,20 +593,21 @@ DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForObjCMethod(
 
   // For Objective-C methods that take arguments, build the selector slots.
   for (unsigned i = 0, end = Method->param_size(); i != end; ++i) {
-    Fragments.appendSpace()
-        .append(Selector.getNameForSlot(i),
-                // The first slot is the name of the method, record as an
-                // identifier, otherwise as exteranl parameters.
-                i == 0 ? DeclarationFragments::FragmentKind::Identifier
-                       : DeclarationFragments::FragmentKind::ExternalParam)
-        .append(":", DeclarationFragments::FragmentKind::Text);
+    // Objective-C method selector parts are considered as identifiers instead
+    // of "external parameters" as in Swift. This is because Objective-C method
+    // symbols are referenced with the entire selector, instead of just the
+    // method name in Swift.
+    SmallString<32> ParamID(Selector.getNameForSlot(i));
+    ParamID.append(":");
+    Fragments.appendSpace().append(
+        ParamID, DeclarationFragments::FragmentKind::Identifier);
 
     // Build the internal parameter.
     const ParmVarDecl *Param = Method->getParamDecl(i);
     Fragments.append(getFragmentsForParam(Param));
   }
 
-  return Fragments;
+  return Fragments.append(";", DeclarationFragments::FragmentKind::Text);
 }
 
 DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForObjCProperty(
index 2416e30..20eefdf 100644 (file)
         {
           "kind": "identifier",
           "spelling": "InstanceMethod"
+        },
+        {
+          "kind": "text",
+          "spelling": ";"
         }
       ],
       "identifier": {
         {
           "kind": "identifier",
           "spelling": "ClassMethod"
+        },
+        {
+          "kind": "text",
+          "spelling": ";"
         }
       ],
       "identifier": {
index a74a53c..5ca6404 100644 (file)
         },
         {
           "kind": "identifier",
-          "spelling": "getWithProperty"
-        },
-        {
-          "kind": "text",
-          "spelling": ":"
+          "spelling": "getWithProperty:"
         },
         {
           "kind": "text",
         {
           "kind": "internalParam",
           "spelling": "Property"
+        },
+        {
+          "kind": "text",
+          "spelling": ";"
         }
       ],
       "identifier": {
         {
           "kind": "identifier",
           "spelling": "getIvar"
+        },
+        {
+          "kind": "text",
+          "spelling": ";"
         }
       ],
       "identifier": {