You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置Eclipse代码格式化工具在赋值运算符处换行

Configure Eclipse Formatter to Wrap Long Assignment Lines Over 120 Characters

Got it, let's get this sorted out for you! Here's a step-by-step guide to tweak Eclipse's code formatter so it wraps those lengthy assignment lines exactly how you want:

  • Open the formatter settings: Go to Window → Preferences → Java → Code Style → Formatter
  • Create an editable profile: Since you can't modify the default built-in profiles directly, click the New button, give your custom profile a name (like "Custom 120 Line Width"), and hit OK to duplicate the default settings.
  • Navigate to Line Wrapping rules: Switch to the Line Wrapping tab in the formatter editor.
  • Target assignment expressions: In the left-hand Wrapping settings pane, expand Expressions and select Assignments.
  • Set up the wrapping policy:
    • Change the Line wrapping policy to Wrap when necessary — this tells Eclipse to only split the line once it exceeds your 120-character limit.
    • Under Settings for wrapped lines, adjust the indentation to your preference. Most folks use Indent by one level so the wrapped part aligns neatly under the start of the line, or Indent on column if you want it to line up with the assignment operator (=).
    • Double-check that your Maximum line width (found in the General settings section of the Line Wrapping tab) is still set to 120 to ensure the trigger works correctly.
  • Optional: Tame long generics: If you also want the generic type arguments to wrap when they're too long, expand Expressions → Generic type arguments and apply the same Wrap when necessary policy there.

Once you save these settings (click Apply then OK), reformat your code with Ctrl+Shift+F. Your example line will now look something like this:

private Map<Instruction, LocalRegisterAssignmentInformation> instructionRegisterMap = 
    new IdentityHashMap<Instruction, LocalRegisterAssignmentInformation>();

Or if you enabled generic wrapping:

private Map<Instruction, LocalRegisterAssignmentInformation> instructionRegisterMap = 
    new IdentityHashMap<>(
        Instruction, 
        LocalRegisterAssignmentInformation
    );

A quick heads-up: If some lines still don't wrap as expected, check for inline formatter comments (// @formatter:off) that might be overriding the global settings, or verify that your custom profile is selected as the active formatter.

内容的提问来源于stack exchange,提问作者Rajat Khanna

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:59:20