Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean Up "Add missing @Override" does not keep indentation #1940

Open
IanKrL opened this issue Jan 15, 2025 · 2 comments
Open

Clean Up "Add missing @Override" does not keep indentation #1940

IanKrL opened this issue Jan 15, 2025 · 2 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@IanKrL
Copy link

IanKrL commented Jan 15, 2025

Eclipse IDE for Java Developers (includes Incubating components)
Version: 2024-09 (4.33.0)
Build id: 20240905-0614

For a file that's indented normally, this is not an issue. However, I have some legacy code that I do want Eclipse to add @Override annotations to (for example) but not change the creative indentation.

Example Code:

package stuffs;

public class DoThings {

 private static class A {
  void foo() {
  }
 }

 private static class B extends A {
  void foo() {

  }
 }
}

The important thing here is that B.foo() is indented 2 spaces (it also occurs for 1 or 3 spaces).
Then I Source->Clean Up->Use configured profiles (Eclipse [build-in]) and Finish. The result is this:

package stuffs;

public class DoThings {

 private static class A {
  void foo() {
  }
 }

 private static class B extends A {
  @Override
void foo() {

  }
 }
}

Note that the void foo() declaration indentation is gone.

I can also reproduce this with adding @Deprecated annotation.

Formatting is set to the default Eclipse [built-in] option with Indentation being tabs of size 4. This also happens if I change the formatting to be "4 spaces" which is what we actually use in my project. The error occurs any time the method indentation is less than the declared indentation in the formatter (like I said, legacy code I don't want to bulk format at this time). However, I don't know that the formatting settings should have any effect, given that I'm only asking for a Clean Up, not a format.

@jukzi jukzi added the bug Something isn't working label Jan 15, 2025
@jukzi
Copy link
Contributor

jukzi commented Jan 15, 2025

Also shown in the preview:
image

@jukzi
Copy link
Contributor

jukzi commented Jan 15, 2025

Note that it happens only if and because of
"Overrride" Clean up is active
image
and Correct indentation is disabled
image

@jukzi jukzi changed the title "Clean Up" Adding Annotations Can Change Indentation Clean Up "Add missing @Override" does not keep indentation Jan 15, 2025
@jjohnstn jjohnstn self-assigned this Jan 16, 2025
@jjohnstn jjohnstn added this to the 4.35 M2 milestone Jan 16, 2025
jjohnstn added a commit to eclipse-jdt/eclipse.jdt.core that referenced this issue Jan 17, 2025
- add new method computeIndentInSpaces() to ASTRewriteFormatter
- modify ASTRewriteAnalyzer.rewriteModifiers2() to add spaces as
  needed to separator of added annotation to match current indent
- needed for eclipse-jdt/eclipse.jdt.ui#1940
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants