|
1 |
| package net.sourceforge.pmd.util; |
|
2 |
| |
|
3 |
| import java.math.BigDecimal; |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| public class ClassUtil { |
|
12 |
| |
|
13 |
0
| private ClassUtil() {};
|
|
14 |
| |
|
15 |
| private static final TypeMap primitiveTypesByName = new TypeMap( new Class[] { |
|
16 |
| int.class, |
|
17 |
| byte.class, |
|
18 |
| long.class, |
|
19 |
| short.class, |
|
20 |
| float.class, |
|
21 |
| double.class, |
|
22 |
| char.class, |
|
23 |
| boolean.class, |
|
24 |
| }); |
|
25 |
| |
|
26 |
| private static final TypeMap typesByNames = new TypeMap( new Class[] { |
|
27 |
| Integer.class, |
|
28 |
| Byte.class, |
|
29 |
| Long.class, |
|
30 |
| Short.class, |
|
31 |
| Float.class, |
|
32 |
| Double.class, |
|
33 |
| Character.class, |
|
34 |
| Boolean.class, |
|
35 |
| BigDecimal.class, |
|
36 |
| String.class, |
|
37 |
| Object.class, |
|
38 |
| }); |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
0
| public static Class getPrimitiveTypeFor(String name) {
|
|
48 |
0
| return primitiveTypesByName.typeFor(name);
|
|
49 |
| } |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
11
| public static Class getTypeFor(String shortName) {
|
|
58 |
| |
|
59 |
11
| Class type = typesByNames.typeFor(shortName);
|
|
60 |
5
| if (type != null) return type;
|
|
61 |
| |
|
62 |
6
| type = primitiveTypesByName.typeFor(shortName);
|
|
63 |
2
| if (type != null) return type;
|
|
64 |
| |
|
65 |
4
| return CollectionUtil.getCollectionTypeFor(shortName);
|
|
66 |
| } |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
7456
| public static String withoutPackageName(String fullTypeName) {
|
|
76 |
| |
|
77 |
7456
| int dotPos = fullTypeName.lastIndexOf('.');
|
|
78 |
| |
|
79 |
7456
| return dotPos > 0 ?
|
|
80 |
| fullTypeName.substring(dotPos+1) : |
|
81 |
| fullTypeName; |
|
82 |
| } |
|
83 |
| } |