Reputation: 100378
I have the following lines of code at the top of my class:
private static final int DEFAULT_A = 0;
private static final int DEFAULT_B = 1;
private int mA = DEFAULT_A;
private int mB = DEFAULT_B;
When I use the 'Rearrange Code' action in IntelliJ (or rather, Android Studio), it thinks that it should stick these together, like this:
private static final int DEFAULT_A = 0;
private int mA = DEFAULT_A;
private static final int DEFAULT_B = 1;
private int mB = DEFAULT_B;
How can I prevent this from happening when using this action? These are my matching rules:
Upvotes: 2
Views: 679
Reputation: 2678
You can't - this is a bug/feature in Intellij. Because you've assigned DEFAULT_A to mA, it decides to ignore the ordering you've specified and keep these two together.
Upvotes: 1
Reputation: 6884
I guess this is the way IntelliJ 'understands' the code in a humanly readable manner.
I'll explain:
In the code above you are declaring the final variables DefaultA and DefaultB, and then setting their value to the mA and mB. What IntelliJ is doing is actually setting the value of mA and mB just after the declaration, therefore refactoring your code.
I am not sure if there is a way to actually change this in IntelliJ, as the way the software was developed handles declarations and setting of variables in a grouped manner to be more developer friendly, (not to make the developer forget about mA and mB.
Hope this helps :)
Upvotes: 1