|
1 | 1 | /* |
2 | | - * Copyright (c) 2002-2020, the original author or authors. |
| 2 | + * Copyright (c) 2002-2021, the original author or authors. |
3 | 3 | * |
4 | 4 | * This software is distributable under the BSD license. See the terms of the |
5 | 5 | * BSD license in the documentation provided with this software. |
|
9 | 9 | package org.jline.groovy |
10 | 10 |
|
11 | 11 | import org.codehaus.groovy.runtime.HandleMetaClass |
| 12 | +import org.codehaus.groovy.runtime.typehandling.GroovyCastException |
12 | 13 |
|
13 | 14 | import java.nio.file.Path |
14 | 15 | import org.jline.script.GroovyEngine.Format |
@@ -37,13 +38,18 @@ class Utils { |
37 | 38 | } |
38 | 39 |
|
39 | 40 | static Map<String,Object> toMap(Object object) { |
40 | | - def out = [:] |
41 | | - if (object instanceof Closure) { |
42 | | - out['closure'] = object.getClass().getName() |
43 | | - } else if (object instanceof HandleMetaClass) { |
44 | | - out['object'] = object.toString() |
45 | | - } else { |
46 | | - out = object != null ? object.properties : null |
| 41 | + Map<String,Object> out = [:] |
| 42 | + try { |
| 43 | + if (object instanceof Closure) { |
| 44 | + out['closure'] = object.getClass().getName() |
| 45 | + } else if (object instanceof HandleMetaClass) { |
| 46 | + out['HandleMetaClass'] = object.toString() |
| 47 | + } else { |
| 48 | + out = object != null ? object.properties : null |
| 49 | + } |
| 50 | + return out |
| 51 | + } catch (GroovyCastException e) { |
| 52 | + out[object.getClass().getSimpleName()] = object.toString() |
47 | 53 | } |
48 | 54 | out |
49 | 55 | } |
|
0 commit comments