VOOZH about

URL: https://qiita.com/takahirom/items/ac1d1b08351610dfcc43

⇱ AndroidStudioのPostfix Completionで爆速コーディング #IntelliJ - Qiita


👁 Image
389

Go to list of users who liked

380

Share on X(Twitter)

Share on Facebook

Add to Hatena Bookmark

More than 5 years have passed since last update.

@takahiromin👁 Image
株式会社サイバーエージェント

AndroidStudioのPostfix Completionで爆速コーディング

389
Posted at

AndroidStudioの元になっているIntelliJ IdeaにはPostfix Completionという機能があります。
例えば 変数.parを入力してエンターを押すと (変数)というようにカッコで囲ってくれたりします。
これを利用して爆速でコーディングしましょう!

.var

testInstance.var
Test test = testInstance;
みたいに代入してローカル変数にすることができます。
普通に代入にも使えますが、これは一行が長くなってしまった時に変数に代入して分かりやすくしたりすることができます。

Toast.makeText(context, context.getString(R.string.app_name), Toast.LENGTH_SHORT).show();

final String name = context.getString(R.string.app_name);
Toast.makeText(context, name, Toast.LENGTH_SHORT).show();

👁 postfix17.gif

.field

メンバ変数に代入してくれます。
👁 postfix12.gif

.notnull (.nnでも可)

NULLチェックのif文が作れます。
👁 postfix14.gif

.for

Listのインスタンスからfor文作れます
👁 postfix15.gif

他にもいろんなPostfix Completionがあるので試してみてください!(設定から確認できます。)
👁 image

Android特化のPostfix Completion

標準では"test".logLog.d(TAG,"test");などはサポートされていません。

なので"Android Postfix Completion"というプラグインをリリースしました。
AndroidStudioでPreferences -> Plugins -> Browse repositoriesで"Android Postfix Completion"と検索するとインストールできます。

Postfix Expression Description Example
.toast トースト表示 Toast.makeText(context, expr, Toast.LENGTH_SHORT).show()
.log メンバ変数に"TAG"があったらそれを利用し、なければクラス名をタグとして利用してロギングする Log.d(TAG, expr)
.logd .logにif (BuildConfig.DEBUG)を追加したもの if (BuildConfig.DEBUG) Log.d(TAG, expr)

👁 postfix16.gif

https://github.com/takahirom/android-postfix-plugin
現在まだ補完できる数が多くないので、こういう補完がほしいなどがございましたらプルリクエストかissueを立てていただけると嬉しいです。

389

Go to list of users who liked

380
1

Go to list of comments

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
389

Go to list of users who liked

380