"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How Can I Prevent Eclipse from Formatting Specific Code Sections?

How Can I Prevent Eclipse from Formatting Specific Code Sections?

Posted on 2025-03-24
Browse:846

How Can I Prevent Eclipse from Formatting Specific Code Sections?

Preventing Eclipse Formatting for Specific Code Sections

When working with code that is formatted semantically across multiple lines, the Eclipse formatter can inadvertently alter the desired formatting. This can be particularly problematic for code like SQL statements, which become difficult to read and maintain when formatted by the IDE.

Eclipse 3.6 and Later: Using Off/On Tags

To address this issue in Eclipse 3.6 and later, a special comment syntax can be used to control formatting:

// @formatter:off
...
// @formatter:on

Within these comment blocks, the Eclipse formatter will be disabled. To enable the formatter within these blocks, use // @formatter:on.

Configuring the Off/On Tags

  1. Navigate to JavaCode StyleFormatter.
  2. Click EditOff/On Tags.
  3. Enable Enable Off/On tags.
  4. Customize the start and end tags if desired.

Additional Considerations

  • Ensure team members using Eclipse are aware of the off/on tags and configure their formatters accordingly.
  • This method does not require any IDE reconfiguration by team members.
  • Avoid placing the off/on tags within Javadoc comments, as this can cause issues with Javadoc generation.

By utilizing these off/on tags, developers can effectively prevent Eclipse from automatically formatting specific sections of Java code, maintaining the desired vertical formatting for ease of reading and maintenance.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3