Skip to content

Commit 3aa280f

Browse files
authored
[jnigen] Generate Dart @deprecated annotations (#3429)
1 parent 7ddfffd commit 3aa280f

10 files changed

Lines changed: 59 additions & 0 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,6 +1961,7 @@ extension EmojiCompat$$Methods on EmojiCompat {
19611961
jni$_.JMethodIDPtr, jni$_.Pointer<jni$_.Void>)>();
19621962

19631963
/// from: `public boolean hasEmojiGlyph(java.lang.CharSequence charSequence)`
1964+
@core$_.Deprecated('This Java method is deprecated.')
19641965
core$_.bool hasEmojiGlyph(
19651966
CharSequence charSequence,
19661967
) {
@@ -1989,6 +1990,7 @@ extension EmojiCompat$$Methods on EmojiCompat {
19891990
jni$_.JMethodIDPtr, jni$_.Pointer<jni$_.Void>, core$_.int)>();
19901991

19911992
/// from: `public boolean hasEmojiGlyph(java.lang.CharSequence charSequence, int i)`
1993+
@core$_.Deprecated('This Java method is deprecated.')
19921994
core$_.bool hasEmojiGlyph$1(
19931995
CharSequence charSequence,
19941996
core$_.int i,

pkgs/jnigen/example/maven_libs/lib/maven_libs_bindings.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ extension Gson$$Methods on Gson {
113113

114114
/// from: `public com.google.gson.internal.Excluder excluder()`
115115
/// The returned object must be released after use, by calling the [release] method.
116+
@core$_.Deprecated('This Java method is deprecated.')
116117
Excluder? excluder() {
117118
final _$$selfRef = reference;
118119
return _excluder(_$$selfRef.pointer, _id_excluder.pointer)

pkgs/jnigen/example/maven_libs_groovy/lib/maven_libs_bindings.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ extension Gson$$Methods on Gson {
113113

114114
/// from: `public com.google.gson.internal.Excluder excluder()`
115115
/// The returned object must be released after use, by calling the [release] method.
116+
@core$_.Deprecated('This Java method is deprecated.')
116117
Excluder? excluder() {
117118
final _$$selfRef = reference;
118119
return _excluder(_$$selfRef.pointer, _id_excluder.pointer)

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
@@ -1309,6 +1309,7 @@ extension PDDocument$$Methods on PDDocument {
13091309
///@throws IOException if there is an error creating required fields
13101310
///@deprecated The method is misleading, because only one signature may be
13111311
/// added in a document. The method will be removed in the future.
1312+
@core$_.Deprecated('This Java method is deprecated.')
13121313
void addSignatureField(
13131314
jni$_.JList<pdsignaturefield$_.PDSignatureField?>? sigFields,
13141315
signatureinterface$_.SignatureInterface? signatureInterface,

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,9 @@ ${modifier}final _$idName = $_protectedExtension
13091309
defArgs.removeLast();
13101310
}
13111311
final params = defArgs.delimited(', ');
1312+
if (node.isDeprecated) {
1313+
s.writeln(" @core\$_.Deprecated('This Java method is deprecated.')");
1314+
}
13121315
if (node.methodKind == MethodKind.getter) {
13131316
s.write(' $ifStatic$returnType get $name ');
13141317
} else if (node.methodKind == MethodKind.setter) {

pkgs/jnigen/lib/src/elements/elements.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,9 @@ class Method with ClassMember, Annotated implements Element<Method> {
756756

757757
bool get isConstructor => name == '<init>';
758758

759+
bool get isDeprecated =>
760+
annotations?.any((a) => a.binaryName == 'java.lang.Deprecated') ?? false;
761+
759762
factory Method.fromJson(Map<String, dynamic> json) => _$MethodFromJson(json);
760763

761764
Method clone({GenerationStage until = GenerationStage.userVisitors}) {

pkgs/jnigen/test/jackson_core_test/third_party/bindings/com/fasterxml/jackson/core/JsonFactory.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,7 @@ extension JsonFactory$$Methods on JsonFactory {
10161016
///@param state Whether to enable or disable the feature
10171017
///@return This factory instance (to allow call chaining)
10181018
///@deprecated since 2.10 use JsonFactoryBuilder\#configure(JsonFactory.Feature, boolean) instead
1019+
@core$_.Deprecated('This Java method is deprecated.')
10191020
JsonFactory? configure(
10201021
JsonFactory$Feature? f,
10211022
core$_.bool state,
@@ -1051,6 +1052,7 @@ extension JsonFactory$$Methods on JsonFactory {
10511052
///@param f Feature to enable
10521053
///@return This factory instance (to allow call chaining)
10531054
///@deprecated since 2.10 use JsonFactoryBuilder\#configure(JsonFactory.Feature, boolean) instead
1055+
@core$_.Deprecated('This Java method is deprecated.')
10541056
JsonFactory? enable(
10551057
JsonFactory$Feature? f,
10561058
) {
@@ -1084,6 +1086,7 @@ extension JsonFactory$$Methods on JsonFactory {
10841086
///@param f Feature to disable
10851087
///@return This factory instance (to allow call chaining)
10861088
///@deprecated since 2.10 use JsonFactoryBuilder\#configure(JsonFactory.Feature, boolean) instead
1089+
@core$_.Deprecated('This Java method is deprecated.')
10871090
JsonFactory? disable(
10881091
JsonFactory$Feature? f,
10891092
) {
@@ -1442,6 +1445,7 @@ extension JsonFactory$$Methods on JsonFactory {
14421445
///@param d Decorator to configure for this factory, if any ({@code null} if none)
14431446
///@return This factory instance (to allow call chaining)
14441447
///@deprecated Since 2.10 use JsonFactoryBuilder\#inputDecorator(InputDecorator) instead
1448+
@core$_.Deprecated('This Java method is deprecated.')
14451449
JsonFactory? setInputDecorator(
14461450
inputdecorator$_.InputDecorator? d,
14471451
) {
@@ -1732,6 +1736,7 @@ extension JsonFactory$$Methods on JsonFactory {
17321736
///@return This factory instance (to allow call chaining)
17331737
///@param d Output decorator to use, if any
17341738
///@deprecated Since 2.10 use JsonFactoryBuilder\#outputDecorator(OutputDecorator) instead
1739+
@core$_.Deprecated('This Java method is deprecated.')
17351740
JsonFactory? setOutputDecorator(
17361741
outputdecorator$_.OutputDecorator? d,
17371742
) {
@@ -2585,6 +2590,7 @@ extension JsonFactory$$Methods on JsonFactory {
25852590
///@throws IOException if parser initialization fails due to I/O (read) problem
25862591
///@throws JsonParseException if parser initialization fails due to content decoding problem
25872592
///@deprecated Since 2.2, use \#createParser(File) instead.
2593+
@core$_.Deprecated('This Java method is deprecated.')
25882594
jsonparser$_.JsonParser? createJsonParser(
25892595
file$_.File? f,
25902596
) {
@@ -2631,6 +2637,7 @@ extension JsonFactory$$Methods on JsonFactory {
26312637
///@throws IOException if parser initialization fails due to I/O (read) problem
26322638
///@throws JsonParseException if parser initialization fails due to content decoding problem
26332639
///@deprecated Since 2.2, use \#createParser(URL) instead.
2640+
@core$_.Deprecated('This Java method is deprecated.')
26342641
jsonparser$_.JsonParser? createJsonParser$1(
26352642
url$_.URL? url,
26362643
) {
@@ -2680,6 +2687,7 @@ extension JsonFactory$$Methods on JsonFactory {
26802687
///@throws IOException if parser initialization fails due to I/O (read) problem
26812688
///@throws JsonParseException if parser initialization fails due to content decoding problem
26822689
///@deprecated Since 2.2, use \#createParser(InputStream) instead.
2690+
@core$_.Deprecated('This Java method is deprecated.')
26832691
jsonparser$_.JsonParser? createJsonParser$2(
26842692
inputstream$_.InputStream? in$,
26852693
) {
@@ -2722,6 +2730,7 @@ extension JsonFactory$$Methods on JsonFactory {
27222730
///@throws IOException if parser initialization fails due to I/O (read) problem
27232731
///@throws JsonParseException if parser initialization fails due to content decoding problem
27242732
///@deprecated Since 2.2, use \#createParser(Reader) instead.
2733+
@core$_.Deprecated('This Java method is deprecated.')
27252734
jsonparser$_.JsonParser? createJsonParser$3(
27262735
reader$_.Reader? r,
27272736
) {
@@ -2757,6 +2766,7 @@ extension JsonFactory$$Methods on JsonFactory {
27572766
///@throws IOException if parser initialization fails due to I/O (read) problem
27582767
///@throws JsonParseException if parser initialization fails due to content decoding problem
27592768
///@deprecated Since 2.2, use \#createParser(byte[]) instead.
2769+
@core$_.Deprecated('This Java method is deprecated.')
27602770
jsonparser$_.JsonParser? createJsonParser$4(
27612771
jni$_.JByteArray? data,
27622772
) {
@@ -2803,6 +2813,7 @@ extension JsonFactory$$Methods on JsonFactory {
28032813
///@throws IOException if parser initialization fails due to I/O (read) problem
28042814
///@throws JsonParseException if parser initialization fails due to content decoding problem
28052815
///@deprecated Since 2.2, use \#createParser(byte[],int,int) instead.
2816+
@core$_.Deprecated('This Java method is deprecated.')
28062817
jsonparser$_.JsonParser? createJsonParser$5(
28072818
jni$_.JByteArray? data,
28082819
core$_.int offset,
@@ -2841,6 +2852,7 @@ extension JsonFactory$$Methods on JsonFactory {
28412852
///@throws IOException if parser initialization fails due to I/O (read) problem
28422853
///@throws JsonParseException if parser initialization fails due to content decoding problem
28432854
///@deprecated Since 2.2, use \#createParser(String) instead.
2855+
@core$_.Deprecated('This Java method is deprecated.')
28442856
jsonparser$_.JsonParser? createJsonParser$6(
28452857
jni$_.JString? content,
28462858
) {
@@ -2896,6 +2908,7 @@ extension JsonFactory$$Methods on JsonFactory {
28962908
///@return Generator constructed
28972909
///@throws IOException if parser initialization fails due to I/O (write) problem
28982910
///@deprecated Since 2.2, use \#createGenerator(OutputStream, JsonEncoding) instead.
2911+
@core$_.Deprecated('This Java method is deprecated.')
28992912
jsongenerator$_.JsonGenerator? createJsonGenerator(
29002913
outputstream$_.OutputStream? out,
29012914
jsonencoding$_.JsonEncoding? enc,
@@ -2940,6 +2953,7 @@ extension JsonFactory$$Methods on JsonFactory {
29402953
///@return Generator constructed
29412954
///@throws IOException if parser initialization fails due to I/O (write) problem
29422955
///@deprecated Since 2.2, use \#createGenerator(Writer) instead.
2956+
@core$_.Deprecated('This Java method is deprecated.')
29432957
jsongenerator$_.JsonGenerator? createJsonGenerator$1(
29442958
writer$_.Writer? out,
29452959
) {
@@ -2977,6 +2991,7 @@ extension JsonFactory$$Methods on JsonFactory {
29772991
///@return Generator constructed
29782992
///@throws IOException if parser initialization fails due to I/O (write) problem
29792993
///@deprecated Since 2.2, use \#createGenerator(OutputStream) instead.
2994+
@core$_.Deprecated('This Java method is deprecated.')
29802995
jsongenerator$_.JsonGenerator? createJsonGenerator$2(
29812996
outputstream$_.OutputStream? out,
29822997
) {

pkgs/jnigen/test/jackson_core_test/third_party/bindings/com/fasterxml/jackson/core/JsonParser.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,6 +1919,7 @@ extension JsonParser$$Methods on JsonParser {
19191919
///@return This parser, to allow call chaining
19201920
///@since 2.3
19211921
///@deprecated Since 2.7, use \#overrideStdFeatures(int, int) instead
1922+
@core$_.Deprecated('This Java method is deprecated.')
19221923
JsonParser? setFeatureMask(
19231924
core$_.int mask,
19241925
) {
@@ -2557,6 +2558,7 @@ extension JsonParser$$Methods on JsonParser {
25572558
/// Deprecated alias for \#currentTokenId().
25582559
///@return {@code int} matching one of constants from JsonTokenId.
25592560
///@deprecated Since 2.12 use \#currentTokenId instead
2561+
@core$_.Deprecated('This Java method is deprecated.')
25602562
core$_.int get currentTokenId$1 {
25612563
final _$$selfRef = reference;
25622564
return _get$currentTokenId$1(

pkgs/jnigen/test/simple_package_test/bindings/simple_package.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,32 @@ extension Example$$Methods on Example {
12641264
.object<jni$_.JString?>();
12651265
}
12661266

1267+
static final _id_deprecatedMethod = Example._class.instanceMethodId(
1268+
r'deprecatedMethod',
1269+
r'()Ljava/lang/String;',
1270+
);
1271+
1272+
static final _deprecatedMethod = jni$_.ProtectedJniExtensions.lookup<
1273+
jni$_.NativeFunction<
1274+
jni$_.JniResult Function(
1275+
jni$_.Pointer<jni$_.Void>,
1276+
jni$_.JMethodIDPtr,
1277+
)>>('globalEnv_CallObjectMethod')
1278+
.asFunction<
1279+
jni$_.JniResult Function(
1280+
jni$_.Pointer<jni$_.Void>,
1281+
jni$_.JMethodIDPtr,
1282+
)>();
1283+
1284+
/// from: `public java.lang.String deprecatedMethod()`
1285+
/// The returned object must be released after use, by calling the [release] method.
1286+
@core$_.Deprecated('This Java method is deprecated.')
1287+
jni$_.JString? deprecatedMethod() {
1288+
final _$$selfRef = reference;
1289+
return _deprecatedMethod(_$$selfRef.pointer, _id_deprecatedMethod.pointer)
1290+
.object<jni$_.JString?>();
1291+
}
1292+
12671293
static final _id_methodWithSeveralParams = Example._class.instanceMethodId(
12681294
r'methodWithSeveralParams',
12691295
r'(CLjava/lang/String;[ILjava/lang/CharSequence;Ljava/util/List;Ljava/util/Map;)V',

pkgs/jnigen/test/simple_package_test/java/com/github/dart_lang/jnigen/simple_package/Example.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ public String joinStrings(List<String> values, String delim) {
147147
return null;
148148
}
149149

150+
@Deprecated
151+
public String deprecatedMethod() {
152+
return "deprecated";
153+
}
154+
150155
public <T extends CharSequence> void methodWithSeveralParams(
151156
char ch, String s, int[] a, T t, List<T> lt, Map<String, ? extends CharSequence> wm) {}
152157

0 commit comments

Comments
 (0)