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

Java formatting #20

Open
Gama11 opened this issue Mar 29, 2017 · 6 comments
Open

Java formatting #20

Gama11 opened this issue Mar 29, 2017 · 6 comments

Comments

@Gama11
Copy link

Gama11 commented Mar 29, 2017

Are there any plans to support Java formatting? According to https://clang.llvm.org/docs/ClangFormat.html, this is supported by clang-format.

Presumably this would mostly be UI work, and clang-format could be called the same way?

@wangzw
Copy link
Owner

wangzw commented Dec 21, 2017

That‘s very cool. Would you like to contribute to this feature?

@Gama11
Copy link
Author

Gama11 commented Dec 21, 2017

I actually got it working in a fork - the functionality itself was simple, the big issue is the CDT dependency. Not sure if you can have optional dependencies in Eclipse plugins? I ended up just removing all CDT references to make it work. Either way, having CDT installed should obviously not be a requirement for formatting Java code.

@RalphSteinhagen
Copy link

Nice and very useful tool!

Would it be possible to merge @Gama11's proposed commit 6edf38b be and eventually release this? The commit seems to be fairly small... I'd use it even with the CDT dependency as we are also using C/C++ in addition to Java.

Many thanks in advance and thanks again for your good work!

@AhmetBilgin
Copy link

AhmetBilgin commented Jul 23, 2020

I actually got it working in a fork - the functionality itself was simple, the big issue is the CDT dependency. Not sure if you can have optional dependencies in Eclipse plugins? I ended up just removing all CDT references to make it work. Either way, having CDT installed should obviously not be a requirement for formatting Java code.

Hi Gama11,
your Java-Fork seems to be failing, when you also have active SaveActions (Preferences -> Java -> Editor -> Save Actions).

Steps to reproduce:

  • Remove an @OverRide annotation and also change some formatting which the formatter should handle.
  • The Formatter formats the code
  • The SaveActions restore the @OverRide Annotation and fails, because of the previous actions of the formatter.
    -- Save action: Add missing '@OverRide' annotations

I didn't understand yet, why the SaveAction fails in combination with the formatter.
Do you have any idea?

Also I saw that you didn't add the ClangFormatFormatter as a JavaFormatter via the extension point

Did you encounter problems with this and decided not to implement it as a formatter?

@AhmetBilgin
Copy link

I got a version which works fine for Java in my fork:
ClangFormat4J

@gregbown
Copy link

gregbown commented Jun 4, 2023

I have tried both CppStyle and ClangFormat4J and the functionality seemed identical in the latest Eclipse (Version: 2023-03 (4.27.0)) configured to format on save.
I am using clang-format 16.0.4.
Maybe I am not set up correctly and am seeing the default Eclipse format because when I compare the clang-format with IntelliJ it responds quite different (more as I would expect clang-format)
My goal is to get identical formatting across IDE so we do not have differences introduced based on editor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants