Commit Graph

863 Commits

Author SHA1 Message Date
Zac Sweers
329d0e14b0 Invoke defaults constructor in kotlin code gen (#896)
* Add Util#invokeDefaultConstructor

* Add defaultPrimitiveValue

This will be used to initialize required properties for later invocation of the default constructor

* Move isTransient into PropertyGenerator

We will need this in order to know how to invoke constructors even if they have transient parameters

* Add notion of hasLocalIsPresentName to PropertyGenerator

* Switch to using invokeDefaultConstructor for any default property types

* Add code gen versions of default constructor test

* Fix mismatched names

* Use Arrays.copyOf

* Unwrap InvocationTargetException

* Use name allocator

* Rename createMask to createDefaultValuesParametersMask, use it directly

* Opportunistically clean up result variable holder

Only needs to be made if we have non-parameter instances, otherwise we can just return directly

* Fix mask name

* Remove unnecessary mod

* Switch to local lazily-initialized constructor reference

Not working because of some issue in kotlinpoet I don't understand

* Fix named usage

* Clean up debugging dots

* Add proguard/R8 rule for keeping defaults constructor in targets

* Make constructor lookup property private

* Add another defensive dot

* Rework invokeDefaultConstructor to accept vararg args

A little more idiomatic

* Update proguard rules
2019-09-08 17:24:25 -04:00
Zac Sweers
711de52ae1 Clean up warnings in KotlinJsonAdapter (#899)
* Use isNotEmpty()

* Use Metadata import directly

* Tighten visibility of IndexedParameterMap

* Use idiomatic require() checks

Didn't use it on a couple other places where readability would suffer

* Remove unnecessary type arg

* Remove unnecessary curly braces

* Use mutable list rather than allocate new lists

IntelliJ thinks this is a better approach

* Tighten KotlinJsonAdapter property visibility

* Suppress existing extraneous warnings
2019-09-04 21:39:35 -04:00
Jake Wharton
7f720c03c9 Merge pull request #898 from ZacSweers/z/excludeMore
Don't reflect on kotlinx and update doc
2019-09-04 21:12:58 -04:00
Zac Sweers
319d7c8bd5 Don't reflect on kotlinx and update doc
This adds kotlinx to the exclusion list, and also updates the doc on ClassJsonAdapter
2019-09-04 20:58:56 -04:00
Zac Sweers
9db91f2dce Kotlin-reflect QoL APIs (#875)
* Start MoshiKotlinExtensions

* Add Moshi.Builder.add() with reified typeOf

* Use non-shadowing name for addAdapter

* Implement KType.toType()

.javaType isn't implemented

* Don't re-wrap wrapped adapters

* Use new adapter functions in tests to smoke test

* Don't enable uses experimental in kotlin-reflect, only the test

* Use internal leniency API

* Use toType in addAdapter too

* Update error message in test
2019-09-04 20:24:59 -04:00
Jake Wharton
73cc9656ba Merge pull request #876 from ZacSweers/z/rawTypeMessage
Pass raw type rather than possibly-generic type in platform type error
2019-09-04 14:16:56 -04:00
Zac Sweers
6ffb94647b Switch to openjdk8 for travis builds (#885)
* Switch to openjdk8 for travis builds

oraclejdk8 isn't available unless we ust trusty dist, which is also an option

* Update deploy_shapshot.sh
2019-08-07 22:56:03 -04:00
Zac Sweers
25fcbb2637 Improve message and match in tests 2019-07-08 12:40:55 -04:00
Zac Sweers
aea8675252 Pass raw type rather than possibly-generic type in platform type error
We only check the raw type here, so the message should match
2019-07-02 18:22:39 -04:00
Nuno Gomes
687acba760 removed limitation where subtypes should be unique (#856)
* removed limitation where subtypes should be unique

There can be use cases where different type labels should match with the same subtype

* added test for PolymorphicJsonAdapter non unique subtypes
2019-06-20 10:39:19 -05:00
Jesse Wilson
54c44c5570 Merge pull request #871 from ZacSweers/z/kotlin1340
Update to Kotlin 1.3.40
2019-06-19 21:47:41 -04:00
Zac Sweers
6a1a15b974 Update to Kotlin 1.3.40 2019-06-19 20:06:50 -05:00
Jesse Wilson
10ac30b0ed Merge pull request #868 from sullis/maven-compiler-plugin-3.8.1
maven-compiler-plugin 3.8.1
2019-06-19 06:38:45 -04:00
Sean Sullivan
0142e2aaf0 maven-compiler-plugin 3.8.1 2019-06-18 17:00:31 -04:00
Jesse Wilson
f1965f0f46 Merge pull request #821 from Syeberman/sye/covariant-map-values
Support covariant Map values, which are used by Kotlin
2019-06-06 10:49:51 -04:00
Sye van der Veen
7e417840e2 Support covariant Map values, which are used by Kotlin 2019-05-28 10:51:55 -04:00
Zac Sweers
0943ef5a61 Allow custom generators (#847)
* Extract generatedJsonAdapterName to public API for other generators/consumers

* Fix kapt location in tests

* Add IDE-generated dependency-reduced-pom.xml to gitignore

This always bites me

* Add generator property to JsonClass and skip in processor

* Opportunistically fix formatting for generateAdapter doc

* Extract NullSafeJsonAdapter for delegate testing

* Add custom adapter tests

* Allow no-moshi constructors for generated adapters

* Fix rebase issue

* Use something other than nullSafe() for lenient check

This no longer propagates lenient

* Add missing copyrights

* Add top-level class note

* Add note about working against Moshi's generated signature

* Add missing bit to "requirements for"

* Note kotlin requirement relaxed in custom generators

* Style
2019-05-15 20:42:08 -04:00
Zac Sweers
a5020ddb3c Support gradle incremental processing in code gen (#824)
* Support gradle incremental processing in code gen

This adds support for incremental compilation in gradle via incap helper and marking the code gen as `ISOLATING`.

Depends on a newer version of KotlinPoet that has https://github.com/square/kotlinpoet/pull/647

Resolves #589

* Opportunistically update to auto-service 1.0-rc5

Supports incremental compilation and moves annotations to a separate artifact

* 1.2.0 final!

* Mark compiler embeddales as test only
2019-04-17 18:12:11 -07:00
Jesse Wilson
11a547023c Merge pull request #834 from square/jakew/dont-wrap/2019-04-10
Don't wrap between throw and exception type
2019-04-10 08:38:38 -07:00
Jake Wharton
bcb6fd4a4d Don't wrap between throw and exception type 2019-04-10 10:28:30 -04:00
Oliver Bestmann
3994723c3c Use StringBuilder to deduplicate String constants 2019-04-02 11:49:40 -04:00
Zac Sweers
30c973e494 Merge pull request #825 from square/z/kotlin13
Update to Kotlin 1.3.21
2019-03-25 20:00:40 -07:00
Zac Sweers
1c3dc89da1 Update to Kotlin 1.3.21
Resolves #777
2019-03-25 19:44:03 -07:00
Eric Cochran
3e848c0cdd Use KotlinPoet's MemberName for emptySet import. (#818)
* Update to KotlinPoet 1.1.0.

* Use KotlinPoet's MemberName for emptySet import.
2019-03-14 02:57:08 -07:00
Eric Cochran
be6f3eb2af Unconditionally close the peeked JsonReader. (#810)
It doesn't have an effect now, but this is for the future when closing the peeked source also clears buffers.
2019-02-17 17:00:29 -08:00
Eric Cochran
a83a9b79e4 Use peekJson in the DefaultOnDataMismatchAdapter example. (#809) 2019-02-15 17:09:50 -08:00
Eric Cochran
d843950731 Make checkstyle happy on JsonReader column width. (#811) 2019-02-15 17:08:46 -08:00
Eric Cochran
13a40edf5b Correct error for duplicate JSON key for Kotlin. (#789)
Before, the KotlinJsonAdapter threw "java.lang.IndexOutOfBoundsException: Index: 0, Size: 0" on a duplicate key when the key matched a property that was not a constructor parameter.
2019-02-15 11:18:50 -08:00
Eric Cochran
126c8ea961 Support fail on unknown in PolymorphicJsonAdapterFactory. (#792)
Before, this would fail when skipping to find the index of the label.
Note that this still requires the type to have a label field.
2019-02-15 11:16:12 -08:00
Thomas Vos
f68035859e Fix typo in documentation for JsonReader.peekJson() (#797) 2019-02-15 11:15:38 -08:00
Eric Cochran
e04c80c1c6 Remove old TODO after KotlinPoet fix. (#790) 2019-02-15 11:15:02 -08:00
Jake Wharton
b8610c7fc7 Merge pull request #805 from Egorand/egorand/190209/broken-travis-config
Remove broken Travis config block
2019-02-09 20:18:26 -05:00
Egor Andreevici
136df54467 Remove broken Travis config block 2019-02-09 20:05:32 -05:00
Zac Sweers
ded3bccc60 Some miscellaneous kotlinpoet updates (#786)
* KotlinPoet 1.0.1

* Nix asNullableIf in favor of plain copy() function use

* Add a test for packages that look like classes

Resolves #783
2019-01-13 10:18:00 -05:00
Jesse Wilson
3588c98b86 Merge pull request #778 from square/z/defaultValue
Add support for default values in PolymorphicJsonAdapterFactory
2018-12-31 22:04:07 -05:00
Zac Sweers
fead71bca0 Add support for default values in PolymorphicJsonAdapterFactory
Picking from #741
Resolves #739
2018-12-31 16:21:57 -08:00
Zac Sweers
5153295988 Merge pull request #771 from square/z/removeRelocation
Remove shading of KotlinPoet
2018-12-11 19:35:47 -08:00
Zac Sweers
e6de367369 Remove shading of KotlinPoet
Resolves #770
2018-12-11 16:19:29 -08:00
Jesse Wilson
9f6197b67c Merge pull request #769 from Egorand/egorand/181210/kotlinpoet-1.0.0
KotlinPoet 1.0.0
2018-12-11 11:05:12 -05:00
Egor Andreevici
6393692926 KotlinPoet 1.0.0 2018-12-10 19:59:37 -05:00
Erik Huizinga
85e86f1fa8 Add section about null safety (#757)
* Add section about null safety

Null safety is an important feature of the Kotlin language.
The fact that Moshi supports wrapping existing adapters in a null safe or non-null variant is important for null safety.
Therefore it makes sense to promote this feature in the readme, as this is one of the first places people should look for support and such features.

* Move factory method section out of Kotlin section

* Fix syntax highlighting

* Remove isLenient() reference

* Rewrite Kotlin example as Java, reformat comments
2018-12-03 22:50:52 -05:00
Jesse Wilson
2e241bff6f Merge pull request #764 from square/jwilson.1128.kp10rc3
Upgrade to KotlinPoet 1.0-RC3
2018-11-29 07:03:27 -05:00
Jesse Wilson
ca4d8f5e34 Upgrade to KotlinPoet 1.0-RC3 2018-11-28 22:20:07 -05:00
Jesse Wilson
a2b39e29e8 Merge pull request #760 from square/eric.toJsonCoercesRuntimeTypeForMaps
Unignore ObjectAdapterTest's toJsonCoercesRuntimeTypeForMaps.
2018-11-27 21:48:38 -05:00
Eric Cochran
737f58cecb Unignore ObjectAdapterTest's toJsonCoercesRuntimeTypeForMaps 2018-11-26 17:04:40 -08:00
Artem Daugel-Dauge
9aaef1f6f8 Treat warnings as errors in moshi-kotlin tests (#730)
* Fix/supress warnings in tests

* Treat kotlinc warnings as errors in tests
2018-11-23 22:24:19 -05:00
Jesse Wilson
2265f5e9b8 Merge pull request #755 from square/z/removesudo
Remove sudo: false from travis config
2018-11-23 22:22:24 -05:00
Zac Sweers
22259af1d1 Remove sudo: false from travis config
https://blog.travis-ci.com/2018-11-19-required-linux-infrastructure-migration
2018-11-23 19:12:30 -08:00
Zac Sweers
1f2a9373b7 Merge pull request #754 from square/z/kotlinTypesFollowup
Use faster isAnnotationPresent check
2018-11-20 17:51:59 -08:00
Zac Sweers
dbe7bfa15f Use faster isAnnotationPresent check
Followup from https://github.com/square/moshi/pull/749#discussion_r235224202
2018-11-20 17:20:09 -08:00