Automatic source code formatting with ABAP in Eclipse
With ABAP in Eclipse it is very easy to format the source code of ABAP objects. Pressing Shift + F1 before saving or activating a development object gets your written source code in a pretty format.
But even though it is not a lot of work pressing two buttons before each saving or activation step I think to a certain degree this repetitive task should be automated. I do not worry about the time needed for this manual tasks but more about the situations where the unsteady source code formatting obfuscates the build-in version database or the abapGit history.
Pretty printer is cool, so why not perform it automatically?
Therefore I added a functionality to ABAP in Eclipse to enable automatic source code formatting of ABAP objects (currently classes, function modules and CDS views are supported). The feature is part of the free abapCI Plugin.
One important characteristic of this feature is that it does not format all objects by default, but only that ones that start with a configurable starting source code comment. This comment is configurable and if not changed the default values to be added as first line of your development object are:
- “#autoformat … for classes, testclasses
- *#autoformat … for function modules
- //#autoformat … for CDS views
In the Eclipse preferences there is the possibility to configure and even remove this mandatory comment. But I think this could lead to unwanted formatted development objects (eg. generated data provider classes, legacy source code items with a non SAP conform style,…). Thus I decided to take the defensive path by introducing the mandatory comment … at least for the first release.
To get the automatic ABAP source code formatting feature up and running three steps are necessary.
1. Installing the abapCi Plugin from the Eclipse Marketplace, if not already done.
2. Enabling the corresponding checkbox in the Eclipse Preferences (Window->Preferences)
3. Adding the above mentioned comment as first line of the development objects which should be autoformatted when saved
Starting from this point it is ensured that on each save or activation of the development object the source code formatting is automatically performed.
Hope that helps to save at least some keystrokes or even better to clear up your abapGit or transport history.
Greetings, Andreas
Great contribution! Is this on GitHub?
Yes, the whole project for the eclipse plugin can be found at:
https://github.com/andau/abapCI
A virtual beer goes to you ;). And dear SAP, please port this option to the good, old SAP GUI.
Thanks and Cheers 🙂
I installed the plug-in, but i get an error. Eclipse Oxygen 3a.
Hi Marcel. The eclipse version seems to be ok. Have you installed the latest ADT?
But lets take a closer look next week on the details of the errormessage. This week I am on vacancies without access to my personal computer.
Greetings, Andreas
Yes, i have the latest ADT installed. But more, next week =)
Hmm, this error I see the first time, but well I am sure its solveable
I made a new version today - 0.3.4, can you please update on this. If this does not solve your issue please post the stack trace of the error (should be in the error log or in the details) then I take a deeper look into this strange behaviour.
Thank you for sharing. I tried but the tool will affect the colors of coding. I am currently using Dark theme. Uninstall of the tool will solve the issue.
before:
after
Hi!
Yes, with the dark theme the color changes are not full supported. If you deactivate the following two checkboxes everything else should work like expected.
Neither of the two are related to the automatic source code formatting.
Greetings, Andreas
Thanks for the information. I will have a try.
Nice Tip! Great feature.
Great feature.
Regards,
Yellappa.
Thanks for sharing this one !!
I was able to add this plugin and #autoformat works.
Thanks,
Pramod
Is this still available?