· 8 years ago · Jun 04, 2018, 11:58 PM
1import org.jetbrains.annotations.Contract;
2import org.jetbrains.annotations.NotNull;
3
4public class WordUtil {
5
6 @Contract(pure = true)
7 public static boolean isSQLKeyword(@NotNull String s) {
8 String[] keywords = new String[]{
9 "all",
10 "allocate",
11 "alter",
12 "and",
13 "any",
14 "are",
15 "array",
16 "as",
17 "asensitive",
18 "asymmetric",
19 "at",
20 "atomic",
21 "authorization",
22 "begin",
23 "between",
24 "bigint",
25 "binary",
26 "blob",
27 "boolean",
28 "both",
29 "by",
30 "call",
31 "called",
32 "cascaded",
33 "case",
34 "cast",
35 "char",
36 "character",
37 "check",
38 "clob",
39 "close",
40 "collate",
41 "column",
42 "commit",
43 "connect",
44 "constraint",
45 "continue",
46 "corresponding",
47 "create",
48 "cross",
49 "cube",
50 "current",
51 "current_date",
52 "current_default_transform_group",
53 "current_path",
54 "current_role",
55 "current_time",
56 "current_timestamp",
57 "current_transform_group_for_type",
58 "current_user",
59 "cursor",
60 "cycle",
61 "date",
62 "day",
63 "deallocate",
64 "dec",
65 "decimal",
66 "declare",
67 "default",
68 "delete",
69 "deref",
70 "describe",
71 "deterministic",
72 "disconnect",
73 "distinct",
74 "double",
75 "drop",
76 "dynamic",
77 "each",
78 "element",
79 "else",
80 "end",
81 "end-exec",
82 "escape",
83 "except",
84 "exec",
85 "execute",
86 "exists",
87 "external",
88 "false",
89 "fetch",
90 "filter",
91 "float",
92 "for",
93 "foreign",
94 "free",
95 "from",
96 "full",
97 "function",
98 "get",
99 "global",
100 "grant",
101 "group",
102 "grouping",
103 "having",
104 "hold",
105 "hour",
106 "identity",
107 "immediate",
108 "in",
109 "indicator",
110 "inner",
111 "inout",
112 "input",
113 "insensitive",
114 "insert",
115 "int",
116 "integer",
117 "intersect",
118 "interval",
119 "into",
120 "is",
121 "isolation",
122 "join",
123 "language",
124 "large",
125 "lateral",
126 "leading",
127 "left",
128 "like",
129 "local",
130 "localtime",
131 "localtimestamp",
132 "match",
133 "member",
134 "merge",
135 "method",
136 "minute",
137 "modifies",
138 "module",
139 "month",
140 "multiset",
141 "national",
142 "natural",
143 "nchar",
144 "nclob",
145 "new",
146 "no",
147 "none",
148 "not",
149 "null",
150 "numeric",
151 "of",
152 "old",
153 "on",
154 "only",
155 "open",
156 "or",
157 "order",
158 "out",
159 "outer",
160 "output",
161 "over",
162 "overlaps",
163 "parameter",
164 "partition",
165 "precision",
166 "prepare",
167 "primary",
168 "procedure",
169 "range",
170 "reads",
171 "real",
172 "recursive",
173 "ref",
174 "references",
175 "referencing",
176 "regr_avgx",
177 "regr_avgy",
178 "regr_count",
179 "regr_intercept",
180 "regr_r2",
181 "regr_slope",
182 "regr_sxx",
183 "regr_sxy",
184 "regr_syy",
185 "release",
186 "result",
187 "return",
188 "returns",
189 "revoke",
190 "right",
191 "rollback",
192 "rollup",
193 "row",
194 "rows",
195 "savepoint",
196 "scroll",
197 "search",
198 "second",
199 "select",
200 "sensitive",
201 "session_user",
202 "set",
203 "similar",
204 "smallint",
205 "some",
206 "specific",
207 "specifictype",
208 "sql",
209 "sqlexception",
210 "sqlstate",
211 "sqlwarning",
212 "start",
213 "static",
214 "submultiset",
215 "symmetric",
216 "system",
217 "system_user",
218 "table",
219 "then",
220 "time",
221 "timestamp",
222 "timezone_hour",
223 "timezone_minute",
224 "to",
225 "trailing",
226 "translation",
227 "treat",
228 "trigger",
229 "true",
230 "uescape",
231 "union",
232 "unique",
233 "unknown",
234 "unnest",
235 "update",
236 "upper",
237 "user",
238 "using",
239 "value",
240 "values",
241 "var_pop",
242 "var_samp",
243 "varchar",
244 "varying",
245 "when",
246 "whenever",
247 "where",
248 "width_bucket",
249 "window",
250 "with",
251 "within",
252 "without",
253 "year",
254 };
255 return lookupIgnoreCase(keywords, s);
256 }
257
258
259 public static boolean isJavaKeyword(@NotNull String s) {
260 String[] keywords = new String[]{
261 "const",
262 "abstract",
263 "continue",
264 "for",
265 "new",
266 "switch",
267 "assert",
268 "default",
269 "goto",
270 "package",
271 "synchronized",
272 "boolean",
273 "do",
274 "if",
275 "private",
276 "this",
277 "break",
278 "double",
279 "implements",
280 "protected",
281 "throw",
282 "byte",
283 "else",
284 "import",
285 "public",
286 "throws",
287 "case",
288 "enum",
289 "instanceof",
290 "return",
291 "transient",
292 "catch",
293 "extends",
294 "int",
295 "short",
296 "try",
297 "char",
298 "final",
299 "interface",
300 "static",
301 "void",
302 "class",
303 "finally",
304 "long",
305 "strictfp",
306 "volatile",
307 "const",
308 "float",
309 "native",
310 "super",
311 "while",
312 };
313 return lookupIgnoreCase(keywords, s);
314 }
315
316
317 @Contract(pure = true)
318 private static boolean lookupIgnoreCase(@NotNull String[] a, @NotNull String s) {
319 for (String it : a) {
320 if (it.equalsIgnoreCase(s)) {
321 return true;
322 }
323 }
324 return false;
325 }
326}