[ANN] Tabifier version 4.0

The tabifier plugin retabs Java code so that syntactic elements are aligned vertically.

The new version has many bug fixes and other improvements. It does a much better job at handling nested expressions and method calls. It also has several new features, such as the ability to right justify integer literals, e.g.

It can align method declaration and method call parameters, even with multiple parameters per line:


And its expression alignment is now recursive, e.g.

  expressionListIndex &&
                 psiExpressionList.getExpressions()[expressionListIndex] == child                 ) ||
                (sawNoParameters                                         == false               &&
                 expressionListIndex                                     >                    0   )   )
]]>


Plugin is available using EAP build 957's plugin manager, or at the Wiki page http://www.intellij.org/twiki/bin/view/Main/TabifierPlugin.

Thanks to all who submitted bug reports, and thanks for your patience. This release was almost a complete rewrite (only the UI didn't change) so that the plugin could handle recursive and nested constructs properly. Hence it took longer than I'd hoped.

Let me know if you find bugs or have suggestions for improvement!

-Dave

8 comments

Hi Dave

I get this code (see below) if I reformat the whole code with Tabifier v4.0
(default settings, Idea 957). Tabifier ignored the lines with the "-1" values
and set all the other integer values and comments too far to the right. I
think the problem is the "{"..."}" block. I love the Tabifier plugin and it
would be great to type blindly (-[A] and) -[ALT]-[SHIFT]-[T] to
get a well formatted code w/o the need to check the code. BTW, is it possible
to do this automatically directly before the "save" and|or "check in" action?

- Jens

... // ====================================================================================================== Fields === public static final int DEFAULT_PORT = 110; public static final int STATE_UNKNOWN = -1; public static final int STATE_AUTHORIZATION = 0; public static final int STATE_TRANSACTION = 1; public static final int STATE_UPDATE = 2; public static final int COMMAND_UNKNOW = -1; public static final int COMMAND_APOP = 0; public static final int COMMAND_DELE = 1; public static final int COMMAND_LIST = 2; public static final int COMMAND_NOOP = 3; public static final int COMMAND_PASS = 4; public static final int COMMAND_QUIT = 5; public static final int COMMAND_RETR = 6; public static final int COMMAND_RSET = 7; public static final int COMMAND_STAT = 8; public static final int COMMAND_TOP = 9; public static final int COMMAND_UIDL = 10; public static final int COMMAND_USER = 11; public static final String[] COMMAND = {"APOP", "DELE", "LIST", "NOOP", "PASS", "QUIT", "RETR", "RSET", "STAT", "TOP", "UIDL", "USER"}; public static final String RESPONSE_OK = "+OK"; public static final String RESPONSE_ERROR = "-ERR"; public static final String RESPONSE_NEWLINE = "\r\n"; public static final int COMMANDLINE_CMD = 0; public static final int COMMANDLINE_ARG1 = 1; public static final int COMMANDLINE_ARG2 = 2; // ================================================================================================ Constructors === ... ]]>

--
<= Nail here for a new monitor!

PGP fingerprint: 5209 35D1 772F 639A 4EB0 D475 3049 D1C1 718D E1D1
Get public key: gpg --keyserver pgp.mit.edu --recv-keys 718DE1D1

0

Hi Jens,

I'll fix the problem with the negative numbers. (That will also fix other unforeseen problems like +1, ~1).

The reason all the other integer values are shoved to the right is that they are being aligned with the rightmost column of the field COMMAND's array initializer.

You have a couple options:

- under the configuration option "Options affecting grouping of lines" enable "blank lines delimit alignable groups".

- manually select the area from DEFAULT_PORT to COMMAND_USER (just click anywhere in the DEFAULT_PORT line and drag down to anywhere in the COMMAND_USER line) and tabify that group independently.

In the latter case you get results like:

I'm almost to the point where I'm always happy with the results of Ctrl-Alt-Shift-T, but I quickly scan the file to see if there might be a group of lines that ought to be tabified separately for better results. It's hard to come up with a general rule that groups lines "correctly" all the time. For example, in the code you supplied, separating groups by blank lines (while avoiding alignment of the integer constant fields with the string constants) would also unfortunately separate DEFAULT_PORT from STATE_* fields, which probably is not what you wanted.

I thought about trying to align lines with right-justified integer constants separately from others, but they can appear anywhere -- e.g., inside an if-statement expression -- and it seemed like a special case that was unnecessarily hard and possibly unpredictable.

I don't know if it is possible to automatically run tabifier before checking in code. Nothing in the tabifier could hook that; is there an "execute before" capability (as there is with Ant tasks) that you might be able to use?

Thanks-
Dave

0

Bug fix: properly right-justify negative integer constants in the same way that unsigned integer constants are.

0

Hi Dave,

Tabifier v4.1 and the enabled "blank lines delimit alignable groups"
fixes the most problems. Also the strange problem with my "comment
separators" ( ^\t// ===...===$ ) (they won't aligned now). But I
think it looks better if the option is disabled. Maybe you can add an
additional option to ignore array initializer (they are very long in
many cases)? I know, there is no Super-Duper-Everything-Is-Fine
solution.

Ant isn't a solution for the pre-checkin/pre-save problem, but a macro
can do.

A progressbar would be nice (or simply change the mouse cursor?).

- Jens

--
<= Nail here for a new monitor!

PGP fingerprint: 5209 35D1 772F 639A 4EB0 D475 3049 D1C1 718D E1D1
Get public key: gpg --keyserver pgp.mit.edu --recv-keys 718DE1D1

0

Jens,

You're reading my mind; I actually started working on a progress bar this morning.

I have some work to do on array initializers still. But I will add an option to leave them intact.

Can you give me an example of the problem with your comments?

-Dave

0

Hi Dave

You're reading my mind; I actually started working on a progress bar
this morning.


Cool.

I have some work to do on array initializers still. But I will add
an option to leave them intact.


Sounds great.

Can you give me an example of the problem with your comments?


Sure. Example 1 shows the code directly after pressing -[ALT]-[L].
Example 2 is the result after pressing -[ALT]-[SHIFT]-[T] (*). My
separator ( // ===...=== Fields === ) starts at column 84 and the result
is a little bit different if I add Java comments. Example 3 shows the code
which I expect (better; what I want). Maybe it's only a problem of my
configuration. I definitively don't want to mark the code before (each
time). I just want to press -[ALT]-[SHIFT]-[T] and get a well
formatted code. I hope that's possible. :)

TIA,
- Jens



Examples (disable word wrapping!!!):
=================================

]]>

package test.tabifier;

/**

  • Class TabifierTest. Column 78 -->|

*/
public class TabifierTest
{
// ============================================================ Fields ===

protected int value;

public static final int VALUE_MINUS_ONE = -1;
public static final int VALUE_NULL = 0;
public static final int VALUE_ONE = 1;
public static final int VALUE_TWO = 2;
public static final int VALUE_THREE = 3;
public static final int VALUE_FOUR = 4;
public static final int VALUE_FIVE = 5;
public static final int VALUE_SIX = 6;
public static final int VALUE_SEVEN = 7;
public static final int VALUE_EIGHT = 8;
public static final int VALUE_NINE = 9;
public static final int VALUE_TEN = 10;

public static final String[] VALUES = {"minus one", "null", "one",
"two", "three", "four",
"five", "six", "seven",
"eight", "nine", "ten"};

} // TabifierTest

]]>


package test.tabifier;

/**

  • Class TabifierTest. Column 78 -->|

*/
public class TabifierTest
{
// ============================================================ Fields ===

protected int value;

public static final int VALUE_MINUS_ONE = -1;
public static final int VALUE_NULL = 0;
public static final int VALUE_ONE = 1;
public static final int VALUE_TWO = 2;
public static final int VALUE_THREE = 3;
public static final int VALUE_FOUR = 4;
public static final int VALUE_FIVE = 5;
public static final int VALUE_SIX = 6;
public static final int VALUE_SEVEN = 7;
public static final int VALUE_EIGHT = 8;
public static final int VALUE_NINE = 9;
public static final int VALUE_TEN = 10;

public static final String[] VALUES = {"minus one", "null", "one",
"two", "three", "four",
"five", "six", "seven",
"eight", "nine", "ten"};

} // TabifierTest

]]>


package test.tabifier;

/**

  • Class TabifierTest. Column 78 -->|

*/
public class TabifierTest
{
// ============================================================ Fields ===

protected int value;

public static final int VALUE_MINUS_ONE = -1;
public static final int VALUE_NULL = 0;
public static final int VALUE_ONE = 1;
public static final int VALUE_TWO = 2;
public static final int VALUE_THREE = 3;
public static final int VALUE_FOUR = 4;
public static final int VALUE_FIVE = 5;
public static final int VALUE_SIX = 6;
public static final int VALUE_SEVEN = 7;
public static final int VALUE_EIGHT = 8;
public static final int VALUE_NINE = 9;
public static final int VALUE_TEN = 10;

public static final String[] VALUES = {"minus one", "null", "one",
"two", "three", "four",
"five", "six", "seven",
"eight", "nine", "ten"};

} // TabifierTest

(*) from ~/.IntelliJIdea/conf/options/other.xml: ]]>

--
<= Nail here for a new monitor!

PGP fingerprint: 5209 35D1 772F 639A 4EB0 D475 3049 D1C1 718D E1D1
Get public key: gpg --keyserver pgp.mit.edu --recv-keys 718DE1D1



Attachment(s):
TabifierTest.java
0

It looks like the comment is being right shifted to follow the rightmost character of the following block. This is not what I intended (i.e., it's wrong!); only comments that trail after a declaration (etc) should be candidates for "align trailing comments." Yours shouldn't move. I'll fix it.

-Dave

0

Jens,

try version 4.3. It should fix your comment problem, and gives you the choice of improved array initializer reformatting, or disabling it completely.

Thanks for the feedback,
-Dave

0

Please sign in to leave a comment.