forked from keyboardsurfer/idea-live-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AndroidParcelable.xml
122 lines (121 loc) · 8.27 KB
/
AndroidParcelable.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?xml version="1.0" encoding="UTF-8"?>
<templateSet group="AndroidParcelable">
<template name="Parcelable" value="protected $className$(Parcel in) { } @Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel dest, int flags) { } public static final Parcelable.Creator<$className$> CREATOR = new Parcelable.Creator<$className$>() { @Override public $className$ createFromParcel(Parcel in) { return new $className$(in); } @Override public $className$[] newArray(int size) { return new $className$[size]; } };" description="Create a parcelable block for your current class" toReformat="true" toShortenFQNames="true">
<variable name="className" expression="className()" defaultValue="" alwaysStopAt="true" />
<context>
<option name="HTML_TEXT" value="false" />
<option name="HTML" value="false" />
<option name="XSL_TEXT" value="false" />
<option name="XML" value="false" />
<option name="JAVA_CODE" value="false" />
<option name="JAVA_STATEMENT" value="false" />
<option name="JAVA_EXPRESSION" value="false" />
<option name="JAVA_DECLARATION" value="true" />
<option name="JAVA_COMMENT" value="false" />
<option name="JAVA_STRING" value="false" />
<option name="COMPLETION" value="false" />
<option name="GROOVY" value="false" />
<option name="GROOVY_EXPRESSION" value="false" />
<option name="GROOVY_STATEMENT" value="false" />
<option name="GROOVY_DECLARATION" value="false" />
<option name="MAVEN" value="false" />
<option name="OTHER" value="false" />
</context>
</template>
<template name="ParcelableEnum" value="@Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(this.ordinal()); } public static final Parcelable.Creator<$className$> CREATOR = new Parcelable.Creator<$className$>() { @Override public $className$ createFromParcel(Parcel in) { return $className$.values()[in.readInt()]; } @Override public $className$[] newArray(int size) { return new $className$[size]; } };" description="Create a parcelable block for your current enum" toReformat="true" toShortenFQNames="true">
<variable name="className" expression="className()" defaultValue="" alwaysStopAt="true" />
<context>
<option name="HTML_TEXT" value="false" />
<option name="HTML" value="false" />
<option name="XSL_TEXT" value="false" />
<option name="XML" value="false" />
<option name="JAVA_CODE" value="false" />
<option name="JAVA_STATEMENT" value="false" />
<option name="JAVA_EXPRESSION" value="false" />
<option name="JAVA_DECLARATION" value="true" />
<option name="JAVA_COMMENT" value="false" />
<option name="JAVA_STRING" value="false" />
<option name="COMPLETION" value="false" />
<option name="GROOVY" value="false" />
<option name="GROOVY_EXPRESSION" value="false" />
<option name="GROOVY_STATEMENT" value="false" />
<option name="GROOVY_DECLARATION" value="false" />
<option name="MAVEN" value="false" />
<option name="OTHER" value="false" />
</context>
</template>
<template name="ParcelableEnumTest" value="@Test public void testDescribeContents() throws Exception { for ($className$ value : $className$.values()) { assertEquals(0, value.describeContents()); } } @Test public void testWriteToParcel() throws Exception { Parcel parcel; for ($className$ value : $className$.values()) { parcel = Parcel.obtain(); Parcel parceled$className$ = ParcelableHelper.writeToParcelAndResetDataPosition(value, 0); value.writeToParcel(parcel, 0); parcel.setDataPosition(0); $className$ unparceled$className$ = $className$.CREATOR.createFromParcel(parceled$className$); assertEquals(value, unparceled$className$); } } @Test public void testArrayParcelable() throws Exception { $className$[] values = $className$.CREATOR.newArray($className$.values().length); assertEquals($className$.values().length, values.length); }" description="Creates basic parcelable enum test methods" toReformat="false" toShortenFQNames="true">
<variable name="className" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="HTML_TEXT" value="false" />
<option name="HTML" value="false" />
<option name="XSL_TEXT" value="false" />
<option name="XML" value="false" />
<option name="JAVA_CODE" value="false" />
<option name="JAVA_STATEMENT" value="false" />
<option name="JAVA_EXPRESSION" value="false" />
<option name="JAVA_DECLARATION" value="true" />
<option name="JAVA_COMMENT" value="false" />
<option name="JAVA_STRING" value="false" />
<option name="COMPLETION" value="false" />
<option name="GROOVY" value="false" />
<option name="GROOVY_EXPRESSION" value="false" />
<option name="GROOVY_STATEMENT" value="false" />
<option name="GROOVY_DECLARATION" value="false" />
<option name="MAVEN" value="false" />
<option name="OTHER" value="false" />
</context>
</template>
<template name="ParcelBoolean" value="dest.writeInt($bool$ ? 0 : 1);" description="writes a single boolean value to a parcel" toReformat="false" toShortenFQNames="true">
<variable name="bool" expression="" defaultValue="" alwaysStopAt="true" />
<context />
</template>
<template name="UnparcelBoolean" value="$bool$ = 0 == in.readInt();" description="reads a single boolean value from a parcel" toReformat="false" toShortenFQNames="true">
<variable name="bool" expression="" defaultValue="" alwaysStopAt="true" />
<context />
</template>
<template name="UnparcelIntArray" value="int $read$[] = in.createIntArray(); in.readIntArray($read$);" description="Unparcels an int array" toReformat="false" toShortenFQNames="true">
<variable name="read" expression="suggestVariableName()" defaultValue="" alwaysStopAt="true" />
<context>
<option name="HTML_TEXT" value="false" />
<option name="HTML" value="false" />
<option name="XSL_TEXT" value="false" />
<option name="XML" value="false" />
<option name="JAVA_CODE" value="false" />
<option name="JAVA_STATEMENT" value="true" />
<option name="JAVA_EXPRESSION" value="false" />
<option name="JAVA_DECLARATION" value="false" />
<option name="JAVA_COMMENT" value="false" />
<option name="JAVA_STRING" value="false" />
<option name="COMPLETION" value="false" />
<option name="GROOVY" value="false" />
<option name="GROOVY_EXPRESSION" value="false" />
<option name="GROOVY_STATEMENT" value="false" />
<option name="GROOVY_DECLARATION" value="false" />
<option name="MAVEN" value="false" />
<option name="OTHER" value="false" />
</context>
</template>
<template name="UnparcelStringArray" value="String $read$[] = in.createStringArray(); in.readStringArray($read$);" description="Unparcels a String array" toReformat="false" toShortenFQNames="true">
<variable name="read" expression="suggestVariableName()" defaultValue="" alwaysStopAt="true" />
<context>
<option name="HTML_TEXT" value="false" />
<option name="HTML" value="false" />
<option name="XSL_TEXT" value="false" />
<option name="XML" value="false" />
<option name="JAVA_CODE" value="false" />
<option name="JAVA_STATEMENT" value="true" />
<option name="JAVA_EXPRESSION" value="false" />
<option name="JAVA_DECLARATION" value="false" />
<option name="JAVA_COMMENT" value="false" />
<option name="JAVA_STRING" value="false" />
<option name="COMPLETION" value="false" />
<option name="GROOVY" value="false" />
<option name="GROOVY_EXPRESSION" value="false" />
<option name="GROOVY_STATEMENT" value="false" />
<option name="GROOVY_DECLARATION" value="false" />
<option name="MAVEN" value="false" />
<option name="OTHER" value="false" />
</context>
</template>
</templateSet>