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 ElementValuePair : {@link ASTNode} ::= <span class="component">&lt;Name:String&gt;</span> <span class="component">{@link ElementValue}</span>;
015     * @ast node
016     * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Annotations.ast:8
017     */
018    public class ElementValuePair extends ASTNode<ASTNode> 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 ElementValuePair clone() throws CloneNotSupportedException {
034        ElementValuePair node = (ElementValuePair)super.clone();
035        node.type_computed = false;
036        node.type_value = null;
037        node.in$Circle(false);
038        node.is$Final(false);
039        return node;
040      }
041    /**
042     * @apilevel internal
043     */
044      @SuppressWarnings({"unchecked", "cast"})
045    public ElementValuePair copy() {
046      
047      try {
048        ElementValuePair node = (ElementValuePair) clone();
049        node.parent = null;
050        if(children != null)
051          node.children = (ASTNode[]) children.clone();
052        
053        return node;
054      } catch (CloneNotSupportedException e) {
055        throw new Error("Error: clone not supported for " + getClass().getName());
056      }
057      
058    }/**
059     * Create a deep copy of the AST subtree at this node.
060     * The copy is dangling, i.e. has no parent.
061     * @return dangling copy of the subtree at this node
062     * @apilevel low-level
063     */
064      @SuppressWarnings({"unchecked", "cast"})
065    public ElementValuePair fullCopy() {
066      
067      ElementValuePair tree = (ElementValuePair) copy();
068      if (children != null) {
069        for (int i = 0; i < children.length; ++i) {
070          
071          ASTNode child = (ASTNode) children[i];
072          if(child != null) {
073            child = child.fullCopy();
074            tree.setChild(child, i);
075          }
076        }
077      }
078      return tree;
079      
080    }  /**
081       * @ast method 
082       * @aspect Annotations
083       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Annotations.jrag:504
084       */
085      public void typeCheck() {
086        if(!type().commensurateWith(getElementValue()))
087          error("can not construct annotation with " + getName() +
088              " = " + getElementValue().toString() + "; " + type().typeName() +
089              " is not commensurate with " + getElementValue().type().typeName());
090      }
091      /**
092       * @ast method 
093       * @aspect Annotations
094       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Annotations.jrag:593
095       */
096      public void toString(StringBuffer s) {
097        s.append(getName() + " = ");
098        getElementValue().toString(s);
099      }
100      /**
101       * @ast method 
102       * 
103       */
104      public ElementValuePair() {
105        super();
106    
107    
108      }
109      /**
110       * Initializes the child array to the correct size.
111       * Initializes List and Opt nta children.
112       * @apilevel internal
113       * @ast method
114       * @ast method 
115       * 
116       */
117      public void init$Children() {
118        children = new ASTNode[1];
119      }
120      /**
121       * @ast method 
122       * 
123       */
124      public ElementValuePair(String p0, ElementValue p1) {
125        setName(p0);
126        setChild(p1, 0);
127      }
128      /**
129       * @ast method 
130       * 
131       */
132      public ElementValuePair(beaver.Symbol p0, ElementValue p1) {
133        setName(p0);
134        setChild(p1, 0);
135      }
136      /**
137       * @apilevel low-level
138       * @ast method 
139       * 
140       */
141      protected int numChildren() {
142        return 1;
143      }
144      /**
145       * @apilevel internal
146       * @ast method 
147       * 
148       */
149      public boolean mayHaveRewrite() {
150        return true;
151      }
152      /**
153       * Replaces the lexeme Name.
154       * @param value The new value for the lexeme Name.
155       * @apilevel high-level
156       * @ast method 
157       * 
158       */
159      public void setName(String value) {
160        tokenString_Name = value;
161      }
162      /**
163       * @apilevel internal
164       * @ast method 
165       * 
166       */
167      
168      /**
169       * @apilevel internal
170       */
171      protected String tokenString_Name;
172      /**
173       * @ast method 
174       * 
175       */
176      
177      public int Namestart;
178      /**
179       * @ast method 
180       * 
181       */
182      
183      public int Nameend;
184      /**
185       * JastAdd-internal setter for lexeme Name using the Beaver parser.
186       * @apilevel internal
187       * @ast method 
188       * 
189       */
190      public void setName(beaver.Symbol symbol) {
191        if(symbol.value != null && !(symbol.value instanceof String))
192          throw new UnsupportedOperationException("setName is only valid for String lexemes");
193        tokenString_Name = (String)symbol.value;
194        Namestart = symbol.getStart();
195        Nameend = symbol.getEnd();
196      }
197      /**
198       * Retrieves the value for the lexeme Name.
199       * @return The value for the lexeme Name.
200       * @apilevel high-level
201       * @ast method 
202       * 
203       */
204      public String getName() {
205        return tokenString_Name != null ? tokenString_Name : "";
206      }
207      /**
208       * Replaces the ElementValue child.
209       * @param node The new node to replace the ElementValue child.
210       * @apilevel high-level
211       * @ast method 
212       * 
213       */
214      public void setElementValue(ElementValue node) {
215        setChild(node, 0);
216      }
217      /**
218       * Retrieves the ElementValue child.
219       * @return The current node used as the ElementValue child.
220       * @apilevel high-level
221       * @ast method 
222       * 
223       */
224      public ElementValue getElementValue() {
225        return (ElementValue)getChild(0);
226      }
227      /**
228       * Retrieves the ElementValue child.
229       * <p><em>This method does not invoke AST transformations.</em></p>
230       * @return The current node used as the ElementValue child.
231       * @apilevel low-level
232       * @ast method 
233       * 
234       */
235      public ElementValue getElementValueNoTransform() {
236        return (ElementValue)getChildNoTransform(0);
237      }
238      /**
239       * @apilevel internal
240       */
241      protected boolean type_computed = false;
242      /**
243       * @apilevel internal
244       */
245      protected TypeDecl type_value;
246      /* The annotation type named by an annotation must be accessible (\ufffd6.6) at the
247      point where the annotation is used, or a compile-time error occurs.
248      Comment: This is done by the access control framework* @attribute syn
249       * @aspect Annotations
250       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Annotations.jrag:450
251       */
252      @SuppressWarnings({"unchecked", "cast"})
253      public TypeDecl type() {
254        if(type_computed) {
255          return type_value;
256        }
257          ASTNode$State state = state();
258      int num = state.boundariesCrossed;
259      boolean isFinal = this.is$Final();
260        type_value = type_compute();
261      if(isFinal && num == state().boundariesCrossed){ type_computed = true; }
262            return type_value;
263      }
264      /**
265       * @apilevel internal
266       */
267      private TypeDecl type_compute() {
268        Map methodMap = enclosingAnnotationDecl().localMethodsSignatureMap();
269        MethodDecl method = (MethodDecl) methodMap.get(getName()+"()");
270        if (method != null)
271          return method.type();
272        else
273          return unknownType();
274      }
275      /**
276       * @attribute inh
277       * @aspect Annotations
278       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Annotations.jrag:458
279       */
280      @SuppressWarnings({"unchecked", "cast"})
281      public TypeDecl unknownType() {
282          ASTNode$State state = state();
283        TypeDecl unknownType_value = getParent().Define_TypeDecl_unknownType(this, null);
284            return unknownType_value;
285      }
286      /**
287       * @attribute inh
288       * @aspect Annotations
289       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Annotations.jrag:460
290       */
291      @SuppressWarnings({"unchecked", "cast"})
292      public TypeDecl enclosingAnnotationDecl() {
293          ASTNode$State state = state();
294        TypeDecl enclosingAnnotationDecl_value = getParent().Define_TypeDecl_enclosingAnnotationDecl(this, null);
295            return enclosingAnnotationDecl_value;
296      }
297      /**
298       * @apilevel internal
299       */
300      public ASTNode rewriteTo() {
301        // Declared in /home/jesper/svn/JastAddJ/Java1.5Frontend/Annotations.jrag at line 527
302        if(type().isArrayDecl() && getElementValue() instanceof ElementConstantValue) {
303          state().duringAnnotations++;
304          ASTNode result = rewriteRule0();
305          state().duringAnnotations--;
306          return result;
307        }
308    
309        return super.rewriteTo();
310      }
311      /**
312       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Annotations.jrag:527
313       * @apilevel internal
314       */  private ElementValuePair rewriteRule0() {
315    {
316          setElementValue(new ElementArrayValue(new List().add(getElementValue())));
317          return this;
318        }  }
319    }