Skip to content

Commit

Permalink
adding visitors to config
Browse files Browse the repository at this point in the history
  • Loading branch information
marshelino-maged committed Dec 6, 2024
1 parent 212efc9 commit 2218500
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkgs/jnigen/lib/src/config/config_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -282,6 +283,7 @@ class Config {
this.logLevel = Level.INFO,
this.dumpJsonTo,
this.imports,
this.visitors
}) {
for (final className in classes) {
_validateClassName(className);
Expand Down Expand Up @@ -349,6 +351,9 @@ class Config {
/// Used for testing package:jnigen.
final Map<String, String>? customClassBody;

// User custom visitors to modify the generated bindings.
List<j_ast.Visitor>? visitors;

Future<void> importClasses() async {
importedClasses = {};
for (final import in [
Expand Down
4 changes: 4 additions & 0 deletions pkgs/jnigen/lib/src/generate_bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -38,6 +39,9 @@ Future<void> 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));
Expand Down

0 comments on commit 2218500

Please sign in to comment.