Debian Codegraph @

native/jpype_module/src/main/java/org/jpype/JPypeKeywords.java

raw symbols SCIP
1 /* ****************************************************************************
2 Licensed under the Apache License, Version 2.0 (the "License");
3 you may not use this file except in compliance with the License.
4 You may obtain a copy of the License at
5
6 http://www.apache.org/licenses/LICENSE-2.0
7
8 Unless required by applicable law or agreed to in writing, software
9 distributed under the License is distributed on an "AS IS" BASIS,
10 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 See the License for the specific language governing permissions and
12 limitations under the License.
13
14 See NOTICE file for details.
15 **************************************************************************** */
16 package org.jpype;
17
18 import java.util.Arrays;
19 import java.util.HashSet;
20 import java.util.Set;
21
22 /**
23 *
24 * @author nelson85
25 */
26 public class JPypeKeywords
27 {
28
29 final public static Set<String> keywords = new HashSet<>();
30
31 public static void setKeywords(String[] s)
32 {
33 keywords.addAll(Arrays.asList(s));
34 }
35
36 public static String wrap(String name)
37 {
38 if (keywords.contains(name))
39 return name + "_";
40 return name;
41 }
42
43 public static String unwrap(String name)
44 {
45 if (!name.endsWith("_"))
46 return name;
47 String name2 = name.substring(0, name.length() - 1);
48 if (keywords.contains(name2))
49 return name2;;
50 return name;
51 }
52
53 static String safepkg(String s)
54 {
55 if (!s.contains("_"))
56 return s;
57 String[] parts = s.split("\\.");
58 for (int i = 0; i < parts.length; ++i)
59 parts[i] = unwrap(parts[i]);
60 return String.join(".", parts);
61 }
62 }