Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Make formatter wrap at function argument rather than qualifier dot(Formatter)
Make formatter wrap at function argument rather than qualifier dot [message #1068060] Thu, 11 July 2013 21:05 Go to next message
John Muir is currently offline John MuirFriend
Messages: 5
Registered: July 2013
Junior Member
Hello.

I'd like to format the following class with a maximum line length of 80 characters:

import javax.swing.JLabel;
import javax.swing.JTextField;

public class FormatterTest {
  public static void main(String[] args) {
    JTextField imagesDirectorySecondPartField = new JTextField();
    JLabel imagesDirectorySecondPartLabel = new JLabel();
    imagesDirectorySecondPartLabel.setFont(imagesDirectorySecondPartField.getFont());
  }
}


When I format it, the last statement gets formatted like this:

    imagesDirectorySecondPartLabel.setFont(imagesDirectorySecondPartField
        .getFont());


But I want it to format like this:

    imagesDirectorySecondPartLabel.setFont(
        imagesDirectorySecondPartField.getFont());


In other words, I don't want the formatter to wrap at function qualifier dots; I want it to wrap at arguments.

How do I make the formatter do this?

I'm using Eclipse IDE for Java Developers version Juno Service Release 2.

Thanks!
Re: Make formatter wrap at function argument rather than qualifier dot [message #1069616 is a reply to message #1068060] Tue, 16 July 2013 08:40 Go to previous messageGo to next message
Noopur Gupta is currently offline Noopur GuptaFriend
Messages: 58
Registered: December 2012
Member
> I don't want the formatter to wrap at function qualifier dots; I want it to wrap at arguments.

Go to Window > Preferences > Java -- Code Style -- Formatter, create a new profile and go to the tab 'Line Wrapping'.

Select 'Function Calls > Qualified Invocations'.
Under 'Settings for qualified invocations', select 'Line wrapping policy' as 'Do not wrap'.
=> This will prevent the formatter from wrapping at function qualifier dots.

Select 'Function Calls > Arguments'.
Under 'Settings for arguments', select 'Line wrapping policy' as 'Wrap all elements, every element on a new line'. You can optionally check 'Force split..'.
=> This will wrap the arguments, each on a new line.

HTH.
Re: Make formatter wrap at function argument rather than qualifier dot [message #1083254 is a reply to message #1069616] Fri, 09 August 2013 17:58 Go to previous message
John Muir is currently offline John MuirFriend
Messages: 5
Registered: July 2013
Junior Member
That does not work.

Making the choices you suggested (and not checking "Force split ..."), it does not wrap the line; it is left longer than 80 characters:

    imagesDirectorySecondPartLabel.setFont(imagesDirectorySecondPartField.getFont());


And since you're suggesting I choose a wrap policy of "Wrap all elements, every element on a new line" for "Function Calls" > Arguments > "Settings for arguments", here's another example, this time with two arguments, that better shows that I don't want each argument to be on its own line:

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.JLabel;

public class FormatterTest2 {
  public static void main(String[] args) {
    String textPropertyName = "text";
    PropertyChangeListener textChangeListener = new PropertyChangeListener() {
      @Override
      public void propertyChange(PropertyChangeEvent evt) {
        // IGNORED
      }
    };
    JLabel imagesDirectorySecondPartLabel = new JLabel();
    imagesDirectorySecondPartLabel.addPropertyChangeListener(textPropertyName.toString(), textChangeListener);
  }
}


With your suggestion, the last statement gets formatted like this:

    imagesDirectorySecondPartLabel.addPropertyChangeListener(
        textPropertyName.toString(),
        textChangeListener);


but I want it to be formatted like this:

    imagesDirectorySecondPartLabel.addPropertyChangeListener(
        textPropertyName.toString(), textChangeListener);
Previous Topic:Where is the profiler?
Next Topic:Eclipse Kepler still slow
Goto Forum:
  


Current Time: Fri Apr 19 22:52:14 GMT 2024

Powered by FUDForum. Page generated in 0.03483 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top