Android 提升开发效率工具(Template/Plugin)
本文由 Luzhuo 编写,转发请保留该信息.
原文: https://blog.youkuaiyun.com/Rozol/article/details/81947949
Templates(模板)
IntelliJ IDEA 自动编码利器
环境: Windows10 / AndroidStudio3.1
参考资源: https://www.jetbrains.com/help/idea/working-with-source-code.html
自定义代码模板 (Live Templates)
- 模板存放位置:
- AndroidStudio 文件存放于:
C:\Users\LZLuz\.AndroidStudio3.1\config\templates
- AndroidStudio 文件存放于:
- 快速打开: Ctrl+Alt+S
- 简介与使用:
- 自带变量参数
$END$
: 最后都编辑完后光标所处的位置$SELECTION$
: 设置环绕实时代码模板 (就是模板包围代码)- …
- 内置函数:
- annotated(“annotation qname”) - Creates a symbol of type with an annotation that resides at the specified location. For an example, see Live Templates in the iterations group.
- anonymousSuper() - Suggests a supertype for a Kotlin object expression.
- arrayVariable() - Suggests all array variables applicable in the current scope. For an example, see Live Templates in the iterations group.
- blockCommentEnd - Returns the characters that indicate the end of a block comment in the current language context.
- blockCommentStart - Returns the characters that indicate the start of a block comment in the current language context.
- camelCase(String) - Converts a string into camelCase. For example, camelCase(my-text-file), camelCase(my text file), and camelCase(my_text_file) all return myTextFile.
- capitalize(String) - Capitalizes the first letter of the parameter.
- capitalizeAndUnderscore(sCamelCaseName) - Capitalizes all the letters of a CamelCase name passed as the parameter, and inserts an underscore between the parts. For example, capitalizeAndUnderscore(FooBar) returns FOO_BAR.
- castToLeftSideType() - Casts the right-side expression to the left-side expression type. It is used in the iterations group to have a single template for generating both raw-type and Generics Collections.
- className() - Returns the name of the current class (the class where the template is expanded).
- classNameComplete() - This expression substitutes for the class name completion at the variable position.
- clipboard() - Returns the contents of the system clipboard.
- commentEnd() - Returns the characters that indicate the end of a comment in the current language context. The return value is empty if line comments are defined in the current language.
- commentStart() - Returns the characters that indicate the start of a comment in the current language context. If line comments are defined in the current language, their start indicator is preferable.
- complete() - Invokes code completion at the position of the variable.
- completeSmart() - Invokes smart type completion at the position of the variable.
- componentTypeOf() - Returns component type of an array. For an example, see live templates in the iterations group and in the other group.
- concat(expressions…) - Returns a concatenation of all the strings passed to the function as parameters.
- currentPackage() - Returns the current package name.
- date(sDate) - Returns the current system date in the specified format.
- date(): 11/23/12
- date(“dd MMM yyyy”): 23 Nov 2012
- decapitalize(sName) - Replaces the first letter of the parameter with the corresponding lowercase letter.
- descendantClassEnum() - Returns the children of the class specified as a string parameter.
- enum(sCompletionString1,sCompletionString2,…) - Returns a list of comma-separated strings suggested for completion when the template is expanded.
- escapeString(sEscapeString) - Escapes the string specified as the parameter.
- expectedType() - Returns the expected type of the expression into which the template expands. Makes sense if the template expands in the right part of an assignment, after return, etc.
- fileName() - Returns the name of the current file with its extension.
- fileNameWithoutExtension() - Returns the name of the current file without its extension.
- firstWord(sFirstWord) - Returns the first word of the string passed as the parameter.
- groovyScript(“”groovy code”“, arg1) - Returns a Groovy script with the specified code.”
- You can use the groovyScript() function with multiple arguments. The first argument is the text of the script that is executed or the path to the file that contains the script. The next arguments are bound to the _1, _2, _3, …_n variables that are available inside your script. Also, the _editor variable is available inside the script. This variable is bound to the current editor.
- 案例:
groovyScript("_1.take(Math.min(23, _1.length()));", className())
- guessElementType () - Makes a guess on the type of elements stored in a java.util.Collection. To make a guess, IntelliJ IDEA tries to find the places where the elements were added to or extracted from the container.
- iterableComponentType() - Returns the type of an iterable component, such as an array or a collection.
- iterableVariable() - Returns the name of a variable that can be iterated.
- JsArrayVariable() - Returns the name of the current JavaScript array.
- jsClassName() - Returns the name of the current JavaScript class.
- jsComponentTypeOf() - Returns the type of the current JavaScript component.
- jsDefineParameter - Based on the name of the module, returns the parameter from**define([“”module”“], function (>) {}).**
- jsMethodName() - Returns the name of the current JavaScript method.
- jsQualifiedClassName() - Returns the complete name of the current JavaScript class.
- jsSuggestIndexName() - Returns a suggested name for an index variable from most commonly used ones: i, j, k, etc. The names that are not used in the the current scope yet are shown first.
- jsSuggestVariableName() - Returns the suggested name for a variable based on its variable type and initializer expression, according to your code style settings that refer to the variable naming rules.
- For example, if it is a variable that holds an element within an iteration, IntelliJ IDEA makes a guess on the most reasonable name, taking into account the name of the container that is iterated.
- jsSuggestDefaultVariableKind(Boolean) - The Boolean parameter determines whether constants are allowed or not in the current context. If no parameter is specified, constants are allowed. When the templates expands, a drop-down list is shown with var, let, const options for TypeScript and ES6 and with only one var option for earlier JavaS