Skip to content

[jnigen] Add a templating language for custom methods in transformers #2285

Open
@HosseinYousefi

Description

@HosseinYousefi

Currently we can add a custom method to an existing JNIgen generated class, however the experience is clunky. We might want to use other Java classes, that exist in different packages, hardcoding all this can be flaky, we would like to write our custom code in a templating language that allows us to reference other Java types, methods, fields, ... These references will be replaced at the generation time with the correct values after all the renaming is done. They also add the necessary import statements to import these types.

An example syntax of such language:

r'''
  @{{dart:core/override}}
  @{{dart:core/StackTrace}} get stackTrace {
    final stringWriter = {{java.io.StringWriter}}();
    {{java.lang.Throwable#printStackTrace(Ljava.io.PrintWriter;)V}}(stringWriter);
    final stackTrace = @{{dart:core/StackTrace}}.fromString(
      stringWriter.toString().toDartString(releaseOriginal: true),
    );
    stringWriter.release();
    return stackTrace;
  }
'''

Metadata

Metadata

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions