Skip to content

Commit

Permalink
Update code style to 100 width (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
drewhamilton authored May 24, 2023
1 parent 4c0452e commit dd30b50
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 24 deletions.
6 changes: 4 additions & 2 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 13 additions & 11 deletions poko-annotations/src/main/kotlin/dev/drewhamilton/poko/Poko.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package dev.drewhamilton.poko

/**
* A `@Poko class` is similar to a `data class`: the Poko compiler plugin will generate [Any.equals], [Any.hashCode],
* and [Any.toString] functions for any Kotlin class marked with this annotation. Unlike normal data classes, `copy` or
* `componentN` functions are not generated. This makes it easier to maintain data models in libraries without breaking
* binary compatibility.
* A `@Poko class` is similar to a `data class`: the Poko compiler plugin will generate [equals],
* [hashCode], and [toString] functions for any Kotlin class marked with this annotation. Unlike
* normal data classes, `copy` or `componentN` functions are not generated. This makes it easier to
* maintain data models in libraries without breaking binary compatibility.
*
* The generated functions will be based on class properties in the primary constructor. Class properties not in the
* primary constructor will not be included, and primary constructor parameters that are not class properties will not
* be included. Compilation will fail if the annotated class does not include a primary constructor.
* The generated functions will be based on class properties in the primary constructor. Class
* properties not in the primary constructor will not be included, and primary constructor
* parameters that are not class properties will not be included. Compilation will fail if the
* annotated class does not include a primary constructor.
*
* Each function will only be generated if it is not already manually overridden in the annotated class.
* Each function will only be generated if it is not already manually overridden in the annotated
* class.
*
* The annotated class cannot be a `data class`, an `inline class`, or an `inner class`.
*
* Like data classes, it is highly recommended that all properties used in equals/hashCode are immutable. `var`s,
* mutable collections, and especially arrays should be avoided. The class itself should also be final. The compiler
* plugin does not enforce these recommendations.
* Like data classes, it is highly recommended that all properties used in equals/hashCode are
* immutable. `var`s, mutable collections, and especially arrays should be avoided. The class itself
* should also be final. The compiler plugin does not enforce these recommendations.
*/
@Retention(AnnotationRetention.BINARY)
@Target(AnnotationTarget.CLASS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ class PokoCompilerPluginRegistrar : CompilerPluginRegistrar() {

val pokoAnnotationString = checkNotNull(configuration[CompilerOptions.POKO_ANNOTATION])
val pokoAnnotationClassId = ClassId.fromString(pokoAnnotationString)
val messageCollector = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE)
val messageCollector = configuration.get(
CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY,
MessageCollector.NONE,
)

IrGenerationExtension.registerExtension(
PokoIrGenerationExtension(pokoAnnotationClassId, messageCollector)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ internal class PokoIrGenerationExtension(
return
}

val pokoMembersTransformer = PokoMembersTransformer(pokoAnnotationName, pluginContext, messageCollector)
val pokoMembersTransformer = PokoMembersTransformer(
pokoAnnotationName = pokoAnnotationName,
pluginContext = pluginContext,
messageCollector = messageCollector,
)
moduleFragment.transform(pokoMembersTransformer, null)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ class PokoGradlePlugin : KotlinCompilerPluginSupportPlugin {
version = ArtifactInfo.VERSION
)

override fun applyToCompilation(kotlinCompilation: KotlinCompilation<*>): Provider<List<SubpluginOption>> {
override fun applyToCompilation(
kotlinCompilation: KotlinCompilation<*>,
): Provider<List<SubpluginOption>> {
val project = kotlinCompilation.target.project
val extension = project.extensions.getByType(PokoPluginExtension::class.java)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package dev.drewhamilton.poko.sample.compose

/**
* Annotation used for Poko compiler plugin, which generates [equals], [hashCode], and [toString] for the annotated
* class.
* Annotation used for Poko compiler plugin, which generates [equals], [hashCode], and [toString]
* for the annotated class.
*/
@Retention(AnnotationRetention.SOURCE)
@Target(AnnotationTarget.CLASS)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package dev.drewhamilton.poko.sample.jvm

/**
* Annotation used for Poko compiler plugin, which generates [equals], [hashCode], and [toString] for the annotated
* class.
* Annotation used for Poko compiler plugin, which generates [equals], [hashCode], and [toString]
* for the annotated class.
*/
@Retention(AnnotationRetention.SOURCE)
@Target(AnnotationTarget.CLASS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class SampleTest {

@Test fun `toString includes class name and each property`() {
val sample = Sample(3, "sample", null)
assertThat(sample.toString()).isEqualTo("Sample(int=3, requiredString=sample, optionalString=null)")
assertThat(sample.toString())
.isEqualTo("Sample(int=3, requiredString=sample, optionalString=null)")
}

@Test fun `toString is equivalent to data class toString`() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ class ArrayTest {
)


val expected = Regex("DataArrayHolder\\(id=id, array=\\[one, two], maybe=\\[Ljava.lang.String;@[0-9a-fA-F]+\\)")
val expected = Regex(
"DataArrayHolder\\(id=id, array=\\[one, two], maybe=\\[Ljava.lang.String;@[0-9a-fA-F]+\\)"
)
assertThat(a.toString()).matches(expected.toPattern())
}

Expand All @@ -117,7 +119,9 @@ class ArrayTest {
maybe = arrayOf("3", "4"),
)

val expected = Regex("HandwrittenArrayHolder\\(id=id, array=\\[one, two], maybe=\\[Ljava.lang.String;@[0-9a-fA-F]+\\)")
val expected = Regex(
"HandwrittenArrayHolder\\(id=id, array=\\[one, two], maybe=\\[Ljava.lang.String;@[0-9a-fA-F]+\\)"
)
assertThat(a.toString()).matches(expected.toPattern())
}

Expand All @@ -128,7 +132,9 @@ class ArrayTest {
maybe = arrayOf("3", "4"),
)

val expected = Regex("PokoArrayHolder\\(id=id, array=\\[one, two], maybe=\\[Ljava.lang.String;@[0-9a-fA-F]+\\)")
val expected = Regex(
"PokoArrayHolder\\(id=id, array=\\[one, two], maybe=\\[Ljava.lang.String;@[0-9a-fA-F]+\\)"
)
assertThat(a.toString()).matches(expected.toPattern())
}
//endregion
Expand Down

0 comments on commit dd30b50

Please sign in to comment.