不信网恋 发表于 2015-11-24 11:30:01

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&#43;&#43;))

使用前:



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() {
&quot;result&quot;.return
}
}
  
  
  使用后:

public class Foo {
String m() {
return &quot;result&quot;;
}
}
  
  
  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(&quot;error&quot;).throw
}
}
  
  使用后:

public class Foo {
void m() {
throw new RuntimeException(&quot;error&quot;);
}
}
  
  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(&quot;test&quot;)
}
}
  
  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, &quot;test&quot;, Toast.LENGTH_SHORT).show();
}
}
  
  


  二、安装
  打开设置,找到插件,输入postfix,第一个出来的就是,然后点击安装即可,安装完成记得需要重新启动Android
Studio。



  
页: [1]
查看完整版本: Android Studio 插件--postfix