Android Studio 插件--postfix

一、介紹

同志們,是不是都已經從Eclipse轉到了Android Studio,沒轉的同志們,在此給個建議,儘快轉到Android Studio吧,能提高工作效率,何樂而不爲。已經在用Android Studio開發的,是不是覺得以前Eclipse的sys的快捷輸入是多麼方便,怎麼Android Studio就不能這麼方便的書寫呢,不要着急,今天介紹的這個插件,可以讓你開發更加輕鬆,看完你會叫好,會去下載的。


二、使用

下面先睹爲快




下面開始具體介紹下插件功能:

1.布爾表達式(非)——!(!expr)

使用前:

public class Foo {
     void m(boolean b) {
         m(b!);
     }
 }

使用後:

public class Foo {
    void m(boolean b) {
        m(!b);
    }
}  

2.創建單元測試的斷言assert——assert(assert expr)
使用前:

public void m(boolean value) {
  value.assert
}

使用後:

public void m(boolean value) {
  assert value;
}

3.包含的表達式——cast((SomeType) expr)

使用前:

public class Foo {
    void m(Object o) {
        o.cast
    }
}

使用後:

public class Foo {
    void m(Object o) {
        (() o)
    }
}

4.檢查Boolean爲假——else(if(!expr))

使用前:

public class Foo {
    void m(boolean b) {
        b.else
    }
}

使用後:

public class Foo {
    void m(boolean b) {
        if (!b) {

        }
    }
}

5.生成field——field(myField = expr)

使用前:

public class Foo {
  public Foo(int arg) {
    arg.field
  }
}

使用後:

public class Foo {
    private int foo;

    public Foo(int arg) {
        foo = arg;
    }
}

6.for循環——for(for(T item : expr))

使用前:

public class Foo {
    void m() {
        int[] values = {1, 2, 3};
        values.for
    }
}

使用後:

public class Foo {
    void m() {
        int[] values = {1, 2, 3};
        for (int value : values) {

        }
    }
}

7.for循環從頭開始——fori(for(int i = 0; i < expr.length; i++))

使用前:

public class Foo {
    void m() {
        int foo = 100;
        foo.fori
    }
}

使用後:

public class Foo {
    void m() {
        int foo = 100;
        for (int i = 0; i < foo; i++) {

        }
    }
}

8.String的format函數——format(String.format(expr))

使用前:

public void m(String value) {
  value.format
}

使用後:

public void m(String value) {
  String.format(value, );
}

9.for循環從最尾開始——forr(for(int i = expr.length-1;i >= 0;i--))

使用前:

public class Foo {
    void m() {
        int foo = 100;
        foo.forr
    }
}

使用後:

public class Foo {
    void m() {
        int foo = 100;
        for (int i = foo; i > 0; i--) {

        }
    }
}

10.if語句——if(if(expr))

使用前:

public class Foo {
    void m(boolean b) {
        b.if
    }
}

使用後:

public class Foo {
    void m(boolean b) {
        if (b) {

        }
    }
}

11.ins語句——inst(expr instanceof Type ? ((Type)expr).:null)

使用前:

public class Foo {
    void m(Object o) {
        o.inst
    }
}

使用後:

public class Foo {
    void m(Object o) {
        o instanceof  ? (() o) : null;
    }
}

12.instanceof語句——inst(expr instanceof Type ? ((Type)expr).:null)

使用前:

public class Foo {
    void m(Object o) {
        o.instanceof
    }
}

使用後:

public class Foo {
    void m(Object o) {
        o instanceof  ? (() o) : null;
    }
}

13.not null語句——nn(if(expr != null))

使用前:

public class Foo {
    void m(Object o) {
        o.nn
    }
}

使用後:

public class Foo {
    void m(Object o) {
        if (o != null){

        }
    }
}

14.布爾表達式(非)——not(!expr)

使用前:

public class Foo {
     void m(boolean b) {
         m(b.not);
     }
 }

使用後:

public class Foo {
    void m(boolean b) {
        m(!b);
    }
}  

15.not null語句——notnull(if(expr != null))

使用前:

public class Foo {
    void m(Object o) {
        o.notnull
    }
}

使用後:

public class Foo {
    void m(Object o) {
        if (o != null){

        }
    }
}

16.null語句——null(if(expr == null))

使用前:

public class Foo {
    void m(Object o) {
        o.null
    }
}

使用後:

public class Foo {
    void m(Object o) {
        if (o == null){

        }
    }
}

17.括號包含——par((expr))

使用前:

public class Foo {
    void m(Object o) {
        o.par
    }
}

使用後:

public class Foo {
    void m(Object o) {
        (o)
    }
}

18.return語句——return(return expr)

使用前:

public class Foo {
    String m() {
        "result".return
    }
}

使用後:

public class Foo {
    String m() {
        return "result";
    }
}

19.sys語句——sout(System.out.println(expr))

使用前:

public class Foo {
  void m(boolean b) {
    b.sout
  }
}

使用後:

public class Foo {
  void m(boolean b) {
      System.out.println(b);
  }
}

20.switch語句——switch(switch(expr))

使用前:

public enum Foo {
    A, B, C;

    void f(Foo foo) {
        foo.switch
    }
}

使用後:

public enum Foo {
    A, B, C;

    void f(Foo foo) {
        switch (foo) {

        }
    }
}

21.鎖定表達式——synchronized(synchronized(expr))

使用前:

public class Foo {
    void m(Object o) {
        o.synchronized
    }
}

使用後:

public class Foo {
    void m(Object o) {
        synchronized (o) {

        }
    }
}

22.異常語句——throw(throw expr)

使用前:

public class Foo {
    void m() {
        new RuntimeException("error").throw
    }
}

使用後:

public class Foo {
    void m() {
        throw new RuntimeException("error");
    }
}

23.捕獲異常語句——try(try { exp } catch (Exception e))

使用前:

public void m2() {
  m().try
}

public void m() throws CheckedException { }

使用後:

public void m2() {
  try {
    m();
  } catch(CheckedException e) {
    e.printStackTrace();
  }
}

public void m() throws CheckedException { }

24.捕獲異常語句——twr(try(Type f = new Type()) catch (Exception e))

使用前:

public class Foo {
    void m() {
        getStream().twr
    }

    AutoCloseable getStream()
    {
        return null;
    }
}

使用後:

public class Foo {
    void m() {
        try (AutoCloseable stream = getStream()) {

        } catch (Exception e) {
        }
    }

    AutoCloseable getStream()
    {
        return null;
    }
}

25.引入變量表達式——var(T name = expr)

使用前:

public class Foo {
    void m(Object o) {
        o instanceof String.var
    }
}

使用後:

public class Foo {
    void m(Object o) {
        boolean foo = o instanceof String;
    }
}

26.while表達式——while(while(expr))

使用前:

public class Foo {
    void m(boolean x) {
        x.while
        return;
    }
}

使用後:

public class Foo {
    void m(boolean x) {
        while (x)
        return;
    }
}

27.判空表達式——isemp(TextUtils.isEmpty(expr))

使用前:

public class Foo {
  void m(Object o) {
    o.isemp
  }
}

使用後:

import com.google.common.base.Preconditions;

public class Foo {
  void m(Object o) {
      TextUtils.isEmpty("test")
  }
}

28.log輸出表達式——log(Log.d(TAG,expr);)

使用前:

public class Foo {
  void m(Object o) {
    o.log
  }
}

使用後:

import com.google.common.base.Preconditions;

public class Foo {
  void m(Object o) {
      Log.d(TAG, o);
  }
}

29.debug模式的log輸出表達式——logd(if(BuildConfig.DEBUG) Log.d(TAG,expr);)

使用前:

public class Foo {
  void m(Object o) {
    o.logd
  }
}

使用後:

import com.google.common.base.Preconditions;

public class Foo {
  void m(Object o) {
      if (BuildConfig.DEBUG) Log.d(TAG, o);
  }
}

30.吐司輸出表達式——toast(Toast.makeText(context,expr,Toast.LENGTH_SHORT).show();)

使用前:

public class Foo {
  void m(Object o) {
    o.toast
  }
}

使用後:

import com.google.common.base.Preconditions;

public class Foo {
  void m(Object o) {
      Toast.makeText(MyActivity.this, "test", Toast.LENGTH_SHORT).show();
  }
}


二、安裝

打開設置,找到插件,輸入postfix,第一個出來的就是,然後點擊安裝即可,安裝完成記得需要重新啓動Android Studio。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章