Skip to content

Commit 817c76e

Browse files
[jnigen] Generate enum values non-nullable (#1902)
1 parent 7295bae commit 817c76e

File tree

15 files changed

+1197
-234
lines changed

15 files changed

+1197
-234
lines changed

pkgs/jnigen/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Fixed a bug where Kotlin wildcards would crash the code generation.
44
- Support nullability annotations that are on Java elements like methods and
55
fields instead of directly on the return type or field type.
6+
- Fixed a bug where enum values were generated as nullable.
67

78
## 0.13.0
89

pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/disasm/AsmClassVisitor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public FieldVisitor visitField(
9090
field.defaultValue = value;
9191
field.modifiers = TypeUtils.access(access);
9292
if ((access & ACC_ENUM) != 0) {
93+
field.type.type.annotations.add(JavaAnnotation.nonNull);
9394
peekVisiting().values.add(name);
9495
}
9596
if (signature != null) {

pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/doclet/SummarizerDoclet.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package com.github.dart_lang.jnigen.apisummarizer.doclet;
66

77
import com.github.dart_lang.jnigen.apisummarizer.elements.ClassDecl;
8+
import com.github.dart_lang.jnigen.apisummarizer.elements.JavaAnnotation;
89
import com.github.dart_lang.jnigen.apisummarizer.elements.Method;
910
import com.github.dart_lang.jnigen.apisummarizer.elements.Package;
1011
import com.github.dart_lang.jnigen.apisummarizer.util.Log;
@@ -119,6 +120,9 @@ public Void visitVariable(VariableElement e, SummaryCollector collector) {
119120
var cls = collector.types.peek();
120121
switch (vk) {
121122
case ENUM_CONSTANT:
123+
var field = builders.field(e);
124+
field.type.type.annotations.add(JavaAnnotation.nonNull);
125+
cls.fields.add(field);
122126
cls.values.add(e.getSimpleName().toString());
123127
break;
124128
case FIELD:

pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/elements/JavaAnnotation.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ public class JavaAnnotation {
1111
public String binaryName;
1212
public Map<String, Object> properties = new HashMap<>();
1313

14+
public JavaAnnotation() {}
15+
16+
public JavaAnnotation(String binaryName) {
17+
this.binaryName = binaryName;
18+
}
19+
20+
public static final JavaAnnotation nonNull = new JavaAnnotation("androidx.annotation.NonNull");
21+
1422
public static class EnumVal {
1523
public String enumClass;
1624
public String value;

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

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,95 @@ class JsonFactory$Feature extends jni$_.JObject {
7575
/// The type which includes information such as the signature of this class.
7676
static const nullableType = $JsonFactory$Feature$NullableType();
7777
static const type = $JsonFactory$Feature$Type();
78+
static final _id_INTERN_FIELD_NAMES = _class.staticFieldId(
79+
r'INTERN_FIELD_NAMES',
80+
r'Lcom/fasterxml/jackson/core/JsonFactory$Feature;',
81+
);
82+
83+
/// from: `static public final com.fasterxml.jackson.core.JsonFactory.Feature INTERN_FIELD_NAMES`
84+
/// The returned object must be released after use, by calling the [release] method.
85+
///
86+
/// Feature that determines whether JSON object field names are
87+
/// to be canonicalized using String\#intern or not:
88+
/// if enabled, all field names will be intern()ed (and caller
89+
/// can count on this being true for all such names); if disabled,
90+
/// no intern()ing is done. There may still be basic
91+
/// canonicalization (that is, same String will be used to represent
92+
/// all identical object property names for a single document).
93+
///
94+
/// Note: this setting only has effect if
95+
/// \#CANONICALIZE_FIELD_NAMES is true -- otherwise no
96+
/// canonicalization of any sort is done.
97+
///
98+
/// This setting is enabled by default.
99+
static JsonFactory$Feature get INTERN_FIELD_NAMES =>
100+
_id_INTERN_FIELD_NAMES.get(_class, const $JsonFactory$Feature$Type());
101+
102+
static final _id_CANONICALIZE_FIELD_NAMES = _class.staticFieldId(
103+
r'CANONICALIZE_FIELD_NAMES',
104+
r'Lcom/fasterxml/jackson/core/JsonFactory$Feature;',
105+
);
106+
107+
/// from: `static public final com.fasterxml.jackson.core.JsonFactory.Feature CANONICALIZE_FIELD_NAMES`
108+
/// The returned object must be released after use, by calling the [release] method.
109+
///
110+
/// Feature that determines whether JSON object field names are
111+
/// to be canonicalized (details of how canonicalization is done
112+
/// then further specified by
113+
/// \#INTERN_FIELD_NAMES).
114+
///
115+
/// This setting is enabled by default.
116+
static JsonFactory$Feature get CANONICALIZE_FIELD_NAMES =>
117+
_id_CANONICALIZE_FIELD_NAMES.get(
118+
_class, const $JsonFactory$Feature$Type());
119+
120+
static final _id_FAIL_ON_SYMBOL_HASH_OVERFLOW = _class.staticFieldId(
121+
r'FAIL_ON_SYMBOL_HASH_OVERFLOW',
122+
r'Lcom/fasterxml/jackson/core/JsonFactory$Feature;',
123+
);
124+
125+
/// from: `static public final com.fasterxml.jackson.core.JsonFactory.Feature FAIL_ON_SYMBOL_HASH_OVERFLOW`
126+
/// The returned object must be released after use, by calling the [release] method.
127+
///
128+
/// Feature that determines what happens if we encounter a case in symbol
129+
/// handling where number of hash collisions exceeds a safety threshold
130+
/// -- which almost certainly means a denial-of-service attack via generated
131+
/// duplicate hash codes.
132+
/// If feature is enabled, an IllegalStateException is
133+
/// thrown to indicate the suspected denial-of-service attack; if disabled, processing continues but
134+
/// canonicalization (and thereby <code>intern()</code>ing) is disabled) as protective
135+
/// measure.
136+
///
137+
/// This setting is enabled by default.
138+
///@since 2.4
139+
static JsonFactory$Feature get FAIL_ON_SYMBOL_HASH_OVERFLOW =>
140+
_id_FAIL_ON_SYMBOL_HASH_OVERFLOW.get(
141+
_class, const $JsonFactory$Feature$Type());
142+
143+
static final _id_USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING = _class.staticFieldId(
144+
r'USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING',
145+
r'Lcom/fasterxml/jackson/core/JsonFactory$Feature;',
146+
);
147+
148+
/// from: `static public final com.fasterxml.jackson.core.JsonFactory.Feature USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING`
149+
/// The returned object must be released after use, by calling the [release] method.
150+
///
151+
/// Feature that determines whether we will use BufferRecycler with
152+
/// ThreadLocal and SoftReference, for efficient reuse of
153+
/// underlying input/output buffers.
154+
/// This usually makes sense on normal J2SE/J2EE server-side processing;
155+
/// but may not make sense on platforms where SoftReference handling
156+
/// is broken (like Android), or if there are retention issues due to
157+
/// ThreadLocal (see
158+
/// <a href="https://github.com/FasterXML/jackson-core/issues/189">jackson-core\#189</a>
159+
/// for a possible case)
160+
///
161+
/// This setting is enabled by default.
162+
///@since 2.6
163+
static JsonFactory$Feature get USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING =>
164+
_id_USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING.get(
165+
_class, const $JsonFactory$Feature$Type());
166+
78167
static final _id_values = _class.staticMethodId(
79168
r'values',
80169
r'()[Lcom/fasterxml/jackson/core/JsonFactory$Feature;',

0 commit comments

Comments
 (0)