diff --git a/pkgs/jnigen/CHANGELOG.md b/pkgs/jnigen/CHANGELOG.md index e3a702bfd..5885fc8e5 100644 --- a/pkgs/jnigen/CHANGELOG.md +++ b/pkgs/jnigen/CHANGELOG.md @@ -3,6 +3,7 @@ - Fixed a bug where Kotlin wildcards would crash the code generation. - Support nullability annotations that are on Java elements like methods and fields instead of directly on the return type or field type. +- Fixed a bug where enum values were generated as nullable. ## 0.13.0 diff --git a/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/disasm/AsmClassVisitor.java b/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/disasm/AsmClassVisitor.java index 575b27b4c..884d04ba2 100644 --- a/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/disasm/AsmClassVisitor.java +++ b/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/disasm/AsmClassVisitor.java @@ -90,6 +90,7 @@ public FieldVisitor visitField( field.defaultValue = value; field.modifiers = TypeUtils.access(access); if ((access & ACC_ENUM) != 0) { + field.type.type.annotations.add(JavaAnnotation.nonNull); peekVisiting().values.add(name); } if (signature != null) { diff --git a/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/doclet/SummarizerDoclet.java b/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/doclet/SummarizerDoclet.java index 7e87444e8..e1953077c 100644 --- a/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/doclet/SummarizerDoclet.java +++ b/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/doclet/SummarizerDoclet.java @@ -5,6 +5,7 @@ package com.github.dart_lang.jnigen.apisummarizer.doclet; import com.github.dart_lang.jnigen.apisummarizer.elements.ClassDecl; +import com.github.dart_lang.jnigen.apisummarizer.elements.JavaAnnotation; import com.github.dart_lang.jnigen.apisummarizer.elements.Method; import com.github.dart_lang.jnigen.apisummarizer.elements.Package; import com.github.dart_lang.jnigen.apisummarizer.util.Log; @@ -119,6 +120,9 @@ public Void visitVariable(VariableElement e, SummaryCollector collector) { var cls = collector.types.peek(); switch (vk) { case ENUM_CONSTANT: + var field = builders.field(e); + field.type.type.annotations.add(JavaAnnotation.nonNull); + cls.fields.add(field); cls.values.add(e.getSimpleName().toString()); break; case FIELD: diff --git a/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/elements/JavaAnnotation.java b/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/elements/JavaAnnotation.java index c463cba55..0942036de 100644 --- a/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/elements/JavaAnnotation.java +++ b/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/elements/JavaAnnotation.java @@ -11,6 +11,14 @@ public class JavaAnnotation { public String binaryName; public Map properties = new HashMap<>(); + public JavaAnnotation() {} + + public JavaAnnotation(String binaryName) { + this.binaryName = binaryName; + } + + public static final JavaAnnotation nonNull = new JavaAnnotation("androidx.annotation.NonNull"); + public static class EnumVal { public String enumClass; public String value; 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 65477c199..d030a41ff 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 @@ -75,6 +75,95 @@ class JsonFactory$Feature extends jni$_.JObject { /// The type which includes information such as the signature of this class. static const nullableType = $JsonFactory$Feature$NullableType(); static const type = $JsonFactory$Feature$Type(); + static final _id_INTERN_FIELD_NAMES = _class.staticFieldId( + r'INTERN_FIELD_NAMES', + r'Lcom/fasterxml/jackson/core/JsonFactory$Feature;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonFactory.Feature INTERN_FIELD_NAMES` + /// The returned object must be released after use, by calling the [release] method. + /// + /// Feature that determines whether JSON object field names are + /// to be canonicalized using String\#intern or not: + /// if enabled, all field names will be intern()ed (and caller + /// can count on this being true for all such names); if disabled, + /// no intern()ing is done. There may still be basic + /// canonicalization (that is, same String will be used to represent + /// all identical object property names for a single document). + /// + /// Note: this setting only has effect if + /// \#CANONICALIZE_FIELD_NAMES is true -- otherwise no + /// canonicalization of any sort is done. + /// + /// This setting is enabled by default. + static JsonFactory$Feature get INTERN_FIELD_NAMES => + _id_INTERN_FIELD_NAMES.get(_class, const $JsonFactory$Feature$Type()); + + static final _id_CANONICALIZE_FIELD_NAMES = _class.staticFieldId( + r'CANONICALIZE_FIELD_NAMES', + r'Lcom/fasterxml/jackson/core/JsonFactory$Feature;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonFactory.Feature CANONICALIZE_FIELD_NAMES` + /// The returned object must be released after use, by calling the [release] method. + /// + /// Feature that determines whether JSON object field names are + /// to be canonicalized (details of how canonicalization is done + /// then further specified by + /// \#INTERN_FIELD_NAMES). + /// + /// This setting is enabled by default. + static JsonFactory$Feature get CANONICALIZE_FIELD_NAMES => + _id_CANONICALIZE_FIELD_NAMES.get( + _class, const $JsonFactory$Feature$Type()); + + static final _id_FAIL_ON_SYMBOL_HASH_OVERFLOW = _class.staticFieldId( + r'FAIL_ON_SYMBOL_HASH_OVERFLOW', + r'Lcom/fasterxml/jackson/core/JsonFactory$Feature;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonFactory.Feature FAIL_ON_SYMBOL_HASH_OVERFLOW` + /// The returned object must be released after use, by calling the [release] method. + /// + /// Feature that determines what happens if we encounter a case in symbol + /// handling where number of hash collisions exceeds a safety threshold + /// -- which almost certainly means a denial-of-service attack via generated + /// duplicate hash codes. + /// If feature is enabled, an IllegalStateException is + /// thrown to indicate the suspected denial-of-service attack; if disabled, processing continues but + /// canonicalization (and thereby intern()ing) is disabled) as protective + /// measure. + /// + /// This setting is enabled by default. + ///@since 2.4 + static JsonFactory$Feature get FAIL_ON_SYMBOL_HASH_OVERFLOW => + _id_FAIL_ON_SYMBOL_HASH_OVERFLOW.get( + _class, const $JsonFactory$Feature$Type()); + + static final _id_USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING = _class.staticFieldId( + r'USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING', + r'Lcom/fasterxml/jackson/core/JsonFactory$Feature;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonFactory.Feature USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING` + /// The returned object must be released after use, by calling the [release] method. + /// + /// Feature that determines whether we will use BufferRecycler with + /// ThreadLocal and SoftReference, for efficient reuse of + /// underlying input/output buffers. + /// This usually makes sense on normal J2SE/J2EE server-side processing; + /// but may not make sense on platforms where SoftReference handling + /// is broken (like Android), or if there are retention issues due to + /// ThreadLocal (see + /// jackson-core\#189 + /// for a possible case) + /// + /// This setting is enabled by default. + ///@since 2.6 + static JsonFactory$Feature get USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING => + _id_USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING.get( + _class, const $JsonFactory$Feature$Type()); + static final _id_values = _class.staticMethodId( r'values', r'()[Lcom/fasterxml/jackson/core/JsonFactory$Feature;', 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 3f5e313c1..20f097787 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 @@ -74,6 +74,365 @@ class JsonParser$Feature extends jni$_.JObject { /// The type which includes information such as the signature of this class. static const nullableType = $JsonParser$Feature$NullableType(); static const type = $JsonParser$Feature$Type(); + static final _id_AUTO_CLOSE_SOURCE = _class.staticFieldId( + r'AUTO_CLOSE_SOURCE', + r'Lcom/fasterxml/jackson/core/JsonParser$Feature;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonParser.Feature AUTO_CLOSE_SOURCE` + /// The returned object must be released after use, by calling the [release] method. + /// + /// Feature that determines whether parser will automatically + /// close underlying input source that is NOT owned by the + /// parser. If disabled, calling application has to separately + /// close the underlying InputStream and Reader + /// instances used to create the parser. If enabled, parser + /// will handle closing, as long as parser itself gets closed: + /// this happens when end-of-input is encountered, or parser + /// is closed by a call to JsonParser\#close. + /// + /// Feature is enabled by default. + static JsonParser$Feature get AUTO_CLOSE_SOURCE => + _id_AUTO_CLOSE_SOURCE.get(_class, const $JsonParser$Feature$Type()); + + static final _id_ALLOW_COMMENTS = _class.staticFieldId( + r'ALLOW_COMMENTS', + r'Lcom/fasterxml/jackson/core/JsonParser$Feature;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonParser.Feature ALLOW_COMMENTS` + /// The returned object must be released after use, by calling the [release] method. + /// + /// Feature that determines whether parser will allow use + /// of Java/C++ style comments (both '/'+'*' and + /// '//' varieties) within parsed content or not. + /// + /// Since JSON specification does not mention comments as legal + /// construct, + /// this is a non-standard feature; however, in the wild + /// this is extensively used. As such, feature is + /// __disabled by default__ for parsers and must be + /// explicitly enabled. + /// + /// NOTE: while not technically deprecated, since 2.10 recommended to use + /// com.fasterxml.jackson.core.json.JsonReadFeature\#ALLOW_JAVA_COMMENTS instead. + static JsonParser$Feature get ALLOW_COMMENTS => + _id_ALLOW_COMMENTS.get(_class, const $JsonParser$Feature$Type()); + + static final _id_ALLOW_YAML_COMMENTS = _class.staticFieldId( + r'ALLOW_YAML_COMMENTS', + r'Lcom/fasterxml/jackson/core/JsonParser$Feature;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonParser.Feature ALLOW_YAML_COMMENTS` + /// The returned object must be released after use, by calling the [release] method. + /// + /// Feature that determines whether parser will allow use + /// of YAML comments, ones starting with '\#' and continuing + /// until the end of the line. This commenting style is common + /// with scripting languages as well. + /// + /// Since JSON specification does not mention comments as legal + /// construct, + /// this is a non-standard feature. As such, feature is + /// __disabled by default__ for parsers and must be + /// explicitly enabled. + /// + /// NOTE: while not technically deprecated, since 2.10 recommended to use + /// com.fasterxml.jackson.core.json.JsonReadFeature\#ALLOW_YAML_COMMENTS instead. + static JsonParser$Feature get ALLOW_YAML_COMMENTS => + _id_ALLOW_YAML_COMMENTS.get(_class, const $JsonParser$Feature$Type()); + + static final _id_ALLOW_UNQUOTED_FIELD_NAMES = _class.staticFieldId( + r'ALLOW_UNQUOTED_FIELD_NAMES', + r'Lcom/fasterxml/jackson/core/JsonParser$Feature;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonParser.Feature ALLOW_UNQUOTED_FIELD_NAMES` + /// The returned object must be released after use, by calling the [release] method. + /// + /// Feature that determines whether parser will allow use + /// of unquoted field names (which is allowed by Javascript, + /// but not by JSON specification). + /// + /// Since JSON specification requires use of double quotes for + /// field names, + /// this is a non-standard feature, and as such disabled by default. + /// + /// NOTE: while not technically deprecated, since 2.10 recommended to use + /// com.fasterxml.jackson.core.json.JsonReadFeature\#ALLOW_UNQUOTED_FIELD_NAMES instead. + static JsonParser$Feature get ALLOW_UNQUOTED_FIELD_NAMES => + _id_ALLOW_UNQUOTED_FIELD_NAMES.get( + _class, const $JsonParser$Feature$Type()); + + static final _id_ALLOW_SINGLE_QUOTES = _class.staticFieldId( + r'ALLOW_SINGLE_QUOTES', + r'Lcom/fasterxml/jackson/core/JsonParser$Feature;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonParser.Feature ALLOW_SINGLE_QUOTES` + /// The returned object must be released after use, by calling the [release] method. + /// + /// Feature that determines whether parser will allow use + /// of single quotes (apostrophe, character '\'') for + /// quoting Strings (names and String values). If so, + /// this is in addition to other acceptable markers. + /// but not by JSON specification). + /// + /// Since JSON specification requires use of double quotes for + /// field names, + /// this is a non-standard feature, and as such disabled by default. + /// + /// NOTE: while not technically deprecated, since 2.10 recommended to use + /// com.fasterxml.jackson.core.json.JsonReadFeature\#ALLOW_SINGLE_QUOTES instead. + static JsonParser$Feature get ALLOW_SINGLE_QUOTES => + _id_ALLOW_SINGLE_QUOTES.get(_class, const $JsonParser$Feature$Type()); + + static final _id_ALLOW_UNQUOTED_CONTROL_CHARS = _class.staticFieldId( + r'ALLOW_UNQUOTED_CONTROL_CHARS', + r'Lcom/fasterxml/jackson/core/JsonParser$Feature;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonParser.Feature ALLOW_UNQUOTED_CONTROL_CHARS` + /// The returned object must be released after use, by calling the [release] method. + /// + /// Feature that determines whether parser will allow + /// JSON Strings to contain unquoted control characters + /// (ASCII characters with value less than 32, including + /// tab and line feed characters) or not. + /// If feature is set false, an exception is thrown if such a + /// character is encountered. + /// + /// Since JSON specification requires quoting for all control characters, + /// this is a non-standard feature, and as such disabled by default. + ///@deprecated Since 2.10 use com.fasterxml.jackson.core.json.JsonReadFeature\#ALLOW_UNESCAPED_CONTROL_CHARS instead + static JsonParser$Feature get ALLOW_UNQUOTED_CONTROL_CHARS => + _id_ALLOW_UNQUOTED_CONTROL_CHARS.get( + _class, const $JsonParser$Feature$Type()); + + static final _id_ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER = + _class.staticFieldId( + r'ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER', + r'Lcom/fasterxml/jackson/core/JsonParser$Feature;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonParser.Feature ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER` + /// The returned object must be released after use, by calling the [release] method. + /// + /// Feature that can be enabled to accept quoting of all character + /// using backslash quoting mechanism: if not enabled, only characters + /// that are explicitly listed by JSON specification can be thus + /// escaped (see JSON spec for small list of these characters) + /// + /// Since JSON specification requires quoting for all control characters, + /// this is a non-standard feature, and as such disabled by default. + ///@deprecated Since 2.10 use com.fasterxml.jackson.core.json.JsonReadFeature\#ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER instead + static JsonParser$Feature get ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER => + _id_ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER.get( + _class, const $JsonParser$Feature$Type()); + + static final _id_ALLOW_NUMERIC_LEADING_ZEROS = _class.staticFieldId( + r'ALLOW_NUMERIC_LEADING_ZEROS', + r'Lcom/fasterxml/jackson/core/JsonParser$Feature;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonParser.Feature ALLOW_NUMERIC_LEADING_ZEROS` + /// The returned object must be released after use, by calling the [release] method. + /// + /// Feature that determines whether parser will allow + /// JSON integral numbers to start with additional (ignorable) + /// zeroes (like: 000001). If enabled, no exception is thrown, and extra + /// nulls are silently ignored (and not included in textual representation + /// exposed via JsonParser\#getText). + /// + /// Since JSON specification does not allow leading zeroes, + /// this is a non-standard feature, and as such disabled by default. + ///@deprecated Since 2.10 use com.fasterxml.jackson.core.json.JsonReadFeature\#ALLOW_LEADING_ZEROS_FOR_NUMBERS instead + static JsonParser$Feature get ALLOW_NUMERIC_LEADING_ZEROS => + _id_ALLOW_NUMERIC_LEADING_ZEROS.get( + _class, const $JsonParser$Feature$Type()); + + static final _id_ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS = + _class.staticFieldId( + r'ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS', + r'Lcom/fasterxml/jackson/core/JsonParser$Feature;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonParser.Feature ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS` + /// The returned object must be released after use, by calling the [release] method. + /// + /// @deprecated Use com.fasterxml.jackson.core.json.JsonReadFeature\#ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS instead + static JsonParser$Feature get ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS => + _id_ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS.get( + _class, const $JsonParser$Feature$Type()); + + static final _id_ALLOW_NON_NUMERIC_NUMBERS = _class.staticFieldId( + r'ALLOW_NON_NUMERIC_NUMBERS', + r'Lcom/fasterxml/jackson/core/JsonParser$Feature;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonParser.Feature ALLOW_NON_NUMERIC_NUMBERS` + /// The returned object must be released after use, by calling the [release] method. + /// + /// Feature that allows parser to recognize set of + /// "Not-a-Number" (NaN) tokens as legal floating number + /// values (similar to how many other data formats and + /// programming language source code allows it). + /// Specific subset contains values that + /// XML Schema + /// (see section 3.2.4.1, Lexical Representation) + /// allows (tokens are quoted contents, not including quotes): + /// + /// + /// Since JSON specification does not allow use of such values, + /// this is a non-standard feature, and as such disabled by default. + ///@deprecated Since 2.10 use com.fasterxml.jackson.core.json.JsonReadFeature\#ALLOW_NON_NUMERIC_NUMBERS instead + static JsonParser$Feature get ALLOW_NON_NUMERIC_NUMBERS => + _id_ALLOW_NON_NUMERIC_NUMBERS.get( + _class, const $JsonParser$Feature$Type()); + + static final _id_ALLOW_MISSING_VALUES = _class.staticFieldId( + r'ALLOW_MISSING_VALUES', + r'Lcom/fasterxml/jackson/core/JsonParser$Feature;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonParser.Feature ALLOW_MISSING_VALUES` + /// The returned object must be released after use, by calling the [release] method. + /// + /// Feature allows the support for "missing" values in a JSON array: missing + /// value meaning sequence of two commas, without value in-between but only + /// optional white space. + /// Enabling this feature will expose "missing" values as JsonToken\#VALUE_NULL + /// tokens, which typically become Java nulls in arrays and java.util.Collection + /// in data-binding. + /// + /// For example, enabling this feature will represent a JSON array ["value1",,"value3",] + /// as ["value1", null, "value3", null] + /// + /// Since the JSON specification does not allow missing values this is a non-compliant JSON + /// feature and is disabled by default. + ///@since 2.8 + ///@deprecated Since 2.10 use com.fasterxml.jackson.core.json.JsonReadFeature\#ALLOW_MISSING_VALUES instead + static JsonParser$Feature get ALLOW_MISSING_VALUES => + _id_ALLOW_MISSING_VALUES.get(_class, const $JsonParser$Feature$Type()); + + static final _id_ALLOW_TRAILING_COMMA = _class.staticFieldId( + r'ALLOW_TRAILING_COMMA', + r'Lcom/fasterxml/jackson/core/JsonParser$Feature;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonParser.Feature ALLOW_TRAILING_COMMA` + /// The returned object must be released after use, by calling the [release] method. + /// + /// Feature that determines whether JsonParser will allow for a single trailing + /// comma following the final value (in an Array) or member (in an Object). These commas + /// will simply be ignored. + /// + /// For example, when this feature is enabled, [true,true,] is equivalent to + /// [true, true] and {"a": true,} is equivalent to + /// {"a": true}. + /// + /// When combined with ALLOW_MISSING_VALUES, this feature takes priority, and + /// the final trailing comma in an array declaration does not imply a missing + /// (null) value. For example, when both ALLOW_MISSING_VALUES + /// and ALLOW_TRAILING_COMMA are enabled, [true,true,] is + /// equivalent to [true, true], and [true,true,,] is equivalent to + /// [true, true, null]. + /// + /// Since the JSON specification does not permit trailing commas, this is a non-standard + /// feature, and as such disabled by default. + ///@since 2.9 + ///@deprecated Since 2.10 use com.fasterxml.jackson.core.json.JsonReadFeature\#ALLOW_TRAILING_COMMA instead + static JsonParser$Feature get ALLOW_TRAILING_COMMA => + _id_ALLOW_TRAILING_COMMA.get(_class, const $JsonParser$Feature$Type()); + + static final _id_STRICT_DUPLICATE_DETECTION = _class.staticFieldId( + r'STRICT_DUPLICATE_DETECTION', + r'Lcom/fasterxml/jackson/core/JsonParser$Feature;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonParser.Feature STRICT_DUPLICATE_DETECTION` + /// The returned object must be released after use, by calling the [release] method. + /// + /// Feature that determines whether JsonParser will explicitly + /// check that no duplicate JSON Object field names are encountered. + /// If enabled, parser will check all names within context and report + /// duplicates by throwing a JsonParseException; if disabled, + /// parser will not do such checking. Assumption in latter case is + /// that caller takes care of handling duplicates at a higher level: + /// data-binding, for example, has features to specify detection to + /// be done there. + /// + /// Note that enabling this feature will incur performance overhead + /// due to having to store and check additional information: this typically + /// adds 20-30% to execution time for basic parsing. + ///@since 2.3 + static JsonParser$Feature get STRICT_DUPLICATE_DETECTION => + _id_STRICT_DUPLICATE_DETECTION.get( + _class, const $JsonParser$Feature$Type()); + + static final _id_IGNORE_UNDEFINED = _class.staticFieldId( + r'IGNORE_UNDEFINED', + r'Lcom/fasterxml/jackson/core/JsonParser$Feature;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonParser.Feature IGNORE_UNDEFINED` + /// The returned object must be released after use, by calling the [release] method. + /// + /// Feature that determines what to do if the underlying data format requires knowledge + /// of all properties to decode (usually via a Schema), and if no definition is + /// found for a property that input content contains. + /// Typically most textual data formats do NOT require schema information (although + /// some do, such as CSV), whereas many binary data formats do require definitions + /// (such as Avro, protobuf), although not all (Smile, CBOR, BSON and MessagePack do not). + /// Further note that some formats that do require schema information will not be able + /// to ignore undefined properties: for example, Avro is fully positional and there is + /// no possibility of undefined data. This leaves formats like Protobuf that have identifiers + /// that may or may not map; and as such Protobuf format does make use of this feature. + /// + /// Note that support for this feature is implemented by individual data format + /// module, if (and only if) it makes sense for the format in question. For JSON, + /// for example, this feature has no effect as properties need not be pre-defined. + /// + /// Feature is disabled by default, meaning that if the underlying data format + /// requires knowledge of all properties to output, attempts to read an unknown + /// property will result in a JsonProcessingException + ///@since 2.6 + static JsonParser$Feature get IGNORE_UNDEFINED => + _id_IGNORE_UNDEFINED.get(_class, const $JsonParser$Feature$Type()); + + static final _id_INCLUDE_SOURCE_IN_LOCATION = _class.staticFieldId( + r'INCLUDE_SOURCE_IN_LOCATION', + r'Lcom/fasterxml/jackson/core/JsonParser$Feature;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonParser.Feature INCLUDE_SOURCE_IN_LOCATION` + /// The returned object must be released after use, by calling the [release] method. + /// + /// Feature that determines whether JsonLocation instances should be constructed + /// with reference to source or not. If source reference is included, its type and contents + /// are included when `toString()` method is called (most notably when printing out parse + /// exception with that location information). If feature is disabled, no source reference + /// is passed and source is only indicated as "UNKNOWN". + /// + /// Most common reason for disabling this feature is to avoid leaking information about + /// internal information; this may be done for security reasons. + /// Note that even if source reference is included, only parts of contents are usually + /// printed, and not the whole contents. Further, many source reference types can not + /// necessarily access contents (like streams), so only type is indicated, not contents. + /// + /// Feature is enabled by default, meaning that "source reference" information is passed + /// and some or all of the source content may be included in JsonLocation information + /// constructed either when requested explicitly, or when needed for an exception. + ///@since 2.9 + static JsonParser$Feature get INCLUDE_SOURCE_IN_LOCATION => + _id_INCLUDE_SOURCE_IN_LOCATION.get( + _class, const $JsonParser$Feature$Type()); + static final _id_values = _class.staticMethodId( r'values', r'()[Lcom/fasterxml/jackson/core/JsonParser$Feature;', @@ -326,6 +685,66 @@ class JsonParser$NumberType extends jni$_.JObject { /// The type which includes information such as the signature of this class. static const nullableType = $JsonParser$NumberType$NullableType(); static const type = $JsonParser$NumberType$Type(); + static final _id_INT = _class.staticFieldId( + r'INT', + r'Lcom/fasterxml/jackson/core/JsonParser$NumberType;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonParser.NumberType INT` + /// The returned object must be released after use, by calling the [release] method. + static JsonParser$NumberType get INT => + _id_INT.get(_class, const $JsonParser$NumberType$Type()); + + static final _id_LONG = _class.staticFieldId( + r'LONG', + r'Lcom/fasterxml/jackson/core/JsonParser$NumberType;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonParser.NumberType LONG` + /// The returned object must be released after use, by calling the [release] method. + static JsonParser$NumberType get LONG => + _id_LONG.get(_class, const $JsonParser$NumberType$Type()); + + static final _id_BIG_INTEGER = _class.staticFieldId( + r'BIG_INTEGER', + r'Lcom/fasterxml/jackson/core/JsonParser$NumberType;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonParser.NumberType BIG_INTEGER` + /// The returned object must be released after use, by calling the [release] method. + static JsonParser$NumberType get BIG_INTEGER => + _id_BIG_INTEGER.get(_class, const $JsonParser$NumberType$Type()); + + static final _id_FLOAT = _class.staticFieldId( + r'FLOAT', + r'Lcom/fasterxml/jackson/core/JsonParser$NumberType;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonParser.NumberType FLOAT` + /// The returned object must be released after use, by calling the [release] method. + static JsonParser$NumberType get FLOAT => + _id_FLOAT.get(_class, const $JsonParser$NumberType$Type()); + + static final _id_DOUBLE = _class.staticFieldId( + r'DOUBLE', + r'Lcom/fasterxml/jackson/core/JsonParser$NumberType;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonParser.NumberType DOUBLE` + /// The returned object must be released after use, by calling the [release] method. + static JsonParser$NumberType get DOUBLE => + _id_DOUBLE.get(_class, const $JsonParser$NumberType$Type()); + + static final _id_BIG_DECIMAL = _class.staticFieldId( + r'BIG_DECIMAL', + r'Lcom/fasterxml/jackson/core/JsonParser$NumberType;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonParser.NumberType BIG_DECIMAL` + /// The returned object must be released after use, by calling the [release] method. + static JsonParser$NumberType get BIG_DECIMAL => + _id_BIG_DECIMAL.get(_class, const $JsonParser$NumberType$Type()); + static final _id_values = _class.staticMethodId( r'values', r'()[Lcom/fasterxml/jackson/core/JsonParser$NumberType;', 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 45e61549d..46f229d45 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 @@ -73,6 +73,194 @@ class JsonToken extends jni$_.JObject { /// The type which includes information such as the signature of this class. static const nullableType = $JsonToken$NullableType(); static const type = $JsonToken$Type(); + static final _id_NOT_AVAILABLE = _class.staticFieldId( + r'NOT_AVAILABLE', + r'Lcom/fasterxml/jackson/core/JsonToken;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonToken NOT_AVAILABLE` + /// The returned object must be released after use, by calling the [release] method. + /// + /// NOT_AVAILABLE can be returned if JsonParser + /// implementation can not currently return the requested + /// token (usually next one), or even if any will be + /// available, but that may be able to determine this in + /// future. This is the case with non-blocking parsers -- + /// they can not block to wait for more data to parse and + /// must return something. + static JsonToken get NOT_AVAILABLE => + _id_NOT_AVAILABLE.get(_class, const $JsonToken$Type()); + + static final _id_START_OBJECT = _class.staticFieldId( + r'START_OBJECT', + r'Lcom/fasterxml/jackson/core/JsonToken;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonToken START_OBJECT` + /// The returned object must be released after use, by calling the [release] method. + /// + /// START_OBJECT is returned when encountering '{' + /// which signals starting of an Object value. + static JsonToken get START_OBJECT => + _id_START_OBJECT.get(_class, const $JsonToken$Type()); + + static final _id_END_OBJECT = _class.staticFieldId( + r'END_OBJECT', + r'Lcom/fasterxml/jackson/core/JsonToken;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonToken END_OBJECT` + /// The returned object must be released after use, by calling the [release] method. + /// + /// END_OBJECT is returned when encountering '}' + /// which signals ending of an Object value + static JsonToken get END_OBJECT => + _id_END_OBJECT.get(_class, const $JsonToken$Type()); + + static final _id_START_ARRAY = _class.staticFieldId( + r'START_ARRAY', + r'Lcom/fasterxml/jackson/core/JsonToken;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonToken START_ARRAY` + /// The returned object must be released after use, by calling the [release] method. + /// + /// START_ARRAY is returned when encountering '[' + /// which signals starting of an Array value + static JsonToken get START_ARRAY => + _id_START_ARRAY.get(_class, const $JsonToken$Type()); + + static final _id_END_ARRAY = _class.staticFieldId( + r'END_ARRAY', + r'Lcom/fasterxml/jackson/core/JsonToken;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonToken END_ARRAY` + /// The returned object must be released after use, by calling the [release] method. + /// + /// END_ARRAY is returned when encountering ']' + /// which signals ending of an Array value + static JsonToken get END_ARRAY => + _id_END_ARRAY.get(_class, const $JsonToken$Type()); + + static final _id_FIELD_NAME = _class.staticFieldId( + r'FIELD_NAME', + r'Lcom/fasterxml/jackson/core/JsonToken;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonToken FIELD_NAME` + /// The returned object must be released after use, by calling the [release] method. + /// + /// FIELD_NAME is returned when a String token is encountered + /// as a field name (same lexical value, different function) + static JsonToken get FIELD_NAME => + _id_FIELD_NAME.get(_class, const $JsonToken$Type()); + + static final _id_VALUE_EMBEDDED_OBJECT = _class.staticFieldId( + r'VALUE_EMBEDDED_OBJECT', + r'Lcom/fasterxml/jackson/core/JsonToken;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonToken VALUE_EMBEDDED_OBJECT` + /// The returned object must be released after use, by calling the [release] method. + /// + /// Placeholder token returned when the input source has a concept + /// of embedded Object that are not accessible as usual structure + /// (of starting with \#START_OBJECT, having values, ending with + /// \#END_OBJECT), but as "raw" objects. + /// + /// Note: this token is never returned by regular JSON readers, but + /// only by readers that expose other kinds of source (like + /// JsonNode-based JSON trees, Maps, Lists and such). + static JsonToken get VALUE_EMBEDDED_OBJECT => + _id_VALUE_EMBEDDED_OBJECT.get(_class, const $JsonToken$Type()); + + static final _id_VALUE_STRING = _class.staticFieldId( + r'VALUE_STRING', + r'Lcom/fasterxml/jackson/core/JsonToken;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonToken VALUE_STRING` + /// The returned object must be released after use, by calling the [release] method. + /// + /// VALUE_STRING is returned when a String token is encountered + /// in value context (array element, field value, or root-level + /// stand-alone value) + static JsonToken get VALUE_STRING => + _id_VALUE_STRING.get(_class, const $JsonToken$Type()); + + static final _id_VALUE_NUMBER_INT = _class.staticFieldId( + r'VALUE_NUMBER_INT', + r'Lcom/fasterxml/jackson/core/JsonToken;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonToken VALUE_NUMBER_INT` + /// The returned object must be released after use, by calling the [release] method. + /// + /// VALUE_NUMBER_INT is returned when an integer numeric token is + /// encountered in value context: that is, a number that does + /// not have floating point or exponent marker in it (consists + /// only of an optional sign, followed by one or more digits; + /// or, for binary formats, is indicated as integral number + /// by internal representation). + static JsonToken get VALUE_NUMBER_INT => + _id_VALUE_NUMBER_INT.get(_class, const $JsonToken$Type()); + + static final _id_VALUE_NUMBER_FLOAT = _class.staticFieldId( + r'VALUE_NUMBER_FLOAT', + r'Lcom/fasterxml/jackson/core/JsonToken;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonToken VALUE_NUMBER_FLOAT` + /// The returned object must be released after use, by calling the [release] method. + /// + /// VALUE_NUMBER_FLOAT is returned when a numeric token other + /// than integer is encountered: that is, a number that does + /// have floating point or exponent marker in it, in addition + /// to one or more digits (or, for non-textual formats, + /// has internal floating-point representation). + static JsonToken get VALUE_NUMBER_FLOAT => + _id_VALUE_NUMBER_FLOAT.get(_class, const $JsonToken$Type()); + + static final _id_VALUE_TRUE = _class.staticFieldId( + r'VALUE_TRUE', + r'Lcom/fasterxml/jackson/core/JsonToken;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonToken VALUE_TRUE` + /// The returned object must be released after use, by calling the [release] method. + /// + /// VALUE_TRUE is returned when encountering literal "true" in + /// value context + static JsonToken get VALUE_TRUE => + _id_VALUE_TRUE.get(_class, const $JsonToken$Type()); + + static final _id_VALUE_FALSE = _class.staticFieldId( + r'VALUE_FALSE', + r'Lcom/fasterxml/jackson/core/JsonToken;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonToken VALUE_FALSE` + /// The returned object must be released after use, by calling the [release] method. + /// + /// VALUE_FALSE is returned when encountering literal "false" in + /// value context + static JsonToken get VALUE_FALSE => + _id_VALUE_FALSE.get(_class, const $JsonToken$Type()); + + static final _id_VALUE_NULL = _class.staticFieldId( + r'VALUE_NULL', + r'Lcom/fasterxml/jackson/core/JsonToken;', + ); + + /// from: `static public final com.fasterxml.jackson.core.JsonToken VALUE_NULL` + /// The returned object must be released after use, by calling the [release] method. + /// + /// VALUE_NULL is returned when encountering literal "null" in + /// value context + static JsonToken get VALUE_NULL => + _id_VALUE_NULL.get(_class, const $JsonToken$Type()); + static final _id_values = _class.staticMethodId( r'values', r'()[Lcom/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 3b28e85a0..464773a2a 100644 --- a/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart +++ b/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart @@ -1936,8 +1936,8 @@ class SpeedUnit extends jni$_.JObject { /// from: `static public final com.github.dart_lang.jnigen.SpeedUnit KmPerHour` /// The returned object must be released after use, by calling the [release] method. - static SpeedUnit? get KmPerHour => - _id_KmPerHour.get(_class, const $SpeedUnit$NullableType()); + static SpeedUnit get KmPerHour => + _id_KmPerHour.get(_class, const $SpeedUnit$Type()); static final _id_MetrePerSec = _class.staticFieldId( r'MetrePerSec', @@ -1946,8 +1946,8 @@ class SpeedUnit extends jni$_.JObject { /// from: `static public final com.github.dart_lang.jnigen.SpeedUnit MetrePerSec` /// The returned object must be released after use, by calling the [release] method. - static SpeedUnit? get MetrePerSec => - _id_MetrePerSec.get(_class, const $SpeedUnit$NullableType()); + static SpeedUnit get MetrePerSec => + _id_MetrePerSec.get(_class, const $SpeedUnit$Type()); static final _id_getSign = _class.instanceMethodId( r'getSign', diff --git a/pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart b/pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart index 81a1c47f7..1582d78bd 100644 --- a/pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart +++ b/pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart @@ -36,8 +36,8 @@ void registerTests(String groupName, TestRunnerCallback test) { test('Generics', () { using((arena) { - final speed = Speed(10, SpeedUnit.MetrePerSec!)..releasedBy(arena); - expect(speed.convertValue(SpeedUnit.KmPerHour!), closeTo(36, 1e-6)); + final speed = Speed(10, SpeedUnit.MetrePerSec)..releasedBy(arena); + expect(speed.convertValue(SpeedUnit.KmPerHour), closeTo(36, 1e-6)); }); }); 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 cb1c8d79d..4efc8709a 100644 --- a/pkgs/jnigen/test/simple_package_test/bindings/simple_package.dart +++ b/pkgs/jnigen/test/simple_package_test/bindings/simple_package.dart @@ -39,203 +39,6 @@ import 'dart:core' as core$_; import 'package:jni/_internal.dart' as jni$_; import 'package:jni/jni.dart' as jni$_; -/// from: `com.github.dart_lang.jnigen.simple_package.Color` -class Color extends jni$_.JObject { - @jni$_.internal - @core$_.override - final jni$_.JObjType $type; - - @jni$_.internal - Color.fromReference( - jni$_.JReference reference, - ) : $type = type, - super.fromReference(reference); - - static final _class = - jni$_.JClass.forName(r'com/github/dart_lang/jnigen/simple_package/Color'); - - /// The type which includes information such as the signature of this class. - static const nullableType = $Color$NullableType(); - static const type = $Color$Type(); - static final _id_RED = _class.staticFieldId( - r'RED', - r'Lcom/github/dart_lang/jnigen/simple_package/Color;', - ); - - /// from: `static public final com.github.dart_lang.jnigen.simple_package.Color RED` - /// The returned object must be released after use, by calling the [release] method. - static Color? get RED => _id_RED.get(_class, const $Color$NullableType()); - - static final _id_BLUE = _class.staticFieldId( - r'BLUE', - r'Lcom/github/dart_lang/jnigen/simple_package/Color;', - ); - - /// from: `static public final com.github.dart_lang.jnigen.simple_package.Color BLUE` - /// The returned object must be released after use, by calling the [release] method. - static Color? get BLUE => _id_BLUE.get(_class, const $Color$NullableType()); - - static final _id_BLACK = _class.staticFieldId( - r'BLACK', - r'Lcom/github/dart_lang/jnigen/simple_package/Color;', - ); - - /// from: `static public final com.github.dart_lang.jnigen.simple_package.Color BLACK` - /// The returned object must be released after use, by calling the [release] method. - static Color? get BLACK => _id_BLACK.get(_class, const $Color$NullableType()); - - static final _id_GREEN = _class.staticFieldId( - r'GREEN', - r'Lcom/github/dart_lang/jnigen/simple_package/Color;', - ); - - /// from: `static public final com.github.dart_lang.jnigen.simple_package.Color GREEN` - /// The returned object must be released after use, by calling the [release] method. - static Color? get GREEN => _id_GREEN.get(_class, const $Color$NullableType()); - - static final _id_YELLOW = _class.staticFieldId( - r'YELLOW', - r'Lcom/github/dart_lang/jnigen/simple_package/Color;', - ); - - /// from: `static public final com.github.dart_lang.jnigen.simple_package.Color YELLOW` - /// The returned object must be released after use, by calling the [release] method. - static Color? get YELLOW => - _id_YELLOW.get(_class, const $Color$NullableType()); - - static final _id_LIME = _class.staticFieldId( - r'LIME', - r'Lcom/github/dart_lang/jnigen/simple_package/Color;', - ); - - /// from: `static public final com.github.dart_lang.jnigen.simple_package.Color LIME` - /// The returned object must be released after use, by calling the [release] method. - static Color? get LIME => _id_LIME.get(_class, const $Color$NullableType()); - - static final _id_values = _class.staticMethodId( - r'values', - r'()[Lcom/github/dart_lang/jnigen/simple_package/Color;', - ); - - static final _values = jni$_.ProtectedJniExtensions.lookup< - jni$_.NativeFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - )>>('globalEnv_CallStaticObjectMethod') - .asFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - )>(); - - /// from: `static public com.github.dart_lang.jnigen.simple_package.Color[] values()` - /// The returned object must be released after use, by calling the [release] method. - static jni$_.JArray? values() { - return _values(_class.reference.pointer, _id_values as jni$_.JMethodIDPtr) - .object?>( - const jni$_.JArrayNullableType($Color$NullableType())); - } - - static final _id_valueOf = _class.staticMethodId( - r'valueOf', - r'(Ljava/lang/String;)Lcom/github/dart_lang/jnigen/simple_package/Color;', - ); - - static final _valueOf = jni$_.ProtectedJniExtensions.lookup< - jni$_.NativeFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - jni$_.VarArgs<(jni$_.Pointer,)>)>>( - 'globalEnv_CallStaticObjectMethod') - .asFunction< - jni$_.JniResult Function(jni$_.Pointer, - jni$_.JMethodIDPtr, jni$_.Pointer)>(); - - /// from: `static public com.github.dart_lang.jnigen.simple_package.Color valueOf(java.lang.String string)` - /// The returned object must be released after use, by calling the [release] method. - static Color? valueOf( - jni$_.JString? string, - ) { - final _$string = string?.reference ?? jni$_.jNullReference; - return _valueOf(_class.reference.pointer, _id_valueOf as jni$_.JMethodIDPtr, - _$string.pointer) - .object(const $Color$NullableType()); - } -} - -final class $Color$NullableType extends jni$_.JObjType { - @jni$_.internal - const $Color$NullableType(); - - @jni$_.internal - @core$_.override - String get signature => r'Lcom/github/dart_lang/jnigen/simple_package/Color;'; - - @jni$_.internal - @core$_.override - Color? fromReference(jni$_.JReference reference) => reference.isNull - ? null - : Color.fromReference( - reference, - ); - @jni$_.internal - @core$_.override - jni$_.JObjType get superType => const jni$_.JObjectNullableType(); - - @jni$_.internal - @core$_.override - jni$_.JObjType get nullableType => this; - - @jni$_.internal - @core$_.override - final superCount = 1; - - @core$_.override - int get hashCode => ($Color$NullableType).hashCode; - - @core$_.override - bool operator ==(Object other) { - return other.runtimeType == ($Color$NullableType) && - other is $Color$NullableType; - } -} - -final class $Color$Type extends jni$_.JObjType { - @jni$_.internal - const $Color$Type(); - - @jni$_.internal - @core$_.override - String get signature => r'Lcom/github/dart_lang/jnigen/simple_package/Color;'; - - @jni$_.internal - @core$_.override - Color fromReference(jni$_.JReference reference) => Color.fromReference( - reference, - ); - @jni$_.internal - @core$_.override - jni$_.JObjType get superType => const jni$_.JObjectNullableType(); - - @jni$_.internal - @core$_.override - jni$_.JObjType get nullableType => const $Color$NullableType(); - - @jni$_.internal - @core$_.override - final superCount = 1; - - @core$_.override - int get hashCode => ($Color$Type).hashCode; - - @core$_.override - bool operator ==(Object other) { - return other.runtimeType == ($Color$Type) && other is $Color$Type; - } -} - /// from: `com.github.dart_lang.jnigen.simple_package.Example$Nested$NestedTwice` class Example$Nested$NestedTwice extends jni$_.JObject { @jni$_.internal @@ -3165,6 +2968,408 @@ final class $Example$1$Type extends jni$_.JObjType { } } +/// from: `com.github.dart_lang.jnigen.enums.Colors$RGB` +class Colors$RGB extends jni$_.JObject { + @jni$_.internal + @core$_.override + final jni$_.JObjType $type; + + @jni$_.internal + Colors$RGB.fromReference( + jni$_.JReference reference, + ) : $type = type, + super.fromReference(reference); + + static final _class = + jni$_.JClass.forName(r'com/github/dart_lang/jnigen/enums/Colors$RGB'); + + /// The type which includes information such as the signature of this class. + static const nullableType = $Colors$RGB$NullableType(); + static const type = $Colors$RGB$Type(); + static final _id_red = _class.instanceFieldId( + r'red', + r'I', + ); + + /// from: `public int red` + int get red => _id_red.get(this, const jni$_.jintType()); + + /// from: `public int red` + set red(int value) => _id_red.set(this, const jni$_.jintType(), value); + + static final _id_green = _class.instanceFieldId( + r'green', + r'I', + ); + + /// from: `public int green` + int get green => _id_green.get(this, const jni$_.jintType()); + + /// from: `public int green` + set green(int value) => _id_green.set(this, const jni$_.jintType(), value); + + static final _id_blue = _class.instanceFieldId( + r'blue', + r'I', + ); + + /// from: `public int blue` + int get blue => _id_blue.get(this, const jni$_.jintType()); + + /// from: `public int blue` + set blue(int value) => _id_blue.set(this, const jni$_.jintType(), value); + + static final _id_new$ = _class.constructorId( + r'(III)V', + ); + + static final _new$ = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + jni$_.VarArgs<(jni$_.Int32, jni$_.Int32, jni$_.Int32)>)>>( + 'globalEnv_NewObject') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, jni$_.JMethodIDPtr, int, int, int)>(); + + /// from: `public void (int i, int i1, int i2)` + /// The returned object must be released after use, by calling the [release] method. + factory Colors$RGB( + int i, + int i1, + int i2, + ) { + return Colors$RGB.fromReference(_new$( + _class.reference.pointer, _id_new$ as jni$_.JMethodIDPtr, i, i1, i2) + .reference); + } + + static final _id_equals = _class.instanceMethodId( + r'equals', + r'(Ljava/lang/Object;)Z', + ); + + static final _equals = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + jni$_.VarArgs<(jni$_.Pointer,)>)>>( + 'globalEnv_CallBooleanMethod') + .asFunction< + jni$_.JniResult Function(jni$_.Pointer, + jni$_.JMethodIDPtr, jni$_.Pointer)>(); + + /// from: `public boolean equals(java.lang.Object object)` + bool equals( + jni$_.JObject? object, + ) { + final _$object = object?.reference ?? jni$_.jNullReference; + return _equals(reference.pointer, _id_equals as jni$_.JMethodIDPtr, + _$object.pointer) + .boolean; + } + + static final _id_hashCode$1 = _class.instanceMethodId( + r'hashCode', + r'()I', + ); + + static final _hashCode$1 = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>>('globalEnv_CallIntMethod') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>(); + + /// from: `public int hashCode()` + int hashCode$1() { + return _hashCode$1(reference.pointer, _id_hashCode$1 as jni$_.JMethodIDPtr) + .integer; + } +} + +final class $Colors$RGB$NullableType extends jni$_.JObjType { + @jni$_.internal + const $Colors$RGB$NullableType(); + + @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) => reference.isNull + ? null + : Colors$RGB.fromReference( + reference, + ); + @jni$_.internal + @core$_.override + jni$_.JObjType get superType => const jni$_.JObjectNullableType(); + + @jni$_.internal + @core$_.override + jni$_.JObjType get nullableType => this; + + @jni$_.internal + @core$_.override + final superCount = 1; + + @core$_.override + int get hashCode => ($Colors$RGB$NullableType).hashCode; + + @core$_.override + bool operator ==(Object other) { + return other.runtimeType == ($Colors$RGB$NullableType) && + other is $Colors$RGB$NullableType; + } +} + +final class $Colors$RGB$Type extends jni$_.JObjType { + @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$_.JObjType get superType => const jni$_.JObjectNullableType(); + + @jni$_.internal + @core$_.override + jni$_.JObjType get nullableType => + const $Colors$RGB$NullableType(); + + @jni$_.internal + @core$_.override + final superCount = 1; + + @core$_.override + int get hashCode => ($Colors$RGB$Type).hashCode; + + @core$_.override + 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$_.JObjType $type; + + @jni$_.internal + Colors.fromReference( + jni$_.JReference reference, + ) : $type = type, + super.fromReference(reference); + + static final _class = + jni$_.JClass.forName(r'com/github/dart_lang/jnigen/enums/Colors'); + + /// The type which includes information such as the signature of this class. + static const nullableType = $Colors$NullableType(); + static const type = $Colors$Type(); + static final _id_red = _class.staticFieldId( + r'red', + r'Lcom/github/dart_lang/jnigen/enums/Colors;', + ); + + /// from: `static public final com.github.dart_lang.jnigen.enums.Colors red` + /// The returned object must be released after use, by calling the [release] method. + static Colors get red => _id_red.get(_class, const $Colors$Type()); + + static final _id_green = _class.staticFieldId( + r'green', + r'Lcom/github/dart_lang/jnigen/enums/Colors;', + ); + + /// from: `static public final com.github.dart_lang.jnigen.enums.Colors green` + /// The returned object must be released after use, by calling the [release] method. + static Colors get green => _id_green.get(_class, const $Colors$Type()); + + static final _id_blue = _class.staticFieldId( + r'blue', + r'Lcom/github/dart_lang/jnigen/enums/Colors;', + ); + + /// from: `static public final com.github.dart_lang.jnigen.enums.Colors blue` + /// The returned object must be released after use, by calling the [release] method. + static Colors get blue => _id_blue.get(_class, const $Colors$Type()); + + static final _id_code = _class.instanceFieldId( + r'code', + r'I', + ); + + /// from: `public final int code` + int get code => _id_code.get(this, const jni$_.jintType()); + + static final _id_values = _class.staticMethodId( + r'values', + r'()[Lcom/github/dart_lang/jnigen/enums/Colors;', + ); + + static final _values = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>>('globalEnv_CallStaticObjectMethod') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>(); + + /// from: `static public com.github.dart_lang.jnigen.enums.Colors[] values()` + /// The returned object must be released after use, by calling the [release] method. + static jni$_.JArray? values() { + return _values(_class.reference.pointer, _id_values as jni$_.JMethodIDPtr) + .object?>( + const jni$_.JArrayNullableType($Colors$NullableType())); + } + + static final _id_valueOf = _class.staticMethodId( + r'valueOf', + r'(Ljava/lang/String;)Lcom/github/dart_lang/jnigen/enums/Colors;', + ); + + static final _valueOf = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + jni$_.VarArgs<(jni$_.Pointer,)>)>>( + 'globalEnv_CallStaticObjectMethod') + .asFunction< + jni$_.JniResult Function(jni$_.Pointer, + jni$_.JMethodIDPtr, jni$_.Pointer)>(); + + /// from: `static public com.github.dart_lang.jnigen.enums.Colors valueOf(java.lang.String string)` + /// The returned object must be released after use, by calling the [release] method. + static Colors? valueOf( + jni$_.JString? string, + ) { + final _$string = string?.reference ?? jni$_.jNullReference; + return _valueOf(_class.reference.pointer, _id_valueOf as jni$_.JMethodIDPtr, + _$string.pointer) + .object(const $Colors$NullableType()); + } + + static final _id_toRGB = _class.instanceMethodId( + r'toRGB', + r'()Lcom/github/dart_lang/jnigen/enums/Colors$RGB;', + ); + + static final _toRGB = jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>>('globalEnv_CallObjectMethod') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + )>(); + + /// from: `public com.github.dart_lang.jnigen.enums.Colors$RGB toRGB()` + /// The returned object must be released after use, by calling the [release] method. + Colors$RGB? toRGB() { + return _toRGB(reference.pointer, _id_toRGB as jni$_.JMethodIDPtr) + .object(const $Colors$RGB$NullableType()); + } +} + +final class $Colors$NullableType extends jni$_.JObjType { + @jni$_.internal + const $Colors$NullableType(); + + @jni$_.internal + @core$_.override + String get signature => r'Lcom/github/dart_lang/jnigen/enums/Colors;'; + + @jni$_.internal + @core$_.override + Colors? fromReference(jni$_.JReference reference) => reference.isNull + ? null + : Colors.fromReference( + reference, + ); + @jni$_.internal + @core$_.override + jni$_.JObjType get superType => const jni$_.JObjectNullableType(); + + @jni$_.internal + @core$_.override + jni$_.JObjType get nullableType => this; + + @jni$_.internal + @core$_.override + final superCount = 1; + + @core$_.override + int get hashCode => ($Colors$NullableType).hashCode; + + @core$_.override + bool operator ==(Object other) { + return other.runtimeType == ($Colors$NullableType) && + other is $Colors$NullableType; + } +} + +final class $Colors$Type extends jni$_.JObjType { + @jni$_.internal + const $Colors$Type(); + + @jni$_.internal + @core$_.override + String get signature => r'Lcom/github/dart_lang/jnigen/enums/Colors;'; + + @jni$_.internal + @core$_.override + Colors fromReference(jni$_.JReference reference) => Colors.fromReference( + reference, + ); + @jni$_.internal + @core$_.override + jni$_.JObjType get superType => const jni$_.JObjectNullableType(); + + @jni$_.internal + @core$_.override + jni$_.JObjType get nullableType => const $Colors$NullableType(); + + @jni$_.internal + @core$_.override + final superCount = 1; + + @core$_.override + int get hashCode => ($Colors$Type).hashCode; + + @core$_.override + bool operator ==(Object other) { + return other.runtimeType == ($Colors$Type) && other is $Colors$Type; + } +} + /// from: `com.github.dart_lang.jnigen.generics.GenericTypeParams` class GenericTypeParams<$S extends jni$_.JObject?, $K extends jni$_.JObject?> extends jni$_.JObject { @@ -10903,8 +11108,8 @@ class JsonSerializable$Case extends jni$_.JObject { /// from: `static public final com.github.dart_lang.jnigen.annotations.JsonSerializable$Case SNAKE_CASE` /// The returned object must be released after use, by calling the [release] method. - static JsonSerializable$Case? get SNAKE_CASE => - _id_SNAKE_CASE.get(_class, const $JsonSerializable$Case$NullableType()); + static JsonSerializable$Case get SNAKE_CASE => + _id_SNAKE_CASE.get(_class, const $JsonSerializable$Case$Type()); static final _id_KEBAB_CASE = _class.staticFieldId( r'KEBAB_CASE', @@ -10913,8 +11118,8 @@ class JsonSerializable$Case extends jni$_.JObject { /// from: `static public final com.github.dart_lang.jnigen.annotations.JsonSerializable$Case KEBAB_CASE` /// The returned object must be released after use, by calling the [release] method. - static JsonSerializable$Case? get KEBAB_CASE => - _id_KEBAB_CASE.get(_class, const $JsonSerializable$Case$NullableType()); + static JsonSerializable$Case get KEBAB_CASE => + _id_KEBAB_CASE.get(_class, const $JsonSerializable$Case$Type()); static final _id_CAMEL_CASE = _class.staticFieldId( r'CAMEL_CASE', @@ -10923,8 +11128,8 @@ class JsonSerializable$Case extends jni$_.JObject { /// from: `static public final com.github.dart_lang.jnigen.annotations.JsonSerializable$Case CAMEL_CASE` /// The returned object must be released after use, by calling the [release] method. - static JsonSerializable$Case? get CAMEL_CASE => - _id_CAMEL_CASE.get(_class, const $JsonSerializable$Case$NullableType()); + static JsonSerializable$Case get CAMEL_CASE => + _id_CAMEL_CASE.get(_class, const $JsonSerializable$Case$Type()); static final _id_values = _class.staticMethodId( r'values', diff --git a/pkgs/jnigen/test/simple_package_test/generate.dart b/pkgs/jnigen/test/simple_package_test/generate.dart index 96b692adc..e526afe82 100644 --- a/pkgs/jnigen/test/simple_package_test/generate.dart +++ b/pkgs/jnigen/test/simple_package_test/generate.dart @@ -28,12 +28,12 @@ final javaFiles = [ join(javaPrefix, 'annotations', 'MyDataClass.java'), join(javaPrefix, 'annotations', 'NotNull.java'), join(javaPrefix, 'annotations', 'Nullable.java'), - join(javaPrefix, 'simple_package', 'Color.java'), join(javaPrefix, 'simple_package', 'Example.java'), join(javaPrefix, 'simple_package', 'Exceptions.java'), join(javaPrefix, 'simple_package', 'Fields.java'), join(javaPrefix, 'pkg2', 'C2.java'), join(javaPrefix, 'pkg2', 'Example.java'), + join(javaPrefix, 'enums', 'Colors.java'), join(javaPrefix, 'generics', 'MyStack.java'), join(javaPrefix, 'generics', 'MyMap.java'), join(javaPrefix, 'generics', 'GenericTypeParams.java'), @@ -75,6 +75,7 @@ Config getConfig() { classes: [ 'com.github.dart_lang.jnigen.simple_package', 'com.github.dart_lang.jnigen.pkg2', + 'com.github.dart_lang.jnigen.enums', 'com.github.dart_lang.jnigen.generics', 'com.github.dart_lang.jnigen.interfaces', 'com.github.dart_lang.jnigen.inheritance', diff --git a/pkgs/jnigen/test/simple_package_test/java/com/github/dart_lang/jnigen/enums/Colors.java b/pkgs/jnigen/test/simple_package_test/java/com/github/dart_lang/jnigen/enums/Colors.java new file mode 100644 index 000000000..74e137f6a --- /dev/null +++ b/pkgs/jnigen/test/simple_package_test/java/com/github/dart_lang/jnigen/enums/Colors.java @@ -0,0 +1,48 @@ +// 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. + +package com.github.dart_lang.jnigen.enums; + +import java.util.Objects; + +public enum Colors { + red(0xFF0000), + green(0x00FF00), + blue(0x0000FF); + + public final int code; + + Colors(int code) { + this.code = code; + } + + public static class RGB { + public int red; + public int green; + public int blue; + + public RGB(int red, int green, int blue) { + this.red = red; + this.green = green; + this.blue = blue; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + RGB rgb = (RGB) o; + return red == rgb.red && green == rgb.green && blue == rgb.blue; + } + + @Override + public int hashCode() { + return Objects.hash(red, green, blue); + } + } + + public RGB toRGB() { + return new RGB(code >> 16, (code >> 8) & 0xFF, code & 0xFF); + } +} diff --git a/pkgs/jnigen/test/simple_package_test/java/com/github/dart_lang/jnigen/simple_package/Color.java b/pkgs/jnigen/test/simple_package_test/java/com/github/dart_lang/jnigen/simple_package/Color.java deleted file mode 100644 index efb96c6e4..000000000 --- a/pkgs/jnigen/test/simple_package_test/java/com/github/dart_lang/jnigen/simple_package/Color.java +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) 2023, 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. - -package com.github.dart_lang.jnigen.simple_package; - -public enum Color { - RED, - BLUE, - BLACK, - GREEN, - YELLOW, - LIME -} diff --git a/pkgs/jnigen/test/simple_package_test/runtime_test_registrant.dart b/pkgs/jnigen/test/simple_package_test/runtime_test_registrant.dart index 3f16f33c7..8f8e94752 100644 --- a/pkgs/jnigen/test/simple_package_test/runtime_test_registrant.dart +++ b/pkgs/jnigen/test/simple_package_test/runtime_test_registrant.dart @@ -1288,6 +1288,25 @@ void registerTests(String groupName, TestRunnerCallback test) { }); }); + group('Enums', () { + test('Color', () { + using((arena) { + final red = Colors.red..releasedBy(arena); + final green = Colors.green..releasedBy(arena); + final blue = Colors.blue..releasedBy(arena); + expect(red.code, 0xFF0000); + expect(green.code, 0x00FF00); + expect(blue.code, 0x0000FF); + expect(red.toRGB()!..releasedBy(arena), + Colors$RGB(255, 0, 0)..releasedBy(arena)); + expect(green.toRGB()!..releasedBy(arena), + Colors$RGB(0, 255, 0)..releasedBy(arena)); + expect(blue.toRGB()!..releasedBy(arena), + Colors$RGB(0, 0, 255)..releasedBy(arena)); + }); + }); + }); + group('$groupName (load tests)', () { const k4 = 4 * 1024; // This is a round number, unlike say 4000 const k256 = 256 * 1024; diff --git a/pkgs/jnigen/test/summary_test.dart b/pkgs/jnigen/test/summary_test.dart index 6987af425..283506a37 100644 --- a/pkgs/jnigen/test/summary_test.dart +++ b/pkgs/jnigen/test/summary_test.dart @@ -64,6 +64,7 @@ void registerCommonTests(Classes classes) { expect(example.getMethod('getNumber').modifiers, isPublic); expect(example.getMethod('privateMethod').modifiers, isPrivate); expect(example.getMethod('protectedMethod').modifiers, isProtected); + print(example.fields.map((f) => f.name).toList()); expect(example.getField('OFF').modifiers, isPublic); expect(example.getField('number').modifiers, isPrivate); expect(example.getField('protectedField').modifiers, isProtected); @@ -226,22 +227,15 @@ void registerCommonTests(Classes classes) { expect(example.declKind, DeclKind.classKind); final myInterface = classes.getClass('interfaces', 'MyInterface'); expect(myInterface.declKind, DeclKind.interfaceKind); - final color = classes.getClass('simple_package', 'Color'); + final color = classes.getClass('enums', 'Colors'); expect(color.declKind, DeclKind.enumKind); }); test('Enum values', () { final example = classes.getExampleClass(); expect(example.values, anyOf(isNull, isEmpty)); - final color = classes.getClass('simple_package', 'Color'); - const expectedEnumValues = { - 'RED', - 'BLUE', - 'BLACK', - 'GREEN', - 'YELLOW', - 'LIME' - }; + final color = classes.getClass('enums', 'Colors'); + const expectedEnumValues = {'red', 'green', 'blue'}; expect(color.values?.toSet(), expectedEnumValues); });