• 请不要在回答技术问题时复制粘贴 AI 生成的内容
laodao1990
V2EX  ›  程序员

Intellij IDEA Java 代码格式化自动换行如何设置的智能一些?

  •  
  •   laodao1990 · Dec 15, 2017 · 14869 views
    This topic created in 3111 days ago, the information mentioned may be changed or developed.

    IDEA 很好用,但是它的格式化后的风格真不是我喜欢的. 如果一行的代码写的太长,如:

    if(a.aMethod() && a.bMethod && a.cMethod && a.xxxxxxxxMethod && b.cMethod) {
    
    }
    

    我设置了行长度边界,格式化时,超出长度自动换行.然后可能就给我换成这样了:

    if(a.aMethod() && a.bMethod && a.cMethod && a.xxxxxxxxMethod && b
        .cMethod) {
    
    }
    

    甚至这样:

    if(a.aMethod() && a.bMethod && a.cMethod && a.xxxxxxxxMethod && b.cMethod
        ){
    
    }
    

    我记得 Eclipse 可以这样的:

    if(a.aMethod() && a.bMethod && a.cMethod 
        && a.xxxxxxxxMethod && b.cMethod) {
    
    }
    

    不知道 IDEA 能不能设置成这种 Eclipse 风格的格式化??

    Supplement 1  ·  Dec 18, 2017
    感谢各位!
    1 楼的可以导入,但是格式化后的和我需要的还是有所差距.
    我现在用了 2 楼和 3 楼的建议.感觉还可以.
    3 replies    2017-12-15 19:10:12 +08:00
    dozeboy
        1
    dozeboy  
       Dec 15, 2017   ❤️ 2
    我在 Android Studio 上都是直接导入下面文件
    https://github.com/aosp-mirror/platform_development/blob/master/ide/intellij/codestyles/AndroidStyle.xml
    不知道 IDEA 能不能用
    humpy
        2
    humpy  
       Dec 15, 2017   ❤️ 2
    File | Settings | Editor | Code Style | Java > Wrapping and Braces > Binary expressions [Wrap if long]
    qinxi
        3
    qinxi  
       Dec 15, 2017   ❤️ 1
    apply plugin: 'com.github.sherter.google-java-format'
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4780 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 09:54 · PVG 17:54 · LAX 02:54 · JFK 05:54
    ♥ Do have faith in what you're doing.