GithubHelp home page GithubHelp logo

Comments (4)

krasa avatar krasa commented on July 24, 2024

what sorting?

Is it something that does not happen in Eclipse? :)

from eclipsecodeformatter.

krasa avatar krasa commented on July 24, 2024

Could you add screenshots?

from eclipsecodeformatter.

fsuchy avatar fsuchy commented on July 24, 2024

Sorry, by "sorting", I meant the "Rearrange Entries" option for the "Reformat Code" operation.

And this may be the key. I did a little more testing in Eclipse and IntelliJ, and I think what I have observed may actually be standard Eclipse behavior. In my previous Eclipse life, I used the "Clean Up" operation primarily, which included Sorting as well as my Formatter configuration. That was clouding the issue for me.

In short, I think this is "working as designed". :)

But, so you can see what I was talking about, here is a simple example. Paste this into IntelliJ:

package formatter.example;

public class Foo {

    private static final String VAR1_LABEL = "var1";

    private static final String VAR2_LABEL = "var2";

    private final int _var1;

    private final int _var2;

    public Foo(final int var1, final int var2) {
        _var1 = var1;
        _var2 = var2;
    }

    @Override
    public String toString() {
        return VAR1_LABEL + "=" + _var1 + ", " + VAR2_LABEL + "=" + _var2;
    }
}

In your imported formatting configuration file, ensure you have blank_lines_before_field = 0, and number_of_empty_lines_to_preserve = 1.

Then Code->Reformat Code.

Note that the blank lines above the fields were not removed.

Cut the _var2 declaration line and paste it below the constructor. Then run Code->Reformat Code and be sure to select the "Rearrange entries" option before clicking Run.

Assuming you have some amount of field rearrangement configured, _var2 will likely end up below _var1. Note that there is no space above the declaration of _var2. It will look like this:

package formatter.example;

public class Foo {

    private static final String VAR1_LABEL = "var1";

    private static final String VAR2_LABEL = "var2";

    private final int _var1;
    private final int _var2;

    public Foo(final int var1, final int var2) {
        _var1 = var1;
        _var2 = var2;
    }

    @Override
    public String toString() {
        return VAR1_LABEL + "=" + _var1 + ", " + VAR2_LABEL + "=" + _var2;
    }
}

from eclipsecodeformatter.

krasa avatar krasa commented on July 24, 2024

I see, IntelliJ rearranger makes it without the blank line (because Blank Lines | Around field = 0) and Eclipse formatter does not insert the blank line either because of blank_lines_before_field=0.

from eclipsecodeformatter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.