org.extendj.ast.AnnotationMethodDecl Maven / Gradle / Ivy
/* 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/Annotations.ast:3
* @astdecl AnnotationMethodDecl : MethodDecl ::= [DefaultValue:ElementValue];
* @production AnnotationMethodDecl : {@link MethodDecl} ::= [DefaultValue:{@link ElementValue}];
*/
public class AnnotationMethodDecl extends MethodDecl implements Cloneable {
/**
* @aspect Java5PrettyPrint
* @declaredat /home/jesper/git/extendj/java5/frontend/PrettyPrint.jadd:68
*/
public void prettyPrint(PrettyPrinter out) {
if (hasDocComment()) {
out.print(docComment());
}
if (!out.isNewLine()) {
out.println();
}
out.print(getModifiers());
out.print(getTypeAccess());
out.print(" ");
out.print(getID());
out.print("()");
if (hasDefaultValue()) {
out.print(" default ");
out.print(getDefaultValue());
}
out.print(";");
}
/**
* @declaredat ASTNode:1
*/
public AnnotationMethodDecl() {
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[6];
setChild(new List(), 2);
setChild(new List(), 3);
setChild(new Opt(), 4);
setChild(new Opt(), 5);
}
/**
* @declaredat ASTNode:17
*/
@ASTNodeAnnotation.Constructor(
name = {"Modifiers", "TypeAccess", "ID", "Parameter", "Exception", "Block", "DefaultValue"},
type = {"Modifiers", "Access", "String", "List", "List", "Opt", "Opt"},
kind = {"Child", "Child", "Token", "List", "List", "Opt", "Opt"}
)
public AnnotationMethodDecl(Modifiers p0, Access p1, String p2, List p3, List p4, Opt p5, Opt p6) {
setChild(p0, 0);
setChild(p1, 1);
setID(p2);
setChild(p3, 2);
setChild(p4, 3);
setChild(p5, 4);
setChild(p6, 5);
}
/**
* @declaredat ASTNode:31
*/
public AnnotationMethodDecl(Modifiers p0, Access p1, beaver.Symbol p2, List p3, List p4, Opt p5, Opt p6) {
setChild(p0, 0);
setChild(p1, 1);
setID(p2);
setChild(p3, 2);
setChild(p4, 3);
setChild(p5, 4);
setChild(p6, 5);
}
/** @apilevel low-level
* @declaredat ASTNode:41
*/
protected int numChildren() {
return 6;
}
/**
* @apilevel internal
* @declaredat ASTNode:47
*/
public boolean mayHaveRewrite() {
return false;
}
/** @apilevel internal
* @declaredat ASTNode:51
*/
public void flushAttrCache() {
super.flushAttrCache();
attributes_reset();
}
/** @apilevel internal
* @declaredat ASTNode:56
*/
public void flushCollectionCache() {
super.flushCollectionCache();
}
/** @apilevel internal
* @declaredat ASTNode:60
*/
public AnnotationMethodDecl clone() throws CloneNotSupportedException {
AnnotationMethodDecl node = (AnnotationMethodDecl) super.clone();
return node;
}
/** @apilevel internal
* @declaredat ASTNode:65
*/
public AnnotationMethodDecl copy() {
try {
AnnotationMethodDecl node = (AnnotationMethodDecl) 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:84
*/
@Deprecated
public AnnotationMethodDecl 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:94
*/
public AnnotationMethodDecl treeCopyNoTransform() {
AnnotationMethodDecl tree = (AnnotationMethodDecl) 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:114
*/
public AnnotationMethodDecl treeCopy() {
AnnotationMethodDecl tree = (AnnotationMethodDecl) copy();
if (children != null) {
for (int i = 0; i < children.length; ++i) {
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) && (tokenString_ID == ((AnnotationMethodDecl) node).tokenString_ID);
}
/**
* Replaces the Modifiers child.
* @param node The new node to replace the Modifiers child.
* @apilevel high-level
*/
public void setModifiers(Modifiers node) {
setChild(node, 0);
}
/**
* Retrieves the Modifiers child.
* @return The current node used as the Modifiers child.
* @apilevel high-level
*/
@ASTNodeAnnotation.Child(name="Modifiers")
public Modifiers getModifiers() {
return (Modifiers) getChild(0);
}
/**
* Retrieves the Modifiers child.
* This method does not invoke AST transformations.
* @return The current node used as the Modifiers child.
* @apilevel low-level
*/
public Modifiers getModifiersNoTransform() {
return (Modifiers) getChildNoTransform(0);
}
/**
* Replaces the TypeAccess child.
* @param node The new node to replace the TypeAccess child.
* @apilevel high-level
*/
public void setTypeAccess(Access node) {
setChild(node, 1);
}
/**
* Retrieves the TypeAccess child.
* @return The current node used as the TypeAccess child.
* @apilevel high-level
*/
@ASTNodeAnnotation.Child(name="TypeAccess")
public Access getTypeAccess() {
return (Access) getChild(1);
}
/**
* Retrieves the TypeAccess child.
* This method does not invoke AST transformations.
* @return The current node used as the TypeAccess child.
* @apilevel low-level
*/
public Access getTypeAccessNoTransform() {
return (Access) getChildNoTransform(1);
}
/**
* Replaces the lexeme ID.
* @param value The new value for the lexeme ID.
* @apilevel high-level
*/
public void setID(String value) {
tokenString_ID = value;
}
/**
* JastAdd-internal setter for lexeme ID using the Beaver parser.
* @param symbol Symbol containing the new value for the lexeme ID
* @apilevel internal
*/
public void setID(beaver.Symbol symbol) {
if (symbol.value != null && !(symbol.value instanceof String))
throw new UnsupportedOperationException("setID is only valid for String lexemes");
tokenString_ID = (String)symbol.value;
IDstart = symbol.getStart();
IDend = symbol.getEnd();
}
/**
* Retrieves the value for the lexeme ID.
* @return The value for the lexeme ID.
* @apilevel high-level
*/
@ASTNodeAnnotation.Token(name="ID")
public String getID() {
return tokenString_ID != null ? tokenString_ID : "";
}
/**
* Replaces the Parameter list.
* @param list The new list node to be used as the Parameter list.
* @apilevel high-level
*/
public void setParameterList(List list) {
setChild(list, 2);
}
/**
* Retrieves the number of children in the Parameter list.
* @return Number of children in the Parameter list.
* @apilevel high-level
*/
public int getNumParameter() {
return getParameterList().getNumChild();
}
/**
* Retrieves the number of children in the Parameter list.
* Calling this method will not trigger rewrites.
* @return Number of children in the Parameter list.
* @apilevel low-level
*/
public int getNumParameterNoTransform() {
return getParameterListNoTransform().getNumChildNoTransform();
}
/**
* Retrieves the element at index {@code i} in the Parameter list.
* @param i Index of the element to return.
* @return The element at position {@code i} in the Parameter list.
* @apilevel high-level
*/
public ParameterDeclaration getParameter(int i) {
return (ParameterDeclaration) getParameterList().getChild(i);
}
/**
* Check whether the Parameter list has any children.
* @return {@code true} if it has at least one child, {@code false} otherwise.
* @apilevel high-level
*/
public boolean hasParameter() {
return getParameterList().getNumChild() != 0;
}
/**
* Append an element to the Parameter list.
* @param node The element to append to the Parameter list.
* @apilevel high-level
*/
public void addParameter(ParameterDeclaration node) {
List list = (parent == null) ? getParameterListNoTransform() : getParameterList();
list.addChild(node);
}
/** @apilevel low-level
*/
public void addParameterNoTransform(ParameterDeclaration node) {
List list = getParameterListNoTransform();
list.addChild(node);
}
/**
* Replaces the Parameter 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 setParameter(ParameterDeclaration node, int i) {
List list = getParameterList();
list.setChild(node, i);
}
/**
* Retrieves the Parameter list.
* @return The node representing the Parameter list.
* @apilevel high-level
*/
@ASTNodeAnnotation.ListChild(name="Parameter")
public List getParameterList() {
List list = (List) getChild(2);
return list;
}
/**
* Retrieves the Parameter list.
* This method does not invoke AST transformations.
* @return The node representing the Parameter list.
* @apilevel low-level
*/
public List getParameterListNoTransform() {
return (List) getChildNoTransform(2);
}
/**
* @return the element at index {@code i} in the Parameter list without
* triggering rewrites.
*/
public ParameterDeclaration getParameterNoTransform(int i) {
return (ParameterDeclaration) getParameterListNoTransform().getChildNoTransform(i);
}
/**
* Retrieves the Parameter list.
* @return The node representing the Parameter list.
* @apilevel high-level
*/
public List getParameters() {
return getParameterList();
}
/**
* Retrieves the Parameter list.
* This method does not invoke AST transformations.
* @return The node representing the Parameter list.
* @apilevel low-level
*/
public List getParametersNoTransform() {
return getParameterListNoTransform();
}
/**
* Replaces the Exception list.
* @param list The new list node to be used as the Exception list.
* @apilevel high-level
*/
public void setExceptionList(List list) {
setChild(list, 3);
}
/**
* Retrieves the number of children in the Exception list.
* @return Number of children in the Exception list.
* @apilevel high-level
*/
public int getNumException() {
return getExceptionList().getNumChild();
}
/**
* Retrieves the number of children in the Exception list.
* Calling this method will not trigger rewrites.
* @return Number of children in the Exception list.
* @apilevel low-level
*/
public int getNumExceptionNoTransform() {
return getExceptionListNoTransform().getNumChildNoTransform();
}
/**
* Retrieves the element at index {@code i} in the Exception list.
* @param i Index of the element to return.
* @return The element at position {@code i} in the Exception list.
* @apilevel high-level
*/
public Access getException(int i) {
return (Access) getExceptionList().getChild(i);
}
/**
* Check whether the Exception list has any children.
* @return {@code true} if it has at least one child, {@code false} otherwise.
* @apilevel high-level
*/
public boolean hasException() {
return getExceptionList().getNumChild() != 0;
}
/**
* Append an element to the Exception list.
* @param node The element to append to the Exception list.
* @apilevel high-level
*/
public void addException(Access node) {
List list = (parent == null) ? getExceptionListNoTransform() : getExceptionList();
list.addChild(node);
}
/** @apilevel low-level
*/
public void addExceptionNoTransform(Access node) {
List list = getExceptionListNoTransform();
list.addChild(node);
}
/**
* Replaces the Exception 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 setException(Access node, int i) {
List list = getExceptionList();
list.setChild(node, i);
}
/**
* Retrieves the Exception list.
* @return The node representing the Exception list.
* @apilevel high-level
*/
@ASTNodeAnnotation.ListChild(name="Exception")
public List getExceptionList() {
List list = (List) getChild(3);
return list;
}
/**
* Retrieves the Exception list.
* This method does not invoke AST transformations.
* @return The node representing the Exception list.
* @apilevel low-level
*/
public List getExceptionListNoTransform() {
return (List) getChildNoTransform(3);
}
/**
* @return the element at index {@code i} in the Exception list without
* triggering rewrites.
*/
public Access getExceptionNoTransform(int i) {
return (Access) getExceptionListNoTransform().getChildNoTransform(i);
}
/**
* Retrieves the Exception list.
* @return The node representing the Exception list.
* @apilevel high-level
*/
public List getExceptions() {
return getExceptionList();
}
/**
* Retrieves the Exception list.
* This method does not invoke AST transformations.
* @return The node representing the Exception list.
* @apilevel low-level
*/
public List getExceptionsNoTransform() {
return getExceptionListNoTransform();
}
/**
* Replaces the optional node for the Block child. This is the Opt
* node containing the child Block, not the actual child!
* @param opt The new node to be used as the optional node for the Block child.
* @apilevel low-level
*/
public void setBlockOpt(Opt opt) {
setChild(opt, 4);
}
/**
* Replaces the (optional) Block child.
* @param node The new node to be used as the Block child.
* @apilevel high-level
*/
public void setBlock(Block node) {
getBlockOpt().setChild(node, 0);
}
/**
* Check whether the optional Block child exists.
* @return {@code true} if the optional Block child exists, {@code false} if it does not.
* @apilevel high-level
*/
public boolean hasBlock() {
return getBlockOpt().getNumChild() != 0;
}
/**
* Retrieves the (optional) Block child.
* @return The Block child, if it exists. Returns {@code null} otherwise.
* @apilevel low-level
*/
public Block getBlock() {
return (Block) getBlockOpt().getChild(0);
}
/**
* Retrieves the optional node for the Block child. This is the Opt
node containing the child Block, not the actual child!
* @return The optional node for child the Block child.
* @apilevel low-level
*/
@ASTNodeAnnotation.OptChild(name="Block")
public Opt getBlockOpt() {
return (Opt) getChild(4);
}
/**
* Retrieves the optional node for child Block. This is the Opt
node containing the child Block, not the actual child!
* This method does not invoke AST transformations.
* @return The optional node for child Block.
* @apilevel low-level
*/
public Opt getBlockOptNoTransform() {
return (Opt) getChildNoTransform(4);
}
/**
* Replaces the optional node for the DefaultValue child. This is the Opt
* node containing the child DefaultValue, not the actual child!
* @param opt The new node to be used as the optional node for the DefaultValue child.
* @apilevel low-level
*/
public void setDefaultValueOpt(Opt opt) {
setChild(opt, 5);
}
/**
* Replaces the (optional) DefaultValue child.
* @param node The new node to be used as the DefaultValue child.
* @apilevel high-level
*/
public void setDefaultValue(ElementValue node) {
getDefaultValueOpt().setChild(node, 0);
}
/**
* Check whether the optional DefaultValue child exists.
* @return {@code true} if the optional DefaultValue child exists, {@code false} if it does not.
* @apilevel high-level
*/
public boolean hasDefaultValue() {
return getDefaultValueOpt().getNumChild() != 0;
}
/**
* Retrieves the (optional) DefaultValue child.
* @return The DefaultValue child, if it exists. Returns {@code null} otherwise.
* @apilevel low-level
*/
public ElementValue getDefaultValue() {
return (ElementValue) getDefaultValueOpt().getChild(0);
}
/**
* Retrieves the optional node for the DefaultValue child. This is the Opt
node containing the child DefaultValue, not the actual child!
* @return The optional node for child the DefaultValue child.
* @apilevel low-level
*/
@ASTNodeAnnotation.OptChild(name="DefaultValue")
public Opt getDefaultValueOpt() {
return (Opt) getChild(5);
}
/**
* Retrieves the optional node for child DefaultValue. This is the Opt
node containing the child DefaultValue, not the actual child!
* This method does not invoke AST transformations.
* @return The optional node for child DefaultValue.
* @apilevel low-level
*/
public Opt getDefaultValueOptNoTransform() {
return (Opt) getChildNoTransform(5);
}
/** @apilevel internal */
private void attributes_reset() {
attributes_computed = null;
attributes_value = null;
}
/** @apilevel internal */
protected ASTState.Cycle attributes_computed = null;
/** @apilevel internal */
protected Collection attributes_value;
/**
* @attribute syn
* @aspect Attributes
* @declaredat /home/jesper/git/extendj/java4/backend/Attributes.jrag:274
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="Attributes", declaredAt="/home/jesper/git/extendj/java4/backend/Attributes.jrag:274")
public Collection attributes() {
ASTState state = state();
if (attributes_computed == ASTState.NON_CYCLE || attributes_computed == state().cycle()) {
return attributes_value;
}
attributes_value = attributes_compute();
if (state().inCircle()) {
attributes_computed = state().cycle();
} else {
attributes_computed = ASTState.NON_CYCLE;
}
return attributes_value;
}
/** @apilevel internal */
private Collection attributes_compute() {
Collection attributes = super.attributes();
// 4.8.19
if (hasDefaultValue()) {
Attribute attribute = new Attribute(hostType().constantPool(), "AnnotationDefault");
getDefaultValue().appendAsAttributeTo(attribute);
attributes.add(attribute);
}
return attributes;
}
/**
* @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:723
* @apilevel internal
*/
public TypeDecl Define_declType(ASTNode _callerNode, ASTNode _childNode) {
int childIndex = this.getIndexOfChild(_callerNode);
return type();
}
/**
* @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:723
* @apilevel internal
* @return {@code true} if this node has an equation for the inherited attribute declType
*/
protected boolean canDefine_declType(ASTNode _callerNode, ASTNode _childNode) {
return true;
}
/** @apilevel internal */
public ASTNode rewriteTo() {
return super.rewriteTo();
}
/** @apilevel internal */
public boolean canRewrite() {
return false;
}
/** @apilevel internal */
protected void collect_contributors_CompilationUnit_problems(CompilationUnit _root, java.util.Map> _map) {
// @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:254
if (hasDefaultValue() && !type().commensurateWith(getDefaultValue())) {
{
java.util.Set contributors = _map.get(_root);
if (contributors == null) {
contributors = new java.util.LinkedHashSet();
_map.put((ASTNode) _root, contributors);
}
contributors.add(this);
}
}
super.collect_contributors_CompilationUnit_problems(_root, _map);
}
/** @apilevel internal */
protected void contributeTo_CompilationUnit_problems(LinkedList collection) {
super.contributeTo_CompilationUnit_problems(collection);
if (hasDefaultValue() && !type().commensurateWith(getDefaultValue())) {
collection.add(errorf("%s is not commensurate with %s",
type().typeName(), getDefaultValue().type().typeName()));
}
}
}