kotlin-style-guide
kotlin-style-guide copied to clipboard
Annotation formatting
Annotations are typically placed on separate lines, before the declaration to which they are attached, and with the same indentation:
@Target(AnnotationTarget.PROPERTY)
annotation class JsonExclude
Annotations without arguments can be placed on the same line:
@JsonExclude @JvmField
var x: String
A single annotation without arguments should be placed on the same line as the corresponding declaration:
@Test fun foo() { ... }
File annotations are placed after the file comment (if any), before the package statement, and are separated from package with a blank line (to emphasize the fact that they target the file and not the package).
/** License, copyright and whatever */
@file:JvmName("FooBar")
package foo.bar
Can the guide recommend placing short annotations on the same line? Like @Test and others. A short annotation is something not much longer than override, e.i. less than 10 characters.
@voddan changed 'can' to 'should'
What about mixing annotations with and without arguments?
@Name("Y")
@JsonExclude @JvmField
var x: String
@stepango Your example looks fine to me.