From 221850093ee97d72d7217601e6e2d3440c252b4a Mon Sep 17 00:00:00 2001 From: Marshelino Maged Date: Fri, 6 Dec 2024 20:48:31 +0200 Subject: [PATCH] adding visitors to config --- pkgs/jnigen/lib/src/config/config_types.dart | 5 +++++ pkgs/jnigen/lib/src/generate_bindings.dart | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/pkgs/jnigen/lib/src/config/config_types.dart b/pkgs/jnigen/lib/src/config/config_types.dart index f5bd848fd..5f871cd44 100644 --- a/pkgs/jnigen/lib/src/config/config_types.dart +++ b/pkgs/jnigen/lib/src/config/config_types.dart @@ -10,6 +10,7 @@ import 'package:pub_semver/pub_semver.dart'; import 'package:yaml/yaml.dart'; import '../elements/elements.dart'; +import '../elements/j_elements.dart' as j_ast; import '../logging/logging.dart'; import '../util/find_package.dart'; import 'config_exception.dart'; @@ -282,6 +283,7 @@ class Config { this.logLevel = Level.INFO, this.dumpJsonTo, this.imports, + this.visitors }) { for (final className in classes) { _validateClassName(className); @@ -349,6 +351,9 @@ class Config { /// Used for testing package:jnigen. final Map? customClassBody; + // User custom visitors to modify the generated bindings. + List? visitors; + Future importClasses() async { importedClasses = {}; for (final import in [ diff --git a/pkgs/jnigen/lib/src/generate_bindings.dart b/pkgs/jnigen/lib/src/generate_bindings.dart index 2e237f211..b331fb36d 100644 --- a/pkgs/jnigen/lib/src/generate_bindings.dart +++ b/pkgs/jnigen/lib/src/generate_bindings.dart @@ -13,6 +13,7 @@ import 'bindings/linker.dart'; import 'bindings/renamer.dart'; import 'config/config.dart'; import 'elements/elements.dart'; +import 'elements/j_elements.dart' as j_ast; import 'logging/logging.dart'; import 'summary/summary.dart'; import 'tools/tools.dart'; @@ -38,6 +39,9 @@ Future generateJniBindings(Config config) async { log.fatal(e.message); } + config.visitors?.forEach((visitor){ + j_ast.Classes(classes).accept(visitor); + }); classes.accept(Excluder(config)); classes.accept(KotlinProcessor()); await classes.accept(Linker(config));