[cfe-commits] r130922 - in /cfe/trunk: include/clang/Sema/CodeCompleteConsumer.h lib/Sema/SemaCodeComplete.cpp test/Index/complete-member-access.m
Douglas Gregor
dgregor at apple.com
Thu May 5 08:50:42 PDT 2011
Author: dgregor
Date: Thu May 5 10:50:42 2011
New Revision: 130922
URL: http://llvm.org/viewvc/llvm-project?rev=130922&view=rev
Log:
When providing code completions for an Objective-C property access,
also include methods with zero-argument selectors. Implements
<rdar://problem/9048332>.
Modified:
cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
cfe/trunk/test/Index/complete-member-access.m
Modified: cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h?rev=130922&r1=130921&r2=130922&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h (original)
+++ cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h Thu May 5 10:50:42 2011
@@ -88,7 +88,10 @@
/// \brief Adjustment for KVC code pattern priorities when it doesn't look
/// like the
- CCD_ProbablyNotObjCCollection = 15
+ CCD_ProbablyNotObjCCollection = 15,
+
+ /// \brief An Objective-C method being used as a property.
+ CCD_MethodAsProperty = 2
};
/// \brief Priority value factors by which we will divide or multiply the
Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=130922&r1=130921&r2=130922&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Thu May 5 10:50:42 2011
@@ -3078,6 +3078,7 @@
static void AddObjCProperties(ObjCContainerDecl *Container,
bool AllowCategories,
+ bool AllowNullaryMethods,
DeclContext *CurContext,
AddedPropertiesSet &AddedProperties,
ResultBuilder &Results) {
@@ -3092,32 +3093,75 @@
Results.MaybeAddResult(Result(*P, 0), CurContext);
}
+ // Add nullary methods
+ if (AllowNullaryMethods) {
+ ASTContext &Context = Container->getASTContext();
+ for (ObjCContainerDecl::method_iterator M = Container->meth_begin(),
+ MEnd = Container->meth_end();
+ M != MEnd; ++M) {
+ if (M->getSelector().isUnarySelector())
+ if (IdentifierInfo *Name = M->getSelector().getIdentifierInfoForSlot(0))
+ if (AddedProperties.insert(Name)) {
+ CodeCompletionBuilder Builder(Results.getAllocator());
+ AddResultTypeChunk(Context, *M, Builder);
+ Builder.AddTypedTextChunk(
+ Results.getAllocator().CopyString(Name->getName()));
+
+ CXAvailabilityKind Availability = CXAvailability_Available;
+ switch (M->getAvailability()) {
+ case AR_Available:
+ case AR_NotYetIntroduced:
+ Availability = CXAvailability_Available;
+ break;
+
+ case AR_Deprecated:
+ Availability = CXAvailability_Deprecated;
+ break;
+
+ case AR_Unavailable:
+ Availability = CXAvailability_NotAvailable;
+ break;
+ }
+
+ Results.MaybeAddResult(Result(Builder.TakeString(),
+ CCP_MemberDeclaration + CCD_MethodAsProperty,
+ M->isInstanceMethod()
+ ? CXCursor_ObjCInstanceMethodDecl
+ : CXCursor_ObjCClassMethodDecl,
+ Availability),
+ CurContext);
+ }
+ }
+ }
+
+
// Add properties in referenced protocols.
if (ObjCProtocolDecl *Protocol = dyn_cast<ObjCProtocolDecl>(Container)) {
for (ObjCProtocolDecl::protocol_iterator P = Protocol->protocol_begin(),
PEnd = Protocol->protocol_end();
P != PEnd; ++P)
- AddObjCProperties(*P, AllowCategories, CurContext, AddedProperties,
- Results);
+ AddObjCProperties(*P, AllowCategories, AllowNullaryMethods, CurContext,
+ AddedProperties, Results);
} else if (ObjCInterfaceDecl *IFace = dyn_cast<ObjCInterfaceDecl>(Container)){
if (AllowCategories) {
// Look through categories.
for (ObjCCategoryDecl *Category = IFace->getCategoryList();
Category; Category = Category->getNextClassCategory())
- AddObjCProperties(Category, AllowCategories, CurContext,
- AddedProperties, Results);
+ AddObjCProperties(Category, AllowCategories, AllowNullaryMethods,
+ CurContext, AddedProperties, Results);
}
// Look through protocols.
for (ObjCInterfaceDecl::all_protocol_iterator
I = IFace->all_referenced_protocol_begin(),
E = IFace->all_referenced_protocol_end(); I != E; ++I)
- AddObjCProperties(*I, AllowCategories, CurContext, AddedProperties,
- Results);
+ AddObjCProperties(*I, AllowCategories, AllowNullaryMethods, CurContext,
+ AddedProperties, Results);
// Look in the superclass.
if (IFace->getSuperClass())
- AddObjCProperties(IFace->getSuperClass(), AllowCategories, CurContext,
+ AddObjCProperties(IFace->getSuperClass(), AllowCategories,
+ AllowNullaryMethods, CurContext,
AddedProperties, Results);
} else if (const ObjCCategoryDecl *Category
= dyn_cast<ObjCCategoryDecl>(Container)) {
@@ -3125,8 +3169,8 @@
for (ObjCCategoryDecl::protocol_iterator P = Category->protocol_begin(),
PEnd = Category->protocol_end();
P != PEnd; ++P)
- AddObjCProperties(*P, AllowCategories, CurContext, AddedProperties,
- Results);
+ AddObjCProperties(*P, AllowCategories, AllowNullaryMethods, CurContext,
+ AddedProperties, Results);
}
}
@@ -3192,14 +3236,16 @@
const ObjCObjectPointerType *ObjCPtr
= BaseType->getAsObjCInterfacePointerType();
assert(ObjCPtr && "Non-NULL pointer guaranteed above!");
- AddObjCProperties(ObjCPtr->getInterfaceDecl(), true, CurContext,
+ AddObjCProperties(ObjCPtr->getInterfaceDecl(), true,
+ /*AllowNullaryMethods=*/true, CurContext,
AddedProperties, Results);
// Add properties from the protocols in a qualified interface.
for (ObjCObjectPointerType::qual_iterator I = ObjCPtr->qual_begin(),
E = ObjCPtr->qual_end();
I != E; ++I)
- AddObjCProperties(*I, true, CurContext, AddedProperties, Results);
+ AddObjCProperties(*I, true, /*AllowNullaryMethods=*/true, CurContext,
+ AddedProperties, Results);
} else if ((IsArrow && BaseType->isObjCObjectPointerType()) ||
(!IsArrow && BaseType->isObjCObjectType())) {
// Objective-C instance variable access.
@@ -5334,11 +5380,13 @@
Results.EnterNewScope();
if (ObjCImplementationDecl *ClassImpl
= dyn_cast<ObjCImplementationDecl>(Container))
- AddObjCProperties(ClassImpl->getClassInterface(), false, CurContext,
+ AddObjCProperties(ClassImpl->getClassInterface(), false,
+ /*AllowNullaryMethods=*/false, CurContext,
AddedProperties, Results);
else
AddObjCProperties(cast<ObjCCategoryImplDecl>(Container)->getCategoryDecl(),
- false, CurContext, AddedProperties, Results);
+ false, /*AllowNullaryMethods=*/false, CurContext,
+ AddedProperties, Results);
Results.ExitScope();
HandleCodeCompleteResults(this, CodeCompleter,
Modified: cfe/trunk/test/Index/complete-member-access.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-member-access.m?rev=130922&r1=130921&r2=130922&view=diff
==============================================================================
--- cfe/trunk/test/Index/complete-member-access.m (original)
+++ cfe/trunk/test/Index/complete-member-access.m Thu May 5 10:50:42 2011
@@ -22,9 +22,26 @@
ptr->IVar = 0;
}
+ at interface Sub : Int
+ at property int myProp;
+
+- (int)myProp;
+- (int)myOtherPropLikeThing;
+- (int)myOtherNonPropThing:(int)value;
+ at end
+
+int test_more_props(Sub *s) {
+ return s.myOtherPropLikeThing;
+}
+
// RUN: c-index-test -code-completion-at=%s:21:7 %s | FileCheck -check-prefix=CHECK-CC1 %s
// CHECK-CC1: ObjCPropertyDecl:{ResultType int}{TypedText prop1}
// CHECK-CC1: ObjCPropertyDecl:{ResultType float}{TypedText ProtoProp}
// RUN: c-index-test -code-completion-at=%s:22:8 %s | FileCheck -check-prefix=CHECK-CC2 %s
// CHECK-CC2: ObjCIvarDecl:{ResultType int}{TypedText IVar} (35)
// CHECK-CC2: ObjCIvarDecl:{ResultType int}{TypedText SuperIVar} (37)
+// RUN: c-index-test -code-completion-at=%s:34:12 %s | FileCheck -check-prefix=CHECK-CC3 %s
+// CHECK-CC3: ObjCInstanceMethodDecl:{ResultType int}{TypedText myOtherPropLikeThing} (37)
+// CHECK-CC3: ObjCPropertyDecl:{ResultType int}{TypedText myProp} (35)
+// CHECK-CC3: ObjCPropertyDecl:{ResultType int}{TypedText prop1} (35)
+// CHECK-CC3: ObjCPropertyDecl:{ResultType float}{TypedText ProtoProp} (35)
More information about the cfe-commits
mailing list