Add quickfix for unsupported typedef NSFoo Bar.

This commit is contained in:
Svyatoslav Scherbina
2017-10-17 11:15:48 +03:00
committed by SvyatoslavScherbina
parent e8f97b0436
commit ffb0d0cfcb
2 changed files with 30 additions and 2 deletions
@@ -520,7 +520,17 @@ internal class NativeIndexImpl(val library: NativeLibrary) : NativeIndex() {
CXCursorKind.CXCursor_ObjCInterfaceDecl ->
ObjCObjectPointer(getObjCClassAt(declaration), nullability, getProtocols(type))
else -> TODO(declarationKind.toString())
CXCursorKind.CXCursor_TypedefDecl ->
// typedef to Objective-C class itself, e.g. `typedef NSObject Object;`,
// (as opposed to `typedef NSObject* Object;`).
// Note: it is not yet represented as Kotlin `typealias`.
ObjCObjectPointer(
getObjCClassAt(getTypedefUnderlyingObjCClass(declaration)),
nullability,
getProtocols(type)
)
else -> TODO("${declarationKind.toString()} ${clang_getTypeSpelling(type).convertAndDispose()}")
}
}
@@ -536,6 +546,22 @@ internal class NativeIndexImpl(val library: NativeLibrary) : NativeIndex() {
}
}
private tailrec fun getTypedefUnderlyingObjCClass(typedefDecl: CValue<CXCursor>): CValue<CXCursor> {
assert(typedefDecl.kind == CXCursorKind.CXCursor_TypedefDecl)
val underlyingType = clang_getTypedefDeclUnderlyingType(typedefDecl)
val underlyingTypeDecl = clang_getTypeDeclaration(underlyingType)
return when (underlyingTypeDecl.kind) {
CXCursorKind.CXCursor_TypedefDecl -> getTypedefUnderlyingObjCClass(underlyingTypeDecl)
CXCursorKind.CXCursor_ObjCInterfaceDecl -> underlyingTypeDecl
else -> TODO(
"""typedef = ${getCursorSpelling(typedefDecl)}
|underlying decl kind = ${underlyingTypeDecl.kind}
|underlying = ${clang_getTypeSpelling(underlyingType).convertAndDispose()}""".trimMargin()
)
}
}
private fun getNullability(
type: CValue<CXType>, typeAttributes: CValue<CXTypeAttributes>?
): ObjCPointer.Nullability {
+3 -1
View File
@@ -5,8 +5,10 @@
-(void)print:(const char*)string;
@end;
typedef NSString NSStringTypedef;
@interface Foo : NSObject
@property NSString* name;
@property NSStringTypedef* name;
-(void)helloWithPrinter:(id <Printer>)printer;
@end;