[cfe-commits] r89103 - in /cfe/trunk: lib/Sema/SemaCodeComplete.cpp test/Index/complete-objc-message.m
Douglas Gregor
dgregor at apple.com
Tue Nov 17 08:44:22 PST 2009
Author: dgregor
Date: Tue Nov 17 10:44:22 2009
New Revision: 89103
URL: http://llvm.org/viewvc/llvm-project?rev=89103&view=rev
Log:
Augment code-completion results to provide argument names and
placeholder arguments for Objective-C message sends.
Added:
cfe/trunk/test/Index/complete-objc-message.m
Modified:
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=89103&r1=89102&r2=89103&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Tue Nov 17 10:44:22 2009
@@ -932,6 +932,39 @@
return Result;
}
+ if (ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(ND)) {
+ CodeCompletionString *Result = new CodeCompletionString;
+ Selector Sel = Method->getSelector();
+ if (Sel.isUnarySelector()) {
+ Result->AddTypedTextChunk(Sel.getIdentifierInfoForSlot(0)->getName());
+ return Result;
+ }
+
+ Result->AddTypedTextChunk(
+ Sel.getIdentifierInfoForSlot(0)->getName().str() + std::string(":"));
+ unsigned Idx = 0;
+ for (ObjCMethodDecl::param_iterator P = Method->param_begin(),
+ PEnd = Method->param_end();
+ P != PEnd; (void)++P, ++Idx) {
+ if (Idx > 0) {
+ std::string Keyword = " ";
+ if (IdentifierInfo *II = Sel.getIdentifierInfoForSlot(Idx))
+ Keyword += II->getName().str();
+ Keyword += ":";
+ Result->AddTextChunk(Keyword);
+ }
+
+ std::string Arg;
+ (*P)->getType().getAsStringInternal(Arg, S.Context.PrintingPolicy);
+ Arg = "(" + Arg + ")";
+ if (IdentifierInfo *II = (*P)->getIdentifier())
+ Arg += II->getName().str();
+ Result->AddPlaceholderChunk(Arg);
+ }
+
+ return Result;
+ }
+
if (Qualifier) {
CodeCompletionString *Result = new CodeCompletionString;
AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative,
Added: cfe/trunk/test/Index/complete-objc-message.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-objc-message.m?rev=89103&view=auto
==============================================================================
--- cfe/trunk/test/Index/complete-objc-message.m (added)
+++ cfe/trunk/test/Index/complete-objc-message.m Tue Nov 17 10:44:22 2009
@@ -0,0 +1,35 @@
+// Note: the run lines follow their respective tests, since line/column
+// matter in this test.
+
+ at protocol FooTestProtocol
++ protocolClassMethod;
+- protocolInstanceMethod : (int)value;
+ at end
+ at interface Foo <FooTestProtocol> {
+ void *isa;
+}
++ (int)classMethod1:a withKeyword:(int)b;
++ (void)classMethod2;
++ new;
+- instanceMethod1;
+ at end
+
+ at interface Foo (FooTestCategory)
++ categoryClassMethod;
+- categoryInstanceMethod;
+ at end
+
+void func() {
+ Foo *obj = [Foo new];
+ [obj xx];
+}
+// RUN: c-index-test -code-completion-at=%s:23:19 %s | FileCheck -check-prefix=CHECK-CC1 %s
+// CHECK-CC1: {TypedText categoryClassMethod}
+// CHECK-CC1: {TypedText classMethod2}
+// CHECK-CC1: {TypedText new}
+// CHECK-CC1: {TypedText protocolClassMethod}
+// CHECK-CC1: {TypedText classMethod1:}{Placeholder (id)a}{Text withKeyword:}{Placeholder (int)b}
+// RUN: c-index-test -code-completion-at=%s:24:8 %s | FileCheck -check-prefix=CHECK-CC2 %s
+// CHECK-CC2: {TypedText categoryInstanceMethod}
+// CHECK-CC2: {TypedText instanceMethod1}
+// CHECK-CC2: {TypedText protocolInstanceMethod:}{Placeholder (int)value}
More information about the cfe-commits
mailing list