Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/GraphPrintVisitor.java @ 9754:98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
author | Christian Wimmer <christian.wimmer@oracle.com> |
---|---|
date | Thu, 16 May 2013 17:03:18 -0700 |
parents | e2965e5cd474 |
children | 29e9a5d18c70 |
comparison
equal
deleted
inserted
replaced
9753:6c2a7fc32416 | 9754:98b004bf3985 |
---|---|
22 */ | 22 */ |
23 package com.oracle.truffle.api.nodes; | 23 package com.oracle.truffle.api.nodes; |
24 | 24 |
25 import java.io.*; | 25 import java.io.*; |
26 import java.lang.annotation.*; | 26 import java.lang.annotation.*; |
27 import java.lang.reflect.*; | |
28 import java.net.*; | 27 import java.net.*; |
29 import java.util.*; | 28 import java.util.*; |
30 | 29 |
31 import javax.xml.parsers.*; | 30 import javax.xml.parsers.*; |
32 import javax.xml.transform.*; | 31 import javax.xml.transform.*; |
33 import javax.xml.transform.dom.*; | 32 import javax.xml.transform.dom.*; |
34 import javax.xml.transform.stream.*; | 33 import javax.xml.transform.stream.*; |
35 | 34 |
36 import org.w3c.dom.*; | 35 import org.w3c.dom.*; |
36 | |
37 import com.oracle.truffle.api.nodes.NodeUtil.NodeClass; | |
38 import com.oracle.truffle.api.nodes.NodeUtil.NodeField; | |
39 import com.oracle.truffle.api.nodes.NodeUtil.NodeFieldKind; | |
37 | 40 |
38 /** | 41 /** |
39 * Utility class for creating output for the ideal graph visualizer. | 42 * Utility class for creating output for the ideal graph visualizer. |
40 */ | 43 */ |
41 public class GraphPrintVisitor { | 44 public class GraphPrintVisitor { |
210 setNodeProperty(node, "shortName", nodeInfo.shortName()); | 213 setNodeProperty(node, "shortName", nodeInfo.shortName()); |
211 } | 214 } |
212 setNodeProperty(node, "nodeType", (Node.class.isAssignableFrom(node.getClass()) ? Node.class.getSimpleName() : "other")); | 215 setNodeProperty(node, "nodeType", (Node.class.isAssignableFrom(node.getClass()) ? Node.class.getSimpleName() : "other")); |
213 setNodeProperty(node, "nodeClass", node.getClass().getSimpleName()); | 216 setNodeProperty(node, "nodeClass", node.getClass().getSimpleName()); |
214 copyDebugProperties(node); // TODO: may overwrite property "name"? (currently allowed) | 217 copyDebugProperties(node); // TODO: may overwrite property "name"? (currently allowed) |
215 readNodeProperties(node); | 218 readNodeProperties((Node) node); |
216 } | 219 } |
217 } | 220 } |
218 | 221 |
219 private Element getPropertyElement(Object node, String propertyName) { | 222 private Element getPropertyElement(Object node, String propertyName) { |
220 Element nodeElem = getElementByObject(node); | 223 Element nodeElem = getElementByObject(node); |
252 setNodeProperty(node, property.getKey(), property.getValue()); | 255 setNodeProperty(node, property.getKey(), property.getValue()); |
253 } | 256 } |
254 } | 257 } |
255 } | 258 } |
256 | 259 |
257 private void readNodeProperties(Object node) { | 260 private void readNodeProperties(Node node) { |
258 Field[] fields = NodeUtil.getAllFields(node.getClass()); | 261 NodeField[] fields = NodeClass.get(node.getClass()).getFields(); |
259 for (Field field : fields) { | 262 for (NodeField field : fields) { |
260 if (Modifier.isStatic(field.getModifiers())) { | 263 if (field.getKind() == NodeFieldKind.DATA) { |
261 continue; | 264 String key = field.getName(); |
262 } | 265 if (getPropertyElement(node, key) == null) { |
263 if (Node.class.isAssignableFrom(field.getType()) || (field.getType().getComponentType() != null && Node.class.isAssignableFrom(field.getType()))) { | 266 Object value = field.loadValue(node); |
264 continue; | |
265 } | |
266 String key = field.getName(); | |
267 if (field.getAnnotation(HiddenField.class) == null && getPropertyElement(node, key) == null) { | |
268 try { | |
269 field.setAccessible(true); | |
270 Object value = field.get(node); | |
271 setNodeProperty(node, key, value); | 267 setNodeProperty(node, key, value); |
272 } catch (IllegalArgumentException | IllegalAccessException e) { | |
273 assert false : e; | |
274 } | 268 } |
275 } | 269 } |
276 } | 270 } |
277 } | 271 } |
278 | 272 |