001    /* This file was generated with JastAdd2 (http://jastadd.org) version R20130213 */
002    package AST;
003    
004    import java.util.HashSet;
005    import java.io.File;
006    import java.util.*;
007    import beaver.*;
008    import java.util.ArrayList;
009    import java.util.zip.*;
010    import java.io.*;
011    import java.io.FileNotFoundException;
012    import java.util.Collection;
013    /**
014     * @production ElementConstantValue : {@link ElementValue} ::= <span class="component">{@link Expr}</span>;
015     * @ast node
016     * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Annotations.ast:11
017     */
018    public class ElementConstantValue extends ElementValue implements Cloneable {
019      /**
020       * @apilevel low-level
021       */
022      public void flushCache() {
023      }
024      /**
025       * @apilevel internal
026       */
027      public void flushCollectionCache() {
028      }
029      /**
030       * @apilevel internal
031       */
032      @SuppressWarnings({"unchecked", "cast"})
033      public ElementConstantValue clone() throws CloneNotSupportedException {
034        ElementConstantValue node = (ElementConstantValue)super.clone();
035        node.in$Circle(false);
036        node.is$Final(false);
037        return node;
038      }
039    /**
040     * @apilevel internal
041     */
042      @SuppressWarnings({"unchecked", "cast"})
043    public ElementConstantValue copy() {
044      
045      try {
046        ElementConstantValue node = (ElementConstantValue) clone();
047        node.parent = null;
048        if(children != null)
049          node.children = (ASTNode[]) children.clone();
050        
051        return node;
052      } catch (CloneNotSupportedException e) {
053        throw new Error("Error: clone not supported for " + getClass().getName());
054      }
055      
056    }/**
057     * Create a deep copy of the AST subtree at this node.
058     * The copy is dangling, i.e. has no parent.
059     * @return dangling copy of the subtree at this node
060     * @apilevel low-level
061     */
062      @SuppressWarnings({"unchecked", "cast"})
063    public ElementConstantValue fullCopy() {
064      
065      ElementConstantValue tree = (ElementConstantValue) copy();
066      if (children != null) {
067        for (int i = 0; i < children.length; ++i) {
068          
069          ASTNode child = (ASTNode) children[i];
070          if(child != null) {
071            child = child.fullCopy();
072            tree.setChild(child, i);
073          }
074        }
075      }
076      return tree;
077      
078    }  /**
079       * @ast method 
080       * @aspect Annotations
081       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Annotations.jrag:169
082       */
083      public void nameCheck() {
084        if(enclosingAnnotationDecl().fullName().equals("java.lang.annotation.Target")) {
085          Variable v = getExpr().varDecl();
086          if(v != null && v.hostType().fullName().equals("java.lang.annotation.ElementType"))
087            if(lookupElementTypeValue(v.name()) != this)
088              error("repeated annotation target");
089        }
090      }
091      /**
092       * @ast method 
093       * @aspect Annotations
094       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Annotations.jrag:597
095       */
096      public void toString(StringBuffer s) {
097        getExpr().toString(s);
098      }
099      /**
100       * @ast method 
101       * @aspect AnnotationsCodegen
102       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Backend/AnnotationsCodegen.jrag:197
103       */
104      public void appendAsAttributeTo(Attribute buf) {
105        if(getExpr().isConstant() && !getExpr().type().isEnumDecl()) {
106          char tag = getExpr().type().isString() ? 's' : getExpr().type().typeDescriptor().charAt(0);
107          int const_value_index = getExpr().type().addAnnotConstant(hostType().constantPool(), getExpr().constant());
108          buf.u1(tag);
109          buf.u2(const_value_index);
110        }
111        else if(getExpr().isClassAccess()) {
112          int const_class_index = hostType().constantPool().addUtf8(getExpr().type().typeDescriptor());
113          buf.u1('c');
114          buf.u2(const_class_index);
115        }
116        else {
117          Variable v = getExpr().varDecl();
118          if(v == null) throw new Error("Expected Enumeration constant");
119    
120          int type_name_index = hostType().constantPool().addUtf8(v.type().typeDescriptor());
121          int const_name_index = hostType().constantPool().addUtf8(v.name());
122          buf.u1('e');
123          buf.u2(type_name_index);
124          buf.u2(const_name_index);
125        }
126      }
127      /**
128       * @ast method 
129       * 
130       */
131      public ElementConstantValue() {
132        super();
133    
134    
135      }
136      /**
137       * Initializes the child array to the correct size.
138       * Initializes List and Opt nta children.
139       * @apilevel internal
140       * @ast method
141       * @ast method 
142       * 
143       */
144      public void init$Children() {
145        children = new ASTNode[1];
146      }
147      /**
148       * @ast method 
149       * 
150       */
151      public ElementConstantValue(Expr p0) {
152        setChild(p0, 0);
153      }
154      /**
155       * @apilevel low-level
156       * @ast method 
157       * 
158       */
159      protected int numChildren() {
160        return 1;
161      }
162      /**
163       * @apilevel internal
164       * @ast method 
165       * 
166       */
167      public boolean mayHaveRewrite() {
168        return false;
169      }
170      /**
171       * Replaces the Expr child.
172       * @param node The new node to replace the Expr child.
173       * @apilevel high-level
174       * @ast method 
175       * 
176       */
177      public void setExpr(Expr node) {
178        setChild(node, 0);
179      }
180      /**
181       * Retrieves the Expr child.
182       * @return The current node used as the Expr child.
183       * @apilevel high-level
184       * @ast method 
185       * 
186       */
187      public Expr getExpr() {
188        return (Expr)getChild(0);
189      }
190      /**
191       * Retrieves the Expr child.
192       * <p><em>This method does not invoke AST transformations.</em></p>
193       * @return The current node used as the Expr child.
194       * @apilevel low-level
195       * @ast method 
196       * 
197       */
198      public Expr getExprNoTransform() {
199        return (Expr)getChildNoTransform(0);
200      }
201      /**
202       * @attribute syn
203       * @aspect Annotations
204       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Annotations.jrag:57
205       */
206      public boolean validTarget(Annotation a) {
207        ASTNode$State state = state();
208        try {
209        Variable v = getExpr().varDecl();
210        if(v == null) return true;
211        return v.hostType().fullName().equals("java.lang.annotation.ElementType") && a.mayUseAnnotationTarget(v.name());
212      }
213        finally {
214        }
215      }
216      /**
217       * @attribute syn
218       * @aspect Annotations
219       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Annotations.jrag:181
220       */
221      public ElementValue definesElementTypeValue(String name) {
222        ASTNode$State state = state();
223        try {
224        Variable v = getExpr().varDecl();
225        if(v != null && v.hostType().fullName().equals("java.lang.annotation.ElementType") && v.name().equals(name))
226          return this;
227        return null;
228      }
229        finally {
230        }
231      }
232      /**
233       * @attribute syn
234       * @aspect Annotations
235       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Annotations.jrag:295
236       */
237      public boolean hasValue(String s) {
238        ASTNode$State state = state();
239        try {  return getExpr().type().isString() &&
240        getExpr().isConstant() && 
241        getExpr().constant().stringValue().equals(s);  }
242        finally {
243        }
244      }
245      /**
246       * @attribute syn
247       * @aspect Annotations
248       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Annotations.jrag:475
249       */
250      public boolean commensurateWithTypeDecl(TypeDecl type) {
251        ASTNode$State state = state();
252        try {
253        Expr v = getExpr();
254        if(!v.type().assignConversionTo(type, v))
255          return false;
256        if((type.isPrimitive() || type.isString()) && !v.isConstant())
257          return false;
258        if(v.type().isNull())
259          return false;
260        if(type.fullName().equals("java.lang.Class") && !v.isClassAccess())
261          return false;
262        if(type.isEnumDecl() && (v.varDecl() == null || !(v.varDecl() instanceof EnumConstant)))
263          return false;
264        return true;
265      }
266        finally {
267        }
268      }
269      /**
270       * @attribute syn
271       * @aspect Annotations
272       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Annotations.jrag:510
273       */
274      public TypeDecl type() {
275        ASTNode$State state = state();
276        try {  return getExpr().type();  }
277        finally {
278        }
279      }
280      /**
281       * @attribute inh
282       * @aspect Annotations
283       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Annotations.jrag:177
284       */
285      @SuppressWarnings({"unchecked", "cast"})
286      public ElementValue lookupElementTypeValue(String name) {
287          ASTNode$State state = state();
288        ElementValue lookupElementTypeValue_String_value = getParent().Define_ElementValue_lookupElementTypeValue(this, null, name);
289            return lookupElementTypeValue_String_value;
290      }
291      /**
292       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Annotations.jrag:550
293       * @apilevel internal
294       */
295      public NameType Define_NameType_nameType(ASTNode caller, ASTNode child) {
296        if(caller == getExprNoTransform()) {
297          return NameType.AMBIGUOUS_NAME;
298        }
299        else {      return getParent().Define_NameType_nameType(this, caller);
300        }
301      }
302      /**
303       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Annotations.jrag:555
304       * @apilevel internal
305       */
306      public String Define_String_methodHost(ASTNode caller, ASTNode child) {
307        if(caller == getExprNoTransform()) {
308          return enclosingAnnotationDecl().typeName();
309        }
310        else {      return getParent().Define_String_methodHost(this, caller);
311        }
312      }
313      /**
314       * @apilevel internal
315       */
316      public ASTNode rewriteTo() {
317        return super.rewriteTo();
318      }
319    }