Skip to content

Commit 42dd764

Browse files
[jnigen] Remove TypeUsage indirection (#2186)
1 parent 04ac104 commit 42dd764

File tree

23 files changed

+498
-510
lines changed

23 files changed

+498
-510
lines changed

pkgs/jnigen/example/in_app_java/lib/android_utils.dart

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// ignore_for_file: camel_case_extensions
66
// ignore_for_file: camel_case_types
77
// ignore_for_file: constant_identifier_names
8+
// ignore_for_file: comment_references
89
// ignore_for_file: doc_directive_unknown
910
// ignore_for_file: file_names
1011
// ignore_for_file: inference_failure_on_untyped_parameter
@@ -782,7 +783,7 @@ class EmojiCompat$Config extends jni$_.JObject {
782783
jni$_.JniResult Function(jni$_.Pointer<jni$_.Void>,
783784
jni$_.JMethodIDPtr, int, jni$_.Pointer<jni$_.Void>)>();
784785

785-
/// from: `public androidx.emoji2.text.EmojiCompat$Config setUseEmojiAsDefaultStyle(boolean z, java.util.List list)`
786+
/// from: `public androidx.emoji2.text.EmojiCompat$Config setUseEmojiAsDefaultStyle(boolean z, java.util.List<java.lang.Integer> list)`
786787
/// The returned object must be released after use, by calling the [release] method.
787788
EmojiCompat$Config setUseEmojiAsDefaultStyle$1(
788789
bool z,
@@ -3737,7 +3738,7 @@ class DefaultEmojiCompatConfig$DefaultEmojiCompatConfigHelper
37373738
jni$_.Pointer<jni$_.Void>,
37383739
int)>();
37393740

3740-
/// from: `public java.util.List queryIntentContentProviders(android.content.pm.PackageManager packageManager, android.content.Intent intent, int i)`
3741+
/// from: `public java.util.List<android.content.pm.ResolveInfo> queryIntentContentProviders(android.content.pm.PackageManager packageManager, android.content.Intent intent, int i)`
37413742
/// The returned object must be released after use, by calling the [release] method.
37423743
jni$_.JList<jni$_.JObject?> queryIntentContentProviders(
37433744
jni$_.JObject packageManager,
@@ -3949,7 +3950,7 @@ class DefaultEmojiCompatConfig$DefaultEmojiCompatConfigHelper_API19
39493950
jni$_.Pointer<jni$_.Void>,
39503951
int)>();
39513952

3952-
/// from: `public java.util.List queryIntentContentProviders(android.content.pm.PackageManager packageManager, android.content.Intent intent, int i)`
3953+
/// from: `public java.util.List<android.content.pm.ResolveInfo> queryIntentContentProviders(android.content.pm.PackageManager packageManager, android.content.Intent intent, int i)`
39533954
/// The returned object must be released after use, by calling the [release] method.
39543955
jni$_.JList<jni$_.JObject?> queryIntentContentProviders(
39553956
jni$_.JObject packageManager,
@@ -5448,7 +5449,7 @@ class Build extends jni$_.JObject {
54485449
jni$_.JMethodIDPtr,
54495450
)>();
54505451

5451-
/// from: `static public java.util.List getFingerprintedPartitions()`
5452+
/// from: `static public java.util.List<android.os.Build$Partition> getFingerprintedPartitions()`
54525453
/// The returned object must be released after use, by calling the [release] method.
54535454
static jni$_.JList<Build$Partition?>? getFingerprintedPartitions() {
54545455
return _getFingerprintedPartitions(_class.reference.pointer,
@@ -5703,7 +5704,7 @@ class HashMap<$K extends jni$_.JObject?, $V extends jni$_.JObject?>
57035704
jni$_.JniResult Function(jni$_.Pointer<jni$_.Void>,
57045705
jni$_.JMethodIDPtr, jni$_.Pointer<jni$_.Void>)>();
57055706

5706-
/// from: `public void <init>(java.util.Map map)`
5707+
/// from: `public void <init>(java.util.Map<? extends K, ? extends V> map)`
57075708
/// The returned object must be released after use, by calling the [release] method.
57085709
factory HashMap.new$3(
57095710
jni$_.JMap<$K?, $V?>? map, {
@@ -5868,7 +5869,7 @@ class HashMap<$K extends jni$_.JObject?, $V extends jni$_.JObject?>
58685869
jni$_.JThrowablePtr Function(jni$_.Pointer<jni$_.Void>,
58695870
jni$_.JMethodIDPtr, jni$_.Pointer<jni$_.Void>)>();
58705871

5871-
/// from: `public void putAll(java.util.Map map)`
5872+
/// from: `public void putAll(java.util.Map<? extends K, ? extends V> map)`
58725873
void putAll(
58735874
jni$_.JMap<$K?, $V?>? map,
58745875
) {
@@ -5969,7 +5970,7 @@ class HashMap<$K extends jni$_.JObject?, $V extends jni$_.JObject?>
59695970
jni$_.JMethodIDPtr,
59705971
)>();
59715972

5972-
/// from: `public java.util.Set keySet()`
5973+
/// from: `public java.util.Set<K> keySet()`
59735974
/// The returned object must be released after use, by calling the [release] method.
59745975
jni$_.JSet<$K?>? keySet() {
59755976
return _keySet(reference.pointer, _id_keySet as jni$_.JMethodIDPtr)
@@ -5993,7 +5994,7 @@ class HashMap<$K extends jni$_.JObject?, $V extends jni$_.JObject?>
59935994
jni$_.JMethodIDPtr,
59945995
)>();
59955996

5996-
/// from: `public java.util.Collection values()`
5997+
/// from: `public java.util.Collection<V> values()`
59975998
/// The returned object must be released after use, by calling the [release] method.
59985999
jni$_.JObject? values() {
59996000
return _values(reference.pointer, _id_values as jni$_.JMethodIDPtr)
@@ -6017,7 +6018,7 @@ class HashMap<$K extends jni$_.JObject?, $V extends jni$_.JObject?>
60176018
jni$_.JMethodIDPtr,
60186019
)>();
60196020

6020-
/// from: `public java.util.Set entrySet()`
6021+
/// from: `public java.util.Set<java.util.Map$Entry<K, V>> entrySet()`
60216022
/// The returned object must be released after use, by calling the [release] method.
60226023
jni$_.JSet<jni$_.JObject?>? entrySet() {
60236024
return _entrySet(reference.pointer, _id_entrySet as jni$_.JMethodIDPtr)
@@ -6231,7 +6232,7 @@ class HashMap<$K extends jni$_.JObject?, $V extends jni$_.JObject?>
62316232
jni$_.Pointer<jni$_.Void>,
62326233
jni$_.Pointer<jni$_.Void>)>();
62336234

6234-
/// from: `public V computeIfAbsent(K object, java.util.function.Function function)`
6235+
/// from: `public V computeIfAbsent(K object, java.util.function.Function<? super K, ? extends V> function)`
62356236
/// The returned object must be released after use, by calling the [release] method.
62366237
$V? computeIfAbsent(
62376238
$K? object,
@@ -6269,7 +6270,7 @@ class HashMap<$K extends jni$_.JObject?, $V extends jni$_.JObject?>
62696270
jni$_.Pointer<jni$_.Void>,
62706271
jni$_.Pointer<jni$_.Void>)>();
62716272

6272-
/// from: `public V computeIfPresent(K object, java.util.function.BiFunction biFunction)`
6273+
/// from: `public V computeIfPresent(K object, java.util.function.BiFunction<? super K, ? super V, ? extends V> biFunction)`
62736274
/// The returned object must be released after use, by calling the [release] method.
62746275
$V? computeIfPresent(
62756276
$K? object,
@@ -6307,7 +6308,7 @@ class HashMap<$K extends jni$_.JObject?, $V extends jni$_.JObject?>
63076308
jni$_.Pointer<jni$_.Void>,
63086309
jni$_.Pointer<jni$_.Void>)>();
63096310

6310-
/// from: `public V compute(K object, java.util.function.BiFunction biFunction)`
6311+
/// from: `public V compute(K object, java.util.function.BiFunction<? super K, ? super V, ? extends V> biFunction)`
63116312
/// The returned object must be released after use, by calling the [release] method.
63126313
$V? compute(
63136314
$K? object,
@@ -6344,7 +6345,7 @@ class HashMap<$K extends jni$_.JObject?, $V extends jni$_.JObject?>
63446345
jni$_.Pointer<jni$_.Void>,
63456346
jni$_.Pointer<jni$_.Void>)>();
63466347

6347-
/// from: `public V merge(K object, V object1, java.util.function.BiFunction biFunction)`
6348+
/// from: `public V merge(K object, V object1, java.util.function.BiFunction<? super V, ? super V, ? extends V> biFunction)`
63486349
/// The returned object must be released after use, by calling the [release] method.
63496350
$V? merge(
63506351
$K? object,
@@ -6375,7 +6376,7 @@ class HashMap<$K extends jni$_.JObject?, $V extends jni$_.JObject?>
63756376
jni$_.JThrowablePtr Function(jni$_.Pointer<jni$_.Void>,
63766377
jni$_.JMethodIDPtr, jni$_.Pointer<jni$_.Void>)>();
63776378

6378-
/// from: `public void forEach(java.util.function.BiConsumer biConsumer)`
6379+
/// from: `public void forEach(java.util.function.BiConsumer<? super K, ? super V> biConsumer)`
63796380
void forEach(
63806381
jni$_.JObject? biConsumer,
63816382
) {
@@ -6401,7 +6402,7 @@ class HashMap<$K extends jni$_.JObject?, $V extends jni$_.JObject?>
64016402
jni$_.JThrowablePtr Function(jni$_.Pointer<jni$_.Void>,
64026403
jni$_.JMethodIDPtr, jni$_.Pointer<jni$_.Void>)>();
64036404

6404-
/// from: `public void replaceAll(java.util.function.BiFunction biFunction)`
6405+
/// from: `public void replaceAll(java.util.function.BiFunction<? super K, ? super V, ? extends V> biFunction)`
64056406
void replaceAll(
64066407
jni$_.JObject? biFunction,
64076408
) {
@@ -6449,7 +6450,7 @@ class HashMap<$K extends jni$_.JObject?, $V extends jni$_.JObject?>
64496450
jni$_.JniResult Function(
64506451
jni$_.Pointer<jni$_.Void>, jni$_.JMethodIDPtr, int)>();
64516452

6452-
/// from: `static public java.util.HashMap newHashMap(int i)`
6453+
/// from: `static public java.util.HashMap<K, V> newHashMap(int i)`
64536454
/// The returned object must be released after use, by calling the [release] method.
64546455
static HashMap<$K?, $V?>?
64556456
newHashMap<$K extends jni$_.JObject?, $V extends jni$_.JObject?>(

pkgs/jnigen/example/kotlin_plugin/lib/kotlin_bindings.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// ignore_for_file: camel_case_extensions
66
// ignore_for_file: camel_case_types
77
// ignore_for_file: constant_identifier_names
8+
// ignore_for_file: comment_references
89
// ignore_for_file: doc_directive_unknown
910
// ignore_for_file: file_names
1011
// ignore_for_file: inference_failure_on_untyped_parameter
@@ -92,7 +93,7 @@ class Example extends jni$_.JObject {
9293
jni$_.JniResult Function(jni$_.Pointer<jni$_.Void>,
9394
jni$_.JMethodIDPtr, jni$_.Pointer<jni$_.Void>)>();
9495

95-
/// from: `public final java.lang.Object thinkBeforeAnswering(kotlin.coroutines.Continuation continuation)`
96+
/// from: `public final java.lang.Object thinkBeforeAnswering(kotlin.coroutines.Continuation<? super java.lang.String> continuation)`
9697
/// The returned object must be released after use, by calling the [release] method.
9798
core$_.Future<jni$_.JString> thinkBeforeAnswering() async {
9899
final $p = jni$_.ReceivePort();

pkgs/jnigen/example/notification_plugin/lib/notifications.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// ignore_for_file: camel_case_extensions
1010
// ignore_for_file: camel_case_types
1111
// ignore_for_file: constant_identifier_names
12+
// ignore_for_file: comment_references
1213
// ignore_for_file: doc_directive_unknown
1314
// ignore_for_file: file_names
1415
// ignore_for_file: inference_failure_on_untyped_parameter

pkgs/jnigen/example/pdfbox_plugin/lib/src/third_party/org/apache/pdfbox/pdmodel/PDDocument.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
// ignore_for_file: camel_case_extensions
2424
// ignore_for_file: camel_case_types
2525
// ignore_for_file: constant_identifier_names
26+
// ignore_for_file: comment_references
2627
// ignore_for_file: doc_directive_unknown
2728
// ignore_for_file: file_names
2829
// ignore_for_file: inference_failure_on_untyped_parameter

pkgs/jnigen/example/pdfbox_plugin/lib/src/third_party/org/apache/pdfbox/pdmodel/PDDocumentInformation.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
// ignore_for_file: camel_case_extensions
2424
// ignore_for_file: camel_case_types
2525
// ignore_for_file: constant_identifier_names
26+
// ignore_for_file: comment_references
2627
// ignore_for_file: doc_directive_unknown
2728
// ignore_for_file: file_names
2829
// ignore_for_file: inference_failure_on_untyped_parameter

pkgs/jnigen/example/pdfbox_plugin/lib/src/third_party/org/apache/pdfbox/text/PDFTextStripper.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
// ignore_for_file: camel_case_extensions
2424
// ignore_for_file: camel_case_types
2525
// ignore_for_file: constant_identifier_names
26+
// ignore_for_file: comment_references
2627
// ignore_for_file: doc_directive_unknown
2728
// ignore_for_file: file_names
2829
// ignore_for_file: inference_failure_on_untyped_parameter

pkgs/jnigen/lib/src/bindings/dart_generator.dart

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ extension on String {
6767

6868
extension on DeclaredType {
6969
List<T> mapTypeParameters<T>(
70-
T Function(bool isNullable, TypeUsage definedType) mapper,
70+
T Function(bool isNullable, ReferredType definedType) mapper,
7171
) {
7272
final result = <T>[];
7373
final offset = classDecl.allTypeParams.length - params.length;
7474
for (var i = 0; i < classDecl.allTypeParams.length; ++i) {
75-
final param = i >= offset ? params[i - offset] : TypeUsage.object;
75+
final param = i >= offset ? params[i - offset] : DeclaredType.object;
7676
result.add(mapper(classDecl.allTypeParams[i].isNullable, param));
7777
}
7878
return result;
@@ -157,6 +157,7 @@ import 'package:jni/jni.dart' as $_jni;
157157
// ignore_for_file: camel_case_extensions
158158
// ignore_for_file: camel_case_types
159159
// ignore_for_file: constant_identifier_names
160+
// ignore_for_file: comment_references
160161
// ignore_for_file: doc_directive_unknown
161162
// ignore_for_file: file_names
162163
// ignore_for_file: inference_failure_on_untyped_parameter
@@ -387,7 +388,7 @@ ${modifier}final $classRef = $_jni.JClass.forName(r'$internalName');
387388
final ctorTypeClassesDef = typeParams
388389
.map((typeParam) => 'this.$typeParam,')
389390
.join(_newLine(depth: 2));
390-
final superClass = node.classDecl.superclass!.type as DeclaredType;
391+
final superClass = node.classDecl.superclass! as DeclaredType;
391392
final superTypeClassesCall = superClass.classDecl.isObject
392393
? ''
393394
: superClass.params
@@ -666,16 +667,12 @@ final class _$implClassName$typeParamsDef with $implClassName$typeParamsCall {
666667
annotations: [Annotation.nullable],
667668
params: node.allTypeParams
668669
.map(
669-
(typeParam) => TypeUsage(
670-
shorthand: '',
671-
kind: Kind.typeVariable,
672-
typeJson: {},
673-
)..type = (TypeVar(name: typeParam.name)
670+
(typeParam) => TypeVar(name: typeParam.name)
674671
..origin = TypeParam(
675672
name: typeParam.name,
676673
annotations: [Annotation.nonNull],
677674
bounds: typeParam.bounds,
678-
)),
675+
),
679676
)
680677
.toList(),
681678
)..classDecl = node)
@@ -818,7 +815,7 @@ class _TypeGenerator extends TypeVisitor<String> {
818815
arrayType: true,
819816
isTopTypeNullable: true,
820817
);
821-
if (innerType.kind == Kind.primitive) {
818+
if (innerType is PrimitiveType) {
822819
return '$_jni.J${innerType.accept(typeGenerator)}Array$nullable';
823820
}
824821
return '$_jArray<${innerType.accept(typeGenerator)}>$nullable';
@@ -973,7 +970,7 @@ class _TypeClassGenerator extends TypeVisitor<_TypeClass> {
973970
final type = includeNullability && node.isNullable && isTopTypeNullable
974971
? 'NullableType'
975972
: 'Type';
976-
if (node.elementType.kind == Kind.primitive) {
973+
if (node.elementType is PrimitiveType) {
977974
return _TypeClass(
978975
'$ifConst$_jni.J${innerType}Array$type()',
979976
innerTypeClass.canBeConst,
@@ -1222,9 +1219,9 @@ ${modifier}final _id_$name =
12221219
}
12231220

12241221
void writeDocs(Field node, {required bool writeReleaseInstructions}) {
1225-
final originalDecl = '${node.type.shorthand} ${node.name}';
1222+
final originalDecl = '${node.type} ${node.name}';
12261223
s.writeln(' /// from: `${node.modifiers.join(' ')} $originalDecl`');
1227-
if (node.type.kind != Kind.primitive && writeReleaseInstructions) {
1224+
if (node.type is! PrimitiveType && writeReleaseInstructions) {
12281225
s.writeln(_releaseInstruction);
12291226
}
12301227
node.javadoc?.accept(_DocGenerator(s, depth: 1));
@@ -1369,10 +1366,10 @@ ${modifier}final _$name = $_protectedExtension
13691366
// Docs
13701367
s.write(' /// from: `');
13711368
s.writeAll(node.modifiers.map((m) => '$m '));
1372-
s.write('${node.returnType.shorthand} ${node.name}(');
1373-
s.writeAll(node.params.map((p) => '${p.type.shorthand} ${p.name}'), ', ');
1369+
s.write('${node.returnType} ${node.name}(');
1370+
s.writeAll(node.params.map((p) => '${p.type} ${p.name}'), ', ');
13741371
s.writeln(')`');
1375-
if (node.returnType.kind != Kind.primitive || node.isConstructor) {
1372+
if (node.returnType is! PrimitiveType || node.isConstructor) {
13761373
s.writeln(_releaseInstruction);
13771374
}
13781375
node.javadoc?.accept(_DocGenerator(s, depth: 1));
@@ -1584,7 +1581,7 @@ class _ParamReference extends Visitor<Param, String> {
15841581

15851582
@override
15861583
String visit(Param node) {
1587-
if (node.type.kind == Kind.primitive) {
1584+
if (node.type is PrimitiveType) {
15881585
return '';
15891586
}
15901587
final nullable = node.isNullable ? '?' : '';
@@ -1606,7 +1603,7 @@ class _ParamCall extends Visitor<Param, String> {
16061603
@override
16071604
String visit(Param node) {
16081605
final nativeSuffix = node.type.accept(const _ToNativeSuffix());
1609-
final nonPrimitive = node.type.kind == Kind.primitive ? '' : r'_$';
1606+
final nonPrimitive = node.type is PrimitiveType ? '' : r'_$';
16101607
final paramCall = '$nonPrimitive${node.finalName}$nativeSuffix';
16111608
return paramCall;
16121609
}
@@ -1945,12 +1942,11 @@ class _InterfaceParamCast extends Visitor<Param, void> {
19451942
),
19461943
)
19471944
.name;
1948-
final nullable =
1949-
node.isNullable && node.type.kind != Kind.primitive ? '?' : '!';
1945+
final nullable = node.isNullable && node.type is! PrimitiveType ? '?' : '!';
19501946
s.write('\$a![$paramIndex]$nullable.as($typeClass, releaseOriginal: true)');
1951-
if (node.type.kind == Kind.primitive) {
1947+
if (node.type is PrimitiveType) {
19521948
// Convert to Dart type.
1953-
final name = (node.type.type as PrimitiveType).name;
1949+
final name = node.type.name;
19541950
s.write('.${name}Value(releaseOriginal: true)');
19551951
}
19561952
s.writeln(',');
@@ -2000,8 +1996,8 @@ class _CallMethodName extends Visitor<Method, String> {
20001996
return 'globalEnv_NewObject';
20011997
}
20021998
final String type;
2003-
if (node.returnType.kind == Kind.primitive) {
2004-
type = (node.returnType.type as PrimitiveType).name.capitalize();
1999+
if (node.returnType is PrimitiveType) {
2000+
type = node.returnType.name.capitalize();
20052001
} else {
20062002
type = 'Object';
20072003
}

pkgs/jnigen/lib/src/bindings/kotlin_processor.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,23 +147,23 @@ class _KotlinMethodProcessor extends Visitor<Method, void> {
147147
if (function.isSuspend) {
148148
const kotlinContinutationType = 'kotlin.coroutines.Continuation';
149149
assert(node.params.isNotEmpty &&
150-
node.params.last.type.kind == Kind.declared &&
150+
node.params.last.type is DeclaredType &&
151151
node.params.last.type.name == kotlinContinutationType);
152152
var continuationType =
153-
(node.params.last.type.type as DeclaredType).params.firstOrNull;
153+
(node.params.last.type as DeclaredType).params.firstOrNull;
154154
if (continuationType != null &&
155-
continuationType.kind == Kind.wildcard &&
156-
(continuationType.type as Wildcard).superBound != null) {
157-
continuationType = (continuationType.type as Wildcard).superBound!;
155+
continuationType is Wildcard &&
156+
continuationType.superBound != null) {
157+
continuationType = continuationType.superBound!;
158158
}
159159
node.asyncReturnType = continuationType == null
160-
? TypeUsage.object
160+
? DeclaredType.object
161161
: continuationType.clone();
162162
node.asyncReturnType!.accept(_KotlinTypeProcessor(function.returnType));
163163

164164
// The continuation object is always non-null.
165-
node.returnType.type.annotations ??= [];
166-
node.returnType.type.annotations!.add(Annotation.nonNull);
165+
node.returnType.annotations ??= [];
166+
node.returnType.annotations!.add(Annotation.nonNull);
167167
} else {
168168
node.returnType.accept(_KotlinTypeProcessor(function.returnType));
169169
}

0 commit comments

Comments
 (0)