01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.helpers;
19:
20: import java.util.Arrays;
21: import java.util.HashSet;
22: import java.util.Set;
23:
24: public final class JavaUtils {
25:
26: /** Use this character as suffix */
27: static final char KEYWORD_PREFIX = '_';
28:
29: /**
30: * These are java keywords as specified at the following URL.
31: * http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#229308
32: * Note that false, true, and null are not strictly keywords; they are
33: * literal values, but for the purposes of this array, they can be treated
34: * as literals.
35: */
36: private static final Set<String> KEYWORDS = new HashSet<String>(
37: Arrays.asList("abstract", "assert", "boolean", "break",
38: "byte", "case", "catch", "char", "class", "const",
39: "continue", "default", "do", "double", "else",
40: "enum", "extends", "false", "final", "finally",
41: "float", "for", "goto", "if", "implements",
42: "import", "instanceof", "int", "interface", "long",
43: "native", "new", "null", "package", "private",
44: "protected", "public", "return", "short", "static",
45: "strictfp", "super", "switch", "synchronized",
46: "this", "throw", "throws", "transient", "true",
47: "try", "void", "volatile", "while"));
48:
49: private JavaUtils() {
50: }
51:
52: /**
53: * checks if the input string is a valid java keyword.
54: *
55: * @return boolean true/false
56: */
57: public static boolean isJavaKeyword(String keyword) {
58: return KEYWORDS.contains(keyword);
59: }
60:
61: /**
62: * Turn a java keyword string into a non-Java keyword string. (Right now
63: * this simply means appending an underscore.)
64: */
65: public static String makeNonJavaKeyword(String keyword) {
66: return KEYWORD_PREFIX + keyword;
67: }
68:
69: }
|