MCPcopy Create free account
hub / github.com/evant/android-retrolambda-lombok / AbstractNode

Class AbstractNode

src/main/lombok/ast/AbstractNode.java:38–226  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36import lombok.ast.printer.TextFormatter;
37
38abstract class AbstractNode implements Node {
39 private Position position = Position.UNPLACED;
40 @Getter private Node parent;
41 private List<Node> danglings;
42 private Map<String, Position> conversionPositions;
43 private Map<MessageKey, Message> messagesMap;
44 private List<Message> messages;
45 @Getter @Setter private Object nativeNode;
46 @Getter @Setter private PositionFactory positionFactory;
47
48 @Override public boolean isGenerated() {
49 return position.getGeneratedBy() != null;
50 }
51
52 @Override public Node getGeneratedBy() {
53 return position.getGeneratedBy();
54 }
55
56 @Override public boolean hasParent() {
57 return parent != null;
58 }
59
60 @Override public List<Node> getChildren() {
61 return emptyList();
62 }
63
64 @Override public boolean replace(Node replacement) throws AstException {
65 if (this.getParent() == null) return false;
66 return this.parent.replaceChild(this, replacement);
67 }
68
69 @Override public void unparent() {
70 if (this.parent != null) this.parent.detach(this);
71 }
72
73 /**
74 * Adopts (accepts as direct child) the provided node.
75 *
76 * @param child The node to adopt
77 * @return The {@code child} parameter for chaining.
78 * @throws IllegalStateException If {@code child} already has a parent (clone or unparent it first).
79 */
80 protected AbstractNode adopt(AbstractNode child) throws IllegalStateException {
81 child.ensureParentless();
82 child.parent = this;
83 return child;
84 }
85
86 /**
87 * Checks if this node is currently parentless.
88 *
89 * @throws IllegalStateException if I have a parent.
90 */
91 protected void ensureParentless() throws IllegalStateException {
92 if (parent == null) return;
93 throw new IllegalStateException(String.format(
94 "I (%s) already have a parent, so you can't add me to something else; clone or unparent me first.",
95 this.getClass().getName()));

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected