Commit Graph

1128 Commits

Author SHA1 Message Date
Zac Sweers
c8c7121e76 Unwrap nested typealiases in code gen (#996)
* Add further nested typealias

* Recursively unwrap classnames

The unwrapped alias could be to something other than a classname!
2019-11-02 09:43:08 -04:00
Zac Sweers
6323a0b7c8 Don't allow toJson() serialization on polymorphic default values
This type explicitly indicates an unknown value. This is an explosive case, but an alternative could be to just write null into the writer?
2019-10-31 15:13:22 -04:00
Zac Sweers
541b53964c Add abstract function note to 1.9.1 changelog 2019-10-30 23:34:36 -04:00
Jesse Wilson
878e9a86d6 [maven-release-plugin] prepare for next development iteration 2019-10-30 23:26:50 -04:00
Jesse Wilson
0af27a39a6 [maven-release-plugin] prepare release moshi-parent-1.9.1 2019-10-30 23:26:43 -04:00
Jesse Wilson
6ec87f0fc1 Update changelog for 1.9.1. 2019-10-30 23:23:29 -04:00
Zac Sweers
092175ae90 Fix handling of typealiases in non-classname envs + wildcard fix… (#987)
* Correctly render non-classname wildcard types

Resolves #984
Resolves #985

* Add thorough typealias test

* Expand unwrapTypeAlias to parameterized and wildcard types

Resolves #983

* Disable Werror for now
2019-10-30 21:15:28 -04:00
Jesse Wilson
ac789070e8 Merge pull request #988 from square/z/regressionForAbstract
Add an abstract non-unit function regression for #974
2019-10-30 21:11:05 -04:00
Zac Sweers
9a0294c3a0 Handle non-property parameters in kotlin code gen (#982)
* Add parameter-only param in multi-masks test

* Add type to target parameters for later reference

* Ensure parameters are ordered

* Reword AdapterGenerator fromJson logic to use sealed FromJsonComponent

This allows us to handle parameter-only types separately (needed for mask index calculation). Resolves #979

* Add more tests
2019-10-30 21:06:04 -04:00
Zac Sweers
510d189e4e Add an abstract non-unit function regression for #974
Resolves #974 for good
2019-10-30 20:24:22 -04:00
Zac Sweers
a384bd0429 KotlinPoet 1.4.3 (#986)
KotlinPoet 1.4.3
2019-10-30 19:36:57 -04:00
Egor Andreevici
13c5ac5e26 KotlinPoet 1.4.3 2019-10-30 18:59:09 -04:00
Zac Sweers
0aacfc7430 Support 32+ parameter constructors in code gen (#978)
* Add MultipleMasksTest test

* Use multiple masks for constructors with more than 32 parameters

Resolves #977

* Add non-default arg to test

* Emit hex literals

* Simpler int math

* Don't allocate a mask if there's no properties
2019-10-30 16:48:00 -04:00
Zac Sweers
4f1c8a5eda Fix support for classes w/ multiple constructors in code gen (#976)
* Fix broken test

This test suite doesn't run on CI builds but fails locally since the method was moved

* Add multiple constructors test case

* Implement TypeName.asTypeBlock()

* Make DEFAULT_CONSTRUCTOR_MARKER public

* Look up constructor via getDeclaredConstructor with exact param types

Resolves #975

* Remove dead code
2019-10-30 00:39:08 -04:00
Jesse Wilson
6acebfaca6 More documentation on configuring Kotlin 2019-10-29 08:18:09 -04:00
Jesse Wilson
55441313cc Update changelog for 1.9.0. 2019-10-29 08:12:37 -04:00
Jesse Wilson
4637950bab [maven-release-plugin] prepare for next development iteration 2019-10-29 07:57:56 -04:00
Jesse Wilson
0c8005bcee [maven-release-plugin] prepare release moshi-parent-1.9.0 2019-10-29 07:57:49 -04:00
Zac Sweers
d5a43e35f3 Update to KotlinPoet 1.4.2 (#972)
* Unwrap typealiases

This was a change in 1.4.2 left over from moshi's prior metadata logic. We need the unwrapped type for class references

* Add toe-hold for testing shared adapter behavior

* Add regression test for abstractSuperProperties

* Kotlinpoet 1.4.2
2019-10-29 07:51:17 -04:00
Jesse Wilson
73bc12735e Merge pull request #970 from square/jwilson.1027.remove_new_k_apis
Don't add new public APIs for Kotlin type inference
2019-10-28 20:19:11 -04:00
Jesse Wilson
c72b856b05 Don't add new public APIs for Kotlin type inference
We can do a better job of this when we make the core Moshi module
depend on the Kotlin stdlib
2019-10-27 21:14:00 -04:00
Jesse Wilson
ed20823c2f Merge pull request #791 from square/eric.2019-01-15.multiple-transient-constructor-parameters
Support multiple transient properties in KotlinJsonAdapter.
2019-10-27 16:17:03 -04:00
Eric Cochran
efb0fc0923 Support multiple transient properties in KotlinJsonAdapter. 2019-10-27 14:11:33 -04:00
Jesse Wilson
5912dfaaf6 Merge pull request #966 from square/jwilson.1026.onlyonce
Look up kotlin.Metadata::class only once
2019-10-27 00:04:49 -04:00
Jesse Wilson
53b045eb86 Look up kotlin.Metadata::class only once 2019-10-26 23:59:27 -04:00
Jesse Wilson
c3cb07989e Merge pull request #965 from square/jwilson.1026.specify_ordering
Specify precedence when a subtype has multiple labels
2019-10-26 23:11:38 -04:00
Jesse Wilson
02cf66f129 Specify precedence when a subtype has multiple labels 2019-10-26 22:57:00 -04:00
Jesse Wilson
537b22f1c3 Merge pull request #964 from square/jwilson.1026.warn_dont_fail
Go back to using Unsafe APIs to create instances without constructors.
2019-10-26 22:08:49 -04:00
Jesse Wilson
eea2981fac Go back to using Unsafe APIs to create instances without constructors.
The attempted fix replaced a warning with a crash. I believe that a
warning is a better developer experience than a crash.

This reverts commit c0639316b1.
2019-10-26 22:02:49 -04:00
Zac Sweers
2a79428891 Merge pull request #963 from jzbrooks/kotlin-enum-values
Keep synthesized values() for EnumJsonAdapter
2019-10-26 15:05:17 -04:00
Zac Sweers
01b7ea4ba2 Update to KotlinPoet 1.4.1/Kotlin 1.3.50 (#956)
* KotlinPoet 1.4.1 & Kotlin 1.3.50

KotlinPoet uses 1.3.50, so this just matches that now

* Remove now-unnecessary custom shade

This uses the same common package prefix in kotlinpoet now

* Add backwardReferencingTypeVars() regression test

Coverage for #955
2019-10-26 15:04:51 -04:00
Justin Brooks
8460155dc5 Keep synthesized values() for EnumJsonAdapter 2019-10-26 12:20:11 -05:00
Zac Sweers
870fee4332 Generate optimized toString() (#957)
* Generate optimized toString()

This optimizes `toString()` functions to emit separate strings for the enclosing prefix and the adapter name

Example:

```kotlin
override fun toString(): String = buildString {
    append("GeneratedJsonAdapter(").append("SmokeTestType").append(")") }
```

* Optimize with capacity and char
2019-10-19 16:11:51 -04:00
Jesse Wilson
2cf3f0204c Merge pull request #943 from square/jakew/value-sink/2019-09-27
Add JsonWriter.valueSink for streaming data
2019-10-17 23:45:38 -04:00
Burkhard Mittelbach
b4e6715248 Added codegen support for inline classes (#923)
* Added codegen support for inline classes

* moved to DualKotlinTest

* added test class consuming inline class
2019-10-16 18:17:23 -04:00
Zac Sweers
ae8b62b3ee Fix TypeVariable/WildcardType recursion causing stackoverflows (#948)
* Port Gson Types recursion fix for subtypeOf/supertypeOf

From a300148003

First step in resolving #338

* Port Gson Type resolve() recursion fix for type variables

From https://github.com/google/gson/pull/1128

Resolves #338

* Capture adapter to make checkstyle happy

* Move RecursiveTypesResolveTest out of internal package

* Use moshi convention for tests

* 2 is not 1
2019-10-15 18:01:48 -04:00
Jake Wharton
3816dbda74 Add JsonWriter.valueSink for streaming data
Unlike `value(BufferedSource)`, this retains the push-based nature of JsonWriter and allows layering other sinks (such as a base64-encoding Sink for binary data). Since `value(BufferedSource)` is trivially replaced by reading the source into the value sink, it is deprecated.
2019-10-10 10:18:06 -04:00
Zac Sweers
dbed99d71b Fix @field:Json parameters annotations always taking precedence (#946)
* Add regression test for field json annotations

* Make json name null if absent rather than default to name

This fixes incorrect behavior where the parameter json name would always win out over the property value
2019-10-05 21:26:43 -04:00
Zac Sweers
9dc331f20c Update kotlin-compile-testing to 1.2.3
https://github.com/tschuchortdev/kotlin-compile-testing/releases/tag/1.2.3

* Check file extensions automatically when creating `SourceFile`s with the new factory functions
* Less noisy output/verbose flag actually works as intended
2019-10-05 20:29:03 -04:00
Burkhard Mittelbach
666d87be65 added test for internal property without backing field (#921) (#947) 2019-10-05 16:51:48 -04:00
Burkhard Mittelbach
f51de08caf added test for transient delegate in kotlin code gen (#922) (#942)
* added test for transient delegate in kotlin code gen (#922)

* cleanup spaces

Co-Authored-By: Zac Sweers <pandanomic@gmail.com>
2019-10-05 16:50:34 -04:00
Zac Sweers
7804d74318 Report json name if different from property name in kotlin (#917)
* Report json name in code gen if different from property name

Resolves #800

* Unify required property name error message

* Report json name in kotlinjsonadapter, match code gen

* Upper case JSON

Co-Authored-By: Jake Wharton <jakew@google.com>

* Upper case JSON

Co-Authored-By: Jake Wharton <jakew@google.com>

* Don't keep constants

* Inline json name - property name comparison to util methods

* Remove unnecessary constructor keyword

* Consolidate non-null/missing property tests to parameterized suite

* Add custom json name tests for nonNull property checks

* Rename test to make maven happy

Maven won't run the test unless it ends with `Test` or `TestCase`
2019-09-30 23:04:21 -04:00
Zac Sweers
336ca952b0 Use char literals for array and object start/end (#944)
Use char literals for array and object start/end
2019-09-30 15:27:38 -04:00
Jake Wharton
ecb7083abf Use char literals for array and object start/end 2019-09-30 14:40:12 -04:00
Jesse Wilson
52aaf9cc84 Merge pull request #933 from square/z/throwOnMissingTypeVars
Throw on missing type variables in Types.newParameterizedType* methods
2019-09-26 21:57:23 -04:00
Jesse Wilson
20aa604489 Merge pull request #940 from square/jakew/skip-name-message/2019-09-26
Point at the offending name when failing on unknown
2019-09-26 21:56:49 -04:00
Jake Wharton
12d37ffdc3 Point at the offending name when failing on unknown 2019-09-26 20:37:34 -04:00
Zac Sweers
86736461c6 Fix misspelled codgen package in tests (#937)
* Fix misspelled codgen package in tests

This has always bothered me

* Remove leftover import

* Fix import one more time

* Imports are the worst
2019-09-25 23:48:31 -04:00
Zac Sweers
902a935f89 Shade kotlinpoet-metadata and kotlinx-metadata (#936)
* Shade kotlinpoet-metadata and kotlinx-metadata

* Relocate KotlinPoet's shaded autocommon dep too
2019-09-25 23:15:06 -04:00
Zac Sweers
54d07b6cbf Migrate to KotlinPoet-metadata (#903)
* Add kotlinpoet version to properties

* Swap in kotlinpoet-metadata for kotlin-metadata in dependencies

* Don't use KotlinMetadataUtils and KotlinAbstractProcessor anymore

* Upcast to TypeElement

* Temporarily add direct kotlinx-metadata dependency

Something is wrong with packaging in my local kotlinpoet, will remove before

* Remove tags API from TargetParameter

No longer needed

* Add PropertySpec directly to TargetProperty, remove holder funs

Simplifies some things!

* Move generated annotation gen into type callback

Removes JsonClassCodegenProcessor completely from codegen API

* Remove unstable autocommon dependency

Won't be using this anymore after this change

* Manually put quotes jsonName in AdapterGenerator

Otherwise we could incur double escaping from kotlinpoet since we directly reuse possible-escaped parsed `@Json` name values

* Opt in to use `@UseExperimental` annotation for preview

* Rework and simplify metadata to just use kotlinpoet-metadata

This is hard to do in broken down 1:1 steps, but the net result is a much smaller implementation footprint, better error messages, and a simpler API interaction with the code gen API. There is some raw parsing of kotlinpoet types required (mostly around annotations), but otherwise it's pretty smooth sailing and a good test of the upcoming kotlinpoet-metadata support

* Declare KotlinPoetMetadataPreview directly

* Try to point to snapshots for CI build

* Update to classinspector API

* Remove TypeResolver API

No longer needed

* Kotlinpoet 1.4.0 final

* Fix missing import from rebase

* Remove old kotlin-metadata version
2019-09-25 22:22:44 -04:00