
se.llbit.nbt.ASTNode Maven / Gradle / Ivy
/* This file was generated with JastAdd2 (http://jastadd.org) version 2.1.13 */
package se.llbit.nbt;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.HashSet;
/**
* @ast node
* @production ASTNode;
*/
public class ASTNode implements Cloneable, Iterable {
/**
* @declaredat ASTNode:1
*/
public ASTNode() {
super();
init$Children();
}
/**
* Initializes the child array to the correct size.
* Initializes List and Opt nta children.
* @apilevel internal
* @ast method
* @declaredat ASTNode:11
*/
public void init$Children() {
}
/**
* @apilevel internal
* @declaredat ASTNode:16
*/
private int childIndex;
/**
* @apilevel low-level
* @declaredat ASTNode:21
*/
public int getIndexOfChild(ASTNode node) {
if (node == null) {
return -1;
}
if (node.childIndex < numChildren && node == children[node.childIndex]) {
return node.childIndex;
}
for(int i = 0; children != null && i < children.length; i++) {
if (children[i] == node) {
node.childIndex = i;
return i;
}
}
return -1;
}
/**
* @apilevel internal
* @declaredat ASTNode:40
*/
public static final boolean generatedWithCacheCycle = true;
/**
* @apilevel internal
* @declaredat ASTNode:44
*/
public static final boolean generatedWithComponentCheck = false;
/**
* Parent pointer
* @apilevel low-level
* @declaredat ASTNode:50
*/
protected ASTNode parent;
/**
* Child array
* @apilevel low-level
* @declaredat ASTNode:56
*/
protected ASTNode[] children;
/**
* @apilevel internal
* @declaredat ASTNode:62
*/
private static ASTNode$State state = new ASTNode$State();
/**
* @apilevel internal
* @declaredat ASTNode:67
*/
public final ASTNode$State state() {
return state;
}
/**
* @apilevel low-level
* @declaredat ASTNode:75
*/
public T getChild(int i) {
// No rewrites
ASTNode child = getChildNoTransform(i);
return (T) child;
}
/**
* @apilevel low-level
* @declaredat ASTNode:85
*/
public void addChild(T node) {
setChild(node, getNumChildNoTransform());
}
/**
* This method does not invoke AST transformations.
* @apilevel low-level
* @declaredat ASTNode:92
*/
public final T getChildNoTransform(int i) {
if (children == null) {
return null;
}
T child = (T)children[i];
return child;
}
/**
* @apilevel low-level
* @declaredat ASTNode:102
*/
protected int numChildren;
/**
* @apilevel low-level
* @declaredat ASTNode:107
*/
protected int numChildren() {
return numChildren;
}
/**
* @apilevel low-level
* @declaredat ASTNode:114
*/
public int getNumChild() {
return numChildren();
}
/**
* This method does not invoke AST transformations.
* @apilevel low-level
* @declaredat ASTNode:122
*/
public final int getNumChildNoTransform() {
return numChildren();
}
/**
* @apilevel low-level
* @declaredat ASTNode:128
*/
public void setChild(ASTNode node, int i) {
if (children == null) {
children = new ASTNode[(i+1>4 || !(this instanceof List))?i+1:4];
} else if (i >= children.length) {
ASTNode c[] = new ASTNode[i << 1];
System.arraycopy(children, 0, c, 0, children.length);
children = c;
}
children[i] = node;
if (i >= numChildren) {
numChildren = i+1;
}
if (node != null) {
node.setParent(this);
node.childIndex = i;
}
}
/**
* @apilevel low-level
* @declaredat ASTNode:148
*/
public void insertChild(ASTNode node, int i) {
if (children == null) {
children = new ASTNode[(i+1>4 || !(this instanceof List))?i+1:4];
children[i] = node;
} else {
ASTNode c[] = new ASTNode[children.length + 1];
System.arraycopy(children, 0, c, 0, i);
c[i] = node;
if (i < children.length) {
System.arraycopy(children, i, c, i+1, children.length-i);
for(int j = i+1; j < c.length; ++j) {
if (c[j] != null) {
c[j].childIndex = j;
}
}
}
children = c;
}
numChildren++;
if (node != null) {
node.setParent(this);
node.childIndex = i;
}
}
/**
* @apilevel low-level
* @declaredat ASTNode:175
*/
public void removeChild(int i) {
if (children != null) {
ASTNode child = (ASTNode) children[i];
if (child != null) {
child.parent = null;
child.childIndex = -1;
}
// Adding a check of this instance to make sure its a List, a move of children doesn't make
// any sense for a node unless its a list. Also, there is a problem if a child of a non-List node is removed
// and siblings are moved one step to the right, with null at the end.
if (this instanceof List || this instanceof Opt) {
System.arraycopy(children, i+1, children, i, children.length-i-1);
children[children.length-1] = null;
numChildren--;
// fix child indices
for(int j = i; j < numChildren; ++j) {
if (children[j] != null) {
child = (ASTNode) children[j];
child.childIndex = j;
}
}
} else {
children[i] = null;
}
}
}
/**
* @apilevel low-level
* @declaredat ASTNode:204
*/
public ASTNode getParent() {
return (ASTNode) parent;
}
/**
* @apilevel low-level
* @declaredat ASTNode:210
*/
public void setParent(ASTNode node) {
parent = node;
}
/**
* @apilevel low-level
* @declaredat ASTNode:260
*/
public java.util.Iterator iterator() {
return new java.util.Iterator() {
private int counter = 0;
public boolean hasNext() {
return counter < getNumChild();
}
public T next() {
if (hasNext())
return (T)getChild(counter++);
else
return null;
}
public void remove() {
throw new UnsupportedOperationException();
}
};
}
/**
* @apilevel low-level
* @declaredat ASTNode:280
*/
public void flushTreeCache() {
flushCache();
if (children == null) {
return;
}
for (int i = 0; i < children.length; i++) {
if (children[i] != null) {
((ASTNode)children[i]).flushTreeCache();
}
}
}
/**
* @apilevel low-level
* @declaredat ASTNode:294
*/
public void flushCache() {
flushAttrAndCollectionCache();
}
/**
* @apilevel internal
* @declaredat ASTNode:300
*/
public void flushAttrAndCollectionCache() {
flushAttrCache();
flushCollectionCache();
}
/**
* @apilevel internal
* @declaredat ASTNode:307
*/
public void flushAttrCache() {
}
/**
* @apilevel internal
* @declaredat ASTNode:312
*/
public void flushCollectionCache() {
}
/**
* @apilevel internal
* @declaredat ASTNode:317
*/
public ASTNode clone() throws CloneNotSupportedException {
ASTNode node = (ASTNode) super.clone();
node.flushAttrAndCollectionCache();
return node;
}
/**
* @apilevel internal
* @declaredat ASTNode:325
*/
public ASTNode copy() {
try {
ASTNode node = (ASTNode) clone();
node.parent = null;
if (children != null) {
node.children = (ASTNode[]) children.clone();
}
return node;
} catch (CloneNotSupportedException e) {
throw new Error("Error: clone not supported for " + getClass().getName());
}
}
/**
* Create a deep copy of the AST subtree at this node.
* The copy is dangling, i.e. has no parent.
* @return dangling copy of the subtree at this node
* @apilevel low-level
* @deprecated Please use treeCopy or treeCopyNoTransform instead
* @declaredat ASTNode:344
*/
@Deprecated
public ASTNode fullCopy() {
return treeCopyNoTransform();
}
/**
* Create a deep copy of the AST subtree at this node.
* The copy is dangling, i.e. has no parent.
* @return dangling copy of the subtree at this node
* @apilevel low-level
* @declaredat ASTNode:354
*/
public ASTNode treeCopyNoTransform() {
ASTNode tree = (ASTNode) copy();
if (children != null) {
for (int i = 0; i < children.length; ++i) {
ASTNode child = (ASTNode) children[i];
if (child != null) {
child = child.treeCopyNoTransform();
tree.setChild(child, i);
}
}
}
return tree;
}
/**
* Create a deep copy of the AST subtree at this node.
* The subtree of this node is traversed to trigger rewrites before copy.
* The copy is dangling, i.e. has no parent.
* @return dangling copy of the subtree at this node
* @apilevel low-level
* @declaredat ASTNode:374
*/
public ASTNode treeCopy() {
doFullTraversal();
return treeCopyNoTransform();
}
/**
* Performs a full traversal of the tree using getChild to trigger rewrites
* @apilevel low-level
* @declaredat ASTNode:382
*/
public void doFullTraversal() {
for (int i = 0; i < getNumChild(); i++) {
getChild(i).doFullTraversal();
}
}
/**
* @apilevel internal
* @declaredat ASTNode:390
*/
protected boolean is$Equal(ASTNode n1, ASTNode n2) {
if (n1 == null && n2 == null) return true;
if (n1 == null || n2 == null) return false;
return n1.is$Equal(n2);
}
/**
* @apilevel internal
* @declaredat ASTNode:398
*/
protected boolean is$Equal(ASTNode node) {
if (getClass() != node.getClass()) {
return false;
}
if (numChildren != node.numChildren) {
return false;
}
for (int i = 0; i < numChildren; i++) {
if (children[i] == null && node.children[i] != null) {
return false;
}
if (!((ASTNode)children[i]).is$Equal(((ASTNode)node.children[i]))) {
return false;
}
}
return true;
}
/**
* @attribute syn
* @aspect DumpTree
* @declaredat /Users/jesper/git/chunky/chunky/src/jastadd/DumpTree.jrag:20
*/
@ASTNodeAnnotation.Attribute
public String dumpTree() {
{
StringBuffer buff = new StringBuffer(4096);
buff = dumpTree(buff, "");
return buff.toString();
}
}
/**
* @attribute syn
* @aspect DumpTree
* @declaredat /Users/jesper/git/chunky/chunky/src/jastadd/DumpTree.jrag:26
*/
@ASTNodeAnnotation.Attribute
public StringBuffer dumpTree(StringBuffer buff) {
{
buff.append(name() + extraInfo());
buff.append('\n');
return buff;
}
}
/**
* @attribute syn
* @aspect DumpTree
* @declaredat /Users/jesper/git/chunky/chunky/src/jastadd/DumpTree.jrag:39
*/
@ASTNodeAnnotation.Attribute
public StringBuffer dumpTree(StringBuffer buff, String indent) {
{
buff.append(indent);
buff = dumpTree(buff);
for (int i = 0; i < getNumChild(); ++i) {
buff = getChild(i).dumpTree(buff, indent+" ");
}
return buff;
}
}
@ASTNodeAnnotation.Attribute
public String name() {
String name_value = "AST.Node";
return name_value;
}
@ASTNodeAnnotation.Attribute
public String extraInfo() {
String extraInfo_value = "";
return extraInfo_value;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy