Home > Java > javaTutorial > How Can I Prevent Eclipse Code Formatter from Reformatting Specific Code Sections?

How Can I Prevent Eclipse Code Formatter from Reformatting Specific Code Sections?

Patricia Arquette
Release: 2024-12-02 04:55:14
Original
928 people have browsed it

How Can I Prevent Eclipse Code Formatter from Reformatting Specific Code Sections?

Disabling Eclipse Code Formatter for Specific Code Sections

Maintaining code that requires vertical formatting, such as SQL statements written as Java strings, can be a challenge when using the Eclipse editor. The Eclipse formatter can deface the semantic formatting of such code, making it more difficult to read and maintain.

The Eclipse @formatter Comment

In Eclipse 3.6, a special comment can be used to disable formatting for specific sections of code. By placing the following comment before and after the code that should not be formatted:

// @formatter:off

// @formatter:on
Copy after login

Users can prevent Eclipse from formatting that specific section.

Enabling Off/On Tags in Eclipse Preferences

To activate this feature, go to:

  • JavaCode StyleFormatter
  • Click Edit
  • Select the Off/On Tags tab
  • Enable Enable Off/On tags

Configure Custom Comment Tags (Optional)

The default values for the Off/On tags are "@formatter:off" and "@formatter:on," but these values can be customized within the preferences.

Additional Notes

  • This preference also allows the user to define one tag to disable and one tag to enable the formatter.
  • Enable the desired flags under Java Formatting to use this feature.
  • Avoid placing these comments within Javadoc comments, as this will cause the Javadoc generation to fail.

The above is the detailed content of How Can I Prevent Eclipse Code Formatter from Reformatting Specific Code Sections?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template