forked from redmouth/java2cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypeConverter.java
More file actions
91 lines (76 loc) · 3.18 KB
/
Copy pathTypeConverter.java
File metadata and controls
91 lines (76 loc) · 3.18 KB
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
package co.deepblue.java2cpp.type;
import java.util.*;
/**
* Created by levin on 17-5-7.
*/
public class TypeConverter {
static TypeConverter instance;
HashMap<String, String> primitiveTypeMaps = new HashMap<>();
HashSet primitiveTypes = new HashSet();
HashMap<String, String> containerTypes = new HashMap<>();
HashMap<String, String> simpleEnumTypes = new HashMap<>();
HashMap<String, String> toUnsignedMap = new HashMap<>();
public static TypeConverter getInstance() {
if (instance == null)
instance = new TypeConverter();
return instance;
}
private TypeConverter() {
init();
}
public void init() {
toUnsignedMap.put("int", "uint32_t");
toUnsignedMap.put("short", "uint16_t");
toUnsignedMap.put("char", "uint16_t");
toUnsignedMap.put("byte", "unsigned char");
toUnsignedMap.put("long", "uint64_t");
toUnsignedMap.put("Integer", "uint32_t");
toUnsignedMap.put("Short", "uint16_t");
toUnsignedMap.put("Char", "uint16_t");
toUnsignedMap.put("Byte", "unsigned char");
toUnsignedMap.put("Long", "uint64_t");
//https://android.googlesource.com/platform/libnativehelper/+/jb-mr2-release/include/nativehelper/jni.h
primitiveTypeMaps.put("boolean", "bool");
primitiveTypeMaps.put("byte", "int8_t");
primitiveTypeMaps.put("char", "uint16_t");
primitiveTypeMaps.put("short", "int16_t");
primitiveTypeMaps.put("int", "int32_t");
primitiveTypeMaps.put("long", "int64_t");
primitiveTypeMaps.put("float", "float");
primitiveTypeMaps.put("double", "double");
containerTypes.put("String", "String");
containerTypes.put("List", "List");
containerTypes.put("Set", "Set");
containerTypes.put("HashMap", "HashMap");
containerTypes.put("Vector", "Vector");
containerTypes.put("Map", "Map");
containerTypes.put("LinkedList", "LinkedList");
containerTypes.put("HashSet", "HashSet");
containerTypes.put("LinkedHashSet", "LinkedHashSet");
containerTypes.put("TreeMap", "TreeMap");
containerTypes.put("IntHashMap", "IntHashMap");
}
public String toUnsignedType(String javaType) {
if (toUnsignedMap.containsKey(javaType))
return toUnsignedMap.get(javaType);
return javaType;
}
public boolean isContainerType(String javaType) {
return containerTypes.containsKey(javaType);
}
public boolean isBasicTypes(String javaType) {
return primitiveTypeMaps.containsKey(javaType) || simpleEnumTypes.containsKey(javaType);
}
//value of primitive type and simple enums can be pass as function parameter
public boolean canPassValueAsArgument(String javaType) {
return primitiveTypeMaps.containsKey(javaType) || simpleEnumTypes.containsKey(javaType);
}
public void addSimpleEnumType(String name, String packageName) {
simpleEnumTypes.put(name, packageName);
}
public String mapJava2CppType(String javaType) {
if (primitiveTypeMaps.containsKey(javaType))
return primitiveTypeMaps.get(javaType);
return javaType;
}
}