/** * Get the (parent) shape that holds the given property. */ public final ShapeImpl getShapeFromProperty(Property prop) { ShapeImpl current = this; while (current != getRoot()) { if (current.getTransitionFromParent() instanceof AddPropertyTransition && ((AddPropertyTransition) current.getTransitionFromParent()).getProperty().equals(prop)) { return current; } current = current.parent; } return null; }
/** * Get the (parent) shape that holds the given property. * * @since 0.17 or earlier */ protected static ShapeImpl getShapeFromProperty(ShapeImpl shape, Property prop) { ShapeImpl current = shape; ShapeImpl root = shape.getRoot(); while (current != root) { if (current.getTransitionFromParent() instanceof AddPropertyTransition && ((AddPropertyTransition) current.getTransitionFromParent()).getProperty().equals(prop)) { return current; } current = current.parent; } return null; } }
/** * Get the (parent) shape that holds the given property. * * @since 0.17 or earlier */ protected static ShapeImpl getShapeFromProperty(ShapeImpl shape, Property prop) { ShapeImpl current = shape; ShapeImpl root = shape.getRoot(); while (current != root) { if (current.getTransitionFromParent() instanceof AddPropertyTransition && ((AddPropertyTransition) current.getTransitionFromParent()).getProperty().equals(prop)) { return current; } current = current.parent; } return null; } }
/** * Get the (parent) shape that holds the given property. */ public final ShapeImpl getShapeFromProperty(Object propertyName) { ShapeImpl current = this; while (current != getRoot()) { if (current.getTransitionFromParent() instanceof AddPropertyTransition && ((AddPropertyTransition) current.getTransitionFromParent()).getProperty().getKey().equals(propertyName)) { return current; } current = current.getParent(); } return null; }
/** * Get the (parent) shape that holds the given property. * * @since 0.17 or earlier */ protected static ShapeImpl getShapeFromProperty(ShapeImpl shape, Object propertyName) { ShapeImpl current = shape; ShapeImpl root = shape.getRoot(); while (current != root) { if (current.getTransitionFromParent() instanceof AddPropertyTransition && ((AddPropertyTransition) current.getTransitionFromParent()).getProperty().getKey().equals(propertyName)) { return current; } current = current.getParent(); } return null; }
/** * Get the (parent) shape that holds the given property. * * @since 0.17 or earlier */ protected static ShapeImpl getShapeFromProperty(ShapeImpl shape, Object propertyName) { ShapeImpl current = shape; ShapeImpl root = shape.getRoot(); while (current != root) { if (current.getTransitionFromParent() instanceof AddPropertyTransition && ((AddPropertyTransition) current.getTransitionFromParent()).getProperty().getKey().equals(propertyName)) { return current; } current = current.getParent(); } return null; }
/** @since 0.17 or earlier */ protected ShapeImpl removeProperty(ShapeImpl shape, Property property) { assert !shape.isShared(); RemovePropertyTransition transition = new RemovePropertyTransition(property); ShapeImpl cachedShape = shape.queryTransition(transition); if (cachedShape != null) { return ensureValid(cachedShape); } ShapeImpl owningShape = getShapeFromProperty(shape, property.getKey()); if (owningShape != null) { List<Transition> transitionList = new ArrayList<>(); ShapeImpl current = shape; while (current != owningShape) { if (!(current.getTransitionFromParent() instanceof Transition.DirectReplacePropertyTransition) || !((Transition.DirectReplacePropertyTransition) current.getTransitionFromParent()).getPropertyBefore().getKey().equals(property.getKey())) { transitionList.add(current.getTransitionFromParent()); } current = current.parent; } ShapeImpl newShape = owningShape.parent; for (ListIterator<Transition> iterator = transitionList.listIterator(transitionList.size()); iterator.hasPrevious();) { Transition previous = iterator.previous(); newShape = applyTransition(newShape, previous, true); } shape.addIndirectTransition(transition, newShape); return newShape; } else { return null; } }
@TruffleBoundary @Override public final ShapeImpl removeProperty(Property prop) { RemovePropertyTransition transition = new RemovePropertyTransition(prop); ShapeImpl cachedShape = queryTransition(transition); if (cachedShape != null) { return cachedShape; } ShapeImpl shape = getShapeFromProperty(prop); if (shape != null) { List<Transition> transitionList = new ArrayList<>(); ShapeImpl current = this; while (current != shape) { transitionList.add(current.getTransitionFromParent()); current = current.parent; } ShapeImpl newShape = shape.parent; for (ListIterator<Transition> iterator = transitionList.listIterator(transitionList.size()); iterator.hasPrevious();) { Transition previous = iterator.previous(); newShape = newShape.applyTransition(previous, true); } addIndirectTransition(transition, newShape); return newShape; } else { return null; } }
/** @since 0.17 or earlier */ protected ShapeImpl removeProperty(ShapeImpl shape, Property property) { assert !shape.isShared(); RemovePropertyTransition transition = new RemovePropertyTransition(property); ShapeImpl cachedShape = shape.queryTransition(transition); if (cachedShape != null) { return ensureValid(cachedShape); } ShapeImpl owningShape = getShapeFromProperty(shape, property.getKey()); if (owningShape != null) { List<Transition> transitionList = new ArrayList<>(); ShapeImpl current = shape; while (current != owningShape) { if (!(current.getTransitionFromParent() instanceof Transition.DirectReplacePropertyTransition) || !((Transition.DirectReplacePropertyTransition) current.getTransitionFromParent()).getPropertyBefore().getKey().equals(property.getKey())) { transitionList.add(current.getTransitionFromParent()); } current = current.parent; } ShapeImpl newShape = owningShape.parent; for (ListIterator<Transition> iterator = transitionList.listIterator(transitionList.size()); iterator.hasPrevious();) { Transition previous = iterator.previous(); newShape = applyTransition(newShape, previous, true); } shape.addIndirectTransition(transition, newShape); return newShape; } else { return null; } }
boolean found = false; while (top != getRoot() && !found) { Transition transition = top.getTransitionFromParent(); transitionList.add(transition); if (transition instanceof AddPropertyTransition && ((AddPropertyTransition) transition).getProperty().getKey().equals(newProperty.getKey())) {
public void visit(Object node, com.oracle.truffle.api.nodes.GraphPrintVisitor.GraphPrintAdapter printer) { if (!printer.visited(node)) { ShapeImpl s = (ShapeImpl) node; printer.createElementForNode(s); String name; if (isRootShape(s)) { name = ("ROOT(" + s.getObjectType() + ")"); } else { name = s.getTransitionFromParent().toString(); if (!s.isValid()) { name = INVALID + name; } } printer.setNodeProperty(s, "name", name); printer.setNodeProperty(s, "valid", s.isValid()); printer.setNodeProperty(s, "leaf", s.isLeaf()); printer.setNodeProperty(s, "identityHashCode", Integer.toHexString(System.identityHashCode(s))); printer.setNodeProperty(s, "objectType", s.getObjectType()); printer.setNodeProperty(s, "shared", s.isShared()); for (Entry<? extends Transition, ? extends ShapeImpl> entry : transitions.entrySet()) { ShapeImpl dst = entry.getValue(); IGVShapeVisitor.this.visitShape((dst)); assert printer.visited(dst); printer.connectNodes(s, dst, entry.getKey().toString()); } } } });
public void visit(Object node, com.oracle.truffle.api.nodes.GraphPrintVisitor.GraphPrintAdapter printer) { if (!printer.visited(node)) { ShapeImpl s = (ShapeImpl) node; printer.createElementForNode(s); String name; if (isRootShape(s)) { name = ("ROOT(" + s.getObjectType() + ")"); } else { name = s.getTransitionFromParent().toString(); if (!s.isValid()) { name = INVALID + name; } } printer.setNodeProperty(s, "name", name); printer.setNodeProperty(s, "valid", s.isValid()); printer.setNodeProperty(s, "leaf", s.isLeaf()); printer.setNodeProperty(s, "identityHashCode", Integer.toHexString(System.identityHashCode(s))); printer.setNodeProperty(s, "objectType", s.getObjectType()); printer.setNodeProperty(s, "shared", s.isShared()); for (Entry<? extends Transition, ? extends ShapeImpl> entry : transitions.entrySet()) { ShapeImpl dst = entry.getValue(); IGVShapeVisitor.this.visitShape((dst)); assert printer.visited(dst); printer.connectNodes(s, dst, entry.getKey().toString()); } } } });
public final void copyProperties(DynamicObject fromObject, Shape ancestor) { ShapeImpl fromShape = (ShapeImpl) fromObject.getShape(); ShapeImpl toShape = getShape(); assert toShape.isRelated(ancestor); assert toShape.isValid(); assert ancestor.isValid(); for (; toShape != ancestor; toShape = toShape.getParent()) { Transition transitionFromParent = toShape.getTransitionFromParent(); if (transitionFromParent instanceof Transition.AddPropertyTransition) { Property toProperty = ((Transition.AddPropertyTransition) transitionFromParent).getProperty(); Property fromProperty = fromShape.getProperty(toProperty.getKey()); // copy only if property has a location and it's not the same as the source location if (toProperty.getLocation() != null && !(toProperty.getLocation() instanceof ValueLocation) && !toProperty.getLocation().equals(fromProperty.getLocation())) { toProperty.setInternal(this, fromProperty.get(fromObject, false)); assert toShape.isValid(); } if (fromShape.getTransitionFromParent() instanceof Transition.AddPropertyTransition && ((Transition.AddPropertyTransition) fromShape.getTransitionFromParent()).getProperty() == fromProperty) { // no property is looked up twice, so we can skip over to parent fromShape = fromShape.getParent(); } } } }