r287771 - [CodeCompletion] Fix incorrect Objective-C block parameter formatting

Alex Lorenz via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 23 08:28:34 PST 2016


Author: arphaman
Date: Wed Nov 23 10:28:34 2016
New Revision: 287771

URL: http://llvm.org/viewvc/llvm-project?rev=287771&view=rev
Log:
[CodeCompletion] Fix incorrect Objective-C block parameter formatting

This commit fixes an incorrectly formatted Objective-C block parameter
placeholder in a code completion result. The incorrect parameter had a
redundant leading parenthesis.

rdar://25224416

Modified:
    cfe/trunk/lib/Sema/SemaCodeComplete.cpp
    cfe/trunk/test/Index/complete-block-properties.m

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=287771&r1=287770&r2=287771&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Wed Nov 23 10:28:34 2016
@@ -2264,9 +2264,13 @@ static std::string FormatFunctionParamet
     QualType Type = Param->getType().getUnqualifiedType();
     
     if (ObjCMethodParam) {
-      Result = "(" + formatObjCParamQualifiers(Param->getObjCDeclQualifier(),
-                                               Type);
-      Result += Type.getAsString(Policy) + Result + ")";
+      Result = Type.getAsString(Policy);
+      std::string Quals =
+          formatObjCParamQualifiers(Param->getObjCDeclQualifier(), Type);
+      if (!Quals.empty())
+        Result = "(" + Quals + " " + Result + ")";
+      if (Result.back() != ')')
+        Result += " ";
       if (Param->getIdentifier())
         Result += Param->getIdentifier()->getName();
     } else {
@@ -2275,7 +2279,7 @@ static std::string FormatFunctionParamet
       
     return Result;
   }
-    
+
   // We have the function prototype behind the block pointer type, as it was
   // written in the source.
   return formatBlockPlaceholder(Policy, Param, Block, BlockProto,

Modified: cfe/trunk/test/Index/complete-block-properties.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-block-properties.m?rev=287771&r1=287770&r2=287771&view=diff
==============================================================================
--- cfe/trunk/test/Index/complete-block-properties.m (original)
+++ cfe/trunk/test/Index/complete-block-properties.m Wed Nov 23 10:28:34 2016
@@ -51,3 +51,22 @@ typedef int (^BarBlock)(int *);
 //CHECK-CC1-NEXT: ObjCPropertyDecl:{ResultType int}{TypedText performB}{LeftParen (}{Placeholder int x}{Comma , }{Placeholder int y}{RightParen )} (35)
 
 @end
+
+// rdar://25224416
+
+ at interface NoQualifierParens
+
+ at property(copy) void (^blockProperty)(void);
+ at property BarBlock blockProperty2;
+
+ at end
+
+void noQualifierParens(NoQualifierParens *f) {
+  [f setBlockProperty: ^{}];
+}
+
+// RUN: c-index-test -code-completion-at=%s:65:6 %s | FileCheck -check-prefix=CHECK-CC2 %s
+//CHECK-CC2: ObjCInstanceMethodDecl:{ResultType void (^)(void)}{TypedText blockProperty} (35)
+//CHECK-CC2-NEXT: ObjCInstanceMethodDecl:{ResultType BarBlock}{TypedText blockProperty2} (35)
+//CHECK-CC2-NEXT: ObjCInstanceMethodDecl:{ResultType void}{TypedText setBlockProperty2:}{Placeholder BarBlock blockProperty2} (35)
+//CHECK-CC2-NEXT: ObjCInstanceMethodDecl:{ResultType void}{TypedText setBlockProperty:}{Placeholder void (^)(void)blockProperty} (35)




More information about the cfe-commits mailing list