* 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
* 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
* 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
* 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
* 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
* 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`
* 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
* 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
* 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
* 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
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
* 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()
* 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
* 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
* 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/647Resolves#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
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.
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
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