Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pkgs/ffigen/lib/src/code_generator/objc_methods.dart
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,9 @@ class ObjCMethod extends AstNode {
);
}

String getDartMethodName(UniqueNamer uniqueNamer) {
if (property != null) {
String getDartMethodName(UniqueNamer uniqueNamer,
{bool usePropertyNaming = true}) {
if (property != null && usePropertyNaming) {
// A getter and a setter are allowed to have the same name, so we can't
// just run the name through uniqueNamer. Instead they need to share
// the dartName, which is run through uniqueNamer.
Expand Down
3 changes: 2 additions & 1 deletion pkgs/ffigen/lib/src/code_generator/objc_protocol.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class ObjCProtocol extends NoLookUpBinding with ObjCMethods {

var anyListeners = false;
for (final method in methods) {
final methodName = method.getDartMethodName(methodNamer);
final methodName =
method.getDartMethodName(methodNamer, usePropertyNaming: false);
final fieldName = methodName;
final argName = methodName;
final block = method.protocolBlock!;
Expand Down
4 changes: 3 additions & 1 deletion pkgs/ffigen/lib/src/visitor/fix_overridden_methods.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ class FixOverriddenMethodsVisitation extends Visitation {
for (final method in node.methods) {
if (method.isClassMethod) continue;
final (root, rootMethod) = _findRootWithMethod(node, method);
if (method.isProperty == rootMethod.isProperty) continue;
// If method and rootMethod are the same kind, then there's nothing to do.
if ((method.kind == ObjCMethodKind.propertyGetter) ==
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So XNOR? Maybe a comment like:

// If method are rootMethod are of the same kind then there is nothing to do.

(rootMethod.kind == ObjCMethodKind.propertyGetter)) continue;
_convertAllSubtreeMethodsToProperties(root, rootMethod);
}
}
Expand Down
37 changes: 20 additions & 17 deletions pkgs/ffigen/test/large_integration_tests/large_objc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ library;

import 'dart:async';
import 'dart:io';
import 'dart:math';

import 'package:ffigen/ffigen.dart';
import 'package:ffigen/src/code_generator/utils.dart';
import 'package:ffigen/src/config_provider/config.dart';
import 'package:ffigen/src/config_provider/config_types.dart';
import 'package:logging/logging.dart';
Expand All @@ -32,12 +32,15 @@ void main() {
// reasonable amount of time.
// TODO(https://github.com/dart-lang/sdk/issues/56247): Remove this.
const inclusionRatio = 0.1;
final rand = Random(1234);
bool randInclude([_, __]) => rand.nextDouble() < inclusionRatio;
final randomFilter = DeclarationFilters(
shouldInclude: randInclude,
shouldIncludeMember: randInclude,
);
const seed = 1234;
bool randInclude(String kind, Declaration clazz, [String? method]) =>
fnvHash32('$seed.$kind.${clazz.usr}.$method') <
((1 << 32) * inclusionRatio);
DeclarationFilters randomFilter(String kind) => DeclarationFilters(
shouldInclude: (Declaration clazz) => randInclude(kind, clazz),
shouldIncludeMember: (Declaration clazz, String method) =>
randInclude('$kind.memb', clazz, method),
);

const outFile = 'test/large_integration_tests/large_objc_bindings.dart';
const outObjCFile = 'test/large_integration_tests/large_objc_bindings.m';
Expand All @@ -51,16 +54,16 @@ void main() {
includeTransitiveObjCInterfaces: false,
includeTransitiveObjCProtocols: false,
includeTransitiveObjCCategories: false,
functionDecl: randomFilter,
structDecl: randomFilter,
unionDecl: randomFilter,
enumClassDecl: randomFilter,
unnamedEnumConstants: randomFilter,
globals: randomFilter,
typedefs: randomFilter,
objcInterfaces: randomFilter,
objcProtocols: randomFilter,
objcCategories: randomFilter,
functionDecl: randomFilter('functionDecl'),
structDecl: randomFilter('structDecl'),
unionDecl: randomFilter('unionDecl'),
enumClassDecl: randomFilter('enumClassDecl'),
unnamedEnumConstants: randomFilter('unnamedEnumConstants'),
globals: randomFilter('globals'),
typedefs: randomFilter('typedefs'),
objcInterfaces: randomFilter('objcInterfaces'),
objcProtocols: randomFilter('objcProtocols'),
objcCategories: randomFilter('objcCategories'),
externalVersions: ExternalVersions(
ios: Versions(min: Version(12, 0, 0)),
macos: Versions(min: Version(10, 14, 0)),
Expand Down
Loading