• Eclipse保存文件时自动格式化代码


    实现效果:Ctrl+S会自动格式化并保存代码。

     

    应用上图所示效果之后,在每次对Eclipse保存的时候都会实现自动格式化代码。

    1. Fomated All lines,格式化该文件的所有代码;还是 Format edited lines 的好,因为如果是修改别人的代码,破坏别人的代码风格就不好了。

    2. 当然了Ctrl + Shift + F运来格式化代码,也是非常不错的。

    3. 配置eclipse-formatter.xml文件下载eclipse-formatter.xml文件,放到eclipse安装目录下。Eclipse中,选择Windows->Preferences->code style。选择 Formatter 选择Import,找到eclipse-formatter.xml的文件目录,选择该文件,选择OK导入。

    /**
     * A sample source file for the code formatter preview
     */
    
    package mypackage;
    
    import java.util.LinkedList;
    
    public class MyIntStack {
        private final LinkedList fStack;
    
        public MyIntStack() {
        fStack = new LinkedList();
        }
    
        public int pop() {
        return ((Integer) fStack.removeFirst()).intValue();
        }
    
        public void push(int elem) {
        fStack.addFirst(new Integer(elem));
        }
    
        public boolean isEmpty() {
        return fStack.isEmpty();
        }
    }

    上面代码是Formatter的格式。但是有一个问题,自动保存的时候,代码的自动换行会把代码搞的特别难看。

    解决办法就是:如上所示操作,指定800行再换行就好了。

      最后建议,最好团队统一来使用格式,不然的话,每次保存的时候,引起行数的变化,SVN下次又会提交,频繁提交这些不同格式问题的文件是没有意义的。

     

     

     

  • 相关阅读:
    删除commit(暂存区)中的文件(git)
    bower安装使用以及git安装
    compass模块----Utilities----Sprites精灵图合图
    compass模块----Utilities
    compass模块----Helpers
    compass模块
    compass安装
    Sass@规则
    Sass函数--颜色函数--Opacity函数
    Sass函数--颜色函数--HSL函数
  • 原文地址:https://www.cnblogs.com/RunForLove/p/5217211.html
Copyright © 2020-2023  润新知