Last active
December 10, 2020 01:35
-
-
Save jonfhancock/5c2d52e60f3038fe900b331fd474dea9 to your computer and use it in GitHub Desktop.
Android Studio live templates. Apply them following directions here: https://www.jetbrains.com/help/idea/sharing-live-templates.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<templateSet group="TimberLogKotlin"> | |
<template name="tlogd" value="timber.log.Timber.d("$KOTLIN_FUNCTION_NAME$: $content$")" description="Timber.d(String)" toReformat="true" toShortenFQNames="true"> | |
<variable name="KOTLIN_FUNCTION_NAME" expression="kotlinFunctionName()" defaultValue="" alwaysStopAt="false" /> | |
<variable name="content" expression="" defaultValue="" alwaysStopAt="true" /> | |
<context> | |
<option name="KOTLIN_STATEMENT" value="true" /> | |
</context> | |
</template> | |
<template name="tloge" value="timber.log.Timber.e($exception$, "$KOTLIN_FUNCTION_NAME$: $content$")" description="Timber.e(Exception, String)" toReformat="true" toShortenFQNames="true"> | |
<variable name="exception" expression="" defaultValue="" alwaysStopAt="true" /> | |
<variable name="KOTLIN_FUNCTION_NAME" expression="kotlinFunctionName()" defaultValue="" alwaysStopAt="false" /> | |
<variable name="content" expression="" defaultValue="" alwaysStopAt="true" /> | |
<context> | |
<option name="KOTLIN_STATEMENT" value="true" /> | |
</context> | |
</template> | |
<template name="tlogi" value="timber.log.Timber.i("$KOTLIN_FUNCTION_NAME$: $content$")" description="Timber.i(String)" toReformat="true" toShortenFQNames="true"> | |
<variable name="KOTLIN_FUNCTION_NAME" expression="kotlinFunctionName()" defaultValue="" alwaysStopAt="false" /> | |
<variable name="content" expression="" defaultValue="" alwaysStopAt="true" /> | |
<context> | |
<option name="KOTLIN_STATEMENT" value="true" /> | |
</context> | |
</template> | |
<template name="tlogm" value="timber.log.Timber.d($content$)" description="Log method name and its arguments" toReformat="true" toShortenFQNames="true"> | |
<variable name="content" expression="groovyScript("def paramNames = _2.collect {it + ' = [%s]'}.join(', '); def paramValues = _2.collect {it}.join(', '); return '\"' + _1 + '() called' + (paramNames.empty ? '' : ' with: ' + paramNames) + '\"'+(paramValues.empty ? '' : ', ' + paramValues) ", kotlinFunctionName(), functionParameters())" defaultValue="" alwaysStopAt="false" /> | |
<context> | |
<option name="KOTLIN_STATEMENT" value="true" /> | |
</context> | |
</template> | |
<template name="tlogr" value="timber.log.Timber.d("$KOTLIN_FUNCTION_NAME$() returned: %s", $result$)" description="Log result of this method" toReformat="true" toShortenFQNames="true"> | |
<variable name="KOTLIN_FUNCTION_NAME" expression="kotlinFunctionName()" defaultValue="" alwaysStopAt="false" /> | |
<variable name="result" expression="" defaultValue="" alwaysStopAt="true" /> | |
<context> | |
<option name="KOTLIN_STATEMENT" value="true" /> | |
</context> | |
</template> | |
<template name="tlogw" value="timber.log.Timber.w($exception$, "$KOTLIN_FUNCTION_NAME$: $content$")" description="Timber.w(Exception, String)" toReformat="true" toShortenFQNames="true"> | |
<variable name="exception" expression="" defaultValue="" alwaysStopAt="true" /> | |
<variable name="KOTLIN_FUNCTION_NAME" expression="kotlinFunctionName()" defaultValue="" alwaysStopAt="false" /> | |
<variable name="content" expression="" defaultValue="" alwaysStopAt="true" /> | |
<context> | |
<option name="KOTLIN_STATEMENT" value="true" /> | |
</context> | |
</template> | |
<template name="twtf" value="timber.log.Timber.wtf($exception$, "$KOTLIN_FUNCTION_NAME$: $content$")" description="Timber.wtf(Exception, String)" toReformat="true" toShortenFQNames="true"> | |
<variable name="exception" expression="" defaultValue="" alwaysStopAt="true" /> | |
<variable name="KOTLIN_FUNCTION_NAME" expression="kotlinFunctionName()" defaultValue="" alwaysStopAt="false" /> | |
<variable name="content" expression="" defaultValue="" alwaysStopAt="true" /> | |
<context> | |
<option name="KOTLIN_STATEMENT" value="true" /> | |
</context> | |
</template> | |
</templateSet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The first one is intended to address the problem expressed here: https://twitter.com/AdamMc331/status/1331662669712158723?s=20
When used inside a function in a class, the live template will prefill the class and function names.

When used in a top level function, the cursor is placed so that you can type something for the class name (or not).

When used in a class, but outside a function (e.g. property assignment), the template will place the cursor so that you can type something for the function name (or not).