diff --git a/pkgs/ffigen/lib/src/code_generator/objc_methods.dart b/pkgs/ffigen/lib/src/code_generator/objc_methods.dart index d8a9317d5..a91e3c35b 100644 --- a/pkgs/ffigen/lib/src/code_generator/objc_methods.dart +++ b/pkgs/ffigen/lib/src/code_generator/objc_methods.dart @@ -15,8 +15,8 @@ import 'writer.dart'; final _logger = Logger('ffigen.code_generator.objc_methods'); mixin ObjCMethods { - final _methods = {}; - final _order = []; + Map _methods = {}; + List _order = []; Iterable get methods => _order.map((name) => _methods[name]).nonNulls; @@ -97,6 +97,20 @@ mixin ObjCMethods { parent: w.topLevelUniqueNamer); void sortMethods() => _order.sort(); + + void filterMethods(bool predicate(ObjCMethod method)) { + final newOrder = []; + final newMethods = {}; + for (final name in _order) { + final method = _methods[name]; + if (method != null && predicate(method)) { + newMethods[name] = method; + newOrder.add(name); + } + } + _order = newOrder; + _methods = newMethods; + } } enum ObjCMethodKind { diff --git a/pkgs/ffigen/lib/src/header_parser/sub_parsers/objcinterfacedecl_parser.dart b/pkgs/ffigen/lib/src/header_parser/sub_parsers/objcinterfacedecl_parser.dart index 80ff64c1a..14f1f35ec 100644 --- a/pkgs/ffigen/lib/src/header_parser/sub_parsers/objcinterfacedecl_parser.dart +++ b/pkgs/ffigen/lib/src/header_parser/sub_parsers/objcinterfacedecl_parser.dart @@ -131,10 +131,6 @@ void _parseProperty( return; } - if (!config.objcInterfaces.shouldIncludeMember(itfDecl, fieldName)) { - return; - } - final dartDoc = getCursorDocComment(cursor); final propertyAttributes = @@ -221,10 +217,6 @@ ObjCMethod? parseObjCMethod(clang_types.CXCursor cursor, Declaration itfDecl, return null; } - if (!filters.shouldIncludeMember(itfDecl, methodName)) { - return null; - } - final method = ObjCMethod( builtInFunctions: objCBuiltInFunctions, originalName: methodName, diff --git a/pkgs/ffigen/lib/src/visitor/apply_config_filters.dart b/pkgs/ffigen/lib/src/visitor/apply_config_filters.dart index b0b5c4aa9..6102f8a3c 100644 --- a/pkgs/ffigen/lib/src/visitor/apply_config_filters.dart +++ b/pkgs/ffigen/lib/src/visitor/apply_config_filters.dart @@ -36,12 +36,18 @@ class ApplyConfigFiltersVisitation extends Visitation { _visitImpl(node, config.macroDecl); @override - void visitObjCInterface(ObjCInterface node) => - _visitImpl(node, config.objcInterfaces); + void visitObjCInterface(ObjCInterface node) { + node.filterMethods((method) => + config.objcInterfaces.shouldIncludeMember(node, method.originalName)); + _visitImpl(node, config.objcInterfaces); + } @override - void visitObjCProtocol(ObjCProtocol node) => - _visitImpl(node, config.objcProtocols); + void visitObjCProtocol(ObjCProtocol node) { + node.filterMethods((method) => + config.objcProtocols.shouldIncludeMember(node, method.originalName)); + _visitImpl(node, config.objcProtocols); + } @override void visitUnnamedEnumConstant(UnnamedEnumConstant node) => diff --git a/pkgs/ffigen/test/native_objc_test/method_filtering_test.dart b/pkgs/ffigen/test/native_objc_test/method_filtering_test.dart index 8e887bba7..509d81221 100644 --- a/pkgs/ffigen/test/native_objc_test/method_filtering_test.dart +++ b/pkgs/ffigen/test/native_objc_test/method_filtering_test.dart @@ -45,6 +45,11 @@ void main() { expect(bindings, contains('includedProtocolMethod')); expect(bindings, isNot(contains('excludedProtocolMethod'))); }); + + test('transitive deps', () { + expect(bindings, isNot(contains('TransitiveInterface'))); + expect(bindings, isNot(contains('someTransitiveMethod'))); + }); }); }); } diff --git a/pkgs/ffigen/test/native_objc_test/method_filtering_test.m b/pkgs/ffigen/test/native_objc_test/method_filtering_test.m index d76fd3526..92c5075db 100644 --- a/pkgs/ffigen/test/native_objc_test/method_filtering_test.m +++ b/pkgs/ffigen/test/native_objc_test/method_filtering_test.m @@ -4,11 +4,16 @@ #import +@interface TransitiveInterface : NSObject {} ++ (instancetype)someTransitiveMethod: (double)arg; +@end + @interface MethodFilteringTestInterface : NSObject {} + (instancetype)includedStaticMethod; + (instancetype)excludedStaticMethod; - (instancetype)includedInstanceMethod: (int32_t)arg with: (int32_t)otherArg; -- (instancetype)excludedInstanceMethod: (int32_t)arg with: (int32_t)otherArg; +- (instancetype)excludedInstanceMethod: (int32_t)arg + with: (TransitiveInterface*)otherArg; @property (assign) NSObject* includedProperty; @property (assign) NSObject* excludedProperty; @end