Skip to content
This repository has been archived by the owner on Jan 28, 2024. It is now read-only.

Commit

Permalink
Better Block names
Browse files Browse the repository at this point in the history
  • Loading branch information
liamappelbe committed Aug 31, 2023
1 parent 416fccd commit 1fa2629
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
19 changes: 19 additions & 0 deletions lib/src/code_generator/objc_block.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ class ObjCBlock extends BindingType {
final ObjCBuiltInFunctions builtInFunctions;

ObjCBlock({
required String usr,
required Type returnType,
required List<Type> argTypes,
required ObjCBuiltInFunctions builtInFunctions,
}) : this._(
usr: usr,
name: _getBlockName(returnType, argTypes),
returnType: returnType,
argTypes: argTypes,
builtInFunctions: builtInFunctions,
);

ObjCBlock._({
required String usr,
required String name,
required this.returnType,
Expand All @@ -24,6 +37,12 @@ class ObjCBlock extends BindingType {
name: name,
);

static final _illegalNameChar = RegExp(r'[^0-9a-zA-Z]');
static String _typeName(Type type) =>
type.toString().replaceAll(_illegalNameChar, ''); // .getDartType(w)
static String _getBlockName(Type returnType, List<Type> argTypes) =>
'ObjCBlock_${_typeName(returnType)}_${argTypes.map(_typeName).join('_')}';

@override
BindingString toBindingString(Writer w) {
final s = StringBuffer();
Expand Down
2 changes: 1 addition & 1 deletion lib/src/config_provider/config_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ class StringConfigSpec<RE extends Object?> extends ConfigSpec<String, RE> {
if (!o.checkType<String>(log: log)) {
return false;
}
if (_regexp != null && !_regexp.hasMatch(o.value as String)) {
if (!(_regexp?.hasMatch(o.value as String) ?? true)) {
if (log) {
_logger.severe(
"Expected value of key '${o.pathString}' to match pattern $pattern (Input - ${o.value}).");
Expand Down
1 change: 0 additions & 1 deletion lib/src/header_parser/sub_parsers/objc_block_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ ObjCBlock parseObjCBlock(clang_types.CXType cxtype) {

return ObjCBlock(
usr: usr.toString(),
name: 'ObjCBlock',
returnType: returnType,
argTypes: argTypes,
builtInFunctions: objCBuiltInFunctions,
Expand Down

0 comments on commit 1fa2629

Please sign in to comment.