org.extendj.ast.EnumInstanceExpr Maven / Gradle / Ivy
The newest version!
/* This file was generated with JastAdd2 (http://jastadd.org) version 2.3.0 */
package org.extendj.ast;
import java.util.ArrayList;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.IOException;
import java.util.Set;
import beaver.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.LinkedHashSet;
import java.util.*;
import org.jastadd.util.PrettyPrintable;
import org.jastadd.util.PrettyPrinter;
import java.util.zip.*;
import java.io.*;
import org.jastadd.util.*;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
/**
* @ast node
* @declaredat /home/jesper/git/extendj/java5/grammar/Enums.ast:5
* @astdecl EnumInstanceExpr : ClassInstanceExpr ::= Access Arg:Expr* [TypeDecl];
* @production EnumInstanceExpr : {@link ClassInstanceExpr} ::= {@link Access} Arg:{@link Expr}* [{@link TypeDecl}];
*/
public class EnumInstanceExpr extends ClassInstanceExpr implements Cloneable {
/**
* @declaredat ASTNode:1
*/
public EnumInstanceExpr() {
super();
}
/**
* Initializes the child array to the correct size.
* Initializes List and Opt nta children.
* @apilevel internal
* @ast method
* @declaredat ASTNode:10
*/
public void init$Children() {
children = new ASTNode[3];
setChild(new Opt(), 0);
setChild(new List(), 2);
}
/**
* @declaredat ASTNode:15
*/
@ASTNodeAnnotation.Constructor(
name = {"TypeDecl"},
type = {"Opt"},
kind = {"Opt"}
)
public EnumInstanceExpr(Opt p0) {
setChild(p0, 0);
}
/** @apilevel low-level
* @declaredat ASTNode:24
*/
protected int numChildren() {
return 1;
}
/**
* @apilevel internal
* @declaredat ASTNode:30
*/
public boolean mayHaveRewrite() {
return false;
}
/** @apilevel internal
* @declaredat ASTNode:34
*/
public void flushAttrCache() {
super.flushAttrCache();
getAccess_reset();
getArgList_reset();
}
/** @apilevel internal
* @declaredat ASTNode:40
*/
public void flushCollectionCache() {
super.flushCollectionCache();
}
/** @apilevel internal
* @declaredat ASTNode:44
*/
public EnumInstanceExpr clone() throws CloneNotSupportedException {
EnumInstanceExpr node = (EnumInstanceExpr) super.clone();
return node;
}
/** @apilevel internal
* @declaredat ASTNode:49
*/
public EnumInstanceExpr copy() {
try {
EnumInstanceExpr node = (EnumInstanceExpr) 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:68
*/
@Deprecated
public EnumInstanceExpr 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:78
*/
public EnumInstanceExpr treeCopyNoTransform() {
EnumInstanceExpr tree = (EnumInstanceExpr) copy();
if (children != null) {
for (int i = 0; i < children.length; ++i) {
switch (i) {
case 1:
tree.children[i] = null;
continue;
case 2:
tree.children[i] = new List();
continue;
}
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:106
*/
public EnumInstanceExpr treeCopy() {
EnumInstanceExpr tree = (EnumInstanceExpr) copy();
if (children != null) {
for (int i = 0; i < children.length; ++i) {
switch (i) {
case 1:
tree.children[i] = null;
continue;
case 2:
tree.children[i] = new List();
continue;
}
ASTNode child = (ASTNode) getChild(i);
if (child != null) {
child = child.treeCopy();
tree.setChild(child, i);
}
}
}
return tree;
}
/** @apilevel internal
* @declaredat ASTNode:128
*/
protected boolean is$Equal(ASTNode node) {
return super.is$Equal(node);
}
/**
* Replaces the optional node for the TypeDecl child. This is the Opt
* node containing the child TypeDecl, not the actual child!
* @param opt The new node to be used as the optional node for the TypeDecl child.
* @apilevel low-level
*/
public void setTypeDeclOpt(Opt opt) {
setChild(opt, 0);
}
/**
* Replaces the (optional) TypeDecl child.
* @param node The new node to be used as the TypeDecl child.
* @apilevel high-level
*/
public void setTypeDecl(TypeDecl node) {
getTypeDeclOpt().setChild(node, 0);
}
/**
* Check whether the optional TypeDecl child exists.
* @return {@code true} if the optional TypeDecl child exists, {@code false} if it does not.
* @apilevel high-level
*/
public boolean hasTypeDecl() {
return getTypeDeclOpt().getNumChild() != 0;
}
/**
* Retrieves the (optional) TypeDecl child.
* @return The TypeDecl child, if it exists. Returns {@code null} otherwise.
* @apilevel low-level
*/
public TypeDecl getTypeDecl() {
return (TypeDecl) getTypeDeclOpt().getChild(0);
}
/**
* Retrieves the optional node for the TypeDecl child. This is the Opt
node containing the child TypeDecl, not the actual child!
* @return The optional node for child the TypeDecl child.
* @apilevel low-level
*/
@ASTNodeAnnotation.OptChild(name="TypeDecl")
public Opt getTypeDeclOpt() {
return (Opt) getChild(0);
}
/**
* Retrieves the optional node for child TypeDecl. This is the Opt
node containing the child TypeDecl, not the actual child!
* This method does not invoke AST transformations.
* @return The optional node for child TypeDecl.
* @apilevel low-level
*/
public Opt getTypeDeclOptNoTransform() {
return (Opt) getChildNoTransform(0);
}
/**
* This method should not be called. This method throws an exception due to
* the corresponding child being an NTA shadowing a non-NTA child.
* @param node
* @apilevel internal
*/
public void setAccess(Access node) {
throw new Error("Can not replace NTA child Access in EnumInstanceExpr!");
}
/**
* Retrieves the Access child.
* This method does not invoke AST transformations.
* @return The current node used as the Access child.
* @apilevel low-level
*/
public Access getAccessNoTransform() {
return (Access) getChildNoTransform(1);
}
/**
* Retrieves the child position of the optional child Access.
* @return The the child position of the optional child Access.
* @apilevel low-level
*/
protected int getAccessChildPosition() {
return 1;
}
/**
* This method should not be called. This method throws an exception due to
* the corresponding child being an NTA shadowing a non-NTA child.
* @param node
* @apilevel internal
*/
public void setArgList(List node) {
throw new Error("Can not replace NTA child ArgList in EnumInstanceExpr!");
}
/**
* Retrieves the number of children in the Arg list.
* @return Number of children in the Arg list.
* @apilevel high-level
*/
public int getNumArg() {
return getArgList().getNumChild();
}
/**
* Retrieves the number of children in the Arg list.
* Calling this method will not trigger rewrites.
* @return Number of children in the Arg list.
* @apilevel low-level
*/
public int getNumArgNoTransform() {
return getArgListNoTransform().getNumChildNoTransform();
}
/**
* Retrieves the element at index {@code i} in the Arg list.
* @param i Index of the element to return.
* @return The element at position {@code i} in the Arg list.
* @apilevel high-level
*/
public Expr getArg(int i) {
return (Expr) getArgList().getChild(i);
}
/**
* Check whether the Arg list has any children.
* @return {@code true} if it has at least one child, {@code false} otherwise.
* @apilevel high-level
*/
public boolean hasArg() {
return getArgList().getNumChild() != 0;
}
/**
* Append an element to the Arg list.
* @param node The element to append to the Arg list.
* @apilevel high-level
*/
public void addArg(Expr node) {
List list = (parent == null) ? getArgListNoTransform() : getArgList();
list.addChild(node);
}
/** @apilevel low-level
*/
public void addArgNoTransform(Expr node) {
List list = getArgListNoTransform();
list.addChild(node);
}
/**
* Replaces the Arg list element at index {@code i} with the new node {@code node}.
* @param node The new node to replace the old list element.
* @param i The list index of the node to be replaced.
* @apilevel high-level
*/
public void setArg(Expr node, int i) {
List list = getArgList();
list.setChild(node, i);
}
/**
* Retrieves the child position of the Arg list.
* @return The the child position of the Arg list.
* @apilevel low-level
*/
protected int getArgListChildPosition() {
return 2;
}
/**
* Retrieves the Arg list.
* This method does not invoke AST transformations.
* @return The node representing the Arg list.
* @apilevel low-level
*/
public List getArgListNoTransform() {
return (List) getChildNoTransform(2);
}
/**
* @return the element at index {@code i} in the Arg list without
* triggering rewrites.
*/
public Expr getArgNoTransform(int i) {
return (Expr) getArgListNoTransform().getChildNoTransform(i);
}
/**
* Retrieves the Arg list.
* @return The node representing the Arg list.
* @apilevel high-level
*/
public List getArgs() {
return getArgList();
}
/**
* Retrieves the Arg list.
* This method does not invoke AST transformations.
* @return The node representing the Arg list.
* @apilevel low-level
*/
public List getArgsNoTransform() {
return getArgListNoTransform();
}
/** @apilevel internal */
private void getAccess_reset() {
getAccess_computed = false;
getAccess_value = null;
}
/** @apilevel internal */
protected boolean getAccess_computed = false;
/** @apilevel internal */
protected Access getAccess_value;
/**
* @attribute syn nta
* @aspect Enums
* @declaredat /home/jesper/git/extendj/java5/frontend/Enums.jrag:292
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN, isNTA=true)
@ASTNodeAnnotation.Source(aspect="Enums", declaredAt="/home/jesper/git/extendj/java5/frontend/Enums.jrag:292")
public Access getAccess() {
ASTState state = state();
if (getAccess_computed) {
return (Access) getChild(getAccessChildPosition());
}
state().enterLazyAttribute();
getAccess_value = getAccess_compute();
setChild(getAccess_value, getAccessChildPosition());
getAccess_computed = true;
state().leaveLazyAttribute();
Access node = (Access) this.getChild(getAccessChildPosition());
return node;
}
/** @apilevel internal */
private Access getAccess_compute() {
return hostType().createQualifiedAccess();
}
/** @apilevel internal */
private void getArgList_reset() {
getArgList_computed = false;
getArgList_value = null;
}
/** @apilevel internal */
protected boolean getArgList_computed = false;
/** @apilevel internal */
protected List getArgList_value;
/**
* @attribute syn nta
* @aspect Enums
* @declaredat /home/jesper/git/extendj/java5/frontend/Enums.jrag:296
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN, isNTA=true)
@ASTNodeAnnotation.Source(aspect="Enums", declaredAt="/home/jesper/git/extendj/java5/frontend/Enums.jrag:296")
public List getArgList() {
ASTState state = state();
if (getArgList_computed) {
return (List) getChild(getArgListChildPosition());
}
state().enterLazyAttribute();
getArgList_value = getArgList_compute();
setChild(getArgList_value, getArgListChildPosition());
getArgList_computed = true;
state().leaveLazyAttribute();
List node = (List) this.getChild(getArgListChildPosition());
return node;
}
/** @apilevel internal */
private List getArgList_compute() {
EnumConstant ec = (EnumConstant) getParent().getParent();
List ecs = (List) ec.getParent();
int idx = ecs.getIndexOfChild(ec);
if (idx == -1) {
throw new Error("internal: cannot determine numeric value of enum constant");
}
List argList = new List();
argList.add(Literal.buildStringLiteral(ec.name()));
argList.add(Literal.buildIntegerLiteral(idx));
for (Expr arg : ec.getArgs()) {
argList.add((Expr) arg.treeCopyNoTransform());
}
return argList;
}
/** @apilevel internal */
public ASTNode rewriteTo() {
return super.rewriteTo();
}
/** @apilevel internal */
public boolean canRewrite() {
return false;
}
}