V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
laodao1990
V2EX  ›  程序员

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

  •  
  •   laodao1990 · 2017-12-15 18:20:42 +08:00 · 14217 次点击
    这是一个创建于 2317 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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 风格的格式化??

    第 1 条附言  ·  2017-12-18 14:55:05 +08:00
    感谢各位!
    1 楼的可以导入,但是格式化后的和我需要的还是有所差距.
    我现在用了 2 楼和 3 楼的建议.感觉还可以.
    3 条回复    2017-12-15 19:10:12 +08:00
    dozeboy
        1
    dozeboy  
       2017-12-15 18:28:56 +08:00   ❤️ 2
    我在 Android Studio 上都是直接导入下面文件
    https://github.com/aosp-mirror/platform_development/blob/master/ide/intellij/codestyles/AndroidStyle.xml
    不知道 IDEA 能不能用
    humpy
        2
    humpy  
       2017-12-15 18:31:17 +08:00   ❤️ 2
    File | Settings | Editor | Code Style | Java > Wrapping and Braces > Binary expressions [Wrap if long]
    qinxi
        3
    qinxi  
       2017-12-15 19:10:12 +08:00   ❤️ 1
    apply plugin: 'com.github.sherter.google-java-format'
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2440 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 15:57 · PVG 23:57 · LAX 08:57 · JFK 11:57
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.