comparison truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/GraphPrintVisitor.java @ 22404:23d2b5513c83

Fixing API error: GraphPrintVisitor shouldn't expose internal API class in an API method. When at it deprecating all protected methods, as GraphPrintVisitor usages don't indicate somebody should be subclassing it at all.
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Fri, 20 Nov 2015 17:27:42 +0100
parents 6598b9b7aafd
children 21f48bc8a535
comparison
equal deleted inserted replaced
22403:5033b980cc68 22404:23d2b5513c83
140 140
141 private static class XMLImpl implements Impl { 141 private static class XMLImpl implements Impl {
142 private static final XMLOutputFactory XML_OUTPUT_FACTORY = XMLOutputFactory.newInstance(); 142 private static final XMLOutputFactory XML_OUTPUT_FACTORY = XMLOutputFactory.newInstance();
143 private final XMLStreamWriter xmlstream; 143 private final XMLStreamWriter xmlstream;
144 144
145 protected XMLImpl(OutputStream outputStream) { 145 XMLImpl(OutputStream outputStream) {
146 try { 146 try {
147 this.xmlstream = XML_OUTPUT_FACTORY.createXMLStreamWriter(outputStream); 147 this.xmlstream = XML_OUTPUT_FACTORY.createXMLStreamWriter(outputStream);
148 } catch (XMLStreamException | FactoryConfigurationError e) { 148 } catch (XMLStreamException | FactoryConfigurationError e) {
149 throw new RuntimeException(e); 149 throw new RuntimeException(e);
150 } 150 }
433 } else { 433 } else {
434 return nextId(); 434 return nextId();
435 } 435 }
436 } 436 }
437 437
438 protected NodeElement getElementByObject(Object obj) { 438 /**
439 * @deprecated to be removed
440 */
441 @Deprecated
442 protected Object getElementByObject(Object obj) {
443 return getElementByObjectImpl(obj);
444 }
445
446 final NodeElement getElementByObjectImpl(Object obj) {
439 return nodeMap.get(obj); 447 return nodeMap.get(obj);
440 } 448 }
441 449
450 /**
451 * @deprecated to be removed
452 */
453 @Deprecated
442 protected void createElementForNode(Object node) { 454 protected void createElementForNode(Object node) {
443 boolean exists = nodeMap.containsKey(node); 455 boolean exists = nodeMap.containsKey(node);
444 if (!exists) { 456 if (!exists) {
445 int nodeId = !exists ? oldOrNextId(node) : nextId(); 457 int nodeId = !exists ? oldOrNextId(node) : nextId();
446 nodeMap.put(node, new NodeElement(nodeId)); 458 nodeMap.put(node, new NodeElement(nodeId));
447 459
448 setNodeProperty(node, "name", node.getClass().getSimpleName().replaceFirst("Node$", "")); 460 setNodePropertyImpl(node, "name", node.getClass().getSimpleName().replaceFirst("Node$", ""));
449 NodeInfo nodeInfo = node.getClass().getAnnotation(NodeInfo.class); 461 NodeInfo nodeInfo = node.getClass().getAnnotation(NodeInfo.class);
450 if (nodeInfo != null) { 462 if (nodeInfo != null) {
451 setNodeProperty(node, "cost", nodeInfo.cost()); 463 setNodePropertyImpl(node, "cost", nodeInfo.cost());
452 if (!nodeInfo.shortName().isEmpty()) { 464 if (!nodeInfo.shortName().isEmpty()) {
453 setNodeProperty(node, "shortName", nodeInfo.shortName()); 465 setNodePropertyImpl(node, "shortName", nodeInfo.shortName());
454 } 466 }
455 } 467 }
456 setNodeProperty(node, "class", node.getClass().getSimpleName()); 468 setNodePropertyImpl(node, "class", node.getClass().getSimpleName());
457 if (node instanceof Node) { 469 if (node instanceof Node) {
458 readNodeProperties((Node) node); 470 readNodeProperties((Node) node);
459 copyDebugProperties((Node) node); 471 copyDebugProperties((Node) node);
460 } 472 }
461 } 473 }
462 } 474 }
463 475
476 /**
477 * @deprecated to be removed
478 */
479 @Deprecated
464 protected void setNodeProperty(Object node, String propertyName, Object value) { 480 protected void setNodeProperty(Object node, String propertyName, Object value) {
465 NodeElement nodeElem = getElementByObject(node); 481 setNodePropertyImpl(node, propertyName, value);
482 }
483
484 final void setNodePropertyImpl(Object node, String propertyName, Object value) {
485 NodeElement nodeElem = getElementByObjectImpl(node);
466 nodeElem.getProperties().put(propertyName, value); 486 nodeElem.getProperties().put(propertyName, value);
467 } 487 }
468 488
469 private void copyDebugProperties(Node node) { 489 private void copyDebugProperties(Node node) {
470 Map<String, Object> debugProperties = node.getDebugProperties(); 490 Map<String, Object> debugProperties = node.getDebugProperties();
471 for (Map.Entry<String, Object> property : debugProperties.entrySet()) { 491 for (Map.Entry<String, Object> property : debugProperties.entrySet()) {
472 setNodeProperty(node, property.getKey(), property.getValue()); 492 setNodePropertyImpl(node, property.getKey(), property.getValue());
473 } 493 }
474 } 494 }
475 495
476 private void readNodeProperties(Node node) { 496 private void readNodeProperties(Node node) {
477 NodeFieldAccessor[] fields = NodeClass.get(node).getFields(); 497 NodeFieldAccessor[] fields = NodeClass.get(node).getFields();
478 for (NodeFieldAccessor field : fields) { 498 for (NodeFieldAccessor field : fields) {
479 if (field.getKind() == NodeFieldKind.DATA) { 499 if (field.getKind() == NodeFieldKind.DATA) {
480 String key = field.getName(); 500 String key = field.getName();
481 if (!getElementByObject(node).getProperties().containsKey(key)) { 501 if (!getElementByObjectImpl(node).getProperties().containsKey(key)) {
482 Object value = field.loadValue(node); 502 Object value = field.loadValue(node);
483 setNodeProperty(node, key, value); 503 setNodePropertyImpl(node, key, value);
484 } 504 }
485 } 505 }
486 } 506 }
487 } 507 }
488 508
509 /**
510 * @deprecated to be removed
511 */
512 @Deprecated
489 protected void connectNodes(Object a, Object b, String label) { 513 protected void connectNodes(Object a, Object b, String label) {
490 NodeElement fromNode = getElementByObject(a); 514 connectNodesImpl(a, b, label);
491 NodeElement toNode = getElementByObject(b); 515 }
516
517 final void connectNodesImpl(Object a, Object b, String label) {
518 NodeElement fromNode = getElementByObjectImpl(a);
519 NodeElement toNode = getElementByObjectImpl(b);
492 if (fromNode == null || toNode == null) { 520 if (fromNode == null || toNode == null) {
493 return; 521 return;
494 } 522 }
495 523
496 // count existing to-edges 524 // count existing to-edges
508 if (openGraphCount == 0) { 536 if (openGraphCount == 0) {
509 beginGraph(DEFAULT_GRAPH_NAME); 537 beginGraph(DEFAULT_GRAPH_NAME);
510 } 538 }
511 539
512 // if node is visited once again, skip 540 // if node is visited once again, skip
513 if (getElementByObject(node) != null) { 541 if (getElementByObjectImpl(node) != null) {
514 return this; 542 return this;
515 } 543 }
516 544
517 // respect node's custom handler 545 // respect node's custom handler
518 if (!TruffleOptions.AOT && NodeUtil.findAnnotation(node.getClass(), CustomGraphPrintHandler.class) != null) { 546 if (!TruffleOptions.AOT && NodeUtil.findAnnotation(node.getClass(), CustomGraphPrintHandler.class) != null) {
591 public void visit(Object node, GraphPrintHandler handler) { 619 public void visit(Object node, GraphPrintHandler handler) {
592 GraphPrintVisitor.this.visit(node, handler); 620 GraphPrintVisitor.this.visit(node, handler);
593 } 621 }
594 622
595 public void connectNodes(Object node, Object child) { 623 public void connectNodes(Object node, Object child) {
596 GraphPrintVisitor.this.connectNodes(node, child, null); 624 GraphPrintVisitor.this.connectNodesImpl(node, child, null);
597 } 625 }
598 626
599 public void connectNodes(Object node, Object child, String label) { 627 public void connectNodes(Object node, Object child, String label) {
600 GraphPrintVisitor.this.connectNodes(node, child, label); 628 GraphPrintVisitor.this.connectNodesImpl(node, child, label);
601 } 629 }
602 630
603 public void setNodeProperty(Object node, String propertyName, Object value) { 631 public void setNodeProperty(Object node, String propertyName, Object value) {
604 GraphPrintVisitor.this.setNodeProperty(node, propertyName, value); 632 GraphPrintVisitor.this.setNodePropertyImpl(node, propertyName, value);
605 } 633 }
606 634
607 public boolean visited(Object node) { 635 public boolean visited(Object node) {
608 return GraphPrintVisitor.this.getElementByObject(node) != null; 636 return GraphPrintVisitor.this.getElementByObjectImpl(node) != null;
609 } 637 }
610 } 638 }
611 639
612 public interface GraphPrintHandler { 640 public interface GraphPrintHandler {
613 641