Annotating auto-generated methods?


#1

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:

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.


Disable componentN() generation in data classes
#2

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.


#3

shouldn’t the synthetic attribute be enough?


#4

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.


#5

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