|
1 |
| package net.sourceforge.pmd.util; |
|
2 |
| |
|
3 |
| import java.util.HashMap; |
|
4 |
| import java.util.Map; |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| public class TypeMap { |
|
12 |
| |
|
13 |
| private Map typesByName; |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
932
| public TypeMap(int initialSize) {
|
|
20 |
932
| typesByName = new HashMap(initialSize);
|
|
21 |
| } |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
932
| public TypeMap(Class[] types) {
|
|
29 |
932
| this(types.length);
|
|
30 |
932
| add(types);
|
|
31 |
| } |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
7456
| public void add(Class type) {
|
|
40 |
7456
| typesByName.put(type.getName(), type);
|
|
41 |
7456
| typesByName.put(ClassUtil.withoutPackageName(type.getName()), type);
|
|
42 |
| } |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
21
| public boolean contains(Class type) {
|
|
51 |
21
| return typesByName.containsValue(type);
|
|
52 |
| } |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
41
| public boolean contains(String typeName) {
|
|
61 |
41
| return typesByName.containsKey(typeName);
|
|
62 |
| } |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
22
| public Class typeFor(String typeName) {
|
|
71 |
22
| return (Class)typesByName.get(typeName);
|
|
72 |
| } |
|
73 |
| |
|
74 |
| |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
932
| public void add(Class[] types) {
|
|
80 |
932
| for (int i=0; i<types.length; i++) {
|
|
81 |
7456
| add(types[i]);
|
|
82 |
| } |
|
83 |
| } |
|
84 |
| } |