Commit Graph

220 Commits

Author SHA1 Message Date
Zac Sweers
751e8219e9 Fix code cleanups (#1441)
* Fix immutable properties

It was intentionally designed the previous way

* Restore limit in for loop

* Another ImmutableProperties
2021-11-30 21:56:00 -05:00
Zac Sweers
9f81ac897a Revert "Omit adapter field names now that we directly instantiate annotations (#1436)" (#1439)
This reverts commit 4a6cfb4d58.
2021-11-30 21:43:48 -05:00
Zac Sweers
9a9cc450c6 Remove ksp.kt copy (#1437) 2021-11-30 21:21:33 -05:00
Zac Sweers
4a6cfb4d58 Omit adapter field names now that we directly instantiate annotations (#1436) 2021-11-30 16:23:47 -05:00
Zac Sweers
73553286fb Upgrade to Kotlin 1.6 + always instantiate annotations (#1425) 2021-11-17 12:46:47 -05:00
Zac Sweers
9440e5c7d0 Update to KSP 1.0.1 and use new jvm modifiers resolver API (#1422)
* Update to KSP 1.0.1 and use new jvm modifiers resolver API

This allows us to fully support transient across compilation boundaries

* Copy in KSP-supported KCT for now

* Update CI refs

* Move up transient check to the right place

Wasn't actually looking at the added annotation later 🤧

* Try regular RC?

* Skip that matrix for now
2021-11-15 11:25:15 -05:00
Zac Sweers
954ca46b9e Add @Json.ignore (#1417)
* Default Json.name to an unset value

* Promote shared transient tests to DualKotlinTest

* Add new ignore property to Json

* Support it in ClassJsonAdapter

* Mention no enum/record support

* Support in KotlinJsonAdapter

* Rework code gen API to know of "ignored"

* Support in apt code gen

* Support in KSP

* Update old non-working transient example test

* Synthetic holders

* Use field on both
2021-11-08 11:16:57 -05:00
Zac Sweers
48e6dd3f03 Support externally-compiled transient property recognition in KSP (#1416) 2021-11-03 15:49:28 -04:00
Zac Sweers
c288ad6133 Switch from internal to experimental internal annotation (#1410) 2021-10-30 12:15:08 -04:00
Zac Sweers
313683fa98 Parameterize kotlin test infra on CI (#1407) 2021-10-25 11:00:56 -04:00
Zac Sweers
b8fbe38118 Support direct annotation instantiation in code gen on Kotlin 1.6 (#1390) 2021-10-22 13:43:09 -04:00
Zac Sweers
a9eaa849e5 Only assign setters if present (#1405)
* Only assign setters if present

Rather than generating

```kotlin
val result: Content
result = Content()
result.content = if (contentSet) content else result.content
result.text = if (textSet) text else result.text
```

This will now conditionally set

```kotlin
val result: Content
result = Content()
if (contentSet) {
  result.content = content
}
if (textSet) {
  result.text = text
}
```

* Spotless
2021-10-22 12:18:59 -04:00
Zac Sweers
2db351f8ed Upstream KSP implementation (#1393) 2021-10-16 01:52:04 -04:00
Zac Sweers
de8bbf12f5 Update KotlinPoet to 1.10.0 (#1396) 2021-09-20 16:13:56 -04:00
Zac Sweers
5756136a72 Move apt-specific classes to apt package (#1392) 2021-09-09 22:14:29 -04:00
Zac Sweers
6947ab00d0 Modernize build a bit (#1383) 2021-08-23 17:09:59 -04:00
Zac Sweers
95250b0359 Implement reflective support for Java Records (#1381)
* Standardize around JDK 8

* Update GJF to support newer JDKs

* Fix misc java 8 issues in tests

* Prepare java 16/records checking at runtime

* Implement real RecordJsonAdapter

* Spotless

* Prepare build for JDK 16+

* Fix property name for kapt

* Small cleanup

* Make FallbackEnum java-8 happy

* Remove animalsniffer

* Fix format

* Add opens for ExtendsPlatformClassWithProtectedFields

* Return null every time in shim for main tests

* Use JDK 16 + release 8 to replace animalsniffer

* Simplify accessor accessible handling

* Remove manifest attrs

* Fix typo

* Fix KCT tests + upgrade it

* Cover another

* Try explicit kotlin daemon args for java 17?

* Disable 17-ea for now until kotlin 1.5.30

* Add JsonQualifier and Json(name) tests + fix qualifiers

* Ensure constructor is accessible

* GJF it properly

* GJF 1.11

* Unwrap InvocationTargetException

* Use MethodHandle for constructor

* Use MethodHandle for accessor too

* Revert "Remove manifest attrs"

This reverts commit 3eb768fd6904bb5c979aa01c3c182e0fb9329d62.

* Proper MR jar

* *actually* fix GJF, which wasn't getting applied before

We can just enable this everywhere now since we require JDK 16 anyway

* Make IDE happy about modules access

* Fixup records tests to play nice with modules

Gotta be public

* Add complex smoke test

* Remove comment

Not a regression test in this case
2021-08-23 12:00:06 -04:00
Goooler
2572c29e42 Code cleanups 2021-08-18 14:51:52 -04:00
Zac Sweers
ce45a68cc3 Small grammar and naming followups for proguard gen (#1365) 2021-07-16 03:06:43 -04:00
Steve SeongUg Jung
72f464bbdc Add an argument to be disable proguard code generating (#1353)
Co-authored-by: SeongUg Jung <seongug.jung@hanwha.com>
Co-authored-by: Zac Sweers <pandanomic@gmail.com>
2021-07-15 21:24:31 -04:00
Zac Sweers
e343751593 Update to Kotlin 1.5 (and associated deps) (#1339) 2021-05-07 12:51:33 -04:00
Zac Sweers
7372baaaa0 Invoke constructor directly if all params with default are set (#1326)
Resolves #1302
2021-03-29 21:47:22 -04:00
wrongwrong
37f34e16f0 Improve KotlinJsonAdapter performance by invoke KFunction by "call". (#1286) 2021-03-29 20:46:42 -04:00
Zac Sweers
bcfce60577 Warn on missing TypeElement rather than error (#1323)
One example I found for this is when a property is annotated with android's `@SuppressLint`, which is only available from the android jar and not visible during apt. This should just be a warning (if even?) and not a hard error.
2021-03-29 20:44:55 -04:00
Zac Sweers
103b60328c Improve readability of constructor invocation params (#1312) 2021-03-13 20:52:25 -05:00
Zac Sweers
3bc47519ab Fix reading property function types (#1311) 2021-03-13 20:47:52 -05:00
Zac Sweers
935f8b872a Support generic arrays with defaults in code gen (#1310) 2021-03-13 20:47:27 -05:00
Masatoshi Kubode
156b1f0365 Fix a crash when processing a parameter annotated with an annotation that placed in annotation package (#1287)
* Update KotlinPoet to 1.7.2

* Fix a Java NPE crash when processing a parameter annotated with an annotation that placed in annotation package

This problem happens with KotlinPoet 1.7.x.
From KotlinPoet 1.7.x, `TypeName.toString()` is escaped with backquotes if the package name contains keywords.
So NPE will be thrown if an annotation is placed in `annotation` package because `elements.getTypeElement(it.typeName.toString())` returns `null`.

* Reformat imports

* Use rawType().canonicalName instead of toString()

* Fix test case

* Require getTypeElement

* Exclude com.google.guava from shadowJar

* Move a test case of processing a qualifier placed in `annotation` package

* Use checkNull instead
2021-02-22 02:43:04 -05:00
Zac Sweers
7f1e7e229e Suppress some poet deprecations (#1306) 2021-02-20 23:27:56 -05:00
Zac Sweers
99ebab66c0 Reserve simple type names referenced by properties to avoid collisions (#1305) 2021-02-15 13:02:28 -05:00
Zac Sweers
6b09dc443d Suppress RedundantVisibilityModifier in generated adapters (#1303) 2021-02-15 12:58:14 -05:00
Zac Sweers
6e5bb3a29b Prepare project for Kotlin migration (#1257) 2021-02-02 13:11:38 -05:00
Zac Sweers
8518f47f52 Update dependencies (#1258) 2021-02-02 13:11:20 -05:00
Zac Sweers
230c3d801f Promote Kotlin type-inferring APIs to the main Moshi package (round 2!) (#1202)
* Make moshi-root a kotlin project

* Move moshi kotlin extensions to moshi core

* Add appropriate experimental annotations

* Add nextAdapter helper

* Add explicit return type on addAdapter

* Expression body for adapter

* Use nextAdapter helper

* Opportunistically fix a couple Util warnings

* Add Types extensions

* Spotless

* Use extensions in more places for added coverage

* Apply java versions on any java plugin type

This way the kotlin projects get this too

* Fix circularAdapters test?

* Use java 8 in java for code gen too

* Fixup with CircularAdaptersTest

* Add coverage for remaining

* Remove nextAdapter

* Remove leftover function

* Use asserts

left checkNotNull for the contract

* boxIfPrimitive

* Fixup docs

* Copyright fixes

* Add parameterized addAdapter

* Switch to using native javaType API

* Spotless

* Back to 2019

* Spotless

* Use rawType extension

* Fix rebase issues
2020-10-04 18:18:52 -04:00
Zac Sweers
f17e7c2584 Fix infinite loop with type var variance stripping + remove from API (#1246)
* Add test case

* Add TypeVariableResolver to handle backward referencing type vars

* Copy nullability in typevars
2020-10-04 18:10:49 -04:00
Zac Sweers
5ce092857a Fix some misc deprecated KotlinPoet APIs (#1249)
* Move off of deprecated AnnotationSpec.className

* Simplify generatedType check and avoid deprecated KP API
2020-10-04 18:03:45 -04:00
Zac Sweers
f192473419 Standardize (almost) all tests on Truth (#1242)
* Replace assertj calls with Truth where possible

* Update test dependencies

* adapters

* reflect

* codegen

* moshi

* Add missing inOrder()

* Spotless
2020-09-26 20:38:39 -04:00
Zac Sweers
bc85227f29 Add JsonString recipe to examples (#1230)
* Start recipes module with JsonString recipe

* Make recipes a kotlin project

* Move JsonString sample to examples

* Add license

* Include all java modules

* Add kotlin options

* Spotless

* Remove jvmtarget

I was today years old when I found out 1.7 isn't a valid target

* Make gradle happy

* Add codegen

* Spotless
2020-09-25 22:51:05 -04:00
Zac Sweers
a1852a7315 Finish spotless license header configuration (#1231)
* Update spotless and enable copyright header bits again

* Reformat square copyright headers

* Create separate format configuration for external files

* Update CI to use java 15 final

* include stacktrace in ci failures

* Update ktlint to 0.39

* Disable java formatting on JDK 15

* Fix google header
2020-09-25 22:18:51 -04:00
Zac Sweers
517ea36fe5 Fix shadow packaging in code gen artifact (#1214)
* Update to shadow 6.0

* Exclude kotlinpoet core artifact from shading

* Replace runtime scopes with compile

* Opportunistically fix old artifact() dep

Gradle 6.6 supports providers now

* Use api instead

* Add link

* Remove accidental gradle plugin config

This only applies to gradle plugins
2020-09-18 21:43:11 -04:00
Zac Sweers
5c07341977 Switch to Github Actions for CI 2020-09-01 15:48:33 -04:00
Zac Sweers
ecca5122a0 Switch to new appendLine APIs
appendLn is deprecated in kotlin 1.4
2020-09-01 01:13:55 -04:00
Zac Sweers
42f1d18f64 Update Okio and kotlin-compile-testing dependencies (#1198)
* Update Okio to latest

* Update kotlin-compile-testing to 1.2.10

* Update to KtLint 0.38.1

No changes affecting moshi, just support for mixing multiple kotlin versions in a project

* Opportunistic disable kotlin-dsl warning

This is noisy on every build

* Update maven publish to 0.12.0
2020-08-28 07:28:58 -04:00
Zac Sweers
538890e8c0 Switch to spotless and format code (#1196)
* Add spotless configuration

* Reformat!

* Add copyright config for build.gradle.kts files

* Add toeholds for headers
2020-08-27 23:40:15 -04:00
Zac Sweers
4dd4a9d222 Migrate to Gradle (#1159)
* Start gradle root

* Clean up test API ambiguities

These don't compile in gradle anymore and the team[] warns

* Exclude .gradle dirs in git

* Set up moshi module

* Set up moshi-adapters

* Add repositories to subprojects

* Set target/source compatibility

* Set up examples

* Fix location of reflect/test dir

* Set up moshi-kotlin

* Set up code gen

* Opportunistic update code gen deps

* Fix up with code gen

* Set up kotlin tests

* Update snapshots

* Update travis build

* Configure checkstyle

* Cache gradle

* Finish fixing up checkstyle

* Now disable checkstyle until we can fix them all :|

* Update contributing

* Fix tests in codegen

* Remove unnecessary annotation

* Remove maven stuff!

* Suppress warning

* Remove jcenter

* Consolidate dependencies

* Revert "Clean up test API ambiguities"

This reverts commit 3ead69b844b5d7f66134b721e95581f5df1cccd6.

* Fix incap dep

* Opportunistically fix some small kotlinpoet deprecations

* Automatically apply the stdlib to all kotlin projects

* Opportunistic move to opt-in and remove unnecessary annotations

The kotlin maven plugin didn't handle these well in the IDE, gradle does

* Fix Type doc warning

* Fix okio version

* Fix dokka support

* Fix copypasta

* Use new snapshot

* Kotlin 1.4.0
2020-08-27 16:50:28 -04:00
Jesse Wilson
28831b04cf [maven-release-plugin] prepare for next development iteration 2020-08-26 21:38:44 -04:00
Jesse Wilson
cff20193c2 [maven-release-plugin] prepare release moshi-parent-1.10.0 2020-08-26 21:38:36 -04:00
Zac Sweers
a5dbc1d642 Update to Kotlin 1.4.0 (#1191)
* Update to Kotlin 1.4.0

* Remove moshi-kotlin rules in favor of Kotlin's

* Ignore tests for now

* Update to OptIn

* Update test for kotlin 1.4 behavior
2020-08-25 22:51:44 -04:00
Oleg Vladimirov
6eb65908e0 bugfix 2020-06-26 13:28:00 +03:00
Ryan Harter
dd8611a1d9 Merge pull request #1080 from square/z/resolveRealTypes
Fix resolution of types in superclass settable properties
2020-05-26 17:53:45 -05:00