Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I stop IntelliJ from putting parameters on their own line?

I just wrote this line:

HDF5CompoundDSBridgeBuilder<WritableDataPoint> actualBridgeBuilder = new HDF5CompoundDSBridgeBuilder<>(actualReader);

and the automatic reformatter gave me:

HDF5CompoundDSBridgeBuilder<WritableDataPoint> actualBridgeBuilder = new HDF5CompoundDSBridgeBuilder<>
                (actualReader);

I think this looks extremely strange and I want to tell IntelliJ to never put parameters on a line of their own. I'd like:

HDF5CompoundDSBridgeBuilder<WritableDataPoint> actualBridgeBuilder = new HDF5CompoundDSBridgeBuilder<>(
                actualReader);

or better yet:

HDF5CompoundDSBridgeBuilder<WritableDataPoint> actualBridgeBuilder = 
       new HDF5CompoundDSBridgeBuilder<>(actualReader);

I'm looking through the project settings under Code Style > Java > Wrapping and Braces but I'm not sure what option I should change. I don't want to always have a new line after '(', I just want to make sure that IntelliJ never breaks there when it breaks multiline statements. I don't see any other options I could change.

Can this be done?

EDIT: If anyone wants to test on their own IntelliJ, I have my margins set to 120 characters, and the exact line (with the correct amount of whitespace -- 8 spaces) is:

        HDF5CompoundDSBridgeBuilder<WritableDataPoint> actualBridgeBuilder = new HDF5CompoundDSBridgeBuilder<>(actualReader)
like image 660
Patrick Collins Avatar asked Aug 04 '14 12:08

Patrick Collins


People also ask

How do I turn off hints in Intellij?

To disable hints completely, uncheck Settings → Editor → General → Appearance → Show parameter name hints.

How do I give command line arguments in Intellij?

Add program argumentsFrom the main menu, select Run | Edit Configurations or choose Edit Configurations from the run/debug configurations selector on the toolbar. In the Run/Debug Configurations dialog that opens, select a configuration where you want to pass the arguments.

How do I show parameters in Intellij?

View parameter hints in the editorOpen the Settings/Preferences dialog ( Ctrl+Alt+S ) and go to Editor | Inlay Hints | <required language>. Select Parameter hints from the list, make sure the Show parameter hints checkbox is selected, and then specify the context where you want parameter hints shown.


1 Answers

The setting that is causing the wrapping to occur is Code Style > Java > [Wrapping and Braces] > "Method call arguments". You can set to "Do not wrap" if you do not want it wrapped. For wrapping, set to "Wrap if Long" or "Chop down if long". Watch the foo1 method in the sample code to see the difference between wrap and chop.

Wrap:

wrapped(
    0x0051, 0x0052, 0x0053,
    0x0054, 0x0055, 0x0056,
    0x0057);

Chop:

chopped(
    0x0051, 
    0x0052,
    0x0053,
    0x0054, 
    0x0055, 
    0x0056,
    0x0057);

To get your first choice, such that the '(' is kept with the method call (or constructor call in this case), set the "new line after '('" option. That will give you:

HDF5CompoundDSBridgeBuilder<WritableDataPoint> actualBridgeBuilder = new HDF5CompoundDSBridgeBuilder<>(
        actualReader);

To get your second "or better yet" option, set Code Style > Java > [Wrapping and Braces] > "Assignment Statements" to "Wrap if long", "Chop if long" or "Wrap always". Set to "Wrap if long" you will get:

HDF5CompoundDSBridgeBuilder<WritableDataPoint> actualBridgeBuilder = 
        new HDF5CompoundDSBridgeBuilder<>(actualReader);
like image 141
Javaru Avatar answered Oct 23 '22 19:10

Javaru