1 /**
2 * Copyright 2006-2016 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.mybatis.generator.api.dom.java;
17
18 import java.util.HashSet;
19 import java.util.Set;
20
21 /**
22 * This class contains a list of Java reserved words.
23 *
24 * @author Jeff Butler
25 *
26 */
27 public class JavaReservedWords {
28
29 private static Set<String> RESERVED_WORDS;
30
31 static {
32 String[] words = { "abstract", //$NON-NLS-1$
33 "assert", //$NON-NLS-1$
34 "boolean", //$NON-NLS-1$
35 "break", //$NON-NLS-1$
36 "byte", //$NON-NLS-1$
37 "case", //$NON-NLS-1$
38 "catch", //$NON-NLS-1$
39 "char", //$NON-NLS-1$
40 "class", //$NON-NLS-1$
41 "const", //$NON-NLS-1$
42 "continue", //$NON-NLS-1$
43 "default", //$NON-NLS-1$
44 "do", //$NON-NLS-1$
45 "double", //$NON-NLS-1$
46 "else", //$NON-NLS-1$
47 "enum", //$NON-NLS-1$
48 "extends", //$NON-NLS-1$
49 "final", //$NON-NLS-1$
50 "finally", //$NON-NLS-1$
51 "float", //$NON-NLS-1$
52 "for", //$NON-NLS-1$
53 "goto", //$NON-NLS-1$
54 "if", //$NON-NLS-1$
55 "implements", //$NON-NLS-1$
56 "import", //$NON-NLS-1$
57 "instanceof", //$NON-NLS-1$
58 "int", //$NON-NLS-1$
59 "interface", //$NON-NLS-1$
60 "long", //$NON-NLS-1$
61 "native", //$NON-NLS-1$
62 "new", //$NON-NLS-1$
63 "package", //$NON-NLS-1$
64 "private", //$NON-NLS-1$
65 "protected", //$NON-NLS-1$
66 "public", //$NON-NLS-1$
67 "return", //$NON-NLS-1$
68 "short", //$NON-NLS-1$
69 "static", //$NON-NLS-1$
70 "strictfp", //$NON-NLS-1$
71 "super", //$NON-NLS-1$
72 "switch", //$NON-NLS-1$
73 "synchronized", //$NON-NLS-1$
74 "this", //$NON-NLS-1$
75 "throw", //$NON-NLS-1$
76 "throws", //$NON-NLS-1$
77 "transient", //$NON-NLS-1$
78 "try", //$NON-NLS-1$
79 "void", //$NON-NLS-1$
80 "volatile", //$NON-NLS-1$
81 "while" //$NON-NLS-1$
82 };
83
84 RESERVED_WORDS = new HashSet<String>(words.length);
85
86 for (String word : words) {
87 RESERVED_WORDS.add(word);
88 }
89 }
90
91 public static boolean containsWord(String word) {
92 boolean rc;
93
94 if (word == null) {
95 rc = false;
96 } else {
97 rc = RESERVED_WORDS.contains(word);
98 }
99
100 return rc;
101 }
102
103 /**
104 * Utility class - no instances allowed
105 */
106 private JavaReservedWords() {
107 }
108 }