IntelliJ autoformat keeps adding a blank lines between class field declarations having annotations.
Do you know how to disable it?
This happens for kotlin files since does not work like that for java files.
Example, between each var intellij adds a blank line each time I execute autoformat.
class Resign : UnitTest() {
#InjectMocks
private lateinit var resignService: ResignServiceImpl
#Mock
private lateinit var actionAccess: ActionAccess
#Mock
private lateinit var userReportConverter: UserReportConverter
....
}
The problem was fixed in KT-37891. The option to disable this behavior should be available in the next plugin version.
You may also consider voting for KT-32185: 'More code style options for minimum blank lines'
Go to Settings > Editor > Code style > Kotlin > Wrapping and Braces.
Change Property annotations to "Do not wrap" or "Wrap if long".
No answer properly points out the exact name of the configuration. Under the Kotlin code style, it can be found on the "Blank Lines" tab, with the name "Before declaration with comment or annotation".
For me, this defaulted to 1. Setting it to 0 let's me decide myself whether I want a new line or not.
Related
Given this Foo interface
interface Foo {
fun whereIsThisImplemented(a: String): String
}
// How do I use the above interface to find the below implementation
class Bar: Foo {
override fun whereIsThisImplemented(a: String): String {
return a
}
}
is there a simple way of finding where the whereIsThisImplemented method is overridden through intellij?
While whereIsThisImplemented is highlighted, Using edit -> Find Usages -> Find Usage Settings, none of the options will find the Override fun whereIsThisImplemented.
I could find all places the interface is implemented, then look for the method, but this is extremely cumbersome and I was hoping there was a simpler way that I was missing.
Menu: Navigate -> Implementations . Note down the shortcut besides the menu.
Alternatively, you can click on the down arrow on the left of the method declaration
Tip: Install key promoter plugin so that you get a notification of keyboard shortcut everytime you use the mouse.
Hover over the green icon next to the interface function to see a list of places where it is implemented. If you click the icon, it jumps you to that spot in the code.
When I extract a method, IDEA generates code like this:
#NotNull
private String getSimpleName(TestInfo testInfo) {
return testInfo.getTestClass().get().getSimpleName();
}
I don't want IDEA to generate the #NotNull annotation - in my project everything is assumed to be "not null" by default.
I've added my own custom #Nullable annotation in the "Nullable/NotNull Configuration" dialog - but it seems like one of the annotations in the "NotNull Annotations" section always has to be selected.
I've looked in the "File and Code Templates" section - neither "Implemented Method Body" nor "New Method Body" template contains the #NotNull code.
How do I tell IDEA that everything is "#NotNull" be default and it should not generate an annotation?
Please try the latest version of IntelliJ IDEA: https://www.jetbrains.com/idea/nextversion/. "Generate annotations" option should be available there:
In my project, I have many serialization classes and, to make the classes more readable, I'm standardizing them, with an argument which has the same name of the $class$, that is $argName$:
#immutable
class $class$_Serialize extends Serialize<$class$> {
final $class$ $argName$;
$class$_Serialize(this.$argName$);
#override
Map<String, Object> run() => $serialize$
}
In the Live Template above, the annoyance is that I have to retype $argName$ instead of the template simply decapitalizing $class$. How would I tie $argName$ to the decapitalization of $class$ in IntelliJ?
I've already tried to mess around with editing the variables and adding the decaptialize() function in the expression column, but so far haven't had much success. It was something like this:
You are using the wrong syntax for the decapitalize function. It should look like this:
decapitalize(class)
Note that there are no $ signs around the class in the function argument.
Kotlin compiler remove the Java runtime annotation annotated on a field.The annotation is shown below.
#Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.TYPE, ElementType.PARAMETER})
#Retention(RetentionPolicy.RUNTIME)
#com.fasterxml.jackson.annotation.JacksonAnnotation
public #interface JsonDeserialize
I declared it on a field, as seen below.
#JsonSerialize(using = IDEncryptJsonSerializer::class)
#JsonDeserialize(using = IDDecryptJsonDeserializer::class)
#Column(name = "sku_id", nullable = false)
open var skuId: Long = 0L
The annotation doesn't work. Then, I take a fist look at the class file, as seen below.
#field:javax.persistence.Column public open var skuId: kotlin.Long
The JsonDeserialize and JsonSerialize annotation are dismiss.
The two annotations are work well in Java.
My kotlin version is 1.1.4.
How can I fix the problem?
Finally, I found the reason that result in the phenomenon.
If I declare a variable in class constructor, some of annotations annotate on that variable may cannot be compiled correctly.
Some of annotations may be lost because of kotlin compiler bug.
Then, I move the variable in the class body. Everything work well.
How to tweak InlliJ IDEA 14 code style for Java, to make it keep closing brace of empty constructor/method right after opening one.
E. g. :
class A {
private A() {}
public void b() {}
}
Go to Settings/Code style/Java/Wrapping and Braces and select these options:
Keep when reformatting
Simple blocks in one line
Simple methods in one line
Simple classes in one line
That will keep code like this untouched while reformatting your code:
if(true) {}
public void foo() {}
public class Bar {}
I tested this on IntelliJ 13.1.5, but hopefully it will work the same way on 14 too.
Isn't this the default behaviour of IntelliJ 14? At least in my version it is. As soon as I open curly bracket it gets closed automatically on the same line.