/// parsed.
virtual void CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols,
unsigned NumProtocols) { }
+
+ /// \brief Code completion for a protocol declaration or definition, after
+ /// the @protocol but before any identifier.
+ ///
+ /// \param S the scope in which the protocol declaration occurs.
+ virtual void CodeCompleteObjCProtocolDecl(Scope *S) { }
//@}
};
/// \brief Add all of the protocol declarations that we find in the given
/// (translation unit) context.
static void AddProtocolResults(DeclContext *Ctx, DeclContext *CurContext,
+ bool OnlyForwardDeclarations,
ResultBuilder &Results) {
typedef CodeCompleteConsumer::Result Result;
D != DEnd; ++D) {
// Record any protocols we find.
if (ObjCProtocolDecl *Proto = dyn_cast<ObjCProtocolDecl>(*D))
- Results.MaybeAddResult(Result(Proto, 0), CurContext);
+ if (!OnlyForwardDeclarations || Proto->isForwardDecl())
+ Results.MaybeAddResult(Result(Proto, 0), CurContext);
// Record any forward-declared protocols we find.
if (ObjCForwardProtocolDecl *Forward
P = Forward->protocol_begin(),
PEnd = Forward->protocol_end();
P != PEnd; ++P)
- Results.MaybeAddResult(Result(*P, 0), CurContext);
+ if (!OnlyForwardDeclarations || (*P)->isForwardDecl())
+ Results.MaybeAddResult(Result(*P, 0), CurContext);
}
}
}
Results.Ignore(Protocol);
// Add all protocols.
- AddProtocolResults(Context.getTranslationUnitDecl(), CurContext, Results);
+ AddProtocolResults(Context.getTranslationUnitDecl(), CurContext, false,
+ Results);
+
+ Results.ExitScope();
+ HandleCodeCompleteResults(this, CodeCompleter, Results.data(),Results.size());
+}
+
+void Sema::CodeCompleteObjCProtocolDecl(Scope *) {
+ ResultBuilder Results(*this);
+ Results.EnterNewScope();
+
+ // Add all protocols.
+ AddProtocolResults(Context.getTranslationUnitDecl(), CurContext, true,
+ Results);
Results.ExitScope();
HandleCodeCompleteResults(this, CodeCompleter, Results.data(),Results.size());
void f(id<Protocol1,Protocol2>);
+@protocol Protocol0;
+@protocol NewProtocol
+{
+}
+@end
+
// RUN: c-index-test -code-completion-at=%s:9:11 %s | FileCheck -check-prefix=CHECK-CC1 %s
// CHECK-CC1: ObjCProtocolDecl:{TypedText Protocol1}
// CHECK-CC1: ObjCProtocolDecl:{TypedText Protocol2}
// RUN: c-index-test -code-completion-at=%s:9:21 %s | FileCheck -check-prefix=CHECK-CC2 %s
// CHECK-CC2-NOT: ObjCProtocolDecl:{TypedText Protocol1}
// CHECK-CC2: ObjCProtocolDecl:{TypedText Protocol2}
+// RUN: c-index-test -code-completion-at=%s:12:11 %s | FileCheck -check-prefix=CHECK-CC3 %s
+// CHECK-CC3: ObjCProtocolDecl:{TypedText Protocol0}
+// CHECK-CC3-NEXT: ObjCProtocolDecl:{TypedText Protocol2}