CppStyle icon indicating copy to clipboard operation
CppStyle copied to clipboard

Java formatting

Open Gama11 opened this issue 7 years ago • 6 comments

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?

Gama11 avatar Mar 29 '17 19:03 Gama11

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

wangzw avatar Dec 21 '17 06:12 wangzw

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.

Gama11 avatar Dec 21 '17 13:12 Gama11

Nice and very useful tool!

Would it be possible to merge @Gama11's proposed commit https://github.com/wangzw/CppStyle/commit/6edf38b7b3694e07b59592f24a2bf56deba4833f 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!

RalphSteinhagen avatar Mar 28 '20 22:03 RalphSteinhagen

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 avatar Jul 23 '20 12:07 AhmetBilgin

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

AhmetBilgin avatar Aug 04 '20 22:08 AhmetBilgin

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.

gregbown avatar Jun 04 '23 06:06 gregbown