|
2 | 2 |
|
3 | 3 | import com.google.common.cache.Cache; |
4 | 4 | import com.google.common.cache.LoadingCache; |
| 5 | +import com.google.common.cache.CacheBuilder; |
5 | 6 | import com.google.common.collect.ImmutableMap; |
6 | 7 | import java.util.Map; |
7 | 8 | import java.util.concurrent.ConcurrentMap; |
| 9 | +import java.util.HashMap; |
| 10 | +import java.util.List; |
| 11 | +import java.util.ArrayList; |
8 | 12 |
|
9 | 13 | // Test case generated by GenerateFlowTestCase.ql |
10 | 14 | public class Test { |
11 | 15 |
|
12 | | - Object getMapKey(Object container) { return null; } |
13 | | - Object getMapValue(Object container) { return null; } |
14 | | - Object newWithElement(Object element) { return null; } |
15 | | - Object newWithMapKey(Object element) { return null; } |
16 | | - Object newWithMapValue(Object element) { return null; } |
17 | | - Object source() { return null; } |
| 16 | + <K,V> K getMapKey(Map<K,V> container) { return container.keySet().iterator().next(); } |
| 17 | + <K,V> K getMapKey(Cache<K,V> container) { return getMapKey(container.asMap()); } |
| 18 | + <K,V> V getMapValue(Map<K,V> container) { return container.values().iterator().next(); } |
| 19 | + <K,V> V getMapValue(Cache<K,V> container) { return getMapValue(container.asMap()); } |
| 20 | + <T> Iterable<T> newWithElement(T element) { |
| 21 | + List<T> l = new ArrayList(); |
| 22 | + l.add(element); |
| 23 | + return l; |
| 24 | + } |
| 25 | + <K,V> Map<K,V> newMapWithMapKey(K element) { |
| 26 | + Map<K,V> m = new HashMap<K,V>(); |
| 27 | + m.put(element, null); |
| 28 | + return m; |
| 29 | + } |
| 30 | + <K,V> LoadingCache<K,V> newCacheWithMapKey(K element) { |
| 31 | + LoadingCache<K,V> lc = CacheBuilder.newBuilder().build(null); |
| 32 | + lc.put(element, null); |
| 33 | + return lc; |
| 34 | + } |
| 35 | + <K,V> Map<K,V> newMapWithMapValue(V element) { |
| 36 | + Map<K,V> m = new HashMap<K,V>(); |
| 37 | + m.put(null, element); |
| 38 | + return m; |
| 39 | + } |
| 40 | + <K,V> LoadingCache<K,V> newCacheWithMapValue(V element) { |
| 41 | + LoadingCache<K,V> lc = CacheBuilder.newBuilder().build(null); |
| 42 | + lc.put(null, element); |
| 43 | + return lc; |
| 44 | + } |
| 45 | + <T> T source() { return null; } |
18 | 46 | void sink(Object o) { } |
19 | 47 |
|
20 | 48 | public void test() throws Exception { |
21 | 49 |
|
22 | 50 | { |
23 | 51 | // "com.google.common.cache;Cache;true;asMap;();;MapKey of Argument[-1];MapKey of ReturnValue;value" |
24 | 52 | ConcurrentMap out = null; |
25 | | - LoadingCache in = (LoadingCache)newWithMapKey(source()); |
| 53 | + LoadingCache in = newCacheWithMapKey(source()); |
26 | 54 | out = in.asMap(); |
27 | 55 | sink(getMapKey(out)); // $ hasValueFlow |
28 | 56 | } |
29 | 57 | { |
30 | 58 | // "com.google.common.cache;Cache;true;asMap;();;MapKey of Argument[-1];MapKey of ReturnValue;value" |
31 | 59 | ConcurrentMap out = null; |
32 | | - Cache in = (Cache)newWithMapKey(source()); |
| 60 | + Cache in = newCacheWithMapKey(source()); |
33 | 61 | out = in.asMap(); |
34 | 62 | sink(getMapKey(out)); // $ hasValueFlow |
35 | 63 | } |
36 | 64 | { |
37 | 65 | // "com.google.common.cache;Cache;true;asMap;();;MapValue of Argument[-1];MapValue of ReturnValue;value" |
38 | 66 | ConcurrentMap out = null; |
39 | | - LoadingCache in = (LoadingCache)newWithMapValue(source()); |
| 67 | + LoadingCache in = newCacheWithMapValue(source()); |
40 | 68 | out = in.asMap(); |
41 | 69 | sink(getMapValue(out)); // $ hasValueFlow |
42 | 70 | } |
43 | 71 | { |
44 | 72 | // "com.google.common.cache;Cache;true;asMap;();;MapValue of Argument[-1];MapValue of ReturnValue;value" |
45 | 73 | ConcurrentMap out = null; |
46 | | - Cache in = (Cache)newWithMapValue(source()); |
| 74 | + Cache in = newCacheWithMapValue(source()); |
47 | 75 | out = in.asMap(); |
48 | 76 | sink(getMapValue(out)); // $ hasValueFlow |
49 | 77 | } |
50 | 78 | { |
51 | 79 | // "com.google.common.cache;Cache;true;get;(Object,Callable);;MapValue of Argument[-1];ReturnValue;value" |
52 | 80 | Object out = null; |
53 | | - Cache in = (Cache)newWithMapValue(source()); |
| 81 | + Cache in = newCacheWithMapValue(source()); |
54 | 82 | out = in.get(null, null); |
55 | 83 | sink(out); // $ hasValueFlow |
56 | 84 | } |
57 | 85 | { |
58 | 86 | // "com.google.common.cache;Cache;true;getAllPresent;(Iterable);;MapValue of Argument[-1];MapValue of ReturnValue;value" |
59 | 87 | ImmutableMap out = null; |
60 | | - Cache in = (Cache)newWithMapValue(source()); |
| 88 | + Cache in = newCacheWithMapValue(source()); |
61 | 89 | out = in.getAllPresent(null); |
62 | 90 | sink(getMapValue(out)); // $ hasValueFlow |
63 | 91 | } |
64 | 92 | { |
65 | | - // "com.google.common.cache;Cache;true;getIfPresent;(Object);;MapValue of Argument[-1];ReturnValue;value" |
| 93 | + // "com.google.common.cache;Cache;true;getIfPresent;;;MapValue of Argument[-1];ReturnValue;value" |
66 | 94 | Object out = null; |
67 | | - Cache in = (Cache)newWithMapValue(source()); |
| 95 | + Cache in = newCacheWithMapValue(source()); |
68 | 96 | out = in.getIfPresent(null); |
69 | 97 | sink(out); // $ hasValueFlow |
70 | 98 | } |
71 | 99 | { |
72 | 100 | // "com.google.common.cache;Cache;true;put;(Object,Object);;Argument[0];MapKey of Argument[-1];value" |
73 | 101 | Cache out = null; |
74 | | - Object in = (Object)source(); |
| 102 | + Object in = source(); |
75 | 103 | out.put(in, null); |
76 | 104 | sink(getMapKey(out)); // $ hasValueFlow |
77 | 105 | } |
78 | 106 | { |
79 | 107 | // "com.google.common.cache;Cache;true;put;(Object,Object);;Argument[1];MapValue of Argument[-1];value" |
80 | 108 | Cache out = null; |
81 | | - Object in = (Object)source(); |
| 109 | + Object in = source(); |
82 | 110 | out.put(null, in); |
83 | 111 | sink(getMapValue(out)); // $ hasValueFlow |
84 | 112 | } |
85 | 113 | { |
86 | 114 | // "com.google.common.cache;Cache;true;putAll;(Map);;MapKey of Argument[0];MapKey of Argument[-1];value" |
87 | 115 | Cache out = null; |
88 | | - Map in = (Map)newWithMapKey(source()); |
| 116 | + Map in = newMapWithMapKey(source()); |
89 | 117 | out.putAll(in); |
90 | 118 | sink(getMapKey(out)); // $ hasValueFlow |
91 | 119 | } |
92 | 120 | { |
93 | 121 | // "com.google.common.cache;Cache;true;putAll;(Map);;MapValue of Argument[0];MapValue of Argument[-1];value" |
94 | 122 | Cache out = null; |
95 | | - Map in = (Map)newWithMapValue(source()); |
| 123 | + Map in = newMapWithMapValue(source()); |
96 | 124 | out.putAll(in); |
97 | 125 | sink(getMapValue(out)); // $ hasValueFlow |
98 | 126 | } |
99 | 127 | { |
100 | | - // "com.google.common.cache;LoadingCache;true;apply;(Object);;MapValue of Argument[-1];ReturnValue;value" |
| 128 | + // "com.google.common.cache;LoadingCache;true;apply;;;MapValue of Argument[-1];ReturnValue;value" |
101 | 129 | Object out = null; |
102 | | - LoadingCache in = (LoadingCache)newWithMapValue(source()); |
| 130 | + LoadingCache in = newCacheWithMapValue(source()); |
103 | 131 | out = in.apply(null); |
104 | 132 | sink(out); // $ hasValueFlow |
105 | 133 | } |
106 | 134 | { |
107 | | - // "com.google.common.cache;LoadingCache;true;get;(Object);;MapValue of Argument[-1];ReturnValue;value" |
| 135 | + // "com.google.common.cache;LoadingCache;true;get;;;MapValue of Argument[-1];ReturnValue;value" |
108 | 136 | Object out = null; |
109 | | - LoadingCache in = (LoadingCache)newWithMapValue(source()); |
| 137 | + LoadingCache in = newCacheWithMapValue(source()); |
110 | 138 | out = in.get(null); |
111 | 139 | sink(out); // $ hasValueFlow |
112 | 140 | } |
113 | 141 | { |
114 | 142 | // "com.google.common.cache;LoadingCache;true;getAll;(Iterable);;Element of Argument[0];MapKey of ReturnValue;value" |
115 | 143 | ImmutableMap out = null; |
116 | | - Iterable in = (Iterable)newWithElement(source()); |
| 144 | + Iterable in = newWithElement(source()); |
117 | 145 | LoadingCache instance = null; |
118 | 146 | out = instance.getAll(in); |
119 | 147 | sink(getMapKey(out)); // $ hasValueFlow |
120 | 148 | } |
121 | 149 | { |
122 | 150 | // "com.google.common.cache;LoadingCache;true;getAll;(Iterable);;MapValue of Argument[-1];MapValue of ReturnValue;value" |
123 | 151 | ImmutableMap out = null; |
124 | | - LoadingCache in = (LoadingCache)newWithMapValue(source()); |
| 152 | + LoadingCache in = newCacheWithMapValue(source()); |
125 | 153 | out = in.getAll(null); |
126 | 154 | sink(getMapValue(out)); // $ hasValueFlow |
127 | 155 | } |
128 | 156 | { |
129 | | - // "com.google.common.cache;LoadingCache;true;getUnchecked;(Object);;MapValue of Argument[-1];ReturnValue;value" |
| 157 | + // "com.google.common.cache;LoadingCache;true;getUnchecked;;;MapValue of Argument[-1];ReturnValue;value" |
130 | 158 | Object out = null; |
131 | | - LoadingCache in = (LoadingCache)newWithMapValue(source()); |
| 159 | + LoadingCache in = newCacheWithMapValue(source()); |
132 | 160 | out = in.getUnchecked(null); |
133 | 161 | sink(out); // $ hasValueFlow |
134 | 162 | } |
|
0 commit comments