-
Notifications
You must be signed in to change notification settings - Fork 755
/
java.py
307 lines (229 loc) · 7.51 KB
/
java.py
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
from talon import Context, Module, actions, settings
ctx = Context()
mod = Module()
ctx.matches = r"""
code.language: java
"""
# Primitive Types
java_primitive_types = {
"boolean": "boolean",
"int": "int",
"float": "float",
"byte": "byte",
"double": "double",
"short": "short",
"long": "long",
"char": "char",
"void": "void",
}
# Java Boxed Types
java_boxed_types = {
"Byte": "Byte",
"Integer": "Integer",
"Double": "Double",
"Short": "Short",
"Float": "Float",
"Long": "Long",
"Boolean": "Boolean",
"Character": "Character",
"Void": "Void",
}
mod.list("java_boxed_type", desc="Java Boxed Types")
ctx.lists["self.java_boxed_type"] = java_boxed_types
# Common Classes
java_common_classes = {
"Object": "Object",
"string": "String",
"thread": "Thread",
"exception": "Exception",
}
mod.list("java_common_class", desc="Java Common Classes")
ctx.lists["self.java_common_class"] = java_common_classes
# Java Generic Data Structures
java_generic_data_structures = {
# Interfaces
"set": "Set",
"list": "List",
"queue": "Queue",
"deque": "Deque",
"map": "Map",
# Classes
"hash set": "HashSet",
"array list": "ArrayList",
"hash map": "HashMap",
}
unboxed_types = java_primitive_types.copy()
unboxed_types.update(java_common_classes)
unboxed_types.update(java_generic_data_structures)
ctx.lists["user.code_type"] = unboxed_types
mod.list("java_generic_data_structure", desc="Java Generic Data Structures")
ctx.lists["self.java_generic_data_structure"] = java_generic_data_structures
# Java Modifies
java_modifiers = {
"public": "public",
"private": "private",
"protected": "protected",
"static": "static",
"synchronized": "synchronized",
"volatile": "volatile",
"transient": "transient",
"abstract": "abstract",
"interface": "interface",
"final": "final",
}
mod.list("java_modifier", desc="Java Modifiers")
ctx.lists["self.java_modifier"] = java_modifiers
@ctx.action_class("user")
class UserActions:
def code_operator_lambda():
actions.insert(" -> ")
def code_operator_subscript():
actions.user.insert_between("[", "]")
def code_operator_assignment():
actions.insert(" = ")
def code_operator_subtraction():
actions.insert(" - ")
def code_operator_subtraction_assignment():
actions.insert(" -= ")
def code_operator_addition():
actions.insert(" + ")
def code_operator_addition_assignment():
actions.insert(" += ")
def code_operator_multiplication():
actions.insert(" * ")
def code_operator_multiplication_assignment():
actions.insert(" *= ")
def code_operator_exponent():
actions.insert(" ^ ")
def code_operator_division():
actions.insert(" / ")
def code_operator_division_assignment():
actions.insert(" /= ")
def code_operator_modulo():
actions.insert(" % ")
def code_operator_modulo_assignment():
actions.insert(" %= ")
def code_operator_equal():
actions.insert(" == ")
def code_operator_not_equal():
actions.insert(" != ")
def code_operator_greater_than():
actions.insert(" > ")
def code_operator_greater_than_or_equal_to():
actions.insert(" >= ")
def code_operator_less_than():
actions.insert(" < ")
def code_operator_less_than_or_equal_to():
actions.insert(" <= ")
def code_operator_and():
actions.insert(" && ")
def code_operator_or():
actions.insert(" || ")
def code_operator_bitwise_and():
actions.insert(" & ")
def code_operator_bitwise_and_assignment():
actions.insert(" &= ")
def code_operator_increment():
actions.insert("++")
def code_operator_bitwise_or():
actions.insert(" | ")
def code_operator_bitwise_exclusive_or():
actions.insert(" ^ ")
def code_operator_bitwise_left_shift():
actions.insert(" << ")
def code_operator_bitwise_left_shift_assignment():
actions.insert(" <<= ")
def code_operator_bitwise_right_shift():
actions.insert(" >> ")
def code_operator_bitwise_right_shift_assignment():
actions.insert(" >>= ")
def code_self():
actions.insert("this")
def code_operator_object_accessor():
actions.insert(".")
def code_insert_null():
actions.insert("null")
def code_insert_is_null():
actions.insert(" == null")
def code_insert_is_not_null():
actions.insert(" != null")
def code_state_if():
actions.user.insert_between("if (", ") ")
def code_state_else_if():
actions.user.insert_between("else if (", ") ")
def code_state_else():
actions.insert("else ")
actions.key("enter")
def code_state_switch():
actions.user.insert_between("switch (", ") ")
def code_state_case():
actions.insert("case \nbreak;")
actions.edit.up()
def code_state_for():
actions.user.insert_between("for (", ") ")
def code_state_while():
actions.user.insert_between("while (", ") ")
def code_break():
actions.insert("break;")
def code_next():
actions.insert("continue;")
def code_insert_true():
actions.insert("true")
def code_insert_false():
actions.insert("false")
def code_define_class():
actions.insert("class ")
def code_import():
actions.insert("import ")
def code_state_return():
actions.insert("return ")
def code_comment_line_prefix():
actions.insert("// ")
def code_insert_function(text: str, selection: str):
text += f"({selection or ''})"
actions.user.paste(text)
actions.edit.left()
def code_private_function(text: str):
"""Inserts private function declaration"""
result = "private void {}".format(
actions.user.formatted_text(
text, settings.get("user.code_private_function_formatter")
)
)
actions.user.code_insert_function(result, None)
def code_private_static_function(text: str):
"""Inserts private static function"""
result = "private static void {}".format(
actions.user.formatted_text(
text, settings.get("user.code_private_function_formatter")
)
)
actions.user.code_insert_function(result, None)
def code_protected_function(text: str):
result = "void {}".format(
actions.user.formatted_text(
text, settings.get("user.code_protected_function_formatter")
)
)
actions.user.code_insert_function(result, None)
def code_protected_static_function(text: str):
result = "static void {}".format(
actions.user.formatted_text(
text, settings.get("user.code_protected_function_formatter")
)
)
actions.user.code_insert_function(result, None)
def code_public_function(text: str):
result = "public void {}".format(
actions.user.formatted_text(
text, settings.get("user.code_public_function_formatter")
)
)
actions.user.code_insert_function(result, None)
def code_public_static_function(text: str):
result = "public static void {}".format(
actions.user.formatted_text(
text, settings.get("user.code_public_function_formatter")
)
)
actions.user.code_insert_function(result, None)