LoginSignup
0
0

More than 5 years have passed since last update.

kotlinで、butterknife → dataBinding移行時の@BindViewの一括置換

Last updated at Posted at 2017-02-08

全部書き換えるのが大変なのだが、下記のようにsublime textとかで正規表現で一発変換すると少し楽だった。

前提条件

  • 変数名がidと同じようになっている時

置換

検索文字:@BindView.+\n.+var (.+): (.+\?) = null
置換文字:val $1: $2 by lazy{ binding?.$1 }


変更前
        @BindView(R.id.itemImage)
        var itemImage: ImageView? = null
        @BindView(R.id.itemName)
        var itemName: TextView? = null

   ↓

変更後
        val itemImage: ImageView? by lazy{ binding?.itemImage }
        val itemName: TextView? by lazy{ binding?.itemName }
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0