# Annotating auto-generated methods?

**URL:** <https://discuss.kotlinlang.org/t/annotating-auto-generated-methods/1693>\
**Category:** Uncategorized\
**Created:** [May 23, 2016, 9:12am UTC](https://discuss.kotlinlang.org/t/annotating-auto-generated-methods/1693 "2016-05-23T09:12:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikehearn](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/mikehearn/32/1424_2.png) [@mikehearn](https://discuss.kotlinlang.org/u/mikehearn)\
**Post date:** [May 23, 2016, 9:12am UTC](https://discuss.kotlinlang.org/t/annotating-auto-generated-methods/1693/1 "2016-05-23T09:12:17Z")

</div>

Mutation testing frameworks like PIT want to modify code that are user authored, to inject bugs and then see if they’re caught by unit tests.

As you can see:

[improve kotlin support · Issue #260 · hcoles/pitest · GitHub](https://github.com/hcoles/pitest/issues/260)

They are attempting to come up with heuristics to identify methods that cannot possibly contain bugs because they are auto-generated by the Kotlin compiler (and we assume, of course, that the JetBrains team do not create bugs in such methods ;)).

It seems like the cleanest solution would be to introduce a new annotation and have the Kotlin compiler attach it to methods that are fully auto generated like data class methods, auto-generated getters/setters, auto-generated constructors and so on.

How hard would that be? I’m assuming not that hard.

---

<div class="post-metadata">

**Author:** ![henry\_coles](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/henry_coles/32/1968_2.png) [@henry\_coles](https://discuss.kotlinlang.org/u/henry_coles)\
**Post date:** [May 23, 2016, 9:16am UTC](https://discuss.kotlinlang.org/t/annotating-auto-generated-methods/1693/2 "2016-05-23T09:16:34Z")

</div>

This would be of benefit to other bytecode based tooling such as line coverage systems as well.

I think this would basically be a ‘synthetic’ annotation, but would be applied more liberally than the synthetic attribute.

---

<div class="post-metadata">

**Author:** ![globalmatador](https://avatars.discourse-cdn.com/v4/letter/g/71e660/32.png) [@globalmatador](https://discuss.kotlinlang.org/u/globalmatador)\
**Post date:** [May 23, 2016, 9:45am UTC](https://discuss.kotlinlang.org/t/annotating-auto-generated-methods/1693/3 "2016-05-23T09:45:39Z")

</div>

shouldn’t the synthetic attribute be enough?

---

<div class="post-metadata">

**Author:** ![henry\_coles](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/henry_coles/32/1968_2.png) [@henry\_coles](https://discuss.kotlinlang.org/u/henry_coles)\
**Post date:** [May 23, 2016, 10:37am UTC](https://discuss.kotlinlang.org/t/annotating-auto-generated-methods/1693/4 "2016-05-23T10:37:25Z")

</div>

As an example

```
data class User(val name: String, val age: Int)

```

Will generate getName, getAge, component1, component2 and copy methods none of which are currently marked as synthetic.

Some-one more knowledgeable than me will need to explain why they can’t be marked as synthetic, but I remember reading through a Scala compiler thread where methods were marked as synthetic then the change reverted as it interacted badly with Java tooling which hid the methods from view.

---

<div class="post-metadata">

**Author:** ![ilya.gorbunov](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/ilya.gorbunov/32/1645_2.png) [@ilya.gorbunov](https://discuss.kotlinlang.org/u/ilya.gorbunov)\
**Post date:** [May 23, 2016, 2:52pm UTC](https://discuss.kotlinlang.org/t/annotating-auto-generated-methods/1693/5 "2016-05-23T14:52:47Z")

</div>

You’re right, synthetic methods are invisible from java.

---

<div class="post-metadata">

**Author:** ![AhmedMourad](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/ahmedmourad/32/7847_2.png) [@AhmedMourad](https://discuss.kotlinlang.org/u/AhmedMourad)\
**Post date:** [March 22, 2020, 1:15pm UTC](https://discuss.kotlinlang.org/t/annotating-auto-generated-methods/1693/6 "2020-03-22T13:15:25Z")

</div>

Are there any plans to implement this? or maybe a viable alternative to it?

---

<div class="post-metadata">

**Author:** ![Alexey.Belkov](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/alexey.belkov/32/5215_2.png) [@Alexey.Belkov](https://discuss.kotlinlang.org/u/Alexey.Belkov)\
**Post date:** [April 3, 2020, 3:48pm UTC](https://discuss.kotlinlang.org/t/annotating-auto-generated-methods/1693/7 "2020-04-03T15:48:35Z")

</div>

Corresponding issue [https://youtrack.jetbrains.com/issue/KT-13102](https://youtrack.jetbrains.com/issue/KT-13102) you can vote and follow.
