Skip to content

Commit

Permalink
Generate null-safe java code
Browse files Browse the repository at this point in the history
  • Loading branch information
HosseinYousefi committed Nov 8, 2024
1 parent e296204 commit 80693da
Show file tree
Hide file tree
Showing 30 changed files with 13,704 additions and 3,169 deletions.
17 changes: 17 additions & 0 deletions pkgs/jni/lib/jni_symbols.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,71 +4,86 @@ files:
'java.lang.Object':
name: JObject
type_class: JObjectType
nullable_type_class: JObjectNullableType
super_count: 0
'java.lang.String':
name: JString
type_class: JStringType
nullable_type_class: JStringNullableType
super_count: 1
'java.lang.Number':
name: JNumber
type_class: JNumberType
nullable_type_class: JNumberNullableType
super_count: 1
'java.lang.Byte':
name: JByte
type_class: JByteType
nullable_type_class: JByteNullableType
super_count: 2
'java.lang.Short':
name: JShort
type_class: JShortType
nullable_type_class: JShortNullableType
super_count: 2
'java.lang.Integer':
name: JInteger
type_class: JIntegerType
nullable_type_class: JIntegerNullableType
super_count: 2
'java.lang.Long':
name: JLong
type_class: JLongType
nullable_type_class: JLongNullableType
super_count: 2
'java.lang.Float':
name: JFloat
type_class: JFloatType
nullable_type_class: JFloatNullableType
super_count: 2
'java.lang.Double':
name: JDouble
type_class: JDoubleType
nullable_type_class: JDoubleNullableType
super_count: 2
'java.lang.Boolean':
name: JBoolean
type_class: JBooleanType
nullable_type_class: JBooleanNullableType
super_count: 1
'java.lang.Character':
name: JCharacter
type_class: JCharacterType
nullable_type_class: JCharacterNullableType
super_count: 1
'java.util.Set':
name: JSet
type_class: JSetType
nullable_type_class: JSetNullableType
super_count: 1
type_params:
E:
'java.lang.Object': DECLARED
'java.util.List':
name: JList
type_class: JListType
nullable_type_class: JListNullableType
super_count: 1
type_params:
E:
'java.lang.Object': DECLARED
'java.util.Iterator':
name: JIterator
type_class: JIteratorType
nullable_type_class: JIteratorNullableType
super_count: 1
type_params:
E:
'java.lang.Object': DECLARED
'java.util.Map':
name: JMap
type_class: JMapType
nullable_type_class: JMapNullableType
super_count: 1
type_params:
K:
Expand All @@ -78,8 +93,10 @@ files:
'java.nio.Buffer':
name: JBuffer
type_class: JBufferType
nullable_type_class: JBufferNullableType
super_count: 1
'java.nio.ByteBuffer':
name: JByteBuffer
type_class: JByteBufferType
nullable_type_class: JByteBufferNullableType
super_count: 2
2 changes: 1 addition & 1 deletion pkgs/jni/lib/src/accessors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ extension JniResultMethods on JniResult {
return pointer == nullptr ? jNullReference : JGlobalReference(pointer);
}

T object<T extends JObject>(JObjType<T> type) {
T object<T extends JObject?>(JObjType<T> type) {
return type.fromReference(reference);
}

Expand Down
2 changes: 0 additions & 2 deletions pkgs/jni/lib/src/jobject.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ class JObject {
return JClass.fromReference(JGlobalReference(classRef));
}

bool get isNull => reference.isNull;

/// Releases the underlying [reference].
///
/// Releasing in one isolate while using or releasing in another isolate might
Expand Down
12 changes: 6 additions & 6 deletions pkgs/jni/lib/src/util/jlist.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import '../types.dart';
import 'jiterator.dart';
import 'jset.dart';

final class JNullableListType<$E extends JObject?>
final class JListNullableType<$E extends JObject?>
extends JObjType<JList<$E>?> {
@internal
final JObjType<$E> E;

@internal
const JNullableListType(
const JListNullableType(
this.E,
);

Expand All @@ -46,12 +46,12 @@ final class JNullableListType<$E extends JObject?>
final superCount = 1;

@override
int get hashCode => Object.hash(JNullableListType, E);
int get hashCode => Object.hash(JListNullableType, E);

@override
bool operator ==(Object other) {
return other.runtimeType == (JNullableListType<$E>) &&
other is JNullableListType<$E> &&
return other.runtimeType == (JListNullableType<$E>) &&
other is JListNullableType<$E> &&
E == other.E;
}
}
Expand Down Expand Up @@ -80,7 +80,7 @@ final class JListType<$E extends JObject?> extends JObjType<JList<$E>> {

@internal
@override
JObjType<JList<$E>?> get nullableType => JNullableListType<$E>(E);
JObjType<JList<$E>?> get nullableType => JListNullableType<$E>(E);

@internal
@override
Expand Down
12 changes: 6 additions & 6 deletions pkgs/jni/lib/src/util/jmap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import '../jreference.dart';
import '../types.dart';
import 'jset.dart';

final class JNullableMapType<$K extends JObject?, $V extends JObject?>
final class JMapNullableType<$K extends JObject?, $V extends JObject?>
extends JObjType<JMap<$K, $V>?> {
@internal
final JObjType<$K> K;
Expand All @@ -20,7 +20,7 @@ final class JNullableMapType<$K extends JObject?, $V extends JObject?>
final JObjType<$V> V;

@internal
const JNullableMapType(
const JMapNullableType(
this.K,
this.V,
);
Expand All @@ -47,12 +47,12 @@ final class JNullableMapType<$K extends JObject?, $V extends JObject?>
final superCount = 1;

@override
int get hashCode => Object.hash(JNullableMapType, K, V);
int get hashCode => Object.hash(JMapNullableType, K, V);

@override
bool operator ==(Object other) {
return other.runtimeType == (JNullableMapType<$K, $V>) &&
other is JNullableMapType<$K, $V> &&
return other.runtimeType == (JMapNullableType<$K, $V>) &&
other is JMapNullableType<$K, $V> &&
K == other.K &&
V == other.V;
}
Expand Down Expand Up @@ -87,7 +87,7 @@ final class JMapType<$K extends JObject?, $V extends JObject?>

@internal
@override
JObjType<JMap<$K, $V>?> get nullableType => JNullableMapType<$K, $V>(K, V);
JObjType<JMap<$K, $V>?> get nullableType => JMapNullableType<$K, $V>(K, V);

@internal
@override
Expand Down
Loading

0 comments on commit 80693da

Please sign in to comment.