|
34 | 34 | public class Utils {
|
35 | 35 |
|
36 | 36 | public static Object mergeMeta(Object x, IPersistentMap m) {
|
37 |
| - if (x instanceof clojure.lang.IObj) { |
| 37 | + if (x instanceof clojure.lang.IObj && RT.count(m) > 0) { |
| 38 | + // if x supports meta and there is meta to merge |
38 | 39 | IObj o = (IObj) x;
|
39 |
| - if (m != null || RT.meta(o) != null) |
40 |
| - { // if there is meta in any of the args |
41 |
| - IPersistentMap retMeta = PersistentHashMap.EMPTY; |
42 |
| - IPersistentMap oMeta = RT.meta(o); |
43 | 40 |
|
44 |
| - if (oMeta != null) |
45 |
| - { |
46 |
| - for (Object meo : oMeta) |
47 |
| - { |
48 |
| - MapEntry me = (MapEntry) meo; |
49 |
| - retMeta = retMeta.assoc(me.getKey(), me.getValue()); |
50 |
| - } |
51 |
| - } |
52 |
| - // m meta overrides the input Object meta when both have |
53 |
| - if (m != null) |
54 |
| - { |
55 |
| - for (Object meo : m) |
56 |
| - { |
57 |
| - MapEntry me = (MapEntry) meo; |
58 |
| - retMeta = retMeta.assoc(me.getKey(), me.getValue()); |
59 |
| - } |
60 |
| - } |
61 |
| - return o.withMeta(retMeta); |
62 |
| - } else { |
63 |
| - return x; |
64 |
| - } |
65 |
| - } |
66 |
| - return x; |
67 |
| - } |
| 41 | + IPersistentMap retMeta = PersistentHashMap.EMPTY; |
| 42 | + IPersistentMap oMeta = RT.meta(o); |
| 43 | + |
| 44 | + if (oMeta != null) { |
| 45 | + for (Object meo : oMeta) { |
| 46 | + MapEntry me = (MapEntry) meo; |
| 47 | + retMeta = retMeta.assoc(me.getKey(), me.getValue()); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + // m meta overrides the input Object meta when both have |
| 52 | + for (Object meo : m) { |
| 53 | + MapEntry me = (MapEntry) meo; |
| 54 | + retMeta = retMeta.assoc(me.getKey(), me.getValue()); |
| 55 | + } |
| 56 | + |
| 57 | + return o.withMeta(retMeta); |
| 58 | + } else { |
| 59 | + return x; |
| 60 | + } |
| 61 | + } |
68 | 62 |
|
69 | 63 | public static Symbol maybeGetTraceSymbol(Symbol sym, ISeq form){
|
70 | 64 | // If the form is the expansion of a defmethod we use the symbol of
|
@@ -219,7 +213,9 @@ public static Object tagFormRecursively(Object form) {
|
219 | 213 | PersistentVector.EMPTY,
|
220 | 214 | new AFn() {
|
221 | 215 | public Object invoke(Object coord, Object frm) {
|
222 |
| - if ((frm instanceof clojure.lang.ISeq) || (frm instanceof clojure.lang.Symbol)) |
| 216 | + // Tag seqs and symbols but don't tag empty lists |
| 217 | + if (((frm instanceof clojure.lang.ISeq) && RT.count(frm) > 0) || |
| 218 | + (frm instanceof clojure.lang.Symbol)) |
223 | 219 | return addCoordMeta(frm, (IPersistentVector)coord);
|
224 | 220 | else
|
225 | 221 | return frm;
|
|
0 commit comments