From f216fd7c7f19a541c12f0417c6b3c01ed59d6e13 Mon Sep 17 00:00:00 2001 From: sagar Date: Fri, 23 Jan 2026 01:26:39 +0530 Subject: [PATCH 01/13] jni: add bounded LRU cache for jclass global refs --- pkgs/jni/lib/src/jclass.dart | 5 ++++ pkgs/jni/lib/src/jni.dart | 18 ++++++++++++ .../third_party/jni_bindings_generated.dart | 29 +++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/pkgs/jni/lib/src/jclass.dart b/pkgs/jni/lib/src/jclass.dart index 4807580e01..7c9a30057c 100644 --- a/pkgs/jni/lib/src/jclass.dart +++ b/pkgs/jni/lib/src/jclass.dart @@ -16,6 +16,11 @@ class JClass extends JObject { JClass.forName(String name) : super.fromReference(JGlobalReference(Jni.findClass(name))); + /// Constructs a [JClass] associated with the class or interface with + /// the given string name, using the global LRU cache. + JClass.forNameCached(String name) + : super.fromReference(JGlobalReference(Jni.getCachedClass(name))); + JConstructorId constructorId(String signature) { return JConstructorId._(this, signature); } diff --git a/pkgs/jni/lib/src/jni.dart b/pkgs/jni/lib/src/jni.dart index 9156e17fc1..ac3bdf53ca 100644 --- a/pkgs/jni/lib/src/jni.dart +++ b/pkgs/jni/lib/src/jni.dart @@ -194,6 +194,24 @@ abstract final class Jni { .checkedClassRef; } + /// Finds the class from its [name], using an internal LRU cache. + /// + /// This is preferred for repeated lookups of the same class, as it avoids + /// repeated JNI calls and global reference creation. + static JClassPtr getCachedClass(String name) { + return using((arena) => _bindings.GetCachedClass(name.toNativeChars(arena))) + .checkedClassRef; + } + + /// Sets the capacity of the internal LRU class cache. + /// + /// If the new size is smaller than the current number of cached classes, + /// the least recently used classes will be evicted and their global + /// references released. + static void setClassCacheSize(int size) { + _bindings.SetClassCacheSize(size); + } + /// Throws an exception. // TODO(#561): Throw an actual `JThrowable`. @internal diff --git a/pkgs/jni/lib/src/third_party/jni_bindings_generated.dart b/pkgs/jni/lib/src/third_party/jni_bindings_generated.dart index 32fcff47e1..c91e291ee7 100644 --- a/pkgs/jni/lib/src/third_party/jni_bindings_generated.dart +++ b/pkgs/jni/lib/src/third_party/jni_bindings_generated.dart @@ -84,6 +84,35 @@ class JniBindings { late final _JniFindClass = _JniFindClassPtr.asFunction< JniClassLookupResult Function(ffi.Pointer)>(); + JniClassLookupResult GetCachedClass( + ffi.Pointer name, + ) { + return _GetCachedClass( + name, + ); + } + + late final _GetCachedClassPtr = _lookup< + ffi.NativeFunction< + JniClassLookupResult Function( + ffi.Pointer)>>('GetCachedClass'); + late final _GetCachedClass = _GetCachedClassPtr.asFunction< + JniClassLookupResult Function(ffi.Pointer)>(); + + void SetClassCacheSize( + int size, + ) { + return _SetClassCacheSize( + size, + ); + } + + late final _SetClassCacheSizePtr = + _lookup>( + 'SetClassCacheSize'); + late final _SetClassCacheSize = + _SetClassCacheSizePtr.asFunction(); + JniExceptionDetails GetExceptionDetails( JThrowablePtr exception, ) { From 90bdb2d37cc03596b48e921516d650e98d9c9726 Mon Sep 17 00:00:00 2001 From: sagar Date: Fri, 23 Jan 2026 01:27:05 +0530 Subject: [PATCH 02/13] jnigen: route class refs through cached JClass lookup --- pkgs/jnigen/lib/src/bindings/dart_generator.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/jnigen/lib/src/bindings/dart_generator.dart b/pkgs/jnigen/lib/src/bindings/dart_generator.dart index dba4346099..bd74629b4e 100644 --- a/pkgs/jnigen/lib/src/bindings/dart_generator.dart +++ b/pkgs/jnigen/lib/src/bindings/dart_generator.dart @@ -363,7 +363,7 @@ class _ClassGenerator extends Visitor { final modifier = node.isTopLevel ? '' : ' static '; final classRef = node.isTopLevel ? '_${node.finalName}Class' : '_class'; s.write(''' -${modifier}final $classRef = $_jni.JClass.forName(r'$internalName'); +${modifier}$_jni.JClass get $classRef => $_jni.JClass.forNameCached(r'$internalName'); '''); return classRef; From 56d6dc888ecd3c120ea68603d91a93048893531f Mon Sep 17 00:00:00 2001 From: sagar Date: Fri, 23 Jan 2026 01:28:02 +0530 Subject: [PATCH 03/13] jni: add test --- pkgs/jni/test/class_cache_test.dart | 116 ++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 pkgs/jni/test/class_cache_test.dart diff --git a/pkgs/jni/test/class_cache_test.dart b/pkgs/jni/test/class_cache_test.dart new file mode 100644 index 0000000000..3a7a4dabd6 --- /dev/null +++ b/pkgs/jni/test/class_cache_test.dart @@ -0,0 +1,116 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +@Tags(['load_test']) +library; + +import 'dart:ffi'; +import 'dart:io'; + +import 'package:jni/jni.dart'; +import 'package:test/test.dart'; + +import 'test_util/test_util.dart'; + +void main() { + if (!Platform.isAndroid) { + checkDylibIsUpToDate(); + spawnJvm(); + } + run(testRunner: test); +} + +void run({required TestRunnerCallback testRunner}) { + testRunner('Basic cache functionality', () { + final stringClass = Jni.getCachedClass('java/lang/String'); + expect(stringClass, isNot(nullptr)); + + final stringClass2 = Jni.getCachedClass('java/lang/String'); + expect(stringClass2, isNot(nullptr)); + expect(stringClass.address, isNot(equals(stringClass2.address))); + + // Check JNI equality (should be same object) + expect(Jni.env.IsSameObject(stringClass, stringClass2), isTrue); + Jni.env.DeleteGlobalRef(stringClass); + Jni.env.DeleteGlobalRef(stringClass2); + }); + + testRunner('Cache capacity configuration', () { + // Set small capacity + Jni.setClassCacheSize(2); + + final c1 = Jni.getCachedClass('java/lang/String'); + final c2 = Jni.getCachedClass('java/util/ArrayList'); + // c3 would evict c1 if strictly LRU logic was only on insert, + // but lookup of c1 moves it to head? No, we haven't looked it up again yet. + // Insert c1. Head=c1. Size=1. + // Insert c2. Head=c2->c1. Size=2. + // Insert c3. Evict Tail(c1). Head=c3->c2. Size=2. + final c3 = Jni.getCachedClass('java/util/HashMap'); + + // Verify c1 still works (it's a new global ref) + expect(c1, isNot(nullptr)); + + // Verify we can reload c1 + final c1Reload = Jni.getCachedClass('java/lang/String'); + expect(Jni.env.IsSameObject(c1, c1Reload), isTrue); + + Jni.env.DeleteGlobalRef(c1); + Jni.env.DeleteGlobalRef(c2); + Jni.env.DeleteGlobalRef(c3); + Jni.env.DeleteGlobalRef(c1Reload); + }); + + testRunner('Stress test cache', () { + Jni.setClassCacheSize(100); + // Load many classes + final classes = [ + 'java/lang/Byte', + 'java/lang/Short', + 'java/lang/Integer', + 'java/lang/Long', + 'java/lang/Float', + 'java/lang/Double', + 'java/lang/Boolean', + 'java/lang/Character', + 'java/lang/Object', + 'java/lang/Class', + 'java/lang/Number', + 'java/util/List', + 'java/util/Map', + 'java/util/Set', + 'java/util/Collection', + 'java/util/Iterator', + 'java/util/Random', + 'java/io/File', + 'java/io/InputStream', + 'java/io/OutputStream', + ]; + + for (var i = 0; i < 1000; i++) { + final name = classes[i % classes.length]; + final cls = Jni.getCachedClass(name); + expect(cls, isNot(nullptr)); + Jni.env.DeleteGlobalRef(cls); + } + }); + + testRunner('Cache hit returns new global ref', () { + final c1 = Jni.getCachedClass('java/lang/Object'); + final c2 = Jni.getCachedClass('java/lang/Object'); + // Pointers are different (different GlobalRefs) + expect(c1, isNot(equals(c2))); + // Objects are same + expect(Jni.env.IsSameObject(c1, c2), isTrue); + + // Cleanup + Jni.env.DeleteGlobalRef(c1); + Jni.env.DeleteGlobalRef(c2); + + // Cache should still hold a ref internally, so getting it again should work + final c3 = Jni.getCachedClass('java/lang/Object'); + expect(c3, isNot(nullptr)); + Jni.env.DeleteGlobalRef(c3); + }); +} From 0b163569fb9f8577f8c473e7831df8b6f6bae99e Mon Sep 17 00:00:00 2001 From: sagar Date: Fri, 23 Jan 2026 01:32:23 +0530 Subject: [PATCH 04/13] jni: add LRU cache for jclass with bounded capacity and eviction --- pkgs/jni/src/dartjni.c | 227 +++++++++++++++++++++++++++++++++++++++++ pkgs/jni/src/dartjni.h | 8 ++ 2 files changed, 235 insertions(+) diff --git a/pkgs/jni/src/dartjni.c b/pkgs/jni/src/dartjni.c index 7007fc7f18..debaa510e0 100644 --- a/pkgs/jni/src/dartjni.c +++ b/pkgs/jni/src/dartjni.c @@ -25,6 +25,233 @@ int8_t getCaptureStackTraceOnRelease() { return captureStackTraceOnRelease; } +#include + +typedef struct JniClassCacheNode { + char* name; + jclass value; + struct JniClassCacheNode* prev; + struct JniClassCacheNode* next; + struct JniClassCacheNode* hashNext; +} JniClassCacheNode; + +typedef struct JniClassCache { + JniClassCacheNode** buckets; + JniClassCacheNode* head; + JniClassCacheNode* tail; + int capacity; + int size; + int bucketCount; + MutexLock lock; +} JniClassCache; + +// Default capacity 256 +#define DEFAULT_CACHE_CAPACITY 256 +// Load factor 0.75 roughly, so buckets = capacity * 1.33 +#define DEFAULT_BUCKET_COUNT 341 + +JniClassCache jniClassCache = { + .buckets = NULL, + .head = NULL, + .tail = NULL, + .capacity = DEFAULT_CACHE_CAPACITY, + .size = 0, + .bucketCount = DEFAULT_BUCKET_COUNT, +}; + +static unsigned long hash_string(const char* str) { + unsigned long hash = 5381; + int c; + while ((c = *str++)) + hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ + return hash; +} + +static void init_cache_if_needed() { + if (jniClassCache.buckets == NULL) { + init_lock(&jniClassCache.lock); + // Double checked locking + acquire_lock(&jniClassCache.lock); + if (jniClassCache.buckets == NULL) { + jniClassCache.buckets = (JniClassCacheNode**)calloc( + jniClassCache.bucketCount, sizeof(JniClassCacheNode*)); + } + release_lock(&jniClassCache.lock); + } +} + +static void remove_node(JniClassCacheNode* node) { + if (node->prev) { + node->prev->next = node->next; + } else { + jniClassCache.head = node->next; + } + if (node->next) { + node->next->prev = node->prev; + } else { + jniClassCache.tail = node->prev; + } +} + +static void add_to_head(JniClassCacheNode* node) { + node->next = jniClassCache.head; + node->prev = NULL; + if (jniClassCache.head) { + jniClassCache.head->prev = node; + } + jniClassCache.head = node; + if (jniClassCache.tail == NULL) { + jniClassCache.tail = node; + } +} + +static void move_to_head(JniClassCacheNode* node) { + remove_node(node); + add_to_head(node); +} + +static void evict_tail() { + if (jniClassCache.tail == NULL) return; + JniClassCacheNode* node = jniClassCache.tail; + + // Remove from list + remove_node(node); + + // Remove from buckets + unsigned long hash = hash_string(node->name); + int index = hash % jniClassCache.bucketCount; + JniClassCacheNode* curr = jniClassCache.buckets[index]; + JniClassCacheNode* prev = NULL; + while (curr != NULL) { + if (curr == node) { + if (prev) { + prev->hashNext = curr->hashNext; + } else { + jniClassCache.buckets[index] = curr->hashNext; + } + break; + } + prev = curr; + curr = curr->hashNext; + } + + // Free resources + attach_thread(); + (*jniEnv)->DeleteGlobalRef(jniEnv, node->value); + free(node->name); + free(node); + jniClassCache.size--; +} + +FFI_PLUGIN_EXPORT +void SetClassCacheSize(int size) { + init_cache_if_needed(); + acquire_lock(&jniClassCache.lock); + jniClassCache.capacity = size; + while (jniClassCache.size > jniClassCache.capacity) { + evict_tail(); + } + release_lock(&jniClassCache.lock); +} + +FFI_PLUGIN_EXPORT +JniClassLookupResult GetCachedClass(const char* name) { + init_cache_if_needed(); + if (name == NULL) { + return (JniClassLookupResult){NULL, NULL}; + } + + acquire_lock(&jniClassCache.lock); + + unsigned long hash = hash_string(name); + int index = hash % jniClassCache.bucketCount; + JniClassCacheNode* node = jniClassCache.buckets[index]; + + while (node != NULL) { + if (strcmp(node->name, name) == 0) { + // Hit + move_to_head(node); + + // Return a new global ref so the caller owns one, + // but the cache keeps its own global ref. + // Wait, requirement says "Return NewGlobalRef". + // The cache holds a GlobalRef. We should hand out a NewGlobalRef + // so the user can release it without affecting the cache. + + // We need to attach thread to call NewGlobalRef + attach_thread(); + jclass cls = (*jniEnv)->NewGlobalRef(jniEnv, node->value); + release_lock(&jniClassCache.lock); + return (JniClassLookupResult){cls, NULL}; + } + node = node->hashNext; + } + + // Miss + // Release lock while loading class to avoid holding it during JNI call + release_lock(&jniClassCache.lock); + + // Load class implementation (similar to FindClassUnchecked) + attach_thread(); + jclass cls; + load_class_platform(&cls, name); + + jthrowable exception = NULL; + if ((*jniEnv)->ExceptionCheck(jniEnv)) { + exception = check_exception(); + return (JniClassLookupResult){NULL, exception}; + } + + // Convert local to global for the cache + jclass globalCls = (*jniEnv)->NewGlobalRef(jniEnv, cls); + (*jniEnv)->DeleteLocalRef(jniEnv, cls); + + // Create new node + JniClassCacheNode* newNode = (JniClassCacheNode*)malloc(sizeof(JniClassCacheNode)); + newNode->name = strdup(name); // Need strdup + newNode->value = globalCls; + newNode->hashNext = NULL; + + // Re-acquire lock to insert + acquire_lock(&jniClassCache.lock); + + // Check if it was inserted while we were loading (double check) + // Re-calculate hash/index as they are same + node = jniClassCache.buckets[index]; + while (node != NULL) { + if (strcmp(node->name, name) == 0) { + // It was inserted by another thread. Use that one. + move_to_head(node); + // Free our speculative load + (*jniEnv)->DeleteGlobalRef(jniEnv, newNode->value); + free(newNode->name); + free(newNode); + + jclass returnCls = (*jniEnv)->NewGlobalRef(jniEnv, node->value); + release_lock(&jniClassCache.lock); + return (JniClassLookupResult){returnCls, NULL}; + } + node = node->hashNext; + } + + // Insert new node + if (jniClassCache.size >= jniClassCache.capacity) { + evict_tail(); + } + + newNode->hashNext = jniClassCache.buckets[index]; + jniClassCache.buckets[index] = newNode; + add_to_head(newNode); + jniClassCache.size++; + + // Return a new global ref for the caller + jclass returnCls = (*jniEnv)->NewGlobalRef(jniEnv, globalCls); + + release_lock(&jniClassCache.lock); + + return (JniClassLookupResult){returnCls, NULL}; +} + jclass FindClassUnchecked(const char* name) { attach_thread(); jclass cls; diff --git a/pkgs/jni/src/dartjni.h b/pkgs/jni/src/dartjni.h index 22368fce09..9b0c24f5cc 100644 --- a/pkgs/jni/src/dartjni.h +++ b/pkgs/jni/src/dartjni.h @@ -204,6 +204,14 @@ typedef struct JniExceptionDetails { FFI_PLUGIN_EXPORT JniClassLookupResult FindClass(const char* name); +/// Returns a global reference to the class with the given name, using an LRU cache. +FFI_PLUGIN_EXPORT +JniClassLookupResult GetCachedClass(const char* name); + +/// Sets the capacity of the LRU cache. +FFI_PLUGIN_EXPORT +void SetClassCacheSize(int size); + FFI_PLUGIN_EXPORT JniExceptionDetails GetExceptionDetails(jthrowable exception); From 74764e4d9c06f57c6c586fd7b1140137a7bbcc79 Mon Sep 17 00:00:00 2001 From: sagar Date: Fri, 23 Jan 2026 14:40:38 +0530 Subject: [PATCH 05/13] jni: move jclass LRU cache from native to Dart --- pkgs/jni/lib/src/jni.dart | 43 +++++- pkgs/jni/src/dartjni.c | 224 ---------------------------- pkgs/jni/src/dartjni.h | 6 - pkgs/jni/test/class_cache_test.dart | 1 - 4 files changed, 39 insertions(+), 235 deletions(-) diff --git a/pkgs/jni/lib/src/jni.dart b/pkgs/jni/lib/src/jni.dart index ac3bdf53ca..352a24674e 100644 --- a/pkgs/jni/lib/src/jni.dart +++ b/pkgs/jni/lib/src/jni.dart @@ -54,6 +54,8 @@ abstract final class Jni { static final DynamicLibrary _dylib = _loadDartJniLibrary(dir: _dylibDir); static final JniBindings _bindings = JniBindings(_dylib); + static final _classCache = _JClassCache(); + /// Store dylibDir if any was used. static String _dylibDir = join('build', 'jni_libs'); @@ -199,8 +201,7 @@ abstract final class Jni { /// This is preferred for repeated lookups of the same class, as it avoids /// repeated JNI calls and global reference creation. static JClassPtr getCachedClass(String name) { - return using((arena) => _bindings.GetCachedClass(name.toNativeChars(arena))) - .checkedClassRef; + return _classCache.get(name); } /// Sets the capacity of the internal LRU class cache. @@ -209,7 +210,7 @@ abstract final class Jni { /// the least recently used classes will be evicted and their global /// references released. static void setClassCacheSize(int size) { - _bindings.SetClassCacheSize(size); + _classCache.capacity = size; } /// Throws an exception. @@ -445,8 +446,42 @@ extension AdditionalEnvMethods on GlobalJniEnv { @internal extension StringMethodsForJni on String { - /// Returns a Utf-8 encoded `Pointer` with contents same as this string. Pointer toNativeChars(Allocator allocator) { return toNativeUtf8(allocator: allocator).cast(); } } + +class _JClassCache { + int _capacity = 256; + final _map = {}; + + JClassPtr get(String name) { + final existing = _map[name]; + if (existing != null) { + // Move to end (MRU) + _map.remove(name); + _map[name] = existing; + return Jni.env.NewGlobalRef(existing); + } + + final cls = Jni.findClass(name); + + if (_map.length >= _capacity) { + final keyToRemove = _map.keys.first; + final valueToRemove = _map.remove(keyToRemove)!; + Jni.env.DeleteGlobalRef(valueToRemove); + } + + _map[name] = cls; + return Jni.env.NewGlobalRef(cls); + } + + set capacity(int size) { + _capacity = size; + while (_map.length > _capacity) { + final keyToRemove = _map.keys.first; + final valueToRemove = _map.remove(keyToRemove)!; + Jni.env.DeleteGlobalRef(valueToRemove); + } + } +} diff --git a/pkgs/jni/src/dartjni.c b/pkgs/jni/src/dartjni.c index debaa510e0..4c7fa8a0c0 100644 --- a/pkgs/jni/src/dartjni.c +++ b/pkgs/jni/src/dartjni.c @@ -27,230 +27,6 @@ int8_t getCaptureStackTraceOnRelease() { #include -typedef struct JniClassCacheNode { - char* name; - jclass value; - struct JniClassCacheNode* prev; - struct JniClassCacheNode* next; - struct JniClassCacheNode* hashNext; -} JniClassCacheNode; - -typedef struct JniClassCache { - JniClassCacheNode** buckets; - JniClassCacheNode* head; - JniClassCacheNode* tail; - int capacity; - int size; - int bucketCount; - MutexLock lock; -} JniClassCache; - -// Default capacity 256 -#define DEFAULT_CACHE_CAPACITY 256 -// Load factor 0.75 roughly, so buckets = capacity * 1.33 -#define DEFAULT_BUCKET_COUNT 341 - -JniClassCache jniClassCache = { - .buckets = NULL, - .head = NULL, - .tail = NULL, - .capacity = DEFAULT_CACHE_CAPACITY, - .size = 0, - .bucketCount = DEFAULT_BUCKET_COUNT, -}; - -static unsigned long hash_string(const char* str) { - unsigned long hash = 5381; - int c; - while ((c = *str++)) - hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ - return hash; -} - -static void init_cache_if_needed() { - if (jniClassCache.buckets == NULL) { - init_lock(&jniClassCache.lock); - // Double checked locking - acquire_lock(&jniClassCache.lock); - if (jniClassCache.buckets == NULL) { - jniClassCache.buckets = (JniClassCacheNode**)calloc( - jniClassCache.bucketCount, sizeof(JniClassCacheNode*)); - } - release_lock(&jniClassCache.lock); - } -} - -static void remove_node(JniClassCacheNode* node) { - if (node->prev) { - node->prev->next = node->next; - } else { - jniClassCache.head = node->next; - } - if (node->next) { - node->next->prev = node->prev; - } else { - jniClassCache.tail = node->prev; - } -} - -static void add_to_head(JniClassCacheNode* node) { - node->next = jniClassCache.head; - node->prev = NULL; - if (jniClassCache.head) { - jniClassCache.head->prev = node; - } - jniClassCache.head = node; - if (jniClassCache.tail == NULL) { - jniClassCache.tail = node; - } -} - -static void move_to_head(JniClassCacheNode* node) { - remove_node(node); - add_to_head(node); -} - -static void evict_tail() { - if (jniClassCache.tail == NULL) return; - JniClassCacheNode* node = jniClassCache.tail; - - // Remove from list - remove_node(node); - - // Remove from buckets - unsigned long hash = hash_string(node->name); - int index = hash % jniClassCache.bucketCount; - JniClassCacheNode* curr = jniClassCache.buckets[index]; - JniClassCacheNode* prev = NULL; - while (curr != NULL) { - if (curr == node) { - if (prev) { - prev->hashNext = curr->hashNext; - } else { - jniClassCache.buckets[index] = curr->hashNext; - } - break; - } - prev = curr; - curr = curr->hashNext; - } - - // Free resources - attach_thread(); - (*jniEnv)->DeleteGlobalRef(jniEnv, node->value); - free(node->name); - free(node); - jniClassCache.size--; -} - -FFI_PLUGIN_EXPORT -void SetClassCacheSize(int size) { - init_cache_if_needed(); - acquire_lock(&jniClassCache.lock); - jniClassCache.capacity = size; - while (jniClassCache.size > jniClassCache.capacity) { - evict_tail(); - } - release_lock(&jniClassCache.lock); -} - -FFI_PLUGIN_EXPORT -JniClassLookupResult GetCachedClass(const char* name) { - init_cache_if_needed(); - if (name == NULL) { - return (JniClassLookupResult){NULL, NULL}; - } - - acquire_lock(&jniClassCache.lock); - - unsigned long hash = hash_string(name); - int index = hash % jniClassCache.bucketCount; - JniClassCacheNode* node = jniClassCache.buckets[index]; - - while (node != NULL) { - if (strcmp(node->name, name) == 0) { - // Hit - move_to_head(node); - - // Return a new global ref so the caller owns one, - // but the cache keeps its own global ref. - // Wait, requirement says "Return NewGlobalRef". - // The cache holds a GlobalRef. We should hand out a NewGlobalRef - // so the user can release it without affecting the cache. - - // We need to attach thread to call NewGlobalRef - attach_thread(); - jclass cls = (*jniEnv)->NewGlobalRef(jniEnv, node->value); - release_lock(&jniClassCache.lock); - return (JniClassLookupResult){cls, NULL}; - } - node = node->hashNext; - } - - // Miss - // Release lock while loading class to avoid holding it during JNI call - release_lock(&jniClassCache.lock); - - // Load class implementation (similar to FindClassUnchecked) - attach_thread(); - jclass cls; - load_class_platform(&cls, name); - - jthrowable exception = NULL; - if ((*jniEnv)->ExceptionCheck(jniEnv)) { - exception = check_exception(); - return (JniClassLookupResult){NULL, exception}; - } - - // Convert local to global for the cache - jclass globalCls = (*jniEnv)->NewGlobalRef(jniEnv, cls); - (*jniEnv)->DeleteLocalRef(jniEnv, cls); - - // Create new node - JniClassCacheNode* newNode = (JniClassCacheNode*)malloc(sizeof(JniClassCacheNode)); - newNode->name = strdup(name); // Need strdup - newNode->value = globalCls; - newNode->hashNext = NULL; - - // Re-acquire lock to insert - acquire_lock(&jniClassCache.lock); - - // Check if it was inserted while we were loading (double check) - // Re-calculate hash/index as they are same - node = jniClassCache.buckets[index]; - while (node != NULL) { - if (strcmp(node->name, name) == 0) { - // It was inserted by another thread. Use that one. - move_to_head(node); - // Free our speculative load - (*jniEnv)->DeleteGlobalRef(jniEnv, newNode->value); - free(newNode->name); - free(newNode); - - jclass returnCls = (*jniEnv)->NewGlobalRef(jniEnv, node->value); - release_lock(&jniClassCache.lock); - return (JniClassLookupResult){returnCls, NULL}; - } - node = node->hashNext; - } - - // Insert new node - if (jniClassCache.size >= jniClassCache.capacity) { - evict_tail(); - } - - newNode->hashNext = jniClassCache.buckets[index]; - jniClassCache.buckets[index] = newNode; - add_to_head(newNode); - jniClassCache.size++; - - // Return a new global ref for the caller - jclass returnCls = (*jniEnv)->NewGlobalRef(jniEnv, globalCls); - - release_lock(&jniClassCache.lock); - - return (JniClassLookupResult){returnCls, NULL}; -} jclass FindClassUnchecked(const char* name) { attach_thread(); diff --git a/pkgs/jni/src/dartjni.h b/pkgs/jni/src/dartjni.h index 9b0c24f5cc..3de5f15723 100644 --- a/pkgs/jni/src/dartjni.h +++ b/pkgs/jni/src/dartjni.h @@ -204,13 +204,7 @@ typedef struct JniExceptionDetails { FFI_PLUGIN_EXPORT JniClassLookupResult FindClass(const char* name); -/// Returns a global reference to the class with the given name, using an LRU cache. -FFI_PLUGIN_EXPORT -JniClassLookupResult GetCachedClass(const char* name); -/// Sets the capacity of the LRU cache. -FFI_PLUGIN_EXPORT -void SetClassCacheSize(int size); FFI_PLUGIN_EXPORT JniExceptionDetails GetExceptionDetails(jthrowable exception); diff --git a/pkgs/jni/test/class_cache_test.dart b/pkgs/jni/test/class_cache_test.dart index 3a7a4dabd6..11cef12269 100644 --- a/pkgs/jni/test/class_cache_test.dart +++ b/pkgs/jni/test/class_cache_test.dart @@ -15,7 +15,6 @@ import 'test_util/test_util.dart'; void main() { if (!Platform.isAndroid) { - checkDylibIsUpToDate(); spawnJvm(); } run(testRunner: test); From aae6081dc983012fcd20bd6599e261f65b21ea18 Mon Sep 17 00:00:00 2001 From: sagar Date: Fri, 23 Jan 2026 14:47:20 +0530 Subject: [PATCH 06/13] cleanup --- pkgs/jni/src/dartjni.c | 3 --- pkgs/jni/src/dartjni.h | 2 -- 2 files changed, 5 deletions(-) diff --git a/pkgs/jni/src/dartjni.c b/pkgs/jni/src/dartjni.c index 4c7fa8a0c0..7007fc7f18 100644 --- a/pkgs/jni/src/dartjni.c +++ b/pkgs/jni/src/dartjni.c @@ -25,9 +25,6 @@ int8_t getCaptureStackTraceOnRelease() { return captureStackTraceOnRelease; } -#include - - jclass FindClassUnchecked(const char* name) { attach_thread(); jclass cls; diff --git a/pkgs/jni/src/dartjni.h b/pkgs/jni/src/dartjni.h index 3de5f15723..22368fce09 100644 --- a/pkgs/jni/src/dartjni.h +++ b/pkgs/jni/src/dartjni.h @@ -204,8 +204,6 @@ typedef struct JniExceptionDetails { FFI_PLUGIN_EXPORT JniClassLookupResult FindClass(const char* name); - - FFI_PLUGIN_EXPORT JniExceptionDetails GetExceptionDetails(jthrowable exception); From 79d71a5eaedc75f1425ce82d1a2e1765d97bb13d Mon Sep 17 00:00:00 2001 From: sagar Date: Tue, 27 Jan 2026 14:08:37 +0530 Subject: [PATCH 07/13] jni:fix GlobalRef ownership model --- pkgs/jni/lib/src/jni.dart | 59 ++++++++++- pkgs/jni/test/class_cache_test.dart | 148 ++++++++++++++++++++++------ 2 files changed, 173 insertions(+), 34 deletions(-) diff --git a/pkgs/jni/lib/src/jni.dart b/pkgs/jni/lib/src/jni.dart index 352a24674e..1104ba6bdc 100644 --- a/pkgs/jni/lib/src/jni.dart +++ b/pkgs/jni/lib/src/jni.dart @@ -199,16 +199,28 @@ abstract final class Jni { /// Finds the class from its [name], using an internal LRU cache. /// /// This is preferred for repeated lookups of the same class, as it avoids - /// repeated JNI calls and global reference creation. + /// repeated JNI calls. + /// + /// **Returns a new JGlobalReference** that the caller owns and must delete + /// when done (via [DeleteGlobalRef] or by wrapping in [JGlobalReference]). + /// Each call returns a distinct global reference, even for cache hits. + /// + /// The cache maintains its own global references internally. Deleting the + /// returned reference does not invalidate the cache. static JClassPtr getCachedClass(String name) { return _classCache.get(name); } /// Sets the capacity of the internal LRU class cache. /// - /// If the new size is smaller than the current number of cached classes, - /// the least recently used classes will be evicted and their global - /// references released. + /// If the new [size] is smaller than the current number of cached classes, + /// the least recently used classes will be **immediately evicted** and + /// their global references released (via [DeleteGlobalRef]). + /// + /// This does **not** affect references returned by prior [getCachedClass] + /// calls. Those are owned by callers and remain valid until deleted. + /// + /// The cache is isolate-local, so this only affects the current isolate. static void setClassCacheSize(int size) { _classCache.capacity = size; } @@ -451,6 +463,33 @@ extension StringMethodsForJni on String { } } +/// Internal LRU cache for JNI class references. +/// +/// **GlobalRef Ownership Model:** +/// +/// This cache is the **sole owner** of the JNI global references it stores. +/// All stored [JClassPtr] values are global references that the cache is +/// responsible for deleting when they are evicted. +/// +/// **Critical Lifecycle Rules:** +/// +/// 1. **Cache owns stored refs**: Each entry in [_map] is a JGlobalReference +/// that belongs to the cache. The cache must call [DeleteGlobalRef] on +/// these entries when they are evicted. +/// +/// 2. **Callers receive duplicates**: [get] always returns a newly created +/// global reference via [NewGlobalRef]. The caller owns this duplicate +/// and must delete it when done. This prevents GC of caller-side +/// [JObject]/[JClass] wrappers from invalidating cache-held references. +/// +/// 3. **Eviction deletes owned refs**: When capacity is reduced or entries +/// are evicted during LRU replacement, the cache calls [DeleteGlobalRef] +/// on the evicted reference that it owns. +/// +/// **Isolate-local**: Each isolate has its own cache instance. References +/// are not shared across isolates. +/// +/// **Thread-safety**: Access is inherently single-threaded per isolate. class _JClassCache { int _capacity = 256; final _map = {}; @@ -458,29 +497,39 @@ class _JClassCache { JClassPtr get(String name) { final existing = _map[name]; if (existing != null) { - // Move to end (MRU) + // Cache hit: Move entry to end for LRU tracking. _map.remove(name); _map[name] = existing; + // CRITICAL: Return a duplicate GlobalRef. The cache still owns + // `existing`. The caller owns the returned duplicate and must delete it. return Jni.env.NewGlobalRef(existing); } + // Cache miss: Jni.findClass returns a new GlobalRef. final cls = Jni.findClass(name); + // Evict LRU entry if at capacity. if (_map.length >= _capacity) { final keyToRemove = _map.keys.first; final valueToRemove = _map.remove(keyToRemove)!; + // CRITICAL: Delete the GlobalRef the cache owned. Jni.env.DeleteGlobalRef(valueToRemove); } + // Store the GlobalRef. The cache now owns `cls`. _map[name] = cls; + // CRITICAL: Return a duplicate GlobalRef. The cache still owns `cls`. + // The caller owns the returned duplicate and must delete it. return Jni.env.NewGlobalRef(cls); } set capacity(int size) { _capacity = size; + // Evict LRU entries immediately if new capacity is smaller. while (_map.length > _capacity) { final keyToRemove = _map.keys.first; final valueToRemove = _map.remove(keyToRemove)!; + // CRITICAL: Delete the GlobalRef the cache owned. Jni.env.DeleteGlobalRef(valueToRemove); } } diff --git a/pkgs/jni/test/class_cache_test.dart b/pkgs/jni/test/class_cache_test.dart index 11cef12269..3baa10ecf1 100644 --- a/pkgs/jni/test/class_cache_test.dart +++ b/pkgs/jni/test/class_cache_test.dart @@ -24,11 +24,11 @@ void run({required TestRunnerCallback testRunner}) { testRunner('Basic cache functionality', () { final stringClass = Jni.getCachedClass('java/lang/String'); expect(stringClass, isNot(nullptr)); - + final stringClass2 = Jni.getCachedClass('java/lang/String'); expect(stringClass2, isNot(nullptr)); expect(stringClass.address, isNot(equals(stringClass2.address))); - + // Check JNI equality (should be same object) expect(Jni.env.IsSameObject(stringClass, stringClass2), isTrue); Jni.env.DeleteGlobalRef(stringClass); @@ -38,29 +38,29 @@ void run({required TestRunnerCallback testRunner}) { testRunner('Cache capacity configuration', () { // Set small capacity Jni.setClassCacheSize(2); - + final c1 = Jni.getCachedClass('java/lang/String'); final c2 = Jni.getCachedClass('java/util/ArrayList'); - // c3 would evict c1 if strictly LRU logic was only on insert, + // c3 would evict c1 if strictly LRU logic was only on insert, // but lookup of c1 moves it to head? No, we haven't looked it up again yet. // Insert c1. Head=c1. Size=1. // Insert c2. Head=c2->c1. Size=2. // Insert c3. Evict Tail(c1). Head=c3->c2. Size=2. - final c3 = Jni.getCachedClass('java/util/HashMap'); - + final c3 = Jni.getCachedClass('java/util/HashMap'); + // Verify c1 still works (it's a new global ref) expect(c1, isNot(nullptr)); - + // Verify we can reload c1 final c1Reload = Jni.getCachedClass('java/lang/String'); expect(Jni.env.IsSameObject(c1, c1Reload), isTrue); - + Jni.env.DeleteGlobalRef(c1); Jni.env.DeleteGlobalRef(c2); Jni.env.DeleteGlobalRef(c3); Jni.env.DeleteGlobalRef(c1Reload); }); - + testRunner('Stress test cache', () { Jni.setClassCacheSize(100); // Load many classes @@ -86,30 +86,120 @@ void run({required TestRunnerCallback testRunner}) { 'java/io/InputStream', 'java/io/OutputStream', ]; - + for (var i = 0; i < 1000; i++) { - final name = classes[i % classes.length]; - final cls = Jni.getCachedClass(name); - expect(cls, isNot(nullptr)); - Jni.env.DeleteGlobalRef(cls); + final name = classes[i % classes.length]; + final cls = Jni.getCachedClass(name); + expect(cls, isNot(nullptr)); + Jni.env.DeleteGlobalRef(cls); } }); testRunner('Cache hit returns new global ref', () { - final c1 = Jni.getCachedClass('java/lang/Object'); - final c2 = Jni.getCachedClass('java/lang/Object'); - // Pointers are different (different GlobalRefs) - expect(c1, isNot(equals(c2))); - // Objects are same - expect(Jni.env.IsSameObject(c1, c2), isTrue); - - // Cleanup - Jni.env.DeleteGlobalRef(c1); - Jni.env.DeleteGlobalRef(c2); - - // Cache should still hold a ref internally, so getting it again should work - final c3 = Jni.getCachedClass('java/lang/Object'); - expect(c3, isNot(nullptr)); - Jni.env.DeleteGlobalRef(c3); + // Tests the ownership model: cache owns refs, callers get duplicates. + final c1 = Jni.getCachedClass('java/lang/Object'); + final c2 = Jni.getCachedClass('java/lang/Object'); + // Pointers are different (different GlobalRefs) + expect(c1, isNot(equals(c2))); + // Objects are same + expect(Jni.env.IsSameObject(c1, c2), isTrue); + + // Cleanup + Jni.env.DeleteGlobalRef(c1); + Jni.env.DeleteGlobalRef(c2); + + // Cache should still hold a ref internally, so getting it again should work + final c3 = Jni.getCachedClass('java/lang/Object'); + expect(c3, isNot(nullptr)); + Jni.env.DeleteGlobalRef(c3); + }); + + testRunner('Cache-held refs survive caller deletion', () { + // Tests that deleting caller-owned refs doesn't invalidate cache. + // This validates the ownership model: cache owns its refs separately. + + final ref1 = Jni.getCachedClass('java/lang/System'); + expect(ref1, isNot(nullptr)); + + // Delete the ref we got (caller-owned duplicate) + Jni.env.DeleteGlobalRef(ref1); + + // Cache should still have its own ref, so we can get it again + final ref2 = Jni.getCachedClass('java/lang/System'); + expect(ref2, isNot(nullptr)); + expect(Jni.env.IsSameObject(ref1, ref2), isTrue); + + Jni.env.DeleteGlobalRef(ref2); + }); + + testRunner('Eviction deletes cache-owned refs', () { + // Tests that cache properly deletes owned GlobalRefs on eviction. + Jni.setClassCacheSize(2); + + final ref1 = Jni.getCachedClass('java/lang/String'); + final ref2 = Jni.getCachedClass('java/lang/Integer'); + + // Insert third class, evicting String (LRU) + final ref3 = Jni.getCachedClass('java/lang/Double'); + + // All caller refs should still be valid + expect(Jni.env.IsSameObject(ref1, ref1), isTrue); + expect(Jni.env.IsSameObject(ref2, ref2), isTrue); + expect(Jni.env.IsSameObject(ref3, ref3), isTrue); + + // String should have been evicted from cache, but we can reload it + final ref1Reload = Jni.getCachedClass('java/lang/String'); + expect(Jni.env.IsSameObject(ref1, ref1Reload), isTrue); + + // Clean up all caller-owned refs + Jni.env.DeleteGlobalRef(ref1); + Jni.env.DeleteGlobalRef(ref2); + Jni.env.DeleteGlobalRef(ref3); + Jni.env.DeleteGlobalRef(ref1Reload); + }); + + testRunner('Capacity reduction evicts and deletes refs', () { + // Tests that reducing capacity immediately evicts and deletes owned refs. + Jni.setClassCacheSize(10); + + // Fill cache with 10 classes + final refs = []; + for (var i = 0; i < 10; i++) { + final className = 'java/lang/String'; // Use same class for simplicity + refs.add(Jni.getCachedClass(className)); + } + + // Reduce capacity - should evict 7 entries + Jni.setClassCacheSize(3); + + // All caller-owned refs should still be valid + for (final ref in refs) { + expect(Jni.env.IsSameObject(ref, ref), isTrue); + } + + // Clean up caller-owned refs + for (final ref in refs) { + Jni.env.DeleteGlobalRef(ref); + } + }); + + testRunner('JClass.forNameCached uses cache', () { + // Tests that JClass.forNameCached integrates correctly with the cache. + // This validates that the ownership model works through the wrapper API. + + final jclass1 = JClass.forNameCached('java/lang/Object'); + final jclass2 = JClass.forNameCached('java/lang/Object'); + + // Different Dart objects + expect(identical(jclass1, jclass2), isFalse); + + // Same underlying JNI class + final ref1 = jclass1.reference; + final ref2 = jclass2.reference; + expect(Jni.env.IsSameObject(ref1.pointer, ref2.pointer), isTrue); + + // JGlobalReference finalizers will clean up when GC'd + jclass1.release(); + jclass2.release(); }); } From b3c58a9d196e6a5edda97c2b1c3bc918dfcefa4b Mon Sep 17 00:00:00 2001 From: sagar Date: Wed, 28 Jan 2026 12:20:58 +0530 Subject: [PATCH 08/13] jni: fix cache ownership implementation. --- pkgs/jni/lib/src/jclass.dart | 14 +++- pkgs/jni/lib/src/jni.dart | 140 ++++++++++++++++++++++--------- pkgs/jni/lib/src/jreference.dart | 52 ++++++++++++ 3 files changed, 166 insertions(+), 40 deletions(-) diff --git a/pkgs/jni/lib/src/jclass.dart b/pkgs/jni/lib/src/jclass.dart index 7c9a30057c..c15dd9d140 100644 --- a/pkgs/jni/lib/src/jclass.dart +++ b/pkgs/jni/lib/src/jclass.dart @@ -18,8 +18,20 @@ class JClass extends JObject { /// Constructs a [JClass] associated with the class or interface with /// the given string name, using the global LRU cache. + /// + /// This constructor uses borrowed references to minimize the number of + /// JGlobalReferences created. Multiple instances of the same class will + /// share a single underlying GlobalRef via reference counting. JClass.forNameCached(String name) - : super.fromReference(JGlobalReference(Jni.getCachedClass(name))); + : super.fromReference(_createBorrowedReference(name)); + + static JReference _createBorrowedReference(String name) { + final entry = Jni.getCachedClassEntry(name); + return BorrowedReference.create( + parent: entry.globalRef, + entryPtr: entry.asPointer, + ); + } JConstructorId constructorId(String signature) { return JConstructorId._(this, signature); diff --git a/pkgs/jni/lib/src/jni.dart b/pkgs/jni/lib/src/jni.dart index 1104ba6bdc..e0df94d105 100644 --- a/pkgs/jni/lib/src/jni.dart +++ b/pkgs/jni/lib/src/jni.dart @@ -202,20 +202,57 @@ abstract final class Jni { /// repeated JNI calls. /// /// **Returns a new JGlobalReference** that the caller owns and must delete - /// when done (via [DeleteGlobalRef] or by wrapping in [JGlobalReference]). + /// when done (via `DeleteGlobalRef` or by wrapping in `JGlobalReference`). /// Each call returns a distinct global reference, even for cache hits. /// /// The cache maintains its own global references internally. Deleting the /// returned reference does not invalidate the cache. + /// + /// **Note**: This API is deprecated for direct use. Prefer + /// [JClass.forNameCached] which uses borrowed references to minimize + /// GlobalRef count. static JClassPtr getCachedClass(String name) { + final entry = _classCache.get(name); + return Jni.env.NewGlobalRef(entry.globalRef.pointer); + } + + /// Internal method to get cache entry for `BorrowedReference` creation. + @internal + static JClassCacheEntry getCachedClassEntry(String name) { + _ensureBorrowedReferenceCallbacks(); return _classCache.get(name); } + static bool _callbacksSetup = false; + + static final _entryRegistry = {}; + + static void _ensureBorrowedReferenceCallbacks() { + if (_callbacksSetup) return; + _callbacksSetup = true; + + BorrowedReference.onBorrowCallback = (Pointer entryId) { + final id = entryId.address; + final entry = _entryRegistry[id]!; + entry.borrowCount++; + }; + + BorrowedReference.onReleaseCallback = (Pointer entryId) { + final id = entryId.address; + final entry = _entryRegistry[id]!; + entry.borrowCount--; + if (entry.isEvicted && entry.borrowCount == 0) { + entry.globalRef.release(); + _entryRegistry.remove(id); + } + }; + } + /// Sets the capacity of the internal LRU class cache. /// /// If the new [size] is smaller than the current number of cached classes, /// the least recently used classes will be **immediately evicted** and - /// their global references released (via [DeleteGlobalRef]). + /// their global references released (via `DeleteGlobalRef`). /// /// This does **not** affect references returned by prior [getCachedClass] /// calls. Those are owned by callers and remain valid until deleted. @@ -463,74 +500,99 @@ extension StringMethodsForJni on String { } } +/// Internal cache entry for JNI class references. +/// +/// Tracks a single JNI global reference along with metadata for reference +/// counting and eviction. +@internal +class JClassCacheEntry { + final String name; + final JGlobalReference globalRef; + int borrowCount = 0; + bool isEvicted = false; + + JClassCacheEntry(this.name, this.globalRef) { + // Register this entry for pointer-based callbacks + Jni._entryRegistry[identityHashCode(this)] = this; + } + + @internal + Pointer get asPointer => Pointer.fromAddress(identityHashCode(this)); +} + /// Internal LRU cache for JNI class references. /// /// **GlobalRef Ownership Model:** /// /// This cache is the **sole owner** of the JNI global references it stores. -/// All stored [JClassPtr] values are global references that the cache is -/// responsible for deleting when they are evicted. +/// Each cache entry contains exactly one [JGlobalReference] and tracks how +/// many wrappers are currently borrowing it via reference counting. /// /// **Critical Lifecycle Rules:** /// -/// 1. **Cache owns stored refs**: Each entry in [_map] is a JGlobalReference -/// that belongs to the cache. The cache must call [DeleteGlobalRef] on -/// these entries when they are evicted. +/// 1. **Cache owns GlobalRefs**: Each [JClassCacheEntry] contains a +/// [JGlobalReference] owned by the cache. The cache is responsible for +/// deleting it when the entry is evicted AND no wrappers are using it. +/// +/// 2. **Callers borrow references**: [get] returns a cache entry that +/// wrappers use to create `BorrowedReference` instances. Each borrow +/// increments `borrowCount`, and each release decrements it. /// -/// 2. **Callers receive duplicates**: [get] always returns a newly created -/// global reference via [NewGlobalRef]. The caller owns this duplicate -/// and must delete it when done. This prevents GC of caller-side -/// [JObject]/[JClass] wrappers from invalidating cache-held references. +/// 3. **Reference counting enables deterministic cleanup**: When an entry is +/// evicted, it's marked as `isEvicted = true`. The underlying GlobalRef is +/// deleted immediately if `borrowCount == 0`, or when the last borrower +/// releases (deterministic, not GC-dependent). /// -/// 3. **Eviction deletes owned refs**: When capacity is reduced or entries -/// are evicted during LRU replacement, the cache calls [DeleteGlobalRef] -/// on the evicted reference that it owns. +/// 4. **Minimal GlobalRef usage**: Only N GlobalRefs exist (where N = number of +/// distinct classes in use), regardless of wrapper count. This is the +/// primary benefit over duplication-based caching. /// /// **Isolate-local**: Each isolate has its own cache instance. References /// are not shared across isolates. -/// -/// **Thread-safety**: Access is inherently single-threaded per isolate. class _JClassCache { int _capacity = 256; - final _map = {}; + final _map = {}; + + JClassCacheEntry get(String name) { + var entry = _map[name]; - JClassPtr get(String name) { - final existing = _map[name]; - if (existing != null) { + if (entry != null) { // Cache hit: Move entry to end for LRU tracking. _map.remove(name); - _map[name] = existing; - // CRITICAL: Return a duplicate GlobalRef. The cache still owns - // `existing`. The caller owns the returned duplicate and must delete it. - return Jni.env.NewGlobalRef(existing); + _map[name] = entry; + return entry; } - // Cache miss: Jni.findClass returns a new GlobalRef. - final cls = Jni.findClass(name); + // Cache miss: Load class and create new entry. + final clsPtr = Jni.findClass(name); + entry = JClassCacheEntry(name, JGlobalReference(clsPtr)); // Evict LRU entry if at capacity. if (_map.length >= _capacity) { - final keyToRemove = _map.keys.first; - final valueToRemove = _map.remove(keyToRemove)!; - // CRITICAL: Delete the GlobalRef the cache owned. - Jni.env.DeleteGlobalRef(valueToRemove); + final keyToEvict = _map.keys.first; + _evict(keyToEvict); } - // Store the GlobalRef. The cache now owns `cls`. - _map[name] = cls; - // CRITICAL: Return a duplicate GlobalRef. The cache still owns `cls`. - // The caller owns the returned duplicate and must delete it. - return Jni.env.NewGlobalRef(cls); + _map[name] = entry; + return entry; + } + + void _evict(String name) { + final entry = _map.remove(name)!; + entry.isEvicted = true; + + // Deterministic cleanup: If no active borrowers, delete immediately. + if (entry.borrowCount == 0) { + entry.globalRef.release(); + } } set capacity(int size) { _capacity = size; // Evict LRU entries immediately if new capacity is smaller. while (_map.length > _capacity) { - final keyToRemove = _map.keys.first; - final valueToRemove = _map.remove(keyToRemove)!; - // CRITICAL: Delete the GlobalRef the cache owned. - Jni.env.DeleteGlobalRef(valueToRemove); + final keyToEvict = _map.keys.first; + _evict(keyToEvict); } } } diff --git a/pkgs/jni/lib/src/jreference.dart b/pkgs/jni/lib/src/jreference.dart index 25c59f5c98..db7055e7ff 100644 --- a/pkgs/jni/lib/src/jreference.dart +++ b/pkgs/jni/lib/src/jreference.dart @@ -190,3 +190,55 @@ final class _JNullReference extends JReference { @override bool get isNull => true; } + +/// A borrowed reference to a cached pointer. +/// +/// Allows multiple wrappers to share one [JGlobalReference]. +/// +/// Lifecycle: +/// Creation: increments cache borrow count +/// Release: decrements count; deletes GlobalRef if evicted and count hits 0 +/// Does not delete the JNI reference in its finalizer +@pragma('vm:deeply-immutable') +final class BorrowedReference extends JReference { + final JReference _parent; + final Pointer _isLocallyReleased; + final Pointer _entryPtr; // Points to _JClassCacheEntry + + @internal + BorrowedReference.create({ + required JReference parent, + required Pointer entryPtr, + }) : _parent = parent, + _entryPtr = entryPtr, + _isLocallyReleased = calloc()..value = false, + super._(parent._finalizable) { + onBorrowCallback(entryPtr); + } + + @override + bool get isReleased => _isLocallyReleased.value || _parent.isReleased; + + @override + bool get isNull => _parent.isNull; + + @override + void _setAsReleased() { + if (_isLocallyReleased.value) { + return; + } + _isLocallyReleased.value = true; + onReleaseCallback(_entryPtr); + } + + @override + void _deleteReference() { + calloc.free(_isLocallyReleased); + } + + // These are set by _setupBorrowedReferenceCallbacks in jni.dart + @internal + static late void Function(Pointer) onBorrowCallback; + @internal + static late void Function(Pointer) onReleaseCallback; +} From 5b7cadf7b8900cf9fd4de765802c30689ab35b10 Mon Sep 17 00:00:00 2001 From: sagar Date: Thu, 29 Jan 2026 15:36:26 +0530 Subject: [PATCH 09/13] Refactor JNI class cache to cache-owned JClass and remove refcounting --- pkgs/jni/lib/src/jclass.dart | 22 ++-- pkgs/jni/lib/src/jni.dart | 120 +++++---------------- pkgs/jni/lib/src/jreference.dart | 51 --------- pkgs/jni/test/class_cache_test.dart | 161 +++++++++++----------------- 4 files changed, 96 insertions(+), 258 deletions(-) diff --git a/pkgs/jni/lib/src/jclass.dart b/pkgs/jni/lib/src/jclass.dart index c15dd9d140..09843ef609 100644 --- a/pkgs/jni/lib/src/jclass.dart +++ b/pkgs/jni/lib/src/jclass.dart @@ -16,21 +16,15 @@ class JClass extends JObject { JClass.forName(String name) : super.fromReference(JGlobalReference(Jni.findClass(name))); - /// Constructs a [JClass] associated with the class or interface with - /// the given string name, using the global LRU cache. + /// Returns a cached [JClass] for the class or interface with the given name. + /// + /// Uses an internal LRU cache to minimize JNI calls and GlobalRef usage. + /// Returns the cached instance owned by the cache. /// - /// This constructor uses borrowed references to minimize the number of - /// JGlobalReferences created. Multiple instances of the same class will - /// share a single underlying GlobalRef via reference counting. - JClass.forNameCached(String name) - : super.fromReference(_createBorrowedReference(name)); - - static JReference _createBorrowedReference(String name) { - final entry = Jni.getCachedClassEntry(name); - return BorrowedReference.create( - parent: entry.globalRef, - entryPtr: entry.asPointer, - ); + /// **Important**: Do NOT call [release] on instances returned by this + /// factory. The cache manages their lifecycle. + factory JClass.forNameCached(String name) { + return Jni.getCachedClass(name); } JConstructorId constructorId(String signature) { diff --git a/pkgs/jni/lib/src/jni.dart b/pkgs/jni/lib/src/jni.dart index e0df94d105..eca2011ad0 100644 --- a/pkgs/jni/lib/src/jni.dart +++ b/pkgs/jni/lib/src/jni.dart @@ -196,58 +196,20 @@ abstract final class Jni { .checkedClassRef; } - /// Finds the class from its [name], using an internal LRU cache. + /// Returns a cached [JClass] for the given class name. /// /// This is preferred for repeated lookups of the same class, as it avoids - /// repeated JNI calls. + /// repeated JNI calls and minimizes GlobalRef usage. /// - /// **Returns a new JGlobalReference** that the caller owns and must delete - /// when done (via `DeleteGlobalRef` or by wrapping in `JGlobalReference`). - /// Each call returns a distinct global reference, even for cache hits. + /// **Returns the cached JClass instance** owned by the cache. Callers must + /// NOT release this instance. The cache manages its lifecycle. /// - /// The cache maintains its own global references internally. Deleting the - /// returned reference does not invalidate the cache. - /// - /// **Note**: This API is deprecated for direct use. Prefer - /// [JClass.forNameCached] which uses borrowed references to minimize - /// GlobalRef count. - static JClassPtr getCachedClass(String name) { - final entry = _classCache.get(name); - return Jni.env.NewGlobalRef(entry.globalRef.pointer); - } - - /// Internal method to get cache entry for `BorrowedReference` creation. + /// The cache is isolate-local and has bounded capacity. @internal - static JClassCacheEntry getCachedClassEntry(String name) { - _ensureBorrowedReferenceCallbacks(); + static JClass getCachedClass(String name) { return _classCache.get(name); } - static bool _callbacksSetup = false; - - static final _entryRegistry = {}; - - static void _ensureBorrowedReferenceCallbacks() { - if (_callbacksSetup) return; - _callbacksSetup = true; - - BorrowedReference.onBorrowCallback = (Pointer entryId) { - final id = entryId.address; - final entry = _entryRegistry[id]!; - entry.borrowCount++; - }; - - BorrowedReference.onReleaseCallback = (Pointer entryId) { - final id = entryId.address; - final entry = _entryRegistry[id]!; - entry.borrowCount--; - if (entry.isEvicted && entry.borrowCount == 0) { - entry.globalRef.release(); - _entryRegistry.remove(id); - } - }; - } - /// Sets the capacity of the internal LRU class cache. /// /// If the new [size] is smaller than the current number of cached classes, @@ -501,71 +463,42 @@ extension StringMethodsForJni on String { } /// Internal cache entry for JNI class references. -/// -/// Tracks a single JNI global reference along with metadata for reference -/// counting and eviction. @internal -class JClassCacheEntry { +class _JClassCacheEntry { final String name; final JGlobalReference globalRef; - int borrowCount = 0; - bool isEvicted = false; + final JClass jclass; - JClassCacheEntry(this.name, this.globalRef) { - // Register this entry for pointer-based callbacks - Jni._entryRegistry[identityHashCode(this)] = this; - } - - @internal - Pointer get asPointer => Pointer.fromAddress(identityHashCode(this)); + _JClassCacheEntry(this.name, this.globalRef, this.jclass); } /// Internal LRU cache for JNI class references. /// -/// **GlobalRef Ownership Model:** -/// -/// This cache is the **sole owner** of the JNI global references it stores. -/// Each cache entry contains exactly one [JGlobalReference] and tracks how -/// many wrappers are currently borrowing it via reference counting. -/// -/// **Critical Lifecycle Rules:** +/// The cache owns [JGlobalReference] instances and provides [JClass] wrappers +/// that share these references. The cache is responsible for releasing +/// GlobalRefs on eviction. /// -/// 1. **Cache owns GlobalRefs**: Each [JClassCacheEntry] contains a -/// [JGlobalReference] owned by the cache. The cache is responsible for -/// deleting it when the entry is evicted AND no wrappers are using it. +/// Cache capacity directly bounds the number of underlying JGlobalReferences. /// -/// 2. **Callers borrow references**: [get] returns a cache entry that -/// wrappers use to create `BorrowedReference` instances. Each borrow -/// increments `borrowCount`, and each release decrements it. -/// -/// 3. **Reference counting enables deterministic cleanup**: When an entry is -/// evicted, it's marked as `isEvicted = true`. The underlying GlobalRef is -/// deleted immediately if `borrowCount == 0`, or when the last borrower -/// releases (deterministic, not GC-dependent). -/// -/// 4. **Minimal GlobalRef usage**: Only N GlobalRefs exist (where N = number of -/// distinct classes in use), regardless of wrapper count. This is the -/// primary benefit over duplication-based caching. -/// -/// **Isolate-local**: Each isolate has its own cache instance. References -/// are not shared across isolates. +/// Isolate-local: Each isolate has its own cache instance. class _JClassCache { int _capacity = 256; - final _map = {}; + final _map = {}; - JClassCacheEntry get(String name) { + JClass get(String name) { var entry = _map[name]; if (entry != null) { // Cache hit: Move entry to end for LRU tracking. _map.remove(name); _map[name] = entry; - return entry; + return entry.jclass; } - // Cache miss: Load class and create new entry. - final clsPtr = Jni.findClass(name); - entry = JClassCacheEntry(name, JGlobalReference(clsPtr)); + // Cache miss: Create GlobalRef and JClass wrapper. + final globalRef = JGlobalReference(Jni.findClass(name)); + final jclass = JClass.fromReference(globalRef); + entry = _JClassCacheEntry(name, globalRef, jclass); // Evict LRU entry if at capacity. if (_map.length >= _capacity) { @@ -574,17 +507,14 @@ class _JClassCache { } _map[name] = entry; - return entry; + return entry.jclass; } void _evict(String name) { final entry = _map.remove(name)!; - entry.isEvicted = true; - - // Deterministic cleanup: If no active borrowers, delete immediately. - if (entry.borrowCount == 0) { - entry.globalRef.release(); - } + // Release the GlobalRef; JClass wrapper becomes invalid but that's OK + // since we only hand out cached instances that should not be released by callers. + entry.globalRef.release(); } set capacity(int size) { diff --git a/pkgs/jni/lib/src/jreference.dart b/pkgs/jni/lib/src/jreference.dart index db7055e7ff..7c7eac1022 100644 --- a/pkgs/jni/lib/src/jreference.dart +++ b/pkgs/jni/lib/src/jreference.dart @@ -191,54 +191,3 @@ final class _JNullReference extends JReference { bool get isNull => true; } -/// A borrowed reference to a cached pointer. -/// -/// Allows multiple wrappers to share one [JGlobalReference]. -/// -/// Lifecycle: -/// Creation: increments cache borrow count -/// Release: decrements count; deletes GlobalRef if evicted and count hits 0 -/// Does not delete the JNI reference in its finalizer -@pragma('vm:deeply-immutable') -final class BorrowedReference extends JReference { - final JReference _parent; - final Pointer _isLocallyReleased; - final Pointer _entryPtr; // Points to _JClassCacheEntry - - @internal - BorrowedReference.create({ - required JReference parent, - required Pointer entryPtr, - }) : _parent = parent, - _entryPtr = entryPtr, - _isLocallyReleased = calloc()..value = false, - super._(parent._finalizable) { - onBorrowCallback(entryPtr); - } - - @override - bool get isReleased => _isLocallyReleased.value || _parent.isReleased; - - @override - bool get isNull => _parent.isNull; - - @override - void _setAsReleased() { - if (_isLocallyReleased.value) { - return; - } - _isLocallyReleased.value = true; - onReleaseCallback(_entryPtr); - } - - @override - void _deleteReference() { - calloc.free(_isLocallyReleased); - } - - // These are set by _setupBorrowedReferenceCallbacks in jni.dart - @internal - static late void Function(Pointer) onBorrowCallback; - @internal - static late void Function(Pointer) onReleaseCallback; -} diff --git a/pkgs/jni/test/class_cache_test.dart b/pkgs/jni/test/class_cache_test.dart index 3baa10ecf1..058c4fc90a 100644 --- a/pkgs/jni/test/class_cache_test.dart +++ b/pkgs/jni/test/class_cache_test.dart @@ -23,16 +23,18 @@ void main() { void run({required TestRunnerCallback testRunner}) { testRunner('Basic cache functionality', () { final stringClass = Jni.getCachedClass('java/lang/String'); - expect(stringClass, isNot(nullptr)); + expect(stringClass, isNotNull); final stringClass2 = Jni.getCachedClass('java/lang/String'); - expect(stringClass2, isNot(nullptr)); - expect(stringClass.address, isNot(equals(stringClass2.address))); + expect(stringClass2, isNotNull); + // Same cached instance + expect(identical(stringClass, stringClass2), isTrue); // Check JNI equality (should be same object) - expect(Jni.env.IsSameObject(stringClass, stringClass2), isTrue); - Jni.env.DeleteGlobalRef(stringClass); - Jni.env.DeleteGlobalRef(stringClass2); + expect( + Jni.env.IsSameObject( + stringClass.reference.pointer, stringClass2.reference.pointer), + isTrue); }); testRunner('Cache capacity configuration', () { @@ -41,29 +43,21 @@ void run({required TestRunnerCallback testRunner}) { final c1 = Jni.getCachedClass('java/lang/String'); final c2 = Jni.getCachedClass('java/util/ArrayList'); - // c3 would evict c1 if strictly LRU logic was only on insert, - // but lookup of c1 moves it to head? No, we haven't looked it up again yet. - // Insert c1. Head=c1. Size=1. - // Insert c2. Head=c2->c1. Size=2. - // Insert c3. Evict Tail(c1). Head=c3->c2. Size=2. + // c3 evicts c1 final c3 = Jni.getCachedClass('java/util/HashMap'); - // Verify c1 still works (it's a new global ref) - expect(c1, isNot(nullptr)); + // c2 and c3 still cached + expect(c2, isNotNull); + expect(c3, isNotNull); - // Verify we can reload c1 + // Reload c1 (was evicted, creates new cached instance) final c1Reload = Jni.getCachedClass('java/lang/String'); - expect(Jni.env.IsSameObject(c1, c1Reload), isTrue); - - Jni.env.DeleteGlobalRef(c1); - Jni.env.DeleteGlobalRef(c2); - Jni.env.DeleteGlobalRef(c3); - Jni.env.DeleteGlobalRef(c1Reload); + // c1Reload is a different Dart instance since eviction recreated it + expect(identical(c1, c1Reload), isFalse); }); testRunner('Stress test cache', () { Jni.setClassCacheSize(100); - // Load many classes final classes = [ 'java/lang/Byte', 'java/lang/Short', @@ -90,116 +84,87 @@ void run({required TestRunnerCallback testRunner}) { for (var i = 0; i < 1000; i++) { final name = classes[i % classes.length]; final cls = Jni.getCachedClass(name); - expect(cls, isNot(nullptr)); - Jni.env.DeleteGlobalRef(cls); + expect(cls, isNotNull); } }); - testRunner('Cache hit returns new global ref', () { - // Tests the ownership model: cache owns refs, callers get duplicates. + testRunner('Cache hit returns same instance', () { final c1 = Jni.getCachedClass('java/lang/Object'); final c2 = Jni.getCachedClass('java/lang/Object'); - // Pointers are different (different GlobalRefs) - expect(c1, isNot(equals(c2))); - // Objects are same - expect(Jni.env.IsSameObject(c1, c2), isTrue); - - // Cleanup - Jni.env.DeleteGlobalRef(c1); - Jni.env.DeleteGlobalRef(c2); - - // Cache should still hold a ref internally, so getting it again should work - final c3 = Jni.getCachedClass('java/lang/Object'); - expect(c3, isNot(nullptr)); - Jni.env.DeleteGlobalRef(c3); + // Both are the same cached instance + expect(identical(c1, c2), isTrue); + // Same underlying JNI object + expect( + Jni.env.IsSameObject( + c1.reference.pointer, c2.reference.pointer), + isTrue); }); - testRunner('Cache-held refs survive caller deletion', () { - // Tests that deleting caller-owned refs doesn't invalidate cache. - // This validates the ownership model: cache owns its refs separately. - - final ref1 = Jni.getCachedClass('java/lang/System'); - expect(ref1, isNot(nullptr)); - - // Delete the ref we got (caller-owned duplicate) - Jni.env.DeleteGlobalRef(ref1); + testRunner('Eviction and reload', () { + Jni.setClassCacheSize(2); - // Cache should still have its own ref, so we can get it again - final ref2 = Jni.getCachedClass('java/lang/System'); - expect(ref2, isNot(nullptr)); - expect(Jni.env.IsSameObject(ref1, ref2), isTrue); + final _name1 = 'java/lang/String'; + final _name2 = 'java/lang/Integer'; + final _name3 = 'java/lang/Double'; - Jni.env.DeleteGlobalRef(ref2); - }); + final ref1 = Jni.getCachedClass(_name1); + final ref2 = Jni.getCachedClass(_name2); - testRunner('Eviction deletes cache-owned refs', () { - // Tests that cache properly deletes owned GlobalRefs on eviction. - Jni.setClassCacheSize(2); + // Insert third class, evicting String (LRU) + final ref3 = Jni.getCachedClass(_name3); - final ref1 = Jni.getCachedClass('java/lang/String'); - final ref2 = Jni.getCachedClass('java/lang/Integer'); + // ref2 and ref3 still cached and valid + expect(ref2, isNotNull); + expect(ref3, isNotNull); - // Insert third class, evicting String (LRU) - final ref3 = Jni.getCachedClass('java/lang/Double'); - - // All caller refs should still be valid - expect(Jni.env.IsSameObject(ref1, ref1), isTrue); - expect(Jni.env.IsSameObject(ref2, ref2), isTrue); - expect(Jni.env.IsSameObject(ref3, ref3), isTrue); - - // String should have been evicted from cache, but we can reload it - final ref1Reload = Jni.getCachedClass('java/lang/String'); - expect(Jni.env.IsSameObject(ref1, ref1Reload), isTrue); - - // Clean up all caller-owned refs - Jni.env.DeleteGlobalRef(ref1); - Jni.env.DeleteGlobalRef(ref2); - Jni.env.DeleteGlobalRef(ref3); - Jni.env.DeleteGlobalRef(ref1Reload); + // String evicted; reload creates new cached instance + final ref1Reload = Jni.getCachedClass(_name1); + // Not identical since eviction recreated it + expect(identical(ref1, ref1Reload), isFalse); }); - testRunner('Capacity reduction evicts and deletes refs', () { - // Tests that reducing capacity immediately evicts and deletes owned refs. + testRunner('Capacity reduction evicts entries', () { Jni.setClassCacheSize(10); - // Fill cache with 10 classes - final refs = []; - for (var i = 0; i < 10; i++) { - final className = 'java/lang/String'; // Use same class for simplicity + final refs = []; + final uniqueClasses = [ + 'java/lang/String', + 'java/lang/Integer', + 'java/lang/Double', + 'java/lang/Boolean', + 'java/lang/Long', + 'java/lang/Float', + 'java/lang/Byte', + 'java/lang/Short', + 'java/lang/Character', + 'java/util/ArrayList', + ]; + + for (final className in uniqueClasses) { refs.add(Jni.getCachedClass(className)); } - // Reduce capacity - should evict 7 entries + // Reduce capacity - cache evicts 7 entries Jni.setClassCacheSize(3); - // All caller-owned refs should still be valid + // All cached instances should still be valid for (final ref in refs) { - expect(Jni.env.IsSameObject(ref, ref), isTrue); - } - - // Clean up caller-owned refs - for (final ref in refs) { - Jni.env.DeleteGlobalRef(ref); + expect(ref, isNotNull); } }); - testRunner('JClass.forNameCached uses cache', () { - // Tests that JClass.forNameCached integrates correctly with the cache. - // This validates that the ownership model works through the wrapper API. - + testRunner('JClass.forNameCached uses cache and returns same instance', () { final jclass1 = JClass.forNameCached('java/lang/Object'); final jclass2 = JClass.forNameCached('java/lang/Object'); - // Different Dart objects - expect(identical(jclass1, jclass2), isFalse); + // Same Dart instance from cache + expect(identical(jclass1, jclass2), isTrue); // Same underlying JNI class final ref1 = jclass1.reference; final ref2 = jclass2.reference; expect(Jni.env.IsSameObject(ref1.pointer, ref2.pointer), isTrue); - // JGlobalReference finalizers will clean up when GC'd - jclass1.release(); - jclass2.release(); + // Do NOT release cached instances - cache owns them }); } From 6f4570c6f4cac942424e004e7843bab3a6af217e Mon Sep 17 00:00:00 2001 From: sagar Date: Thu, 29 Jan 2026 15:44:41 +0530 Subject: [PATCH 10/13] fix analyzer issue --- pkgs/jni/lib/src/jni.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkgs/jni/lib/src/jni.dart b/pkgs/jni/lib/src/jni.dart index eca2011ad0..138d98776e 100644 --- a/pkgs/jni/lib/src/jni.dart +++ b/pkgs/jni/lib/src/jni.dart @@ -463,7 +463,6 @@ extension StringMethodsForJni on String { } /// Internal cache entry for JNI class references. -@internal class _JClassCacheEntry { final String name; final JGlobalReference globalRef; @@ -513,7 +512,7 @@ class _JClassCache { void _evict(String name) { final entry = _map.remove(name)!; // Release the GlobalRef; JClass wrapper becomes invalid but that's OK - // since we only hand out cached instances that should not be released by callers. + // since cached instances; callers must not release entry.globalRef.release(); } From 4e34a94996aba92f55a86099cadfd334cff8380f Mon Sep 17 00:00:00 2001 From: sagar Date: Tue, 17 Feb 2026 01:04:41 +0530 Subject: [PATCH 11/13] regenerate all bindings after codegen update and address reviewer feedback --- pkgs/jni/lib/src/jclass.dart | 4 +- pkgs/jni/lib/src/jni.dart | 1 + pkgs/jni/lib/src/jreference.dart | 1 - .../org/apache/pdfbox/pdmodel/PDDocument.dart | 4 +- .../pdfbox/pdmodel/PDDocumentInformation.dart | 4 +- .../apache/pdfbox/text/PDFTextStripper.dart | 4 +- .../lib/src/bindings/dart_generator.dart | 2 +- .../fasterxml/jackson/core/JsonFactory.dart | 8 +- .../fasterxml/jackson/core/JsonParser.dart | 12 +- .../com/fasterxml/jackson/core/JsonToken.dart | 4 +- .../test/kotlin_test/bindings/kotlin.dart | 939 ++++++++++++++++-- .../bindings/simple_package.dart | 128 +-- 12 files changed, 956 insertions(+), 155 deletions(-) diff --git a/pkgs/jni/lib/src/jclass.dart b/pkgs/jni/lib/src/jclass.dart index 09843ef609..1f6feed736 100644 --- a/pkgs/jni/lib/src/jclass.dart +++ b/pkgs/jni/lib/src/jclass.dart @@ -21,8 +21,8 @@ class JClass extends JObject { /// Uses an internal LRU cache to minimize JNI calls and GlobalRef usage. /// Returns the cached instance owned by the cache. /// - /// **Important**: Do NOT call [release] on instances returned by this - /// factory. The cache manages their lifecycle. + /// Do NOT hold a long term reference to the returned [JClass]. The cache + /// manages their lifecycle and may evict it at any time. factory JClass.forNameCached(String name) { return Jni.getCachedClass(name); } diff --git a/pkgs/jni/lib/src/jni.dart b/pkgs/jni/lib/src/jni.dart index 138d98776e..2e8b5d57fd 100644 --- a/pkgs/jni/lib/src/jni.dart +++ b/pkgs/jni/lib/src/jni.dart @@ -457,6 +457,7 @@ extension AdditionalEnvMethods on GlobalJniEnv { @internal extension StringMethodsForJni on String { + /// Returns a Utf-8 encoded `Pointer` with contents same as this string. Pointer toNativeChars(Allocator allocator) { return toNativeUtf8(allocator: allocator).cast(); } diff --git a/pkgs/jni/lib/src/jreference.dart b/pkgs/jni/lib/src/jreference.dart index 7c7eac1022..25c59f5c98 100644 --- a/pkgs/jni/lib/src/jreference.dart +++ b/pkgs/jni/lib/src/jreference.dart @@ -190,4 +190,3 @@ final class _JNullReference extends JReference { @override bool get isNull => true; } - diff --git a/pkgs/jnigen/example/pdfbox_plugin/lib/src/third_party/org/apache/pdfbox/pdmodel/PDDocument.dart b/pkgs/jnigen/example/pdfbox_plugin/lib/src/third_party/org/apache/pdfbox/pdmodel/PDDocument.dart index d10b3730d2..d10d3e0ad4 100644 --- a/pkgs/jnigen/example/pdfbox_plugin/lib/src/third_party/org/apache/pdfbox/pdmodel/PDDocument.dart +++ b/pkgs/jnigen/example/pdfbox_plugin/lib/src/third_party/org/apache/pdfbox/pdmodel/PDDocument.dart @@ -72,8 +72,8 @@ class PDDocument extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = - jni$_.JClass.forName(r'org/apache/pdfbox/pdmodel/PDDocument'); + static jni$_.JClass get _class => + jni$_.JClass.forNameCached(r'org/apache/pdfbox/pdmodel/PDDocument'); /// The type which includes information such as the signature of this class. static const jni$_.JType nullableType = diff --git a/pkgs/jnigen/example/pdfbox_plugin/lib/src/third_party/org/apache/pdfbox/pdmodel/PDDocumentInformation.dart b/pkgs/jnigen/example/pdfbox_plugin/lib/src/third_party/org/apache/pdfbox/pdmodel/PDDocumentInformation.dart index 2023c10520..87c2c63bc2 100644 --- a/pkgs/jnigen/example/pdfbox_plugin/lib/src/third_party/org/apache/pdfbox/pdmodel/PDDocumentInformation.dart +++ b/pkgs/jnigen/example/pdfbox_plugin/lib/src/third_party/org/apache/pdfbox/pdmodel/PDDocumentInformation.dart @@ -72,8 +72,8 @@ class PDDocumentInformation extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = - jni$_.JClass.forName(r'org/apache/pdfbox/pdmodel/PDDocumentInformation'); + static jni$_.JClass get _class => jni$_.JClass.forNameCached( + r'org/apache/pdfbox/pdmodel/PDDocumentInformation'); /// The type which includes information such as the signature of this class. static const jni$_.JType nullableType = diff --git a/pkgs/jnigen/example/pdfbox_plugin/lib/src/third_party/org/apache/pdfbox/text/PDFTextStripper.dart b/pkgs/jnigen/example/pdfbox_plugin/lib/src/third_party/org/apache/pdfbox/text/PDFTextStripper.dart index d261e65c10..62a23b86d1 100644 --- a/pkgs/jnigen/example/pdfbox_plugin/lib/src/third_party/org/apache/pdfbox/text/PDFTextStripper.dart +++ b/pkgs/jnigen/example/pdfbox_plugin/lib/src/third_party/org/apache/pdfbox/text/PDFTextStripper.dart @@ -76,8 +76,8 @@ class PDFTextStripper extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = - jni$_.JClass.forName(r'org/apache/pdfbox/text/PDFTextStripper'); + static jni$_.JClass get _class => + jni$_.JClass.forNameCached(r'org/apache/pdfbox/text/PDFTextStripper'); /// The type which includes information such as the signature of this class. static const jni$_.JType nullableType = diff --git a/pkgs/jnigen/lib/src/bindings/dart_generator.dart b/pkgs/jnigen/lib/src/bindings/dart_generator.dart index bd74629b4e..7f9eb7d00c 100644 --- a/pkgs/jnigen/lib/src/bindings/dart_generator.dart +++ b/pkgs/jnigen/lib/src/bindings/dart_generator.dart @@ -363,7 +363,7 @@ class _ClassGenerator extends Visitor { final modifier = node.isTopLevel ? '' : ' static '; final classRef = node.isTopLevel ? '_${node.finalName}Class' : '_class'; s.write(''' -${modifier}$_jni.JClass get $classRef => $_jni.JClass.forNameCached(r'$internalName'); +$modifier$_jni.JClass get $classRef => $_jni.JClass.forNameCached(r'$internalName'); '''); return classRef; diff --git a/pkgs/jnigen/test/jackson_core_test/third_party/bindings/com/fasterxml/jackson/core/JsonFactory.dart b/pkgs/jnigen/test/jackson_core_test/third_party/bindings/com/fasterxml/jackson/core/JsonFactory.dart index 099396b1c8..1df65fe864 100644 --- a/pkgs/jnigen/test/jackson_core_test/third_party/bindings/com/fasterxml/jackson/core/JsonFactory.dart +++ b/pkgs/jnigen/test/jackson_core_test/third_party/bindings/com/fasterxml/jackson/core/JsonFactory.dart @@ -70,8 +70,8 @@ class JsonFactory$Feature extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = - jni$_.JClass.forName(r'com/fasterxml/jackson/core/JsonFactory$Feature'); + static jni$_.JClass get _class => jni$_.JClass.forNameCached( + r'com/fasterxml/jackson/core/JsonFactory$Feature'); /// The type which includes information such as the signature of this class. static const jni$_.JType nullableType = @@ -431,8 +431,8 @@ class JsonFactory extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = - jni$_.JClass.forName(r'com/fasterxml/jackson/core/JsonFactory'); + static jni$_.JClass get _class => + jni$_.JClass.forNameCached(r'com/fasterxml/jackson/core/JsonFactory'); /// The type which includes information such as the signature of this class. static const jni$_.JType nullableType = diff --git a/pkgs/jnigen/test/jackson_core_test/third_party/bindings/com/fasterxml/jackson/core/JsonParser.dart b/pkgs/jnigen/test/jackson_core_test/third_party/bindings/com/fasterxml/jackson/core/JsonParser.dart index ef413f8833..7e2fc079d1 100644 --- a/pkgs/jnigen/test/jackson_core_test/third_party/bindings/com/fasterxml/jackson/core/JsonParser.dart +++ b/pkgs/jnigen/test/jackson_core_test/third_party/bindings/com/fasterxml/jackson/core/JsonParser.dart @@ -69,8 +69,8 @@ class JsonParser$Feature extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = - jni$_.JClass.forName(r'com/fasterxml/jackson/core/JsonParser$Feature'); + static jni$_.JClass get _class => jni$_.JClass.forNameCached( + r'com/fasterxml/jackson/core/JsonParser$Feature'); /// The type which includes information such as the signature of this class. static const jni$_.JType nullableType = @@ -683,8 +683,8 @@ class JsonParser$NumberType extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = - jni$_.JClass.forName(r'com/fasterxml/jackson/core/JsonParser$NumberType'); + static jni$_.JClass get _class => jni$_.JClass.forNameCached( + r'com/fasterxml/jackson/core/JsonParser$NumberType'); /// The type which includes information such as the signature of this class. static const jni$_.JType nullableType = @@ -902,8 +902,8 @@ class JsonParser extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = - jni$_.JClass.forName(r'com/fasterxml/jackson/core/JsonParser'); + static jni$_.JClass get _class => + jni$_.JClass.forNameCached(r'com/fasterxml/jackson/core/JsonParser'); /// The type which includes information such as the signature of this class. static const jni$_.JType nullableType = diff --git a/pkgs/jnigen/test/jackson_core_test/third_party/bindings/com/fasterxml/jackson/core/JsonToken.dart b/pkgs/jnigen/test/jackson_core_test/third_party/bindings/com/fasterxml/jackson/core/JsonToken.dart index fe88517378..0e2d102321 100644 --- a/pkgs/jnigen/test/jackson_core_test/third_party/bindings/com/fasterxml/jackson/core/JsonToken.dart +++ b/pkgs/jnigen/test/jackson_core_test/third_party/bindings/com/fasterxml/jackson/core/JsonToken.dart @@ -68,8 +68,8 @@ class JsonToken extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = - jni$_.JClass.forName(r'com/fasterxml/jackson/core/JsonToken'); + static jni$_.JClass get _class => + jni$_.JClass.forNameCached(r'com/fasterxml/jackson/core/JsonToken'); /// The type which includes information such as the signature of this class. static const jni$_.JType nullableType = diff --git a/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart b/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart index 735c300f5d..63d023e099 100644 --- a/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart +++ b/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart @@ -40,6 +40,300 @@ import 'dart:core' show Object, String, double, int; import 'package:jni/_internal.dart' as jni$_; import 'package:jni/jni.dart' as jni$_; +/// from: `com.github.dart_lang.jnigen.AllDefaults` +class AllDefaults extends jni$_.JObject { + @jni$_.internal + @core$_.override + final jni$_.JType $type; + + @jni$_.internal + AllDefaults.fromReference( + jni$_.JReference reference, + ) : $type = type, + super.fromReference(reference); + + static jni$_.JClass get _class => + jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/AllDefaults'); + + /// The type which includes information such as the signature of this class. + static const jni$_.JType nullableType = + $AllDefaults$NullableType$(); + + /// The type which includes information such as the signature of this class. + static const jni$_.JType type = $AllDefaults$Type$(); + static final _id_new$ = _class.constructorId( + r'(ILjava/lang/String;Z)V', + ); + + static final _new$ = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + jni$_.VarArgs< + ( + jni$_.Int32, + jni$_.Pointer, + jni$_.Int32 + )>)>>('globalEnv_NewObject') + .asFunction< + jni$_.JniResult Function(jni$_.Pointer, + jni$_.JMethodIDPtr, int, jni$_.Pointer, int)>(); + + /// from: `public void (int i, java.lang.String string, boolean z)` + /// The returned object must be released after use, by calling the [release] method. + factory AllDefaults( + int i, + jni$_.JString string, + core$_.bool z, + ) { + final _$string = string.reference; + return AllDefaults.fromReference(_new$(_class.reference.pointer, + _id_new$ as jni$_.JMethodIDPtr, i, _$string.pointer, z ? 1 : 0) + .reference); + } + + static final _id_new$1 = _class.constructorId( + r'(ILjava/lang/String;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V', + ); + + static final _new$1 = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + jni$_.VarArgs< + ( + jni$_.Int32, + jni$_.Pointer, + jni$_.Int32, + jni$_.Int32, + jni$_.Pointer + )>)>>('globalEnv_NewObject') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + int, + jni$_.Pointer, + int, + int, + jni$_.Pointer)>(); + + /// from: `synthetic public void (int i, java.lang.String string, boolean z, int i1, kotlin.jvm.internal.DefaultConstructorMarker defaultConstructorMarker)` + /// The returned object must be released after use, by calling the [release] method. + factory AllDefaults.new$1( + int i, + jni$_.JString? string, + core$_.bool z, + int i1, + jni$_.JObject? defaultConstructorMarker, + ) { + final _$string = string?.reference ?? jni$_.jNullReference; + final _$defaultConstructorMarker = + defaultConstructorMarker?.reference ?? jni$_.jNullReference; + return AllDefaults.fromReference(_new$1( + _class.reference.pointer, + _id_new$1 as jni$_.JMethodIDPtr, + i, + _$string.pointer, + z ? 1 : 0, + i1, + _$defaultConstructorMarker.pointer) + .reference); + } + + static final _id_getA = _class.instanceMethodId( + r'getA', + r'()I', + ); + + static final _getA = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>>('globalEnv_CallIntMethod') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>(); + + /// from: `public final int getA()` + int getA() { + return _getA(reference.pointer, _id_getA as jni$_.JMethodIDPtr).integer; + } + + static final _id_getB = _class.instanceMethodId( + r'getB', + r'()Ljava/lang/String;', + ); + + static final _getB = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>>('globalEnv_CallObjectMethod') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>(); + + /// from: `public final java.lang.String getB()` + /// The returned object must be released after use, by calling the [release] method. + jni$_.JString getB() { + return _getB(reference.pointer, _id_getB as jni$_.JMethodIDPtr) + .object(const jni$_.$JString$Type$()); + } + + static final _id_getC = _class.instanceMethodId( + r'getC', + r'()Z', + ); + + static final _getC = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>>('globalEnv_CallBooleanMethod') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>(); + + /// from: `public final boolean getC()` + core$_.bool getC() { + return _getC(reference.pointer, _id_getC as jni$_.JMethodIDPtr).boolean; + } + + static final _id_summary = _class.instanceMethodId( + r'summary', + r'()Ljava/lang/String;', + ); + + static final _summary = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>>('globalEnv_CallObjectMethod') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>(); + + /// from: `public fun summary(): kotlin.String` + /// The returned object must be released after use, by calling the [release] method. + jni$_.JString summary() { + return _summary(reference.pointer, _id_summary as jni$_.JMethodIDPtr) + .object(const jni$_.$JString$Type$()); + } + + static final _id_new$2 = _class.constructorId( + r'()V', + ); + + static final _new$2 = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>>('globalEnv_NewObject') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>(); + + /// from: `public void ()` + /// The returned object must be released after use, by calling the [release] method. + factory AllDefaults.new$2() { + return AllDefaults.fromReference( + _new$2(_class.reference.pointer, _id_new$2 as jni$_.JMethodIDPtr) + .reference); + } +} + +final class $AllDefaults$NullableType$ extends jni$_.JType { + @jni$_.internal + const $AllDefaults$NullableType$(); + + @jni$_.internal + @core$_.override + String get signature => r'Lcom/github/dart_lang/jnigen/AllDefaults;'; + + @jni$_.internal + @core$_.override + AllDefaults? fromReference(jni$_.JReference reference) => reference.isNull + ? null + : AllDefaults.fromReference( + reference, + ); + @jni$_.internal + @core$_.override + jni$_.JType get superType => const jni$_.$JObject$Type$(); + + @jni$_.internal + @core$_.override + jni$_.JType get nullableType => this; + + @jni$_.internal + @core$_.override + final superCount = 1; + + @core$_.override + int get hashCode => ($AllDefaults$NullableType$).hashCode; + + @core$_.override + core$_.bool operator ==(Object other) { + return other.runtimeType == ($AllDefaults$NullableType$) && + other is $AllDefaults$NullableType$; + } +} + +final class $AllDefaults$Type$ extends jni$_.JType { + @jni$_.internal + const $AllDefaults$Type$(); + + @jni$_.internal + @core$_.override + String get signature => r'Lcom/github/dart_lang/jnigen/AllDefaults;'; + + @jni$_.internal + @core$_.override + AllDefaults fromReference(jni$_.JReference reference) => + AllDefaults.fromReference( + reference, + ); + @jni$_.internal + @core$_.override + jni$_.JType get superType => const jni$_.$JObject$Type$(); + + @jni$_.internal + @core$_.override + jni$_.JType get nullableType => + const $AllDefaults$NullableType$(); + + @jni$_.internal + @core$_.override + final superCount = 1; + + @core$_.override + int get hashCode => ($AllDefaults$Type$).hashCode; + + @core$_.override + core$_.bool operator ==(Object other) { + return other.runtimeType == ($AllDefaults$Type$) && + other is $AllDefaults$Type$; + } +} + /// from: `com.github.dart_lang.jnigen.CanDoA` class CanDoA extends jni$_.JObject { @jni$_.internal @@ -52,8 +346,8 @@ class CanDoA extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = - jni$_.JClass.forName(r'com/github/dart_lang/jnigen/CanDoA'); + static jni$_.JClass get _class => + jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/CanDoA'); /// The type which includes information such as the signature of this class. static const jni$_.JType nullableType = $CanDoA$NullableType$(); @@ -267,8 +561,8 @@ class CanDoB extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = - jni$_.JClass.forName(r'com/github/dart_lang/jnigen/CanDoB'); + static jni$_.JClass get _class => + jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/CanDoB'); /// The type which includes information such as the signature of this class. static const jni$_.JType nullableType = $CanDoB$NullableType$(); @@ -364,54 +658,315 @@ class CanDoB extends jni$_.JObject { _$impls[$a] = $impl; } - factory CanDoB.implement( - $CanDoB $impl, - ) { - final $i = jni$_.JImplementer(); - implementIn($i, $impl); - return CanDoB.fromReference( - $i.implementReference(), - ); + factory CanDoB.implement( + $CanDoB $impl, + ) { + final $i = jni$_.JImplementer(); + implementIn($i, $impl); + return CanDoB.fromReference( + $i.implementReference(), + ); + } +} + +abstract base mixin class $CanDoB { + factory $CanDoB({ + required void Function() doB, + core$_.bool doB$async, + }) = _$CanDoB; + + void doB(); + core$_.bool get doB$async => false; +} + +final class _$CanDoB with $CanDoB { + _$CanDoB({ + required void Function() doB, + this.doB$async = false, + }) : _doB = doB; + + final void Function() _doB; + final core$_.bool doB$async; + + void doB() { + return _doB(); + } +} + +final class $CanDoB$NullableType$ extends jni$_.JType { + @jni$_.internal + const $CanDoB$NullableType$(); + + @jni$_.internal + @core$_.override + String get signature => r'Lcom/github/dart_lang/jnigen/CanDoB;'; + + @jni$_.internal + @core$_.override + CanDoB? fromReference(jni$_.JReference reference) => reference.isNull + ? null + : CanDoB.fromReference( + reference, + ); + @jni$_.internal + @core$_.override + jni$_.JType get superType => const jni$_.$JObject$Type$(); + + @jni$_.internal + @core$_.override + jni$_.JType get nullableType => this; + + @jni$_.internal + @core$_.override + final superCount = 1; + + @core$_.override + int get hashCode => ($CanDoB$NullableType$).hashCode; + + @core$_.override + core$_.bool operator ==(Object other) { + return other.runtimeType == ($CanDoB$NullableType$) && + other is $CanDoB$NullableType$; + } +} + +final class $CanDoB$Type$ extends jni$_.JType { + @jni$_.internal + const $CanDoB$Type$(); + + @jni$_.internal + @core$_.override + String get signature => r'Lcom/github/dart_lang/jnigen/CanDoB;'; + + @jni$_.internal + @core$_.override + CanDoB fromReference(jni$_.JReference reference) => CanDoB.fromReference( + reference, + ); + @jni$_.internal + @core$_.override + jni$_.JType get superType => const jni$_.$JObject$Type$(); + + @jni$_.internal + @core$_.override + jni$_.JType get nullableType => const $CanDoB$NullableType$(); + + @jni$_.internal + @core$_.override + final superCount = 1; + + @core$_.override + int get hashCode => ($CanDoB$Type$).hashCode; + + @core$_.override + core$_.bool operator ==(Object other) { + return other.runtimeType == ($CanDoB$Type$) && other is $CanDoB$Type$; + } +} + +/// from: `com.github.dart_lang.jnigen.DefaultParams` +class DefaultParams extends jni$_.JObject { + @jni$_.internal + @core$_.override + final jni$_.JType $type; + + @jni$_.internal + DefaultParams.fromReference( + jni$_.JReference reference, + ) : $type = type, + super.fromReference(reference); + + static jni$_.JClass get _class => + jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/DefaultParams'); + + /// The type which includes information such as the signature of this class. + static const jni$_.JType nullableType = + $DefaultParams$NullableType$(); + + /// The type which includes information such as the signature of this class. + static const jni$_.JType type = $DefaultParams$Type$(); + static final _id_new$ = _class.constructorId( + r'(ILjava/lang/String;)V', + ); + + static final _new$ = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + jni$_ + .VarArgs<(jni$_.Int32, jni$_.Pointer)>)>>( + 'globalEnv_NewObject') + .asFunction< + jni$_.JniResult Function(jni$_.Pointer, + jni$_.JMethodIDPtr, int, jni$_.Pointer)>(); + + /// from: `public void (int i, java.lang.String string)` + /// The returned object must be released after use, by calling the [release] method. + factory DefaultParams( + int i, + jni$_.JString string, + ) { + final _$string = string.reference; + return DefaultParams.fromReference(_new$(_class.reference.pointer, + _id_new$ as jni$_.JMethodIDPtr, i, _$string.pointer) + .reference); + } + + static final _id_new$1 = _class.constructorId( + r'(ILjava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V', + ); + + static final _new$1 = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + jni$_.VarArgs< + ( + jni$_.Int32, + jni$_.Pointer, + jni$_.Int32, + jni$_.Pointer + )>)>>('globalEnv_NewObject') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + int, + jni$_.Pointer, + int, + jni$_.Pointer)>(); + + /// from: `synthetic public void (int i, java.lang.String string, int i1, kotlin.jvm.internal.DefaultConstructorMarker defaultConstructorMarker)` + /// The returned object must be released after use, by calling the [release] method. + factory DefaultParams.new$1( + int i, + jni$_.JString? string, + int i1, + jni$_.JObject? defaultConstructorMarker, + ) { + final _$string = string?.reference ?? jni$_.jNullReference; + final _$defaultConstructorMarker = + defaultConstructorMarker?.reference ?? jni$_.jNullReference; + return DefaultParams.fromReference(_new$1( + _class.reference.pointer, + _id_new$1 as jni$_.JMethodIDPtr, + i, + _$string.pointer, + i1, + _$defaultConstructorMarker.pointer) + .reference); + } + + static final _id_getX = _class.instanceMethodId( + r'getX', + r'()I', + ); + + static final _getX = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>>('globalEnv_CallIntMethod') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>(); + + /// from: `public final int getX()` + int getX() { + return _getX(reference.pointer, _id_getX as jni$_.JMethodIDPtr).integer; + } + + static final _id_getY = _class.instanceMethodId( + r'getY', + r'()Ljava/lang/String;', + ); + + static final _getY = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>>('globalEnv_CallObjectMethod') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>(); + + /// from: `public final java.lang.String getY()` + /// The returned object must be released after use, by calling the [release] method. + jni$_.JString getY() { + return _getY(reference.pointer, _id_getY as jni$_.JMethodIDPtr) + .object(const jni$_.$JString$Type$()); } -} -abstract base mixin class $CanDoB { - factory $CanDoB({ - required void Function() doB, - core$_.bool doB$async, - }) = _$CanDoB; + static final _id_greet = _class.instanceMethodId( + r'greet', + r'()Ljava/lang/String;', + ); - void doB(); - core$_.bool get doB$async => false; -} + static final _greet = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>>('globalEnv_CallObjectMethod') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>(); -final class _$CanDoB with $CanDoB { - _$CanDoB({ - required void Function() doB, - this.doB$async = false, - }) : _doB = doB; + /// from: `public fun greet(): kotlin.String` + /// The returned object must be released after use, by calling the [release] method. + jni$_.JString greet() { + return _greet(reference.pointer, _id_greet as jni$_.JMethodIDPtr) + .object(const jni$_.$JString$Type$()); + } - final void Function() _doB; - final core$_.bool doB$async; + static final _id_new$2 = _class.constructorId( + r'()V', + ); - void doB() { - return _doB(); + static final _new$2 = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>>('globalEnv_NewObject') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>(); + + /// from: `public void ()` + /// The returned object must be released after use, by calling the [release] method. + factory DefaultParams.new$2() { + return DefaultParams.fromReference( + _new$2(_class.reference.pointer, _id_new$2 as jni$_.JMethodIDPtr) + .reference); } } -final class $CanDoB$NullableType$ extends jni$_.JType { +final class $DefaultParams$NullableType$ extends jni$_.JType { @jni$_.internal - const $CanDoB$NullableType$(); + const $DefaultParams$NullableType$(); @jni$_.internal @core$_.override - String get signature => r'Lcom/github/dart_lang/jnigen/CanDoB;'; + String get signature => r'Lcom/github/dart_lang/jnigen/DefaultParams;'; @jni$_.internal @core$_.override - CanDoB? fromReference(jni$_.JReference reference) => reference.isNull + DefaultParams? fromReference(jni$_.JReference reference) => reference.isNull ? null - : CanDoB.fromReference( + : DefaultParams.fromReference( reference, ); @jni$_.internal @@ -420,33 +975,34 @@ final class $CanDoB$NullableType$ extends jni$_.JType { @jni$_.internal @core$_.override - jni$_.JType get nullableType => this; + jni$_.JType get nullableType => this; @jni$_.internal @core$_.override final superCount = 1; @core$_.override - int get hashCode => ($CanDoB$NullableType$).hashCode; + int get hashCode => ($DefaultParams$NullableType$).hashCode; @core$_.override core$_.bool operator ==(Object other) { - return other.runtimeType == ($CanDoB$NullableType$) && - other is $CanDoB$NullableType$; + return other.runtimeType == ($DefaultParams$NullableType$) && + other is $DefaultParams$NullableType$; } } -final class $CanDoB$Type$ extends jni$_.JType { +final class $DefaultParams$Type$ extends jni$_.JType { @jni$_.internal - const $CanDoB$Type$(); + const $DefaultParams$Type$(); @jni$_.internal @core$_.override - String get signature => r'Lcom/github/dart_lang/jnigen/CanDoB;'; + String get signature => r'Lcom/github/dart_lang/jnigen/DefaultParams;'; @jni$_.internal @core$_.override - CanDoB fromReference(jni$_.JReference reference) => CanDoB.fromReference( + DefaultParams fromReference(jni$_.JReference reference) => + DefaultParams.fromReference( reference, ); @jni$_.internal @@ -455,18 +1011,20 @@ final class $CanDoB$Type$ extends jni$_.JType { @jni$_.internal @core$_.override - jni$_.JType get nullableType => const $CanDoB$NullableType$(); + jni$_.JType get nullableType => + const $DefaultParams$NullableType$(); @jni$_.internal @core$_.override final superCount = 1; @core$_.override - int get hashCode => ($CanDoB$Type$).hashCode; + int get hashCode => ($DefaultParams$Type$).hashCode; @core$_.override core$_.bool operator ==(Object other) { - return other.runtimeType == ($CanDoB$Type$) && other is $CanDoB$Type$; + return other.runtimeType == ($DefaultParams$Type$) && + other is $DefaultParams$Type$; } } @@ -486,8 +1044,8 @@ class Measure<$T extends jni$_.JObject> extends jni$_.JObject { ) : $type = type<$T>(T), super.fromReference(reference); - static final _class = - jni$_.JClass.forName(r'com/github/dart_lang/jnigen/Measure'); + static jni$_.JClass get _class => + jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/Measure'); /// The type which includes information such as the signature of this class. static jni$_.JType?> nullableType<$T extends jni$_.JObject>( @@ -682,8 +1240,8 @@ class MeasureUnit extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = - jni$_.JClass.forName(r'com/github/dart_lang/jnigen/MeasureUnit'); + static jni$_.JClass get _class => + jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/MeasureUnit'); /// The type which includes information such as the signature of this class. static const jni$_.JType nullableType = @@ -926,6 +1484,249 @@ final class $MeasureUnit$Type$ extends jni$_.JType { } } +/// from: `com.github.dart_lang.jnigen.MixedParams` +class MixedParams extends jni$_.JObject { + @jni$_.internal + @core$_.override + final jni$_.JType $type; + + @jni$_.internal + MixedParams.fromReference( + jni$_.JReference reference, + ) : $type = type, + super.fromReference(reference); + + static jni$_.JClass get _class => + jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/MixedParams'); + + /// The type which includes information such as the signature of this class. + static const jni$_.JType nullableType = + $MixedParams$NullableType$(); + + /// The type which includes information such as the signature of this class. + static const jni$_.JType type = $MixedParams$Type$(); + static final _id_new$ = _class.constructorId( + r'(Ljava/lang/String;I)V', + ); + + static final _new$ = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + jni$_ + .VarArgs<(jni$_.Pointer, jni$_.Int32)>)>>( + 'globalEnv_NewObject') + .asFunction< + jni$_.JniResult Function(jni$_.Pointer, + jni$_.JMethodIDPtr, jni$_.Pointer, int)>(); + + /// from: `public void (java.lang.String string, int i)` + /// The returned object must be released after use, by calling the [release] method. + factory MixedParams( + jni$_.JString string, + int i, + ) { + final _$string = string.reference; + return MixedParams.fromReference(_new$(_class.reference.pointer, + _id_new$ as jni$_.JMethodIDPtr, _$string.pointer, i) + .reference); + } + + static final _id_new$1 = _class.constructorId( + r'(Ljava/lang/String;IILkotlin/jvm/internal/DefaultConstructorMarker;)V', + ); + + static final _new$1 = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + jni$_.VarArgs< + ( + jni$_.Pointer, + jni$_.Int32, + jni$_.Int32, + jni$_.Pointer + )>)>>('globalEnv_NewObject') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + jni$_.Pointer, + int, + int, + jni$_.Pointer)>(); + + /// from: `synthetic public void (java.lang.String string, int i, int i1, kotlin.jvm.internal.DefaultConstructorMarker defaultConstructorMarker)` + /// The returned object must be released after use, by calling the [release] method. + factory MixedParams.new$1( + jni$_.JString? string, + int i, + int i1, + jni$_.JObject? defaultConstructorMarker, + ) { + final _$string = string?.reference ?? jni$_.jNullReference; + final _$defaultConstructorMarker = + defaultConstructorMarker?.reference ?? jni$_.jNullReference; + return MixedParams.fromReference(_new$1( + _class.reference.pointer, + _id_new$1 as jni$_.JMethodIDPtr, + _$string.pointer, + i, + i1, + _$defaultConstructorMarker.pointer) + .reference); + } + + static final _id_getRequired = _class.instanceMethodId( + r'getRequired', + r'()Ljava/lang/String;', + ); + + static final _getRequired = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>>('globalEnv_CallObjectMethod') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>(); + + /// from: `public final java.lang.String getRequired()` + /// The returned object must be released after use, by calling the [release] method. + jni$_.JString getRequired() { + return _getRequired( + reference.pointer, _id_getRequired as jni$_.JMethodIDPtr) + .object(const jni$_.$JString$Type$()); + } + + static final _id_getOptional = _class.instanceMethodId( + r'getOptional', + r'()I', + ); + + static final _getOptional = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>>('globalEnv_CallIntMethod') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>(); + + /// from: `public final int getOptional()` + int getOptional() { + return _getOptional( + reference.pointer, _id_getOptional as jni$_.JMethodIDPtr) + .integer; + } + + static final _id_describe = _class.instanceMethodId( + r'describe', + r'()Ljava/lang/String;', + ); + + static final _describe = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>>('globalEnv_CallObjectMethod') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>(); + + /// from: `public fun describe(): kotlin.String` + /// The returned object must be released after use, by calling the [release] method. + jni$_.JString describe() { + return _describe(reference.pointer, _id_describe as jni$_.JMethodIDPtr) + .object(const jni$_.$JString$Type$()); + } +} + +final class $MixedParams$NullableType$ extends jni$_.JType { + @jni$_.internal + const $MixedParams$NullableType$(); + + @jni$_.internal + @core$_.override + String get signature => r'Lcom/github/dart_lang/jnigen/MixedParams;'; + + @jni$_.internal + @core$_.override + MixedParams? fromReference(jni$_.JReference reference) => reference.isNull + ? null + : MixedParams.fromReference( + reference, + ); + @jni$_.internal + @core$_.override + jni$_.JType get superType => const jni$_.$JObject$Type$(); + + @jni$_.internal + @core$_.override + jni$_.JType get nullableType => this; + + @jni$_.internal + @core$_.override + final superCount = 1; + + @core$_.override + int get hashCode => ($MixedParams$NullableType$).hashCode; + + @core$_.override + core$_.bool operator ==(Object other) { + return other.runtimeType == ($MixedParams$NullableType$) && + other is $MixedParams$NullableType$; + } +} + +final class $MixedParams$Type$ extends jni$_.JType { + @jni$_.internal + const $MixedParams$Type$(); + + @jni$_.internal + @core$_.override + String get signature => r'Lcom/github/dart_lang/jnigen/MixedParams;'; + + @jni$_.internal + @core$_.override + MixedParams fromReference(jni$_.JReference reference) => + MixedParams.fromReference( + reference, + ); + @jni$_.internal + @core$_.override + jni$_.JType get superType => const jni$_.$JObject$Type$(); + + @jni$_.internal + @core$_.override + jni$_.JType get nullableType => + const $MixedParams$NullableType$(); + + @jni$_.internal + @core$_.override + final superCount = 1; + + @core$_.override + int get hashCode => ($MixedParams$Type$).hashCode; + + @core$_.override + core$_.bool operator ==(Object other) { + return other.runtimeType == ($MixedParams$Type$) && + other is $MixedParams$Type$; + } +} + /// from: `com.github.dart_lang.jnigen.Nullability$InnerClass` class Nullability$InnerClass<$T extends jni$_.JObject?, $U extends jni$_.JObject, $V extends jni$_.JObject?> extends jni$_.JObject { @@ -951,7 +1752,7 @@ class Nullability$InnerClass<$T extends jni$_.JObject?, ) : $type = type<$T, $U, $V>(T, U, V), super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/Nullability$InnerClass'); /// The type which includes information such as the signature of this class. @@ -1210,8 +2011,8 @@ class Nullability<$T extends jni$_.JObject?, $U extends jni$_.JObject> ) : $type = type<$T, $U>(T, U), super.fromReference(reference); - static final _class = - jni$_.JClass.forName(r'com/github/dart_lang/jnigen/Nullability'); + static jni$_.JClass get _class => + jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/Nullability'); /// The type which includes information such as the signature of this class. static jni$_.JType?> @@ -2124,8 +2925,8 @@ class Operators extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = - jni$_.JClass.forName(r'com/github/dart_lang/jnigen/Operators'); + static jni$_.JClass get _class => + jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/Operators'); /// The type which includes information such as the signature of this class. static const jni$_.JType nullableType = @@ -2564,8 +3365,8 @@ class Speed extends Measure { ) : $type = type, super.fromReference(const $SpeedUnit$Type$(), reference); - static final _class = - jni$_.JClass.forName(r'com/github/dart_lang/jnigen/Speed'); + static jni$_.JClass get _class => + jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/Speed'); /// The type which includes information such as the signature of this class. static const jni$_.JType nullableType = $Speed$NullableType$(); @@ -2886,8 +3687,8 @@ class SpeedUnit extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = - jni$_.JClass.forName(r'com/github/dart_lang/jnigen/SpeedUnit'); + static jni$_.JClass get _class => + jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/SpeedUnit'); /// The type which includes information such as the signature of this class. static const jni$_.JType nullableType = @@ -3101,8 +3902,8 @@ class SuspendFun extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = - jni$_.JClass.forName(r'com/github/dart_lang/jnigen/SuspendFun'); + static jni$_.JClass get _class => + jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/SuspendFun'); /// The type which includes information such as the signature of this class. static const jni$_.JType nullableType = @@ -3673,8 +4474,8 @@ final class $SuspendFun$Type$ extends jni$_.JType { } } -final _SuspendFunKtClass = - jni$_.JClass.forName(r'com/github/dart_lang/jnigen/SuspendFunKt'); +jni$_.JClass get _SuspendFunKtClass => + jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/SuspendFunKt'); final _id_consumeOnAnotherThread = _SuspendFunKtClass.staticMethodId( r'consumeOnAnotherThread', @@ -3802,8 +4603,8 @@ class SuspendInterface extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = - jni$_.JClass.forName(r'com/github/dart_lang/jnigen/SuspendInterface'); + static jni$_.JClass get _class => jni$_.JClass.forNameCached( + r'com/github/dart_lang/jnigen/SuspendInterface'); /// The type which includes information such as the signature of this class. static const jni$_.JType nullableType = @@ -4510,8 +5311,8 @@ final class $SuspendInterface$Type$ extends jni$_.JType { } } -final _TopLevelKtClass = - jni$_.JClass.forName(r'com/github/dart_lang/jnigen/TopLevelKt'); +jni$_.JClass get _TopLevelKtClass => + jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/TopLevelKt'); final _id_getTopLevelField = _TopLevelKtClass.staticMethodId( r'getTopLevelField', @@ -4610,8 +5411,8 @@ int topLevelSum( .integer; } -final _TopLevelKt$1Class = - jni$_.JClass.forName(r'com/github/dart_lang/jnigen/subpackage/TopLevelKt'); +jni$_.JClass get _TopLevelKt$1Class => jni$_.JClass.forNameCached( + r'com/github/dart_lang/jnigen/subpackage/TopLevelKt'); final _id_getTopLevelField$1 = _TopLevelKt$1Class.staticMethodId( r'getTopLevelField', diff --git a/pkgs/jnigen/test/simple_package_test/bindings/simple_package.dart b/pkgs/jnigen/test/simple_package_test/bindings/simple_package.dart index 8397115e89..8924d6984c 100644 --- a/pkgs/jnigen/test/simple_package_test/bindings/simple_package.dart +++ b/pkgs/jnigen/test/simple_package_test/bindings/simple_package.dart @@ -52,7 +52,7 @@ class Example$Nested$NestedTwice extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/simple_package/Example$Nested$NestedTwice'); /// The type which includes information such as the signature of this class. @@ -190,7 +190,7 @@ class Example$Nested extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/simple_package/Example$Nested'); /// The type which includes information such as the signature of this class. @@ -382,7 +382,7 @@ class Example$NonStaticNested extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/simple_package/Example$NonStaticNested'); /// The type which includes information such as the signature of this class. @@ -522,7 +522,7 @@ class Example extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/simple_package/Example'); /// The type which includes information such as the signature of this class. @@ -1855,7 +1855,7 @@ class Exceptions extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/simple_package/Exceptions'); /// The type which includes information such as the signature of this class. @@ -2386,7 +2386,7 @@ class Fields$Nested extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/simple_package/Fields$Nested'); /// The type which includes information such as the signature of this class. @@ -2535,7 +2535,7 @@ class Fields extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/simple_package/Fields'); /// The type which includes information such as the signature of this class. @@ -2787,8 +2787,8 @@ class C2 extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = - jni$_.JClass.forName(r'com/github/dart_lang/jnigen/pkg2/C2'); + static jni$_.JClass get _class => + jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/pkg2/C2'); /// The type which includes information such as the signature of this class. static const jni$_.JType nullableType = $C2$NullableType$(); @@ -2915,8 +2915,8 @@ class Example$1 extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = - jni$_.JClass.forName(r'com/github/dart_lang/jnigen/pkg2/Example'); + static jni$_.JClass get _class => + jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/pkg2/Example'); /// The type which includes information such as the signature of this class. static const jni$_.JType nullableType = @@ -3057,8 +3057,8 @@ class Colors$RGB extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = - jni$_.JClass.forName(r'com/github/dart_lang/jnigen/enums/Colors$RGB'); + static jni$_.JClass get _class => jni$_.JClass.forNameCached( + r'com/github/dart_lang/jnigen/enums/Colors$RGB'); /// The type which includes information such as the signature of this class. static const jni$_.JType nullableType = @@ -3262,8 +3262,8 @@ class Colors extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = - jni$_.JClass.forName(r'com/github/dart_lang/jnigen/enums/Colors'); + static jni$_.JClass get _class => + jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/enums/Colors'); /// The type which includes information such as the signature of this class. static const jni$_.JType nullableType = $Colors$NullableType$(); @@ -3475,7 +3475,7 @@ class GenericTypeParams<$S extends jni$_.JObject?, $K extends jni$_.JObject?> ) : $type = type<$S, $K>(S, K), super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/generics/GenericTypeParams'); /// The type which includes information such as the signature of this class. @@ -3664,7 +3664,7 @@ class GrandParent$Parent$Child< ) : $type = type<$T, $S, $U>(T, S, U), super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/generics/GrandParent$Parent$Child'); /// The type which includes information such as the signature of this class. @@ -3936,7 +3936,7 @@ class GrandParent$Parent<$T extends jni$_.JObject?, $S extends jni$_.JObject?> ) : $type = type<$T, $S>(T, S), super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/generics/GrandParent$Parent'); /// The type which includes information such as the signature of this class. @@ -4160,7 +4160,7 @@ class GrandParent$StaticParent$Child<$S extends jni$_.JObject?, ) : $type = type<$S, $U>(S, U), super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/generics/GrandParent$StaticParent$Child'); /// The type which includes information such as the signature of this class. @@ -4390,7 +4390,7 @@ class GrandParent$StaticParent<$S extends jni$_.JObject?> ) : $type = type<$S>(S), super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/generics/GrandParent$StaticParent'); /// The type which includes information such as the signature of this class. @@ -4565,8 +4565,8 @@ class GrandParent<$T extends jni$_.JObject?> extends jni$_.JObject { ) : $type = type<$T>(T), super.fromReference(reference); - static final _class = - jni$_.JClass.forName(r'com/github/dart_lang/jnigen/generics/GrandParent'); + static jni$_.JClass get _class => jni$_.JClass.forNameCached( + r'com/github/dart_lang/jnigen/generics/GrandParent'); /// The type which includes information such as the signature of this class. static jni$_.JType?> nullableType<$T extends jni$_.JObject?>( @@ -4880,7 +4880,7 @@ class MyMap$MyEntry<$K extends jni$_.JObject?, $V extends jni$_.JObject?> ) : $type = type<$K, $V>(K, V), super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/generics/MyMap$MyEntry'); /// The type which includes information such as the signature of this class. @@ -5109,8 +5109,8 @@ class MyMap<$K extends jni$_.JObject?, $V extends jni$_.JObject?> ) : $type = type<$K, $V>(K, V), super.fromReference(reference); - static final _class = - jni$_.JClass.forName(r'com/github/dart_lang/jnigen/generics/MyMap'); + static jni$_.JClass get _class => + jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/generics/MyMap'); /// The type which includes information such as the signature of this class. static jni$_.JType?> @@ -5373,8 +5373,8 @@ class MyStack<$T extends jni$_.JObject?> extends jni$_.JObject { ) : $type = type<$T>(T), super.fromReference(reference); - static final _class = - jni$_.JClass.forName(r'com/github/dart_lang/jnigen/generics/MyStack'); + static jni$_.JClass get _class => jni$_.JClass.forNameCached( + r'com/github/dart_lang/jnigen/generics/MyStack'); /// The type which includes information such as the signature of this class. static jni$_.JType?> nullableType<$T extends jni$_.JObject?>( @@ -5750,7 +5750,7 @@ class StringKeyedMap<$V extends jni$_.JObject?> super.fromReference( const jni$_.$JString$NullableType$(), V.nullableType, reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/generics/StringKeyedMap'); /// The type which includes information such as the signature of this class. @@ -5907,8 +5907,8 @@ class StringMap extends StringKeyedMap { ) : $type = type, super.fromReference(const jni$_.$JString$NullableType$(), reference); - static final _class = - jni$_.JClass.forName(r'com/github/dart_lang/jnigen/generics/StringMap'); + static jni$_.JClass get _class => jni$_.JClass.forNameCached( + r'com/github/dart_lang/jnigen/generics/StringMap'); /// The type which includes information such as the signature of this class. static const jni$_.JType nullableType = @@ -6029,8 +6029,8 @@ class StringStack extends MyStack { ) : $type = type, super.fromReference(const jni$_.$JString$NullableType$(), reference); - static final _class = - jni$_.JClass.forName(r'com/github/dart_lang/jnigen/generics/StringStack'); + static jni$_.JClass get _class => jni$_.JClass.forNameCached( + r'com/github/dart_lang/jnigen/generics/StringStack'); /// The type which includes information such as the signature of this class. static const jni$_.JType nullableType = @@ -6157,7 +6157,7 @@ class StringValuedMap<$K extends jni$_.JObject?> super.fromReference( K.nullableType, const jni$_.$JString$NullableType$(), reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/generics/StringValuedMap'); /// The type which includes information such as the signature of this class. @@ -6318,7 +6318,7 @@ class GenericInterface<$T extends jni$_.JObject?> extends jni$_.JObject { ) : $type = type<$T>(T), super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/interfaces/GenericInterface'); /// The type which includes information such as the signature of this class. @@ -6911,7 +6911,7 @@ class InheritedFromMyInterface extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/interfaces/InheritedFromMyInterface'); /// The type which includes information such as the signature of this class. @@ -7293,7 +7293,7 @@ class InheritedFromMyRunnable extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/interfaces/InheritedFromMyRunnable'); /// The type which includes information such as the signature of this class. @@ -7522,7 +7522,7 @@ class MyInterface<$T extends jni$_.JObject?> extends jni$_.JObject { ) : $type = type<$T>(T), super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/interfaces/MyInterface'); /// The type which includes information such as the signature of this class. @@ -7937,7 +7937,7 @@ class MyInterfaceConsumer extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/interfaces/MyInterfaceConsumer'); /// The type which includes information such as the signature of this class. @@ -8181,7 +8181,7 @@ class MyRunnable extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/interfaces/MyRunnable'); /// The type which includes information such as the signature of this class. @@ -8403,7 +8403,7 @@ class MyRunnableRunner extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/interfaces/MyRunnableRunner'); /// The type which includes information such as the signature of this class. @@ -8616,7 +8616,7 @@ class StringConversionException extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/interfaces/StringConversionException'); /// The type which includes information such as the signature of this class. @@ -8746,7 +8746,7 @@ class StringConverter extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/interfaces/StringConverter'); /// The type which includes information such as the signature of this class. @@ -8968,7 +8968,7 @@ class StringConverterConsumer extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/interfaces/StringConverterConsumer'); /// The type which includes information such as the signature of this class. @@ -9176,7 +9176,7 @@ class BaseClass<$T extends jni$_.JObject?> extends jni$_.JObject { ) : $type = type<$T>(T), super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/inheritance/BaseClass'); /// The type which includes information such as the signature of this class. @@ -9333,7 +9333,7 @@ class BaseGenericInterface<$T extends jni$_.JObject?> extends jni$_.JObject { ) : $type = type<$T>(T), super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/inheritance/BaseGenericInterface'); /// The type which includes information such as the signature of this class. @@ -9593,7 +9593,7 @@ class BaseInterface extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/inheritance/BaseInterface'); /// The type which includes information such as the signature of this class. @@ -9814,7 +9814,7 @@ class DerivedInterface extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/inheritance/DerivedInterface'); /// The type which includes information such as the signature of this class. @@ -10041,7 +10041,7 @@ class GenericDerivedClass<$T extends jni$_.JObject?> extends BaseClass<$T?> { ) : $type = type<$T>(T), super.fromReference(T.nullableType, reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/inheritance/GenericDerivedClass'); /// The type which includes information such as the signature of this class. @@ -10196,7 +10196,7 @@ class SpecificDerivedClass extends BaseClass { ) : $type = type, super.fromReference(const jni$_.$JString$NullableType$(), reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/inheritance/SpecificDerivedClass'); /// The type which includes information such as the signature of this class. @@ -10341,7 +10341,7 @@ class Annotated$Nested<$T extends jni$_.JObject?, $U extends jni$_.JObject, ) : $type = type<$T, $U, $W, $V>(T, U, W, V), super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/annotations/Annotated$Nested'); /// The type which includes information such as the signature of this class. @@ -10630,7 +10630,7 @@ class Annotated<$T extends jni$_.JObject?, $U extends jni$_.JObject, ) : $type = type<$T, $U, $W>(T, U, W), super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/annotations/Annotated'); /// The type which includes information such as the signature of this class. @@ -12545,7 +12545,7 @@ class JsonSerializable$Case extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/annotations/JsonSerializable$Case'); /// The type which includes information such as the signature of this class. @@ -12731,7 +12731,7 @@ class JsonSerializable extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/annotations/JsonSerializable'); /// The type which includes information such as the signature of this class. @@ -12956,7 +12956,7 @@ class MyDataClass extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/annotations/MyDataClass'); /// The type which includes information such as the signature of this class. @@ -13078,8 +13078,8 @@ class NotNull extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = - jni$_.JClass.forName(r'com/github/dart_lang/jnigen/annotations/NotNull'); + static jni$_.JClass get _class => jni$_.JClass.forNameCached( + r'com/github/dart_lang/jnigen/annotations/NotNull'); /// The type which includes information such as the signature of this class. static const jni$_.JType nullableType = $NotNull$NullableType$(); @@ -13250,8 +13250,8 @@ class Nullable extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = - jni$_.JClass.forName(r'com/github/dart_lang/jnigen/annotations/Nullable'); + static jni$_.JClass get _class => jni$_.JClass.forNameCached( + r'com/github/dart_lang/jnigen/annotations/Nullable'); /// The type which includes information such as the signature of this class. static const jni$_.JType nullableType = $Nullable$NullableType$(); @@ -13422,7 +13422,7 @@ class R2250$Child extends jni$_.JObject { ) : $type = type, super.fromReference(reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/regressions/R2250$Child'); /// The type which includes information such as the signature of this class. @@ -13652,8 +13652,8 @@ class R2250<$T extends jni$_.JObject?> extends jni$_.JObject { ) : $type = type<$T>(T), super.fromReference(reference); - static final _class = - jni$_.JClass.forName(r'com/github/dart_lang/jnigen/regressions/R2250'); + static jni$_.JClass get _class => jni$_.JClass.forNameCached( + r'com/github/dart_lang/jnigen/regressions/R2250'); /// The type which includes information such as the signature of this class. static jni$_.JType?> nullableType<$T extends jni$_.JObject?>( @@ -13911,7 +13911,7 @@ class R693$Child extends R693 { ) : $type = type, super.fromReference(const $R693$Child$NullableType$(), reference); - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/regressions/R693$Child'); /// The type which includes information such as the signature of this class. @@ -14039,8 +14039,8 @@ class R693<$T extends jni$_.JObject?> extends jni$_.JObject { ) : $type = type<$T>(T), super.fromReference(reference); - static final _class = - jni$_.JClass.forName(r'com/github/dart_lang/jnigen/regressions/R693'); + static jni$_.JClass get _class => jni$_.JClass.forNameCached( + r'com/github/dart_lang/jnigen/regressions/R693'); /// The type which includes information such as the signature of this class. static jni$_.JType?> nullableType<$T extends jni$_.JObject?>( From aaaba8c9145c03d796c5b64b5c94a1d58a26a077 Mon Sep 17 00:00:00 2001 From: sagar Date: Thu, 26 Feb 2026 11:25:29 +0530 Subject: [PATCH 12/13] add chagelog, revert jni_bindings, regenerted kotlin.dart --- pkgs/jni/CHANGELOG.md | 9 + .../third_party/jni_bindings_generated.dart | 29 - pkgs/jni/test/class_cache_test.dart | 4 +- pkgs/jnigen/CHANGELOG.md | 3 + .../test/kotlin_test/bindings/kotlin.dart | 913 ++---------------- 5 files changed, 69 insertions(+), 889 deletions(-) diff --git a/pkgs/jni/CHANGELOG.md b/pkgs/jni/CHANGELOG.md index 95f96d1a2a..5b6ec04215 100644 --- a/pkgs/jni/CHANGELOG.md +++ b/pkgs/jni/CHANGELOG.md @@ -8,6 +8,15 @@ - Changed the behavior of `JObject.releasedBy`. It now does not throw a `DoubleReleaseError` if the object was manually released before the end of arena. +- Added an isolate-local LRU cache for `JClass` global references, bounded by a + configurable capacity (default 256 entries). +- Added `Jni.getCachedClass(String name)` which returns a cached `JClass` + instance, minimizing redundant JNI `FindClass` calls and `GlobalRef` + allocations. +- Added `JClass.forNameCached(String name)` factory which delegates to + `Jni.getCachedClass`. +- Added `Jni.setClassCacheSize(int size)` to configure the cache capacity at + runtime. Reducing the capacity evicts least-recently-used entries immediately. ## 0.15.2 diff --git a/pkgs/jni/lib/src/third_party/jni_bindings_generated.dart b/pkgs/jni/lib/src/third_party/jni_bindings_generated.dart index c91e291ee7..32fcff47e1 100644 --- a/pkgs/jni/lib/src/third_party/jni_bindings_generated.dart +++ b/pkgs/jni/lib/src/third_party/jni_bindings_generated.dart @@ -84,35 +84,6 @@ class JniBindings { late final _JniFindClass = _JniFindClassPtr.asFunction< JniClassLookupResult Function(ffi.Pointer)>(); - JniClassLookupResult GetCachedClass( - ffi.Pointer name, - ) { - return _GetCachedClass( - name, - ); - } - - late final _GetCachedClassPtr = _lookup< - ffi.NativeFunction< - JniClassLookupResult Function( - ffi.Pointer)>>('GetCachedClass'); - late final _GetCachedClass = _GetCachedClassPtr.asFunction< - JniClassLookupResult Function(ffi.Pointer)>(); - - void SetClassCacheSize( - int size, - ) { - return _SetClassCacheSize( - size, - ); - } - - late final _SetClassCacheSizePtr = - _lookup>( - 'SetClassCacheSize'); - late final _SetClassCacheSize = - _SetClassCacheSizePtr.asFunction(); - JniExceptionDetails GetExceptionDetails( JThrowablePtr exception, ) { diff --git a/pkgs/jni/test/class_cache_test.dart b/pkgs/jni/test/class_cache_test.dart index 058c4fc90a..a08935497e 100644 --- a/pkgs/jni/test/class_cache_test.dart +++ b/pkgs/jni/test/class_cache_test.dart @@ -94,9 +94,7 @@ void run({required TestRunnerCallback testRunner}) { // Both are the same cached instance expect(identical(c1, c2), isTrue); // Same underlying JNI object - expect( - Jni.env.IsSameObject( - c1.reference.pointer, c2.reference.pointer), + expect(Jni.env.IsSameObject(c1.reference.pointer, c2.reference.pointer), isTrue); }); diff --git a/pkgs/jnigen/CHANGELOG.md b/pkgs/jnigen/CHANGELOG.md index a52874a94f..92e679f2f2 100644 --- a/pkgs/jnigen/CHANGELOG.md +++ b/pkgs/jnigen/CHANGELOG.md @@ -7,6 +7,9 @@ `bool`. - Kotlin suspend functions with no result (a return type of `Unit`) now return `Future` in Dart instead of `Future`. +- Generated bindings now use `JClass.forNameCached` instead of `JClass.forName` + for class lookups, reducing redundant `FindClass` JNI calls via the new + isolate-local LRU cache in `package:jni`. ## 0.15.0 diff --git a/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart b/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart index 63d023e099..f1d4d107e9 100644 --- a/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart +++ b/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart @@ -40,300 +40,6 @@ import 'dart:core' show Object, String, double, int; import 'package:jni/_internal.dart' as jni$_; import 'package:jni/jni.dart' as jni$_; -/// from: `com.github.dart_lang.jnigen.AllDefaults` -class AllDefaults extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - AllDefaults.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - - static jni$_.JClass get _class => - jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/AllDefaults'); - - /// The type which includes information such as the signature of this class. - static const jni$_.JType nullableType = - $AllDefaults$NullableType$(); - - /// The type which includes information such as the signature of this class. - static const jni$_.JType type = $AllDefaults$Type$(); - static final _id_new$ = _class.constructorId( - r'(ILjava/lang/String;Z)V', - ); - - static final _new$ = jni$_.ProtectedJniExtensions.lookup< - jni$_.NativeFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - jni$_.VarArgs< - ( - jni$_.Int32, - jni$_.Pointer, - jni$_.Int32 - )>)>>('globalEnv_NewObject') - .asFunction< - jni$_.JniResult Function(jni$_.Pointer, - jni$_.JMethodIDPtr, int, jni$_.Pointer, int)>(); - - /// from: `public void (int i, java.lang.String string, boolean z)` - /// The returned object must be released after use, by calling the [release] method. - factory AllDefaults( - int i, - jni$_.JString string, - core$_.bool z, - ) { - final _$string = string.reference; - return AllDefaults.fromReference(_new$(_class.reference.pointer, - _id_new$ as jni$_.JMethodIDPtr, i, _$string.pointer, z ? 1 : 0) - .reference); - } - - static final _id_new$1 = _class.constructorId( - r'(ILjava/lang/String;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V', - ); - - static final _new$1 = jni$_.ProtectedJniExtensions.lookup< - jni$_.NativeFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - jni$_.VarArgs< - ( - jni$_.Int32, - jni$_.Pointer, - jni$_.Int32, - jni$_.Int32, - jni$_.Pointer - )>)>>('globalEnv_NewObject') - .asFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - int, - jni$_.Pointer, - int, - int, - jni$_.Pointer)>(); - - /// from: `synthetic public void (int i, java.lang.String string, boolean z, int i1, kotlin.jvm.internal.DefaultConstructorMarker defaultConstructorMarker)` - /// The returned object must be released after use, by calling the [release] method. - factory AllDefaults.new$1( - int i, - jni$_.JString? string, - core$_.bool z, - int i1, - jni$_.JObject? defaultConstructorMarker, - ) { - final _$string = string?.reference ?? jni$_.jNullReference; - final _$defaultConstructorMarker = - defaultConstructorMarker?.reference ?? jni$_.jNullReference; - return AllDefaults.fromReference(_new$1( - _class.reference.pointer, - _id_new$1 as jni$_.JMethodIDPtr, - i, - _$string.pointer, - z ? 1 : 0, - i1, - _$defaultConstructorMarker.pointer) - .reference); - } - - static final _id_getA = _class.instanceMethodId( - r'getA', - r'()I', - ); - - static final _getA = jni$_.ProtectedJniExtensions.lookup< - jni$_.NativeFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - )>>('globalEnv_CallIntMethod') - .asFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - )>(); - - /// from: `public final int getA()` - int getA() { - return _getA(reference.pointer, _id_getA as jni$_.JMethodIDPtr).integer; - } - - static final _id_getB = _class.instanceMethodId( - r'getB', - r'()Ljava/lang/String;', - ); - - static final _getB = jni$_.ProtectedJniExtensions.lookup< - jni$_.NativeFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - )>>('globalEnv_CallObjectMethod') - .asFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - )>(); - - /// from: `public final java.lang.String getB()` - /// The returned object must be released after use, by calling the [release] method. - jni$_.JString getB() { - return _getB(reference.pointer, _id_getB as jni$_.JMethodIDPtr) - .object(const jni$_.$JString$Type$()); - } - - static final _id_getC = _class.instanceMethodId( - r'getC', - r'()Z', - ); - - static final _getC = jni$_.ProtectedJniExtensions.lookup< - jni$_.NativeFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - )>>('globalEnv_CallBooleanMethod') - .asFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - )>(); - - /// from: `public final boolean getC()` - core$_.bool getC() { - return _getC(reference.pointer, _id_getC as jni$_.JMethodIDPtr).boolean; - } - - static final _id_summary = _class.instanceMethodId( - r'summary', - r'()Ljava/lang/String;', - ); - - static final _summary = jni$_.ProtectedJniExtensions.lookup< - jni$_.NativeFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - )>>('globalEnv_CallObjectMethod') - .asFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - )>(); - - /// from: `public fun summary(): kotlin.String` - /// The returned object must be released after use, by calling the [release] method. - jni$_.JString summary() { - return _summary(reference.pointer, _id_summary as jni$_.JMethodIDPtr) - .object(const jni$_.$JString$Type$()); - } - - static final _id_new$2 = _class.constructorId( - r'()V', - ); - - static final _new$2 = jni$_.ProtectedJniExtensions.lookup< - jni$_.NativeFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - )>>('globalEnv_NewObject') - .asFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - )>(); - - /// from: `public void ()` - /// The returned object must be released after use, by calling the [release] method. - factory AllDefaults.new$2() { - return AllDefaults.fromReference( - _new$2(_class.reference.pointer, _id_new$2 as jni$_.JMethodIDPtr) - .reference); - } -} - -final class $AllDefaults$NullableType$ extends jni$_.JType { - @jni$_.internal - const $AllDefaults$NullableType$(); - - @jni$_.internal - @core$_.override - String get signature => r'Lcom/github/dart_lang/jnigen/AllDefaults;'; - - @jni$_.internal - @core$_.override - AllDefaults? fromReference(jni$_.JReference reference) => reference.isNull - ? null - : AllDefaults.fromReference( - reference, - ); - @jni$_.internal - @core$_.override - jni$_.JType get superType => const jni$_.$JObject$Type$(); - - @jni$_.internal - @core$_.override - jni$_.JType get nullableType => this; - - @jni$_.internal - @core$_.override - final superCount = 1; - - @core$_.override - int get hashCode => ($AllDefaults$NullableType$).hashCode; - - @core$_.override - core$_.bool operator ==(Object other) { - return other.runtimeType == ($AllDefaults$NullableType$) && - other is $AllDefaults$NullableType$; - } -} - -final class $AllDefaults$Type$ extends jni$_.JType { - @jni$_.internal - const $AllDefaults$Type$(); - - @jni$_.internal - @core$_.override - String get signature => r'Lcom/github/dart_lang/jnigen/AllDefaults;'; - - @jni$_.internal - @core$_.override - AllDefaults fromReference(jni$_.JReference reference) => - AllDefaults.fromReference( - reference, - ); - @jni$_.internal - @core$_.override - jni$_.JType get superType => const jni$_.$JObject$Type$(); - - @jni$_.internal - @core$_.override - jni$_.JType get nullableType => - const $AllDefaults$NullableType$(); - - @jni$_.internal - @core$_.override - final superCount = 1; - - @core$_.override - int get hashCode => ($AllDefaults$Type$).hashCode; - - @core$_.override - core$_.bool operator ==(Object other) { - return other.runtimeType == ($AllDefaults$Type$) && - other is $AllDefaults$Type$; - } -} - /// from: `com.github.dart_lang.jnigen.CanDoA` class CanDoA extends jni$_.JObject { @jni$_.internal @@ -643,330 +349,69 @@ class CanDoB extends jni$_.JObject { return; } final $i = jni$_.MethodInvocation.fromMessage($m); - final $r = _$invokeMethod($p.sendPort.nativePort, $i); - jni$_.ProtectedJniExtensions.returnResult($i.result, $r); - }); - implementer.add( - r'com.github.dart_lang.jnigen.CanDoB', - $p, - _$invokePointer, - [ - if ($impl.doB$async) r'doB()V', - ], - ); - final $a = $p.sendPort.nativePort; - _$impls[$a] = $impl; - } - - factory CanDoB.implement( - $CanDoB $impl, - ) { - final $i = jni$_.JImplementer(); - implementIn($i, $impl); - return CanDoB.fromReference( - $i.implementReference(), - ); - } -} - -abstract base mixin class $CanDoB { - factory $CanDoB({ - required void Function() doB, - core$_.bool doB$async, - }) = _$CanDoB; - - void doB(); - core$_.bool get doB$async => false; -} - -final class _$CanDoB with $CanDoB { - _$CanDoB({ - required void Function() doB, - this.doB$async = false, - }) : _doB = doB; - - final void Function() _doB; - final core$_.bool doB$async; - - void doB() { - return _doB(); - } -} - -final class $CanDoB$NullableType$ extends jni$_.JType { - @jni$_.internal - const $CanDoB$NullableType$(); - - @jni$_.internal - @core$_.override - String get signature => r'Lcom/github/dart_lang/jnigen/CanDoB;'; - - @jni$_.internal - @core$_.override - CanDoB? fromReference(jni$_.JReference reference) => reference.isNull - ? null - : CanDoB.fromReference( - reference, - ); - @jni$_.internal - @core$_.override - jni$_.JType get superType => const jni$_.$JObject$Type$(); - - @jni$_.internal - @core$_.override - jni$_.JType get nullableType => this; - - @jni$_.internal - @core$_.override - final superCount = 1; - - @core$_.override - int get hashCode => ($CanDoB$NullableType$).hashCode; - - @core$_.override - core$_.bool operator ==(Object other) { - return other.runtimeType == ($CanDoB$NullableType$) && - other is $CanDoB$NullableType$; - } -} - -final class $CanDoB$Type$ extends jni$_.JType { - @jni$_.internal - const $CanDoB$Type$(); - - @jni$_.internal - @core$_.override - String get signature => r'Lcom/github/dart_lang/jnigen/CanDoB;'; - - @jni$_.internal - @core$_.override - CanDoB fromReference(jni$_.JReference reference) => CanDoB.fromReference( - reference, - ); - @jni$_.internal - @core$_.override - jni$_.JType get superType => const jni$_.$JObject$Type$(); - - @jni$_.internal - @core$_.override - jni$_.JType get nullableType => const $CanDoB$NullableType$(); - - @jni$_.internal - @core$_.override - final superCount = 1; - - @core$_.override - int get hashCode => ($CanDoB$Type$).hashCode; - - @core$_.override - core$_.bool operator ==(Object other) { - return other.runtimeType == ($CanDoB$Type$) && other is $CanDoB$Type$; - } -} - -/// from: `com.github.dart_lang.jnigen.DefaultParams` -class DefaultParams extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - DefaultParams.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - - static jni$_.JClass get _class => - jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/DefaultParams'); - - /// The type which includes information such as the signature of this class. - static const jni$_.JType nullableType = - $DefaultParams$NullableType$(); - - /// The type which includes information such as the signature of this class. - static const jni$_.JType type = $DefaultParams$Type$(); - static final _id_new$ = _class.constructorId( - r'(ILjava/lang/String;)V', - ); - - static final _new$ = jni$_.ProtectedJniExtensions.lookup< - jni$_.NativeFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - jni$_ - .VarArgs<(jni$_.Int32, jni$_.Pointer)>)>>( - 'globalEnv_NewObject') - .asFunction< - jni$_.JniResult Function(jni$_.Pointer, - jni$_.JMethodIDPtr, int, jni$_.Pointer)>(); - - /// from: `public void (int i, java.lang.String string)` - /// The returned object must be released after use, by calling the [release] method. - factory DefaultParams( - int i, - jni$_.JString string, - ) { - final _$string = string.reference; - return DefaultParams.fromReference(_new$(_class.reference.pointer, - _id_new$ as jni$_.JMethodIDPtr, i, _$string.pointer) - .reference); - } - - static final _id_new$1 = _class.constructorId( - r'(ILjava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V', - ); - - static final _new$1 = jni$_.ProtectedJniExtensions.lookup< - jni$_.NativeFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - jni$_.VarArgs< - ( - jni$_.Int32, - jni$_.Pointer, - jni$_.Int32, - jni$_.Pointer - )>)>>('globalEnv_NewObject') - .asFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - int, - jni$_.Pointer, - int, - jni$_.Pointer)>(); - - /// from: `synthetic public void (int i, java.lang.String string, int i1, kotlin.jvm.internal.DefaultConstructorMarker defaultConstructorMarker)` - /// The returned object must be released after use, by calling the [release] method. - factory DefaultParams.new$1( - int i, - jni$_.JString? string, - int i1, - jni$_.JObject? defaultConstructorMarker, - ) { - final _$string = string?.reference ?? jni$_.jNullReference; - final _$defaultConstructorMarker = - defaultConstructorMarker?.reference ?? jni$_.jNullReference; - return DefaultParams.fromReference(_new$1( - _class.reference.pointer, - _id_new$1 as jni$_.JMethodIDPtr, - i, - _$string.pointer, - i1, - _$defaultConstructorMarker.pointer) - .reference); - } - - static final _id_getX = _class.instanceMethodId( - r'getX', - r'()I', - ); - - static final _getX = jni$_.ProtectedJniExtensions.lookup< - jni$_.NativeFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - )>>('globalEnv_CallIntMethod') - .asFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - )>(); - - /// from: `public final int getX()` - int getX() { - return _getX(reference.pointer, _id_getX as jni$_.JMethodIDPtr).integer; - } - - static final _id_getY = _class.instanceMethodId( - r'getY', - r'()Ljava/lang/String;', - ); - - static final _getY = jni$_.ProtectedJniExtensions.lookup< - jni$_.NativeFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - )>>('globalEnv_CallObjectMethod') - .asFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - )>(); - - /// from: `public final java.lang.String getY()` - /// The returned object must be released after use, by calling the [release] method. - jni$_.JString getY() { - return _getY(reference.pointer, _id_getY as jni$_.JMethodIDPtr) - .object(const jni$_.$JString$Type$()); + final $r = _$invokeMethod($p.sendPort.nativePort, $i); + jni$_.ProtectedJniExtensions.returnResult($i.result, $r); + }); + implementer.add( + r'com.github.dart_lang.jnigen.CanDoB', + $p, + _$invokePointer, + [ + if ($impl.doB$async) r'doB()V', + ], + ); + final $a = $p.sendPort.nativePort; + _$impls[$a] = $impl; } - static final _id_greet = _class.instanceMethodId( - r'greet', - r'()Ljava/lang/String;', - ); + factory CanDoB.implement( + $CanDoB $impl, + ) { + final $i = jni$_.JImplementer(); + implementIn($i, $impl); + return CanDoB.fromReference( + $i.implementReference(), + ); + } +} - static final _greet = jni$_.ProtectedJniExtensions.lookup< - jni$_.NativeFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - )>>('globalEnv_CallObjectMethod') - .asFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - )>(); +abstract base mixin class $CanDoB { + factory $CanDoB({ + required void Function() doB, + core$_.bool doB$async, + }) = _$CanDoB; - /// from: `public fun greet(): kotlin.String` - /// The returned object must be released after use, by calling the [release] method. - jni$_.JString greet() { - return _greet(reference.pointer, _id_greet as jni$_.JMethodIDPtr) - .object(const jni$_.$JString$Type$()); - } + void doB(); + core$_.bool get doB$async => false; +} - static final _id_new$2 = _class.constructorId( - r'()V', - ); +final class _$CanDoB with $CanDoB { + _$CanDoB({ + required void Function() doB, + this.doB$async = false, + }) : _doB = doB; - static final _new$2 = jni$_.ProtectedJniExtensions.lookup< - jni$_.NativeFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - )>>('globalEnv_NewObject') - .asFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - )>(); + final void Function() _doB; + final core$_.bool doB$async; - /// from: `public void ()` - /// The returned object must be released after use, by calling the [release] method. - factory DefaultParams.new$2() { - return DefaultParams.fromReference( - _new$2(_class.reference.pointer, _id_new$2 as jni$_.JMethodIDPtr) - .reference); + void doB() { + return _doB(); } } -final class $DefaultParams$NullableType$ extends jni$_.JType { +final class $CanDoB$NullableType$ extends jni$_.JType { @jni$_.internal - const $DefaultParams$NullableType$(); + const $CanDoB$NullableType$(); @jni$_.internal @core$_.override - String get signature => r'Lcom/github/dart_lang/jnigen/DefaultParams;'; + String get signature => r'Lcom/github/dart_lang/jnigen/CanDoB;'; @jni$_.internal @core$_.override - DefaultParams? fromReference(jni$_.JReference reference) => reference.isNull + CanDoB? fromReference(jni$_.JReference reference) => reference.isNull ? null - : DefaultParams.fromReference( + : CanDoB.fromReference( reference, ); @jni$_.internal @@ -975,34 +420,33 @@ final class $DefaultParams$NullableType$ extends jni$_.JType { @jni$_.internal @core$_.override - jni$_.JType get nullableType => this; + jni$_.JType get nullableType => this; @jni$_.internal @core$_.override final superCount = 1; @core$_.override - int get hashCode => ($DefaultParams$NullableType$).hashCode; + int get hashCode => ($CanDoB$NullableType$).hashCode; @core$_.override core$_.bool operator ==(Object other) { - return other.runtimeType == ($DefaultParams$NullableType$) && - other is $DefaultParams$NullableType$; + return other.runtimeType == ($CanDoB$NullableType$) && + other is $CanDoB$NullableType$; } } -final class $DefaultParams$Type$ extends jni$_.JType { +final class $CanDoB$Type$ extends jni$_.JType { @jni$_.internal - const $DefaultParams$Type$(); + const $CanDoB$Type$(); @jni$_.internal @core$_.override - String get signature => r'Lcom/github/dart_lang/jnigen/DefaultParams;'; + String get signature => r'Lcom/github/dart_lang/jnigen/CanDoB;'; @jni$_.internal @core$_.override - DefaultParams fromReference(jni$_.JReference reference) => - DefaultParams.fromReference( + CanDoB fromReference(jni$_.JReference reference) => CanDoB.fromReference( reference, ); @jni$_.internal @@ -1011,20 +455,18 @@ final class $DefaultParams$Type$ extends jni$_.JType { @jni$_.internal @core$_.override - jni$_.JType get nullableType => - const $DefaultParams$NullableType$(); + jni$_.JType get nullableType => const $CanDoB$NullableType$(); @jni$_.internal @core$_.override final superCount = 1; @core$_.override - int get hashCode => ($DefaultParams$Type$).hashCode; + int get hashCode => ($CanDoB$Type$).hashCode; @core$_.override core$_.bool operator ==(Object other) { - return other.runtimeType == ($DefaultParams$Type$) && - other is $DefaultParams$Type$; + return other.runtimeType == ($CanDoB$Type$) && other is $CanDoB$Type$; } } @@ -1484,249 +926,6 @@ final class $MeasureUnit$Type$ extends jni$_.JType { } } -/// from: `com.github.dart_lang.jnigen.MixedParams` -class MixedParams extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - MixedParams.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - - static jni$_.JClass get _class => - jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/MixedParams'); - - /// The type which includes information such as the signature of this class. - static const jni$_.JType nullableType = - $MixedParams$NullableType$(); - - /// The type which includes information such as the signature of this class. - static const jni$_.JType type = $MixedParams$Type$(); - static final _id_new$ = _class.constructorId( - r'(Ljava/lang/String;I)V', - ); - - static final _new$ = jni$_.ProtectedJniExtensions.lookup< - jni$_.NativeFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - jni$_ - .VarArgs<(jni$_.Pointer, jni$_.Int32)>)>>( - 'globalEnv_NewObject') - .asFunction< - jni$_.JniResult Function(jni$_.Pointer, - jni$_.JMethodIDPtr, jni$_.Pointer, int)>(); - - /// from: `public void (java.lang.String string, int i)` - /// The returned object must be released after use, by calling the [release] method. - factory MixedParams( - jni$_.JString string, - int i, - ) { - final _$string = string.reference; - return MixedParams.fromReference(_new$(_class.reference.pointer, - _id_new$ as jni$_.JMethodIDPtr, _$string.pointer, i) - .reference); - } - - static final _id_new$1 = _class.constructorId( - r'(Ljava/lang/String;IILkotlin/jvm/internal/DefaultConstructorMarker;)V', - ); - - static final _new$1 = jni$_.ProtectedJniExtensions.lookup< - jni$_.NativeFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - jni$_.VarArgs< - ( - jni$_.Pointer, - jni$_.Int32, - jni$_.Int32, - jni$_.Pointer - )>)>>('globalEnv_NewObject') - .asFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - jni$_.Pointer, - int, - int, - jni$_.Pointer)>(); - - /// from: `synthetic public void (java.lang.String string, int i, int i1, kotlin.jvm.internal.DefaultConstructorMarker defaultConstructorMarker)` - /// The returned object must be released after use, by calling the [release] method. - factory MixedParams.new$1( - jni$_.JString? string, - int i, - int i1, - jni$_.JObject? defaultConstructorMarker, - ) { - final _$string = string?.reference ?? jni$_.jNullReference; - final _$defaultConstructorMarker = - defaultConstructorMarker?.reference ?? jni$_.jNullReference; - return MixedParams.fromReference(_new$1( - _class.reference.pointer, - _id_new$1 as jni$_.JMethodIDPtr, - _$string.pointer, - i, - i1, - _$defaultConstructorMarker.pointer) - .reference); - } - - static final _id_getRequired = _class.instanceMethodId( - r'getRequired', - r'()Ljava/lang/String;', - ); - - static final _getRequired = jni$_.ProtectedJniExtensions.lookup< - jni$_.NativeFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - )>>('globalEnv_CallObjectMethod') - .asFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - )>(); - - /// from: `public final java.lang.String getRequired()` - /// The returned object must be released after use, by calling the [release] method. - jni$_.JString getRequired() { - return _getRequired( - reference.pointer, _id_getRequired as jni$_.JMethodIDPtr) - .object(const jni$_.$JString$Type$()); - } - - static final _id_getOptional = _class.instanceMethodId( - r'getOptional', - r'()I', - ); - - static final _getOptional = jni$_.ProtectedJniExtensions.lookup< - jni$_.NativeFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - )>>('globalEnv_CallIntMethod') - .asFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - )>(); - - /// from: `public final int getOptional()` - int getOptional() { - return _getOptional( - reference.pointer, _id_getOptional as jni$_.JMethodIDPtr) - .integer; - } - - static final _id_describe = _class.instanceMethodId( - r'describe', - r'()Ljava/lang/String;', - ); - - static final _describe = jni$_.ProtectedJniExtensions.lookup< - jni$_.NativeFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - )>>('globalEnv_CallObjectMethod') - .asFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - )>(); - - /// from: `public fun describe(): kotlin.String` - /// The returned object must be released after use, by calling the [release] method. - jni$_.JString describe() { - return _describe(reference.pointer, _id_describe as jni$_.JMethodIDPtr) - .object(const jni$_.$JString$Type$()); - } -} - -final class $MixedParams$NullableType$ extends jni$_.JType { - @jni$_.internal - const $MixedParams$NullableType$(); - - @jni$_.internal - @core$_.override - String get signature => r'Lcom/github/dart_lang/jnigen/MixedParams;'; - - @jni$_.internal - @core$_.override - MixedParams? fromReference(jni$_.JReference reference) => reference.isNull - ? null - : MixedParams.fromReference( - reference, - ); - @jni$_.internal - @core$_.override - jni$_.JType get superType => const jni$_.$JObject$Type$(); - - @jni$_.internal - @core$_.override - jni$_.JType get nullableType => this; - - @jni$_.internal - @core$_.override - final superCount = 1; - - @core$_.override - int get hashCode => ($MixedParams$NullableType$).hashCode; - - @core$_.override - core$_.bool operator ==(Object other) { - return other.runtimeType == ($MixedParams$NullableType$) && - other is $MixedParams$NullableType$; - } -} - -final class $MixedParams$Type$ extends jni$_.JType { - @jni$_.internal - const $MixedParams$Type$(); - - @jni$_.internal - @core$_.override - String get signature => r'Lcom/github/dart_lang/jnigen/MixedParams;'; - - @jni$_.internal - @core$_.override - MixedParams fromReference(jni$_.JReference reference) => - MixedParams.fromReference( - reference, - ); - @jni$_.internal - @core$_.override - jni$_.JType get superType => const jni$_.$JObject$Type$(); - - @jni$_.internal - @core$_.override - jni$_.JType get nullableType => - const $MixedParams$NullableType$(); - - @jni$_.internal - @core$_.override - final superCount = 1; - - @core$_.override - int get hashCode => ($MixedParams$Type$).hashCode; - - @core$_.override - core$_.bool operator ==(Object other) { - return other.runtimeType == ($MixedParams$Type$) && - other is $MixedParams$Type$; - } -} - /// from: `com.github.dart_lang.jnigen.Nullability$InnerClass` class Nullability$InnerClass<$T extends jni$_.JObject?, $U extends jni$_.JObject, $V extends jni$_.JObject?> extends jni$_.JObject { From 77622f6bd1f707e1cce4e9d9f477983249c511bf Mon Sep 17 00:00:00 2001 From: sagar Date: Thu, 12 Mar 2026 23:37:35 +0530 Subject: [PATCH 13/13] fix: regenerate generated bindings --- pkgs/jni/test/class_cache_test.dart | 15 +- .../org/apache/pdfbox/pdmodel/PDDocument.dart | 12 +- .../pdfbox/pdmodel/PDDocumentInformation.dart | 13 +- .../apache/pdfbox/text/PDFTextStripper.dart | 13 +- .../fasterxml/jackson/core/JsonFactory.dart | 25 +- .../fasterxml/jackson/core/JsonParser.dart | 38 +- .../com/fasterxml/jackson/core/JsonToken.dart | 12 +- .../test/kotlin_test/bindings/kotlin.dart | 679 ++++++++-- .../bindings/simple_package.dart | 1125 ++--------------- 9 files changed, 700 insertions(+), 1232 deletions(-) diff --git a/pkgs/jni/test/class_cache_test.dart b/pkgs/jni/test/class_cache_test.dart index a08935497e..bfad6ccbc3 100644 --- a/pkgs/jni/test/class_cache_test.dart +++ b/pkgs/jni/test/class_cache_test.dart @@ -5,7 +5,6 @@ @Tags(['load_test']) library; -import 'dart:ffi'; import 'dart:io'; import 'package:jni/jni.dart'; @@ -101,22 +100,22 @@ void run({required TestRunnerCallback testRunner}) { testRunner('Eviction and reload', () { Jni.setClassCacheSize(2); - final _name1 = 'java/lang/String'; - final _name2 = 'java/lang/Integer'; - final _name3 = 'java/lang/Double'; + const name1 = 'java/lang/String'; + const name2 = 'java/lang/Integer'; + const name3 = 'java/lang/Double'; - final ref1 = Jni.getCachedClass(_name1); - final ref2 = Jni.getCachedClass(_name2); + final ref1 = Jni.getCachedClass(name1); + final ref2 = Jni.getCachedClass(name2); // Insert third class, evicting String (LRU) - final ref3 = Jni.getCachedClass(_name3); + final ref3 = Jni.getCachedClass(name3); // ref2 and ref3 still cached and valid expect(ref2, isNotNull); expect(ref3, isNotNull); // String evicted; reload creates new cached instance - final ref1Reload = Jni.getCachedClass(_name1); + final ref1Reload = Jni.getCachedClass(name1); // Not identical since eviction recreated it expect(identical(ref1, ref1Reload), isFalse); }); diff --git a/pkgs/jnigen/example/pdfbox_plugin/lib/src/third_party/org/apache/pdfbox/pdmodel/PDDocument.dart b/pkgs/jnigen/example/pdfbox_plugin/lib/src/third_party/org/apache/pdfbox/pdmodel/PDDocument.dart index 40f7d7c643..7f351b8f7c 100644 --- a/pkgs/jnigen/example/pdfbox_plugin/lib/src/third_party/org/apache/pdfbox/pdmodel/PDDocument.dart +++ b/pkgs/jnigen/example/pdfbox_plugin/lib/src/third_party/org/apache/pdfbox/pdmodel/PDDocument.dart @@ -61,17 +61,7 @@ import 'PDDocumentInformation.dart' as pddocumentinformation$_; /// This is the in-memory representation of the PDF document. /// The \#close() method must be called once the document is no longer needed. ///@author Ben Litchfield -class PDDocument extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - PDDocument.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type PDDocument._(jni$_.JObject _$this) implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached(r'org/apache/pdfbox/pdmodel/PDDocument'); diff --git a/pkgs/jnigen/example/pdfbox_plugin/lib/src/third_party/org/apache/pdfbox/pdmodel/PDDocumentInformation.dart b/pkgs/jnigen/example/pdfbox_plugin/lib/src/third_party/org/apache/pdfbox/pdmodel/PDDocumentInformation.dart index 01b033ddd0..74316650d9 100644 --- a/pkgs/jnigen/example/pdfbox_plugin/lib/src/third_party/org/apache/pdfbox/pdmodel/PDDocumentInformation.dart +++ b/pkgs/jnigen/example/pdfbox_plugin/lib/src/third_party/org/apache/pdfbox/pdmodel/PDDocumentInformation.dart @@ -61,17 +61,8 @@ import 'package:jni/jni.dart' as jni$_; /// method then it will clear the value. ///@author Ben Litchfield ///@author Gerardo Ortiz -class PDDocumentInformation extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - PDDocumentInformation.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type PDDocumentInformation._(jni$_.JObject _$this) + implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'org/apache/pdfbox/pdmodel/PDDocumentInformation'); diff --git a/pkgs/jnigen/example/pdfbox_plugin/lib/src/third_party/org/apache/pdfbox/text/PDFTextStripper.dart b/pkgs/jnigen/example/pdfbox_plugin/lib/src/third_party/org/apache/pdfbox/text/PDFTextStripper.dart index 28d1cebeae..8df4503848 100644 --- a/pkgs/jnigen/example/pdfbox_plugin/lib/src/third_party/org/apache/pdfbox/text/PDFTextStripper.dart +++ b/pkgs/jnigen/example/pdfbox_plugin/lib/src/third_party/org/apache/pdfbox/text/PDFTextStripper.dart @@ -65,17 +65,8 @@ import '../pdmodel/PDDocument.dart' as pddocument$_; /// The basic flow of this process is that we get a document and use a series of processXXX() functions that work on /// smaller and smaller chunks of the page. Eventually, we fully process each page and then print it. ///@author Ben Litchfield -class PDFTextStripper extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - PDFTextStripper.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type PDFTextStripper._(jni$_.JObject _$this) + implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached(r'org/apache/pdfbox/text/PDFTextStripper'); diff --git a/pkgs/jnigen/test/jackson_core_test/third_party/bindings/com/fasterxml/jackson/core/JsonFactory.dart b/pkgs/jnigen/test/jackson_core_test/third_party/bindings/com/fasterxml/jackson/core/JsonFactory.dart index 775fc77ba4..4fb3009451 100644 --- a/pkgs/jnigen/test/jackson_core_test/third_party/bindings/com/fasterxml/jackson/core/JsonFactory.dart +++ b/pkgs/jnigen/test/jackson_core_test/third_party/bindings/com/fasterxml/jackson/core/JsonFactory.dart @@ -59,17 +59,8 @@ import 'JsonParser.dart' as jsonparser$_; /// /// Enumeration that defines all on/off features that can only be /// changed for JsonFactory. -class JsonFactory$Feature extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - JsonFactory$Feature.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type JsonFactory$Feature._(jni$_.JObject _$this) + implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/fasterxml/jackson/core/JsonFactory$Feature'); @@ -343,17 +334,7 @@ final class $JsonFactory$Feature$Type$ /// the default constructor is used for constructing factory /// instances. ///@author Tatu Saloranta -class JsonFactory extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - JsonFactory.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type JsonFactory._(jni$_.JObject _$this) implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached(r'com/fasterxml/jackson/core/JsonFactory'); diff --git a/pkgs/jnigen/test/jackson_core_test/third_party/bindings/com/fasterxml/jackson/core/JsonParser.dart b/pkgs/jnigen/test/jackson_core_test/third_party/bindings/com/fasterxml/jackson/core/JsonParser.dart index 7967bd6dd2..02faea4dc1 100644 --- a/pkgs/jnigen/test/jackson_core_test/third_party/bindings/com/fasterxml/jackson/core/JsonParser.dart +++ b/pkgs/jnigen/test/jackson_core_test/third_party/bindings/com/fasterxml/jackson/core/JsonParser.dart @@ -58,17 +58,8 @@ import 'JsonToken.dart' as jsontoken$_; /// from: `com.fasterxml.jackson.core.JsonParser$Feature` /// /// Enumeration that defines all on/off features for parsers. -class JsonParser$Feature extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - JsonParser$Feature.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type JsonParser$Feature._(jni$_.JObject _$this) + implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/fasterxml/jackson/core/JsonParser$Feature'); @@ -602,17 +593,8 @@ final class $JsonParser$Feature$Type$ extends jni$_.JType { /// /// Enumeration of possible "native" (optimal) types that can be /// used for numbers. -class JsonParser$NumberType extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - JsonParser$NumberType.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type JsonParser$NumberType._(jni$_.JObject _$this) + implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/fasterxml/jackson/core/JsonParser$NumberType'); @@ -751,17 +733,7 @@ final class $JsonParser$NumberType$Type$ /// Instances are created using factory methods of /// a JsonFactory instance. ///@author Tatu Saloranta -class JsonParser extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - JsonParser.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type JsonParser._(jni$_.JObject _$this) implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached(r'com/fasterxml/jackson/core/JsonParser'); diff --git a/pkgs/jnigen/test/jackson_core_test/third_party/bindings/com/fasterxml/jackson/core/JsonToken.dart b/pkgs/jnigen/test/jackson_core_test/third_party/bindings/com/fasterxml/jackson/core/JsonToken.dart index e8d052cea7..f0c07ed03f 100644 --- a/pkgs/jnigen/test/jackson_core_test/third_party/bindings/com/fasterxml/jackson/core/JsonToken.dart +++ b/pkgs/jnigen/test/jackson_core_test/third_party/bindings/com/fasterxml/jackson/core/JsonToken.dart @@ -57,17 +57,7 @@ import 'package:jni/jni.dart' as jni$_; /// /// Enumeration for basic token types used for returning results /// of parsing JSON content. -class JsonToken extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - JsonToken.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type JsonToken._(jni$_.JObject _$this) implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached(r'com/fasterxml/jackson/core/JsonToken'); diff --git a/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart b/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart index 8688fd46e2..4797d8055b 100644 --- a/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart +++ b/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart @@ -40,18 +40,215 @@ import 'dart:core' show Object, String, double, int; import 'package:jni/_internal.dart' as jni$_; import 'package:jni/jni.dart' as jni$_; -/// from: `com.github.dart_lang.jnigen.CanDoA` -class CanDoA extends jni$_.JObject { +/// from: `com.github.dart_lang.jnigen.AllDefaults` +extension type AllDefaults._(jni$_.JObject _$this) implements jni$_.JObject { + static jni$_.JClass get _class => + jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/AllDefaults'); + + /// The type which includes information such as the signature of this class. + static const jni$_.JType type = $AllDefaults$Type$(); + static final _id_new$ = _class.constructorId( + r'(ILjava/lang/String;Z)V', + ); + + static final _new$ = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + jni$_.VarArgs< + ( + jni$_.Int32, + jni$_.Pointer, + jni$_.Int32 + )>)>>('globalEnv_NewObject') + .asFunction< + jni$_.JniResult Function(jni$_.Pointer, + jni$_.JMethodIDPtr, int, jni$_.Pointer, int)>(); + + /// from: `public void (int i, java.lang.String string, boolean z)` + /// The returned object must be released after use, by calling the [release] method. + factory AllDefaults( + int i, + jni$_.JString string, + core$_.bool z, + ) { + final _$string = string.reference; + return _new$(_class.reference.pointer, _id_new$.pointer, i, + _$string.pointer, z ? 1 : 0) + .object(); + } + + static final _id_new$1 = _class.constructorId( + r'(ILjava/lang/String;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V', + ); + + static final _new$1 = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + jni$_.VarArgs< + ( + jni$_.Int32, + jni$_.Pointer, + jni$_.Int32, + jni$_.Int32, + jni$_.Pointer + )>)>>('globalEnv_NewObject') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + int, + jni$_.Pointer, + int, + int, + jni$_.Pointer)>(); + + /// from: `synthetic public void (int i, java.lang.String string, boolean z, int i1, kotlin.jvm.internal.DefaultConstructorMarker defaultConstructorMarker)` + /// The returned object must be released after use, by calling the [release] method. + factory AllDefaults.new$1( + int i, + jni$_.JString? string, + core$_.bool z, + int i1, + jni$_.JObject? defaultConstructorMarker, + ) { + final _$string = string?.reference ?? jni$_.jNullReference; + final _$defaultConstructorMarker = + defaultConstructorMarker?.reference ?? jni$_.jNullReference; + return _new$1(_class.reference.pointer, _id_new$1.pointer, i, + _$string.pointer, z ? 1 : 0, i1, _$defaultConstructorMarker.pointer) + .object(); + } + + static final _id_getA = _class.instanceMethodId( + r'getA', + r'()I', + ); + + static final _getA = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>>('globalEnv_CallIntMethod') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>(); + + /// from: `public final int getA()` + int getA() { + return _getA(reference.pointer, _id_getA.pointer).integer; + } + + static final _id_getB = _class.instanceMethodId( + r'getB', + r'()Ljava/lang/String;', + ); + + static final _getB = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>>('globalEnv_CallObjectMethod') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>(); + + /// from: `public final java.lang.String getB()` + /// The returned object must be released after use, by calling the [release] method. + jni$_.JString getB() { + return _getB(reference.pointer, _id_getB.pointer).object(); + } + + static final _id_getC = _class.instanceMethodId( + r'getC', + r'()Z', + ); + + static final _getC = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>>('globalEnv_CallBooleanMethod') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>(); + + /// from: `public final boolean getC()` + core$_.bool getC() { + return _getC(reference.pointer, _id_getC.pointer).boolean; + } + + static final _id_summary = _class.instanceMethodId( + r'summary', + r'()Ljava/lang/String;', + ); + + static final _summary = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>>('globalEnv_CallObjectMethod') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>(); + + /// from: `public fun summary(): kotlin.String` + /// The returned object must be released after use, by calling the [release] method. + jni$_.JString summary() { + return _summary(reference.pointer, _id_summary.pointer) + .object(); + } + + static final _id_new$2 = _class.constructorId( + r'()V', + ); + + static final _new$2 = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>>('globalEnv_NewObject') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>(); + + /// from: `public void ()` + /// The returned object must be released after use, by calling the [release] method. + factory AllDefaults.new$2() { + return _new$2(_class.reference.pointer, _id_new$2.pointer) + .object(); + } +} + +final class $AllDefaults$Type$ extends jni$_.JType { @jni$_.internal - @core$_.override - final jni$_.JType $type; + const $AllDefaults$Type$(); @jni$_.internal - CanDoA.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); + @core$_.override + String get signature => r'Lcom/github/dart_lang/jnigen/AllDefaults;'; +} +/// from: `com.github.dart_lang.jnigen.CanDoA` +extension type CanDoA._(jni$_.JObject _$this) implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/CanDoA'); @@ -189,17 +386,7 @@ final class $CanDoA$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.CanDoB` -class CanDoB extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - CanDoB.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type CanDoB._(jni$_.JObject _$this) implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/CanDoB'); @@ -336,22 +523,186 @@ final class $CanDoB$Type$ extends jni$_.JType { String get signature => r'Lcom/github/dart_lang/jnigen/CanDoB;'; } -/// from: `com.github.dart_lang.jnigen.Measure` -class Measure<$T extends jni$_.JObject> extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType> $type; +/// from: `com.github.dart_lang.jnigen.DefaultParams` +extension type DefaultParams._(jni$_.JObject _$this) implements jni$_.JObject { + static jni$_.JClass get _class => + jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/DefaultParams'); + + /// The type which includes information such as the signature of this class. + static const jni$_.JType type = $DefaultParams$Type$(); + static final _id_new$ = _class.constructorId( + r'(ILjava/lang/String;)V', + ); + + static final _new$ = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + jni$_ + .VarArgs<(jni$_.Int32, jni$_.Pointer)>)>>( + 'globalEnv_NewObject') + .asFunction< + jni$_.JniResult Function(jni$_.Pointer, + jni$_.JMethodIDPtr, int, jni$_.Pointer)>(); + + /// from: `public void (int i, java.lang.String string)` + /// The returned object must be released after use, by calling the [release] method. + factory DefaultParams( + int i, + jni$_.JString string, + ) { + final _$string = string.reference; + return _new$( + _class.reference.pointer, _id_new$.pointer, i, _$string.pointer) + .object(); + } + + static final _id_new$1 = _class.constructorId( + r'(ILjava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V', + ); + + static final _new$1 = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + jni$_.VarArgs< + ( + jni$_.Int32, + jni$_.Pointer, + jni$_.Int32, + jni$_.Pointer + )>)>>('globalEnv_NewObject') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + int, + jni$_.Pointer, + int, + jni$_.Pointer)>(); + + /// from: `synthetic public void (int i, java.lang.String string, int i1, kotlin.jvm.internal.DefaultConstructorMarker defaultConstructorMarker)` + /// The returned object must be released after use, by calling the [release] method. + factory DefaultParams.new$1( + int i, + jni$_.JString? string, + int i1, + jni$_.JObject? defaultConstructorMarker, + ) { + final _$string = string?.reference ?? jni$_.jNullReference; + final _$defaultConstructorMarker = + defaultConstructorMarker?.reference ?? jni$_.jNullReference; + return _new$1(_class.reference.pointer, _id_new$1.pointer, i, + _$string.pointer, i1, _$defaultConstructorMarker.pointer) + .object(); + } + static final _id_getX = _class.instanceMethodId( + r'getX', + r'()I', + ); + + static final _getX = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>>('globalEnv_CallIntMethod') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>(); + + /// from: `public final int getX()` + int getX() { + return _getX(reference.pointer, _id_getX.pointer).integer; + } + + static final _id_getY = _class.instanceMethodId( + r'getY', + r'()Ljava/lang/String;', + ); + + static final _getY = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>>('globalEnv_CallObjectMethod') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>(); + + /// from: `public final java.lang.String getY()` + /// The returned object must be released after use, by calling the [release] method. + jni$_.JString getY() { + return _getY(reference.pointer, _id_getY.pointer).object(); + } + + static final _id_greet = _class.instanceMethodId( + r'greet', + r'()Ljava/lang/String;', + ); + + static final _greet = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>>('globalEnv_CallObjectMethod') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>(); + + /// from: `public fun greet(): kotlin.String` + /// The returned object must be released after use, by calling the [release] method. + jni$_.JString greet() { + return _greet(reference.pointer, _id_greet.pointer).object(); + } + + static final _id_new$2 = _class.constructorId( + r'()V', + ); + + static final _new$2 = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>>('globalEnv_NewObject') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>(); + + /// from: `public void ()` + /// The returned object must be released after use, by calling the [release] method. + factory DefaultParams.new$2() { + return _new$2(_class.reference.pointer, _id_new$2.pointer) + .object(); + } +} + +final class $DefaultParams$Type$ extends jni$_.JType { @jni$_.internal - final jni$_.JType<$T> T; + const $DefaultParams$Type$(); @jni$_.internal - Measure.fromReference( - this.T, - jni$_.JReference reference, - ) : $type = type<$T>(T), - super.fromReference(reference); + @core$_.override + String get signature => r'Lcom/github/dart_lang/jnigen/DefaultParams;'; +} +/// from: `com.github.dart_lang.jnigen.Measure` +extension type Measure<$T extends jni$_.JObject>._(jni$_.JObject _$this) + implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/Measure'); @@ -439,17 +790,7 @@ final class $Measure$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.MeasureUnit` -class MeasureUnit extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - MeasureUnit.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type MeasureUnit._(jni$_.JObject _$this) implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/MeasureUnit'); @@ -621,31 +962,168 @@ final class $MeasureUnit$Type$ extends jni$_.JType { String get signature => r'Lcom/github/dart_lang/jnigen/MeasureUnit;'; } -/// from: `com.github.dart_lang.jnigen.Nullability$InnerClass` -class Nullability$InnerClass<$T extends jni$_.JObject?, - $U extends jni$_.JObject, $V extends jni$_.JObject?> extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType> $type; +/// from: `com.github.dart_lang.jnigen.MixedParams` +extension type MixedParams._(jni$_.JObject _$this) implements jni$_.JObject { + static jni$_.JClass get _class => + jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/MixedParams'); - @jni$_.internal - final jni$_.JType<$T> T; + /// The type which includes information such as the signature of this class. + static const jni$_.JType type = $MixedParams$Type$(); + static final _id_new$ = _class.constructorId( + r'(Ljava/lang/String;I)V', + ); - @jni$_.internal - final jni$_.JType<$U> U; + static final _new$ = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + jni$_ + .VarArgs<(jni$_.Pointer, jni$_.Int32)>)>>( + 'globalEnv_NewObject') + .asFunction< + jni$_.JniResult Function(jni$_.Pointer, + jni$_.JMethodIDPtr, jni$_.Pointer, int)>(); + + /// from: `public void (java.lang.String string, int i)` + /// The returned object must be released after use, by calling the [release] method. + factory MixedParams( + jni$_.JString string, + int i, + ) { + final _$string = string.reference; + return _new$( + _class.reference.pointer, _id_new$.pointer, _$string.pointer, i) + .object(); + } + + static final _id_new$1 = _class.constructorId( + r'(Ljava/lang/String;IILkotlin/jvm/internal/DefaultConstructorMarker;)V', + ); + + static final _new$1 = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + jni$_.VarArgs< + ( + jni$_.Pointer, + jni$_.Int32, + jni$_.Int32, + jni$_.Pointer + )>)>>('globalEnv_NewObject') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + jni$_.Pointer, + int, + int, + jni$_.Pointer)>(); + + /// from: `synthetic public void (java.lang.String string, int i, int i1, kotlin.jvm.internal.DefaultConstructorMarker defaultConstructorMarker)` + /// The returned object must be released after use, by calling the [release] method. + factory MixedParams.new$1( + jni$_.JString? string, + int i, + int i1, + jni$_.JObject? defaultConstructorMarker, + ) { + final _$string = string?.reference ?? jni$_.jNullReference; + final _$defaultConstructorMarker = + defaultConstructorMarker?.reference ?? jni$_.jNullReference; + return _new$1(_class.reference.pointer, _id_new$1.pointer, _$string.pointer, + i, i1, _$defaultConstructorMarker.pointer) + .object(); + } + + static final _id_getRequired = _class.instanceMethodId( + r'getRequired', + r'()Ljava/lang/String;', + ); + + static final _getRequired = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>>('globalEnv_CallObjectMethod') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>(); + + /// from: `public final java.lang.String getRequired()` + /// The returned object must be released after use, by calling the [release] method. + jni$_.JString getRequired() { + return _getRequired(reference.pointer, _id_getRequired.pointer) + .object(); + } + + static final _id_getOptional = _class.instanceMethodId( + r'getOptional', + r'()I', + ); + + static final _getOptional = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>>('globalEnv_CallIntMethod') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>(); + + /// from: `public final int getOptional()` + int getOptional() { + return _getOptional(reference.pointer, _id_getOptional.pointer).integer; + } + + static final _id_describe = _class.instanceMethodId( + r'describe', + r'()Ljava/lang/String;', + ); + + static final _describe = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>>('globalEnv_CallObjectMethod') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>(); + + /// from: `public fun describe(): kotlin.String` + /// The returned object must be released after use, by calling the [release] method. + jni$_.JString describe() { + return _describe(reference.pointer, _id_describe.pointer) + .object(); + } +} +final class $MixedParams$Type$ extends jni$_.JType { @jni$_.internal - final jni$_.JType<$V> V; + const $MixedParams$Type$(); @jni$_.internal - Nullability$InnerClass.fromReference( - this.T, - this.U, - this.V, - jni$_.JReference reference, - ) : $type = type<$T, $U, $V>(T, U, V), - super.fromReference(reference); + @core$_.override + String get signature => r'Lcom/github/dart_lang/jnigen/MixedParams;'; +} +/// from: `com.github.dart_lang.jnigen.Nullability$InnerClass` +extension type Nullability$InnerClass< + $T extends jni$_.JObject?, + $U extends jni$_.JObject, + $V extends jni$_.JObject?>._(jni$_.JObject _$this) + implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/Nullability$InnerClass'); @@ -729,26 +1207,8 @@ final class $Nullability$InnerClass$Type$ } /// from: `com.github.dart_lang.jnigen.Nullability` -class Nullability<$T extends jni$_.JObject?, $U extends jni$_.JObject> - extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType> $type; - - @jni$_.internal - final jni$_.JType<$T> T; - - @jni$_.internal - final jni$_.JType<$U> U; - - @jni$_.internal - Nullability.fromReference( - this.T, - this.U, - jni$_.JReference reference, - ) : $type = type<$T, $U>(T, U), - super.fromReference(reference); - +extension type Nullability<$T extends jni$_.JObject?, + $U extends jni$_.JObject>._(jni$_.JObject _$this) implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/Nullability'); @@ -1481,17 +1941,7 @@ final class $Nullability$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.Operators` -class Operators extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - Operators.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type Operators._(jni$_.JObject _$this) implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/Operators'); @@ -1846,17 +2296,7 @@ final class $Operators$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.Speed` -class Speed extends Measure { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - Speed.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(const $SpeedUnit$Type$(), reference); - +extension type Speed._(jni$_.JObject _$this) implements Measure { static jni$_.JClass get _class => jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/Speed'); @@ -2096,17 +2536,7 @@ final class $Speed$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.SpeedUnit` -class SpeedUnit extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - SpeedUnit.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type SpeedUnit._(jni$_.JObject _$this) implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/SpeedUnit'); @@ -2240,17 +2670,7 @@ final class $SpeedUnit$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.SuspendFun` -class SuspendFun extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - SuspendFun.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type SuspendFun._(jni$_.JObject _$this) implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/SuspendFun'); @@ -2861,17 +3281,8 @@ core$_.Future consumeOnSameThread( } /// from: `com.github.dart_lang.jnigen.SuspendInterface` -class SuspendInterface extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - SuspendInterface.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type SuspendInterface._(jni$_.JObject _$this) + implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/SuspendInterface'); diff --git a/pkgs/jnigen/test/simple_package_test/bindings/simple_package.dart b/pkgs/jnigen/test/simple_package_test/bindings/simple_package.dart index 924ac2a023..34baed0233 100644 --- a/pkgs/jnigen/test/simple_package_test/bindings/simple_package.dart +++ b/pkgs/jnigen/test/simple_package_test/bindings/simple_package.dart @@ -41,17 +41,8 @@ import 'package:jni/_internal.dart' as jni$_; import 'package:jni/jni.dart' as jni$_; /// from: `com.github.dart_lang.jnigen.simple_package.Example$Nested$NestedTwice` -class Example$Nested$NestedTwice extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - Example$Nested$NestedTwice.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type Example$Nested$NestedTwice._(jni$_.JObject _$this) + implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/simple_package/Example$Nested$NestedTwice'); @@ -105,17 +96,7 @@ final class $Example$Nested$NestedTwice$Type$ } /// from: `com.github.dart_lang.jnigen.simple_package.Example$Nested` -class Example$Nested extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - Example$Nested.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type Example$Nested._(jni$_.JObject _$this) implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/simple_package/Example$Nested'); @@ -224,17 +205,8 @@ final class $Example$Nested$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.simple_package.Example$NonStaticNested` -class Example$NonStaticNested extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - Example$NonStaticNested.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type Example$NonStaticNested._(jni$_.JObject _$this) + implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/simple_package/Example$NonStaticNested'); @@ -292,17 +264,7 @@ final class $Example$NonStaticNested$Type$ } /// from: `com.github.dart_lang.jnigen.simple_package.Example` -class Example extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - Example.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type Example._(jni$_.JObject _$this) implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/simple_package/Example'); @@ -1523,7 +1485,7 @@ final class $Example$Type$ extends jni$_.JType { /// from: `com.github.dart_lang.jnigen.simple_package.Exceptions$MyException` extension type Exceptions$MyException._(jni$_.JObject _$this) implements jni$_.JObject { - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/simple_package/Exceptions$MyException'); /// The type which includes information such as the signature of this class. @@ -1581,17 +1543,7 @@ final class $Exceptions$MyException$Type$ } /// from: `com.github.dart_lang.jnigen.simple_package.Exceptions` -class Exceptions extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - Exceptions.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type Exceptions._(jni$_.JObject _$this) implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/simple_package/Exceptions'); @@ -2054,17 +2006,7 @@ final class $Exceptions$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.simple_package.Fields$Nested` -class Fields$Nested extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - Fields$Nested.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type Fields$Nested._(jni$_.JObject _$this) implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/simple_package/Fields$Nested'); @@ -2131,17 +2073,7 @@ final class $Fields$Nested$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.simple_package.Fields` -class Fields extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - Fields.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type Fields._(jni$_.JObject _$this) implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/simple_package/Fields'); @@ -2316,17 +2248,7 @@ final class $Fields$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.pkg2.C2` -class C2 extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - C2.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type C2._(jni$_.JObject _$this) implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/pkg2/C2'); @@ -2378,17 +2300,7 @@ final class $C2$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.pkg2.Example` -class Example$1 extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - Example$1.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type Example$1._(jni$_.JObject _$this) implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/pkg2/Example'); @@ -2450,17 +2362,7 @@ final class $Example$1$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.enums.Colors$RGB` -class Colors$RGB extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - Colors$RGB.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type Colors$RGB._(jni$_.JObject _$this) implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/enums/Colors$RGB'); @@ -2584,78 +2486,9 @@ final class $Colors$RGB$Type$ extends jni$_.JType { /// from: `com.github.dart_lang.jnigen.enums.Colors` extension type Colors._(jni$_.JObject _$this) implements jni$_.JObject { - static final _class = - jni$_.JClass.forName(r'com/github/dart_lang/jnigen/enums/Colors'); - - @jni$_.internal - @core$_.override - final superCount = 1; - - @core$_.override - int get hashCode => ($Colors$RGB$NullableType$).hashCode; - - @core$_.override - core$_.bool operator ==(Object other) { - return other.runtimeType == ($Colors$RGB$NullableType$) && - other is $Colors$RGB$NullableType$; - } -} - -final class $Colors$RGB$Type$ extends jni$_.JType { - @jni$_.internal - const $Colors$RGB$Type$(); - - @jni$_.internal - @core$_.override - String get signature => r'Lcom/github/dart_lang/jnigen/enums/Colors$RGB;'; - - @jni$_.internal - @core$_.override - Colors$RGB fromReference(jni$_.JReference reference) => - Colors$RGB.fromReference( - reference, - ); - @jni$_.internal - @core$_.override - jni$_.JType get superType => const jni$_.$JObject$NullableType$(); - - @jni$_.internal - @core$_.override - jni$_.JType get nullableType => - const $Colors$RGB$NullableType$(); - - @jni$_.internal - @core$_.override - final superCount = 1; - - @core$_.override - int get hashCode => ($Colors$RGB$Type$).hashCode; - - @core$_.override - core$_.bool operator ==(Object other) { - return other.runtimeType == ($Colors$RGB$Type$) && - other is $Colors$RGB$Type$; - } -} - -/// from: `com.github.dart_lang.jnigen.enums.Colors` -class Colors extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - Colors.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - static jni$_.JClass get _class => jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/enums/Colors'); - /// The type which includes information such as the signature of this class. - static const jni$_.JType nullableType = $Colors$NullableType$(); - /// The type which includes information such as the signature of this class. static const jni$_.JType type = $Colors$Type$(); static final _id_red = _class.staticFieldId( @@ -2778,26 +2611,9 @@ final class $Colors$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.generics.GenericTypeParams` -class GenericTypeParams<$S extends jni$_.JObject?, $K extends jni$_.JObject?> - extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType> $type; - - @jni$_.internal - final jni$_.JType<$S> S; - - @jni$_.internal - final jni$_.JType<$K> K; - - @jni$_.internal - GenericTypeParams.fromReference( - this.S, - this.K, - jni$_.JReference reference, - ) : $type = type<$S, $K>(S, K), - super.fromReference(reference); - +extension type GenericTypeParams<$S extends jni$_.JObject?, + $K extends jni$_.JObject?>._(jni$_.JObject _$this) + implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/generics/GenericTypeParams'); @@ -2838,32 +2654,11 @@ final class $GenericTypeParams$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.generics.GrandParent$Parent$Child` -class GrandParent$Parent$Child< - $T extends jni$_.JObject?, - $S extends jni$_.JObject?, - $U extends jni$_.JObject?> extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType> $type; - - @jni$_.internal - final jni$_.JType<$T> T; - - @jni$_.internal - final jni$_.JType<$S> S; - - @jni$_.internal - final jni$_.JType<$U> U; - - @jni$_.internal - GrandParent$Parent$Child.fromReference( - this.T, - this.S, - this.U, - jni$_.JReference reference, - ) : $type = type<$T, $S, $U>(T, S, U), - super.fromReference(reference); - +extension type GrandParent$Parent$Child< + $T extends jni$_.JObject?, + $S extends jni$_.JObject?, + $U extends jni$_.JObject?>._(jni$_.JObject _$this) + implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/generics/GrandParent$Parent$Child'); @@ -2960,26 +2755,9 @@ final class $GrandParent$Parent$Child$Type$ } /// from: `com.github.dart_lang.jnigen.generics.GrandParent$Parent` -class GrandParent$Parent<$T extends jni$_.JObject?, $S extends jni$_.JObject?> - extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType> $type; - - @jni$_.internal - final jni$_.JType<$T> T; - - @jni$_.internal - final jni$_.JType<$S> S; - - @jni$_.internal - GrandParent$Parent.fromReference( - this.T, - this.S, - jni$_.JReference reference, - ) : $type = type<$T, $S>(T, S), - super.fromReference(reference); - +extension type GrandParent$Parent<$T extends jni$_.JObject?, + $S extends jni$_.JObject?>._(jni$_.JObject _$this) + implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/generics/GrandParent$Parent'); @@ -3060,26 +2838,9 @@ final class $GrandParent$Parent$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.generics.GrandParent$StaticParent$Child` -class GrandParent$StaticParent$Child<$S extends jni$_.JObject?, - $U extends jni$_.JObject?> extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType> $type; - - @jni$_.internal - final jni$_.JType<$S> S; - - @jni$_.internal - final jni$_.JType<$U> U; - - @jni$_.internal - GrandParent$StaticParent$Child.fromReference( - this.S, - this.U, - jni$_.JReference reference, - ) : $type = type<$S, $U>(S, U), - super.fromReference(reference); - +extension type GrandParent$StaticParent$Child<$S extends jni$_.JObject?, + $U extends jni$_.JObject?>._(jni$_.JObject _$this) + implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/generics/GrandParent$StaticParent$Child'); @@ -3165,22 +2926,8 @@ final class $GrandParent$StaticParent$Child$Type$ } /// from: `com.github.dart_lang.jnigen.generics.GrandParent$StaticParent` -class GrandParent$StaticParent<$S extends jni$_.JObject?> - extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType> $type; - - @jni$_.internal - final jni$_.JType<$S> S; - - @jni$_.internal - GrandParent$StaticParent.fromReference( - this.S, - jni$_.JReference reference, - ) : $type = type<$S>(S), - super.fromReference(reference); - +extension type GrandParent$StaticParent<$S extends jni$_.JObject?>._( + jni$_.JObject _$this) implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/generics/GrandParent$StaticParent'); @@ -3238,21 +2985,8 @@ final class $GrandParent$StaticParent$Type$ } /// from: `com.github.dart_lang.jnigen.generics.GrandParent` -class GrandParent<$T extends jni$_.JObject?> extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType> $type; - - @jni$_.internal - final jni$_.JType<$T> T; - - @jni$_.internal - GrandParent.fromReference( - this.T, - jni$_.JReference reference, - ) : $type = type<$T>(T), - super.fromReference(reference); - +extension type GrandParent<$T extends jni$_.JObject?>._(jni$_.JObject _$this) + implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/generics/GrandParent'); @@ -3439,7 +3173,7 @@ final class $GrandParent$Type$ extends jni$_.JType { extension type MyMap$MyEntry<$K extends jni$_.JObject?, $V extends jni$_.JObject?>._(jni$_.JObject _$this) implements jni$_.JObject { - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/generics/MyMap$MyEntry'); /// The type which includes information such as the signature of this class. @@ -3470,88 +3204,6 @@ extension type MyMap$MyEntry<$K extends jni$_.JObject?, /// The returned object must be released after use, by calling the [release] method. set value($V? value) => _id_value.set(this, jni$_.JObject.type, value); - @core$_.override - core$_.bool operator ==(Object other) { - return other.runtimeType == ($GrandParent$Type$<$T>) && - other is $GrandParent$Type$<$T> && - T == other.T; - } -} - -/// from: `com.github.dart_lang.jnigen.generics.MyMap$MyEntry` -class MyMap$MyEntry<$K extends jni$_.JObject?, $V extends jni$_.JObject?> - extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType> $type; - - @jni$_.internal - final jni$_.JType<$K> K; - - @jni$_.internal - final jni$_.JType<$V> V; - - @jni$_.internal - MyMap$MyEntry.fromReference( - this.K, - this.V, - jni$_.JReference reference, - ) : $type = type<$K, $V>(K, V), - super.fromReference(reference); - - static jni$_.JClass get _class => jni$_.JClass.forNameCached( - r'com/github/dart_lang/jnigen/generics/MyMap$MyEntry'); - - /// The type which includes information such as the signature of this class. - static jni$_.JType?> - nullableType<$K extends jni$_.JObject?, $V extends jni$_.JObject?>( - jni$_.JType<$K> K, - jni$_.JType<$V> V, - ) { - return $MyMap$MyEntry$NullableType$<$K, $V>( - K, - V, - ); - } - - /// The type which includes information such as the signature of this class. - static jni$_.JType> - type<$K extends jni$_.JObject?, $V extends jni$_.JObject?>( - jni$_.JType<$K> K, - jni$_.JType<$V> V, - ) { - return $MyMap$MyEntry$Type$<$K, $V>( - K, - V, - ); - } - - static final _id_key = _class.instanceFieldId( - r'key', - r'Ljava/lang/Object;', - ); - - /// from: `public K key` - /// The returned object must be released after use, by calling the [release] method. - $K? get key => _id_key.get(this, K.nullableType); - - /// from: `public K key` - /// The returned object must be released after use, by calling the [release] method. - set key($K? value) => _id_key.set(this, K.nullableType, value); - - static final _id_value = _class.instanceFieldId( - r'value', - r'Ljava/lang/Object;', - ); - - /// from: `public V value` - /// The returned object must be released after use, by calling the [release] method. - $V? get value => _id_value.get(this, V.nullableType); - - /// from: `public V value` - /// The returned object must be released after use, by calling the [release] method. - set value($V? value) => _id_value.set(this, V.nullableType, value); - static final _id_new$ = _class.constructorId( r'(Lcom/github/dart_lang/jnigen/generics/MyMap;Ljava/lang/Object;Ljava/lang/Object;)V', ); @@ -3602,26 +3254,8 @@ final class $MyMap$MyEntry$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.generics.MyMap` -class MyMap<$K extends jni$_.JObject?, $V extends jni$_.JObject?> - extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType> $type; - - @jni$_.internal - final jni$_.JType<$K> K; - - @jni$_.internal - final jni$_.JType<$V> V; - - @jni$_.internal - MyMap.fromReference( - this.K, - this.V, - jni$_.JReference reference, - ) : $type = type<$K, $V>(K, V), - super.fromReference(reference); - +extension type MyMap<$K extends jni$_.JObject?, $V extends jni$_.JObject?>._( + jni$_.JObject _$this) implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached(r'com/github/dart_lang/jnigen/generics/MyMap'); @@ -3746,21 +3380,8 @@ final class $MyMap$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.generics.MyStack` -class MyStack<$T extends jni$_.JObject?> extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType> $type; - - @jni$_.internal - final jni$_.JType<$T> T; - - @jni$_.internal - MyStack.fromReference( - this.T, - jni$_.JReference reference, - ) : $type = type<$T>(T), - super.fromReference(reference); - +extension type MyStack<$T extends jni$_.JObject?>._(jni$_.JObject _$this) + implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/generics/MyStack'); @@ -4010,23 +3631,8 @@ final class $MyStack$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.generics.StringKeyedMap` -class StringKeyedMap<$V extends jni$_.JObject?> - extends MyMap { - @jni$_.internal - @core$_.override - final jni$_.JType> $type; - - @jni$_.internal - final jni$_.JType<$V> V; - - @jni$_.internal - StringKeyedMap.fromReference( - this.V, - jni$_.JReference reference, - ) : $type = type<$V>(V), - super.fromReference( - const jni$_.$JString$NullableType$(), V.nullableType, reference); - +extension type StringKeyedMap<$V extends jni$_.JObject?>._(jni$_.JObject _$this) + implements MyMap { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/generics/StringKeyedMap'); @@ -4050,262 +3656,68 @@ class StringKeyedMap<$V extends jni$_.JObject?> /// from: `public void ()` /// The returned object must be released after use, by calling the [release] method. - factory StringKeyedMap() { - return _new$(_class.reference.pointer, _id_new$.pointer) - .object>(); - } -} - -final class $StringKeyedMap$Type$ extends jni$_.JType { - @jni$_.internal - const $StringKeyedMap$Type$(); - - @jni$_.internal - @core$_.override - String get signature => - r'Lcom/github/dart_lang/jnigen/generics/StringKeyedMap;'; -} - -/// from: `com.github.dart_lang.jnigen.generics.StringMap` -class StringMap extends StringKeyedMap { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - StringMap.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(const jni$_.$JString$NullableType$(), reference); - - static jni$_.JClass get _class => jni$_.JClass.forNameCached( - r'com/github/dart_lang/jnigen/generics/StringMap'); - - /// The type which includes information such as the signature of this class. - static const jni$_.JType type = $StringMap$Type$(); - static final _id_new$ = _class.constructorId( - r'()V', - ); - - static final _new$ = jni$_.ProtectedJniExtensions.lookup< - jni$_.NativeFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - )>>('globalEnv_NewObject') - .asFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - )>(); - - /// from: `public void ()` - /// The returned object must be released after use, by calling the [release] method. - factory StringMap() { - return _new$(_class.reference.pointer, _id_new$.pointer) - .object(); - } -} - -final class $StringMap$Type$ extends jni$_.JType { - @jni$_.internal - const $StringMap$Type$(); - - @jni$_.internal - @core$_.override - String get signature => r'Lcom/github/dart_lang/jnigen/generics/StringMap;'; -} - - @jni$_.internal - @core$_.override - StringMap fromReference(jni$_.JReference reference) => - StringMap.fromReference( - reference, - ); - @jni$_.internal - @core$_.override - jni$_.JType get superType => - const $StringKeyedMap$NullableType$( - jni$_.$JString$NullableType$()); - - @jni$_.internal - @core$_.override - jni$_.JType get nullableType => const $StringMap$NullableType$(); - - @jni$_.internal - @core$_.override - final superCount = 3; - - @core$_.override - int get hashCode => ($StringMap$Type$).hashCode; - - @core$_.override - core$_.bool operator ==(Object other) { - return other.runtimeType == ($StringMap$Type$) && other is $StringMap$Type$; - } -} - -/// from: `com.github.dart_lang.jnigen.generics.StringStack` -class StringStack extends MyStack { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - StringStack.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(const jni$_.$JString$NullableType$(), reference); - - static jni$_.JClass get _class => jni$_.JClass.forNameCached( - r'com/github/dart_lang/jnigen/generics/StringStack'); - - /// The type which includes information such as the signature of this class. - static const jni$_.JType nullableType = - $StringStack$NullableType$(); - - /// The type which includes information such as the signature of this class. - static const jni$_.JType type = $StringStack$Type$(); - static final _id_new$ = _class.constructorId( - r'()V', - ); - - static final _new$ = jni$_.ProtectedJniExtensions.lookup< - jni$_.NativeFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - )>>('globalEnv_NewObject') - .asFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - )>(); - - /// from: `public void ()` - /// The returned object must be released after use, by calling the [release] method. - factory StringStack() { - return StringStack.fromReference( - _new$(_class.reference.pointer, _id_new$ as jni$_.JMethodIDPtr) - .reference); + factory StringKeyedMap() { + return _new$(_class.reference.pointer, _id_new$.pointer) + .object>(); } } -final class $StringStack$NullableType$ extends jni$_.JType { - @jni$_.internal - const $StringStack$NullableType$(); - +final class $StringKeyedMap$Type$ extends jni$_.JType { @jni$_.internal - @core$_.override - String get signature => r'Lcom/github/dart_lang/jnigen/generics/StringStack;'; + const $StringKeyedMap$Type$(); @jni$_.internal @core$_.override - StringStack? fromReference(jni$_.JReference reference) => reference.isNull - ? null - : StringStack.fromReference( - reference, - ); - @jni$_.internal - @core$_.override - jni$_.JType get superType => const $MyStack$NullableType$( - jni$_.$JString$NullableType$()); + String get signature => + r'Lcom/github/dart_lang/jnigen/generics/StringKeyedMap;'; +} - @jni$_.internal - @core$_.override - jni$_.JType get nullableType => this; +/// from: `com.github.dart_lang.jnigen.generics.StringMap` +extension type StringMap._(jni$_.JObject _$this) + implements StringKeyedMap { + static jni$_.JClass get _class => jni$_.JClass.forNameCached( + r'com/github/dart_lang/jnigen/generics/StringMap'); - @jni$_.internal - @core$_.override - final superCount = 2; + /// The type which includes information such as the signature of this class. + static const jni$_.JType type = $StringMap$Type$(); + static final _id_new$ = _class.constructorId( + r'()V', + ); - @core$_.override - int get hashCode => ($StringStack$NullableType$).hashCode; + static final _new$ = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>>('globalEnv_NewObject') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>(); - @core$_.override - core$_.bool operator ==(Object other) { - return other.runtimeType == ($StringStack$NullableType$) && - other is $StringStack$NullableType$; + /// from: `public void ()` + /// The returned object must be released after use, by calling the [release] method. + factory StringMap() { + return _new$(_class.reference.pointer, _id_new$.pointer) + .object(); } } -final class $StringStack$Type$ extends jni$_.JType { - @jni$_.internal - const $StringStack$Type$(); - - @jni$_.internal - @core$_.override - String get signature => r'Lcom/github/dart_lang/jnigen/generics/StringStack;'; - - @jni$_.internal - @core$_.override - StringStack fromReference(jni$_.JReference reference) => - StringStack.fromReference( - reference, - ); - @jni$_.internal - @core$_.override - jni$_.JType get superType => const $MyStack$NullableType$( - jni$_.$JString$NullableType$()); - +final class $StringMap$Type$ extends jni$_.JType { @jni$_.internal - @core$_.override - jni$_.JType get nullableType => - const $StringStack$NullableType$(); + const $StringMap$Type$(); @jni$_.internal @core$_.override - final superCount = 2; - - @core$_.override - int get hashCode => ($StringStack$Type$).hashCode; - - @core$_.override - core$_.bool operator ==(Object other) { - return other.runtimeType == ($StringStack$Type$) && - other is $StringStack$Type$; - } + String get signature => r'Lcom/github/dart_lang/jnigen/generics/StringMap;'; } -/// from: `com.github.dart_lang.jnigen.generics.StringValuedMap` -class StringValuedMap<$K extends jni$_.JObject?> - extends MyMap<$K?, jni$_.JString?> { - @jni$_.internal - @core$_.override - final jni$_.JType> $type; - - @jni$_.internal - final jni$_.JType<$K> K; - - @jni$_.internal - StringValuedMap.fromReference( - this.K, - jni$_.JReference reference, - ) : $type = type<$K>(K), - super.fromReference( - K.nullableType, const jni$_.$JString$NullableType$(), reference); - +/// from: `com.github.dart_lang.jnigen.generics.StringStack` +extension type StringStack._(jni$_.JObject _$this) + implements MyStack { static jni$_.JClass get _class => jni$_.JClass.forNameCached( - r'com/github/dart_lang/jnigen/generics/StringValuedMap'); - - /// The type which includes information such as the signature of this class. - static jni$_.JType?> - nullableType<$K extends jni$_.JObject?>( - jni$_.JType<$K> K, - ) { - return $StringValuedMap$NullableType$<$K>( - K, - ); - } - - /// The type which includes information such as the signature of this class. - static jni$_.JType> type<$K extends jni$_.JObject?>( - jni$_.JType<$K> K, - ) { - return $StringValuedMap$Type$<$K>( - K, - ); - } + r'com/github/dart_lang/jnigen/generics/StringStack'); /// The type which includes information such as the signature of this class. static const jni$_.JType type = $StringStack$Type$(); @@ -4345,7 +3757,7 @@ final class $StringStack$Type$ extends jni$_.JType { /// from: `com.github.dart_lang.jnigen.generics.StringValuedMap` extension type StringValuedMap<$K extends jni$_.JObject?>._( jni$_.JObject _$this) implements MyMap<$K?, jni$_.JString?> { - static final _class = jni$_.JClass.forName( + static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/generics/StringValuedMap'); /// The type which includes information such as the signature of this class. @@ -4385,21 +3797,8 @@ final class $StringValuedMap$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.interfaces.GenericInterface` -class GenericInterface<$T extends jni$_.JObject?> extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType> $type; - - @jni$_.internal - final jni$_.JType<$T> T; - - @jni$_.internal - GenericInterface.fromReference( - this.T, - jni$_.JReference reference, - ) : $type = type<$T>(T), - super.fromReference(reference); - +extension type GenericInterface<$T extends jni$_.JObject?>._( + jni$_.JObject _$this) implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/interfaces/GenericInterface'); @@ -4848,17 +4247,8 @@ final class $GenericInterface$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.interfaces.InheritedFromMyInterface` -class InheritedFromMyInterface extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - InheritedFromMyInterface.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type InheritedFromMyInterface._(jni$_.JObject _$this) + implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/interfaces/InheritedFromMyInterface'); @@ -5147,17 +4537,8 @@ final class $InheritedFromMyInterface$Type$ } /// from: `com.github.dart_lang.jnigen.interfaces.InheritedFromMyRunnable` -class InheritedFromMyRunnable extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - InheritedFromMyRunnable.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type InheritedFromMyRunnable._(jni$_.JObject _$this) + implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/interfaces/InheritedFromMyRunnable'); @@ -5298,42 +4679,11 @@ final class $InheritedFromMyRunnable$Type$ } /// from: `com.github.dart_lang.jnigen.interfaces.MyInterface` -class MyInterface<$T extends jni$_.JObject?> extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType> $type; - - @jni$_.internal - final jni$_.JType<$T> T; - - @jni$_.internal - MyInterface.fromReference( - this.T, - jni$_.JReference reference, - ) : $type = type<$T>(T), - super.fromReference(reference); - +extension type MyInterface<$T extends jni$_.JObject?>._(jni$_.JObject _$this) + implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/interfaces/MyInterface'); - /// The type which includes information such as the signature of this class. - static jni$_.JType?> nullableType<$T extends jni$_.JObject?>( - jni$_.JType<$T> T, - ) { - return $MyInterface$NullableType$<$T>( - T, - ); - } - - /// The type which includes information such as the signature of this class. - static jni$_.JType> type<$T extends jni$_.JObject?>( - jni$_.JType<$T> T, - ) { - return $MyInterface$Type$<$T>( - T, - ); - } - /// The type which includes information such as the signature of this class. static const jni$_.JType type = $MyInterface$Type$(); static final _id_voidCallback = _class.instanceMethodId( @@ -5618,17 +4968,8 @@ final class $MyInterface$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.interfaces.MyInterfaceConsumer` -class MyInterfaceConsumer extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - MyInterfaceConsumer.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type MyInterfaceConsumer._(jni$_.JObject _$this) + implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/interfaces/MyInterfaceConsumer'); @@ -5787,17 +5128,7 @@ final class $MyInterfaceConsumer$Type$ } /// from: `com.github.dart_lang.jnigen.interfaces.MyRunnable` -class MyRunnable extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - MyRunnable.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type MyRunnable._(jni$_.JObject _$this) implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/interfaces/MyRunnable'); @@ -5937,17 +5268,8 @@ final class $MyRunnable$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.interfaces.MyRunnableRunner` -class MyRunnableRunner extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - MyRunnableRunner.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type MyRunnableRunner._(jni$_.JObject _$this) + implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/interfaces/MyRunnableRunner'); @@ -6075,17 +5397,8 @@ final class $MyRunnableRunner$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.interfaces.StringConversionException` -class StringConversionException extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - StringConversionException.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type StringConversionException._(jni$_.JObject _$this) + implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/interfaces/StringConversionException'); @@ -6130,17 +5443,8 @@ final class $StringConversionException$Type$ } /// from: `com.github.dart_lang.jnigen.interfaces.StringConverter` -class StringConverter extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - StringConverter.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type StringConverter._(jni$_.JObject _$this) + implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/interfaces/StringConverter'); @@ -6279,17 +5583,8 @@ final class $StringConverter$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.interfaces.StringConverterConsumer` -class StringConverterConsumer extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - StringConverterConsumer.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type StringConverterConsumer._(jni$_.JObject _$this) + implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/interfaces/StringConverterConsumer'); @@ -6410,21 +5705,8 @@ final class $StringConverterConsumer$Type$ } /// from: `com.github.dart_lang.jnigen.inheritance.BaseClass` -class BaseClass<$T extends jni$_.JObject?> extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType> $type; - - @jni$_.internal - final jni$_.JType<$T> T; - - @jni$_.internal - BaseClass.fromReference( - this.T, - jni$_.JReference reference, - ) : $type = type<$T>(T), - super.fromReference(reference); - +extension type BaseClass<$T extends jni$_.JObject?>._(jni$_.JObject _$this) + implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/inheritance/BaseClass'); @@ -6492,21 +5774,8 @@ final class $BaseClass$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.inheritance.BaseGenericInterface` -class BaseGenericInterface<$T extends jni$_.JObject?> extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType> $type; - - @jni$_.internal - final jni$_.JType<$T> T; - - @jni$_.internal - BaseGenericInterface.fromReference( - this.T, - jni$_.JReference reference, - ) : $type = type<$T>(T), - super.fromReference(reference); - +extension type BaseGenericInterface<$T extends jni$_.JObject?>._( + jni$_.JObject _$this) implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/inheritance/BaseGenericInterface'); @@ -6647,17 +5916,7 @@ final class $BaseGenericInterface$Type$ } /// from: `com.github.dart_lang.jnigen.inheritance.BaseInterface` -class BaseInterface extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - BaseInterface.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type BaseInterface._(jni$_.JObject _$this) implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/inheritance/BaseInterface'); @@ -6795,17 +6054,8 @@ final class $BaseInterface$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.inheritance.DerivedInterface` -class DerivedInterface extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - DerivedInterface.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type DerivedInterface._(jni$_.JObject _$this) + implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/inheritance/DerivedInterface'); @@ -6943,21 +6193,8 @@ final class $DerivedInterface$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.inheritance.GenericDerivedClass` -class GenericDerivedClass<$T extends jni$_.JObject?> extends BaseClass<$T?> { - @jni$_.internal - @core$_.override - final jni$_.JType> $type; - - @jni$_.internal - final jni$_.JType<$T> T; - - @jni$_.internal - GenericDerivedClass.fromReference( - this.T, - jni$_.JReference reference, - ) : $type = type<$T>(T), - super.fromReference(T.nullableType, reference); - +extension type GenericDerivedClass<$T extends jni$_.JObject?>._( + jni$_.JObject _$this) implements BaseClass<$T?> { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/inheritance/GenericDerivedClass'); @@ -7000,17 +6237,8 @@ final class $GenericDerivedClass$Type$ } /// from: `com.github.dart_lang.jnigen.inheritance.SpecificDerivedClass` -class SpecificDerivedClass extends BaseClass { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - SpecificDerivedClass.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(const jni$_.$JString$NullableType$(), reference); - +extension type SpecificDerivedClass._(jni$_.JObject _$this) + implements BaseClass { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/inheritance/SpecificDerivedClass'); @@ -7079,6 +6307,13 @@ final class $SpecificDerivedClass$Type$ r'Lcom/github/dart_lang/jnigen/inheritance/SpecificDerivedClass;'; } +/// from: `com.github.dart_lang.jnigen.annotations.Annotated$Nested` +extension type Annotated$Nested< + $T extends jni$_.JObject?, + $U extends jni$_.JObject, + $W extends jni$_.JObject, + $V extends jni$_.JObject?>._(jni$_.JObject _$this) + implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/annotations/Annotated$Nested'); @@ -7156,30 +6391,8 @@ final class $Annotated$Nested$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.annotations.Annotated` -class Annotated<$T extends jni$_.JObject?, $U extends jni$_.JObject, - $W extends jni$_.JObject> extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType> $type; - - @jni$_.internal - final jni$_.JType<$T> T; - - @jni$_.internal - final jni$_.JType<$U> U; - - @jni$_.internal - final jni$_.JType<$W> W; - - @jni$_.internal - Annotated.fromReference( - this.T, - this.U, - this.W, - jni$_.JReference reference, - ) : $type = type<$T, $U, $W>(T, U, W), - super.fromReference(reference); - +extension type Annotated<$T extends jni$_.JObject?, $U extends jni$_.JObject, + $W extends jni$_.JObject>._(jni$_.JObject _$this) implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/annotations/Annotated'); @@ -8786,6 +7999,9 @@ final class $Annotated$Type$ extends jni$_.JType { r'Lcom/github/dart_lang/jnigen/annotations/Annotated;'; } +/// from: `com.github.dart_lang.jnigen.annotations.JsonSerializable$Case` +extension type JsonSerializable$Case._(jni$_.JObject _$this) + implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/annotations/JsonSerializable$Case'); @@ -8889,17 +8105,8 @@ final class $JsonSerializable$Case$Type$ } /// from: `com.github.dart_lang.jnigen.annotations.JsonSerializable` -class JsonSerializable extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - JsonSerializable.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type JsonSerializable._(jni$_.JObject _$this) + implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/annotations/JsonSerializable'); @@ -9039,17 +8246,7 @@ final class $JsonSerializable$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.annotations.MyDataClass` -class MyDataClass extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - MyDataClass.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type MyDataClass._(jni$_.JObject _$this) implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/annotations/MyDataClass'); @@ -9090,17 +8287,7 @@ final class $MyDataClass$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.annotations.NotNull` -class NotNull extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - NotNull.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type NotNull._(jni$_.JObject _$this) implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/annotations/NotNull'); @@ -9195,17 +8382,7 @@ final class $NotNull$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.annotations.Nullable` -class Nullable extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - Nullable.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - +extension type Nullable._(jni$_.JObject _$this) implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/annotations/Nullable'); @@ -9299,6 +8476,8 @@ final class $Nullable$Type$ extends jni$_.JType { String get signature => r'Lcom/github/dart_lang/jnigen/annotations/Nullable;'; } +/// from: `com.github.dart_lang.jnigen.regressions.R2250$Child` +extension type R2250$Child._(jni$_.JObject _$this) implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/regressions/R2250$Child'); @@ -9435,21 +8614,8 @@ final class $R2250$Child$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.regressions.R2250` -class R2250<$T extends jni$_.JObject?> extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType> $type; - - @jni$_.internal - final jni$_.JType<$T> T; - - @jni$_.internal - R2250.fromReference( - this.T, - jni$_.JReference reference, - ) : $type = type<$T>(T), - super.fromReference(reference); - +extension type R2250<$T extends jni$_.JObject?>._(jni$_.JObject _$this) + implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/regressions/R2250'); @@ -9585,17 +8751,7 @@ final class $R2250$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.regressions.R693$Child` -class R693$Child extends R693 { - @jni$_.internal - @core$_.override - final jni$_.JType $type; - - @jni$_.internal - R693$Child.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(const $R693$Child$NullableType$(), reference); - +extension type R693$Child._(jni$_.JObject _$this) implements R693 { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/regressions/R693$Child'); @@ -9636,21 +8792,8 @@ final class $R693$Child$Type$ extends jni$_.JType { } /// from: `com.github.dart_lang.jnigen.regressions.R693` -class R693<$T extends jni$_.JObject?> extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JType> $type; - - @jni$_.internal - final jni$_.JType<$T> T; - - @jni$_.internal - R693.fromReference( - this.T, - jni$_.JReference reference, - ) : $type = type<$T>(T), - super.fromReference(reference); - +extension type R693<$T extends jni$_.JObject?>._(jni$_.JObject _$this) + implements jni$_.JObject { static jni$_.JClass get _class => jni$_.JClass.forNameCached( r'com/github/dart_lang/jnigen/regressions/R693');