Commit Graph

56 Commits

Author SHA1 Message Date
Zac Sweers
5f98e93698 Switch to kotlin-compile-testing for JsonClassCodegenProcessorTe… (#928)
* Add kotlin-compile-testing dependency

* Add Okio dependency to tests to match kotlin-compile-testing

Without this, Okio.sink() fails to resolve at runtime

* Try converting privateConstructor() to kotlin-compile-testing

* Space

* Update to 1.2.2

* Use new kotlin source file API

* Use temporaryFolder as workingDir

* Extract prepareCompilation helper method

This allows for modifying the compilation with extra bits as needed

* Migrate tests entirely to new API

* Remove incorrect error message

This passed before, but was picked up in https://github.com/square/moshi/pull/903 before and observed to be incorrect.

* Remove custom kotlin compiler implementations

* Add an OK exit code test

This wasn't possible before!

* Remove jitpack dependency now that it's on mavencentral

* Move versions to parent pom

* Fix new test from rebase
2019-09-25 16:41:31 -04:00
Zac Sweers
1e541fc66c Use raw type for kclass references in dynamic invocation code gen (#911)
* Use raw type for kclass references in dynamic invocation code gen

Added a compile-only regression test
Resolves #905

* Make it actually generic

* Mostly fix generation

Will need to wait for inlined instantiation to merge

* Fix rebase issues and use newInstance
2019-09-12 21:55:47 -04:00
Zac Sweers
dd0e3807d3 Fail on sealed classes in KotlinJsonAdapterFactory and code gen (#914)
Resolves #906
2019-09-12 20:38:46 -04:00
Zac Sweers
a67b4d6a72 Inline mask generation and constructor invocation (#908)
* Differentiate local naming from properties with constructor defaults

* Remove constructor invocation and mask creation methods

We're inlining all this

* Add explanatory comment for why we use the default primitive value

* Inline mask generation and constructor invocation to generated adapters

* Remove unused argument

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

* Compute masks directly during code gen

* Opportunistic: remove extraneous double space from control flow

* Just mask and invert directly
2019-09-12 16:42:31 -04:00
Zac Sweers
7a4f3513a1 Don't generate generic type information in adapter lookup (#919)
This is redundant since the property it's being assigned to already defines it, so we can omit this and save some generated code bloat
2019-09-12 16:29:53 -04:00
Zac Sweers
489b178a9b Only add constructor property if it will be used (#918)
Before - we would always add the constructor property even if the class had no default constructor parameters. Apparently -Werror doesn't flag this as a warning either, so we didn't catch it before
2019-09-12 16:07:41 -04:00
Zac Sweers
98092d0727 Update KotlinPoet to 1.3.0 (#915)
* Update to KotlinPoet 1.3.0

* Add hotwords test case

* Use %N for toJson parameter names to ensure escaping
2019-09-12 14:13:23 -04:00
Zac Sweers
c820314107 Followups from #896 (#907)
* Simplify parameterProperties and parameterProperties

* Match only on synthetic constructors

* Limit synthetic constructor keeps to kotlin classes
2019-09-11 04:55:24 -04:00
Zac Sweers
ea300997a1 Decouple code gen API from apt and kotlin-metadata (#816)
* Decouple AdapterGenerator from kotlin-metadata

* Decouple AdapterGenerator from javax elements API

* Extract checkIsVisibility helper

* Remove elements and kotlinmetadata from property, constructor, type

* Extract kotlinpoet-only parts to new API package for better separation

* Add mirroring APIs

* Finish extraction of PropertyGenerator to no-elements/no-kotlin-metadata

* Update for new tag API in KotlinPoet

* Update for new tag API in KotlinPoet

* Move rest of elements utils out of API

We should split this up better as metadata.kt has become a dumping ground

* Move type handling to JsonClassCodegenProcessor

* Rebase fix

* Opportunistic idiomatic require()
2019-09-08 21:24:10 -04:00
Zac Sweers
619be26e95 Refactor missing/null properties to helper utils instead (#900)
* Create missing property and unexpected null templates

* Fix rebase conflicts
2019-09-08 17:36:58 -04:00
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
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
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
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
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
Zac Sweers
e6de367369 Remove shading of KotlinPoet
Resolves #770
2018-12-11 16:19:29 -08:00
Egor Andreevici
6393692926 KotlinPoet 1.0.0 2018-12-10 19:59:37 -05:00
Jesse Wilson
ca4d8f5e34 Upgrade to KotlinPoet 1.0-RC3 2018-11-28 22:20:07 -05:00
Jesse Wilson
6b6c1af907 [maven-release-plugin] prepare for next development iteration 2018-11-09 10:04:52 +11:00
Jesse Wilson
eb7110bf59 [maven-release-plugin] prepare release moshi-parent-1.8.0 2018-11-09 10:04:36 +11:00
Jesse Wilson
a8102bccd2 Merge pull request #733 from daugeldauge/fix-variance-issues
Fix variance issues in kotlin-codegen
2018-11-05 07:22:40 +11:00
Artem Daugel-Dauge
8a22f6b133 Do not check required property for null second time (#732)
* Do not check required property second time

* Fix codestyle
2018-11-04 09:44:10 -08:00
Artem Daugel-Dauge
0e3a52b729 Use javaObjectType instead of Java primitives while creating parametrized type (#731)
* Add test for collection of primitives

* Use javaObjectType instead of Java primitives while creating parametrized type
2018-11-04 09:42:51 -08:00
Artem Daugel-Dauge
e0be5f5a54 Fix variance issues 2018-11-04 17:11:22 +03:00
Eric Cochran
0795e9cbd5 Update to KotlinPoet 1.0.0-RC2.
Also, use KotlinPoet's escaping for $ characters in formatted strings.
This is partly a revert of 01f600c (https://github.com/square/moshi/pull/604/).
2018-11-02 16:59:27 -07:00
Zac Sweers
a34ca365f0 Allow other processors to process JsonClass
Someone at KotlinConf brought this to my attention, as they're trying to generate their own adapter factory but can't since moshi consumes the annotation and doesn't allow others.
2018-10-06 17:05:06 +02:00
Zac Sweers
e0861cca57 Improve enum exception message (#694)
* Improve enum exception message

It is applicable to enums for proguard reasons, just not with code gen as well

* Update test message
2018-09-28 00:24:58 -04:00
Jesse Wilson
705ddc24e3 Merge pull request #687 from hzsweers/z/removeExtensions
Completely remove companion object jsonAdapter extension function gen
2018-09-25 07:08:54 -04:00
Eric Cochran
526717ec36 Remove duplicate kotlin-metadata version declaration.
The version is already defined in the root.
2018-09-25 00:17:32 -07:00
Zac Sweers
86c8671d64 Completely remove companion object jsonAdapter extension function gen
It's broken currently (see #611), and after talking with @swankjesse decided it's best to just nix this API
2018-09-25 00:58:52 -04:00
Jesse Wilson
2cb81857ac [maven-release-plugin] prepare for next development iteration 2018-09-24 22:55:49 -04:00
Jesse Wilson
9a652f8788 [maven-release-plugin] prepare release moshi-parent-1.7.0 2018-09-24 22:55:35 -04:00
Eric Cochran
242b7b1055 Use the adapter lookup hint API in Kotlin codegen adapters. 2018-09-20 21:00:18 -07:00
Eric Cochran
8e151b1df3 Allow user adapters to convert null to non-null in codegen.
Delegate to installed adapters instead of checking for null.
2018-09-11 22:25:42 -07:00
Jesse Wilson
cb86194f8f Merge pull request #651 from square/jwilson.0909.enclosed_parameterized
Call Types.newParameterizedTypeWithOwner when necessary.
2018-09-09 23:16:38 -04:00
Jesse Wilson
306664fb6a Call Types.newParameterizedTypeWithOwner when necessary.
Otherwise we crash with an exception attempting to create an adapter
for an enclosed type that has a type parameter.

I ran into this looking for a test case for issue 615.
https://github.com/square/moshi/issues/615
2018-09-09 17:05:33 -04:00
Jesse Wilson
7382145318 Change DelegateKey to use AnnotationSpec instead of AnnotationMirror
AnnotationSpec implements equals() in the way we need, but
AnnotationMirror doesn't. As a consequence this fixes a problem
where we were generating redundant adapters.

Closes: https://github.com/square/moshi/issues/563
2018-09-09 15:27:21 -04:00
Jesse Wilson
354db6b46f Merge pull request #627 from square/eric.2018-08-17.boxed-primitive-adapters
Make nullable primitives in codegen use boxed type adapters.
2018-08-19 07:36:12 -04:00
Eric Cochran
1b17423343 Make nullable primitives in codegen use boxed type adapters. 2018-08-17 13:41:43 -07:00
Jesse Wilson
9ea1f845a8 Generate Kotlin documentation with Dokka 2018-08-14 20:20:15 -04:00
Jesse Wilson
9251309c3f Merge pull request #603 from square/eric.patch-1
Simplify Options initializer generation.
2018-08-05 22:36:29 -04:00
Eric Cochran
248be5805b Fix dollar sign escaping for json key names. 2018-07-24 18:03:23 -07:00
Eric Cochran
6bb83abf84 Simplify Options initializer generation. 2018-07-24 17:51:18 -07:00
Zac Sweers
78821bbc80 Update to KotlinPoet 1.0.0-RC1 (#599)
* Update to kotlinpoet 1.0.0-RC1

* Move to WildcardTypeName.STAR

* simpleNames() function -> simpleNames property

* packageName() fun -> packageName property

* simpleName() fun -> simpleName property

* Check if bounds are empty for TypeVariableName. If so, use no-bounds creator

* Use new parameterizedBy/plusParameter API where appropriate
2018-07-17 22:44:20 -04:00
Zac Sweers
c9aee2e853 Fix GeneratedAnnotation member definition
Before this was just adding both as varargs of "value"
2018-06-15 22:09:13 -07:00
Eric Cochran
4666e06910 Allow private transient Kotlin properties. 2018-06-06 17:12:29 -07:00
Zac Sweers
3ecdfb6374 Fix generic typealiases (#551)
* Add generic type alias

* Fix missing resolveAliases check to fix generics

* Reword to useAbbreviatedType
2018-05-17 22:06:43 -04:00
Zac Sweers
b956b06f6d Fix companion object names not being resolved (#549)
* Fix companion object names not being resolved

This slipped through the cracks before the release

Fixes #546

* Add braces on the else clause for symmetry
2018-05-16 15:44:07 -04:00