001    /* This file was generated with JastAdd2 (http://jastadd.org) version 2.1.13-12-g880e696 */
002    package org.extendj.ast;
003    
004    import java.util.HashSet;
005    import java.io.File;
006    import java.util.Set;
007    import java.util.Collections;
008    import java.util.Collection;
009    import java.util.ArrayList;
010    import beaver.*;
011    import java.util.*;
012    import java.io.ByteArrayOutputStream;
013    import java.io.PrintStream;
014    import java.lang.reflect.InvocationTargetException;
015    import java.lang.reflect.Method;
016    import org.jastadd.util.*;
017    import java.util.zip.*;
018    import java.io.*;
019    import org.jastadd.util.PrettyPrintable;
020    import org.jastadd.util.PrettyPrinter;
021    import java.io.FileNotFoundException;
022    import java.io.BufferedInputStream;
023    import java.io.DataInputStream;
024    /**
025     * @ast node
026     * @declaredat /home/jesper/git/extendj/java5/grammar/Annotations.ast:8
027     * @production ElementValuePair : {@link ASTNode} ::= <span class="component">&lt;Name:String&gt;</span> <span class="component">{@link ElementValue}</span>;
028    
029     */
030    public class ElementValuePair extends ASTNode<ASTNode> implements Cloneable {
031      /**
032       * @aspect Annotations
033       * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:594
034       */
035      public void typeCheck() {
036        if (!type().commensurateWith(getElementValue())) {
037          errorf("can not construct annotation with %s = %s; %s is not commensurate with %s",
038              getName(), getElementValue().prettyPrint(), type().typeName(), getElementValue().type().typeName());
039        }
040      }
041      /**
042       * @aspect Java5PrettyPrint
043       * @declaredat /home/jesper/git/extendj/java5/frontend/PrettyPrint.jadd:232
044       */
045      public void prettyPrint(PrettyPrinter out) {
046        out.print(getName());
047        out.print(" = ");
048        out.print(getElementValue());
049      }
050      /**
051       * @declaredat ASTNode:1
052       */
053      public ElementValuePair() {
054        super();
055      }
056      /**
057       * Initializes the child array to the correct size.
058       * Initializes List and Opt nta children.
059       * @apilevel internal
060       * @ast method
061       * @declaredat ASTNode:10
062       */
063      public void init$Children() {
064        children = new ASTNode[1];
065      }
066      /**
067       * @declaredat ASTNode:13
068       */
069      public ElementValuePair(String p0, ElementValue p1) {
070        setName(p0);
071        setChild(p1, 0);
072      }
073      /**
074       * @declaredat ASTNode:17
075       */
076      public ElementValuePair(beaver.Symbol p0, ElementValue p1) {
077        setName(p0);
078        setChild(p1, 0);
079      }
080      /**
081       * @apilevel low-level
082       * @declaredat ASTNode:24
083       */
084      protected int numChildren() {
085        return 1;
086      }
087      /**
088       * @apilevel internal
089       * @declaredat ASTNode:30
090       */
091      public boolean mayHaveRewrite() {
092        return true;
093      }
094      /**
095       * @apilevel internal
096       * @declaredat ASTNode:36
097       */
098      public void flushAttrCache() {
099        super.flushAttrCache();
100        type_reset();
101      }
102      /**
103       * @apilevel internal
104       * @declaredat ASTNode:43
105       */
106      public void flushCollectionCache() {
107        super.flushCollectionCache();
108      }
109      /**
110       * @apilevel internal
111       * @declaredat ASTNode:49
112       */
113      public void flushRewriteCache() {
114        super.flushRewriteCache();
115      }
116      /**
117       * @apilevel internal
118       * @declaredat ASTNode:55
119       */
120      public ElementValuePair clone() throws CloneNotSupportedException {
121        ElementValuePair node = (ElementValuePair) super.clone();
122        return node;
123      }
124      /**
125       * @apilevel internal
126       * @declaredat ASTNode:62
127       */
128      public ElementValuePair copy() {
129        try {
130          ElementValuePair node = (ElementValuePair) clone();
131          node.parent = null;
132          if (children != null) {
133            node.children = (ASTNode[]) children.clone();
134          }
135          return node;
136        } catch (CloneNotSupportedException e) {
137          throw new Error("Error: clone not supported for " + getClass().getName());
138        }
139      }
140      /**
141       * Create a deep copy of the AST subtree at this node.
142       * The copy is dangling, i.e. has no parent.
143       * @return dangling copy of the subtree at this node
144       * @apilevel low-level
145       * @deprecated Please use treeCopy or treeCopyNoTransform instead
146       * @declaredat ASTNode:81
147       */
148      @Deprecated
149      public ElementValuePair fullCopy() {
150        return treeCopyNoTransform();
151      }
152      /**
153       * Create a deep copy of the AST subtree at this node.
154       * The copy is dangling, i.e. has no parent.
155       * @return dangling copy of the subtree at this node
156       * @apilevel low-level
157       * @declaredat ASTNode:91
158       */
159      public ElementValuePair treeCopyNoTransform() {
160        ElementValuePair tree = (ElementValuePair) copy();
161        if (children != null) {
162          for (int i = 0; i < children.length; ++i) {
163            ASTNode child = (ASTNode) children[i];
164            if (child != null) {
165              child = child.treeCopyNoTransform();
166              tree.setChild(child, i);
167            }
168          }
169        }
170        return tree;
171      }
172      /**
173       * Create a deep copy of the AST subtree at this node.
174       * The subtree of this node is traversed to trigger rewrites before copy.
175       * The copy is dangling, i.e. has no parent.
176       * @return dangling copy of the subtree at this node
177       * @apilevel low-level
178       * @declaredat ASTNode:111
179       */
180      public ElementValuePair treeCopy() {
181        doFullTraversal();
182        return treeCopyNoTransform();
183      }
184      /**
185       * @apilevel internal
186       * @declaredat ASTNode:118
187       */
188      protected boolean is$Equal(ASTNode node) {
189        return super.is$Equal(node) && (tokenString_Name == ((ElementValuePair)node).tokenString_Name);    
190      }
191      /**
192       * Replaces the lexeme Name.
193       * @param value The new value for the lexeme Name.
194       * @apilevel high-level
195       */
196      public void setName(String value) {
197        tokenString_Name = value;
198      }
199      /**
200       * @apilevel internal
201       */
202      protected String tokenString_Name;
203      /**
204       */
205      public int Namestart;
206      /**
207       */
208      public int Nameend;
209      /**
210       * JastAdd-internal setter for lexeme Name using the Beaver parser.
211       * @param symbol Symbol containing the new value for the lexeme Name
212       * @apilevel internal
213       */
214      public void setName(beaver.Symbol symbol) {
215        if (symbol.value != null && !(symbol.value instanceof String))
216        throw new UnsupportedOperationException("setName is only valid for String lexemes");
217        tokenString_Name = (String)symbol.value;
218        Namestart = symbol.getStart();
219        Nameend = symbol.getEnd();
220      }
221      /**
222       * Retrieves the value for the lexeme Name.
223       * @return The value for the lexeme Name.
224       * @apilevel high-level
225       */
226      @ASTNodeAnnotation.Token(name="Name")
227      public String getName() {
228        return tokenString_Name != null ? tokenString_Name : "";
229      }
230      /**
231       * Replaces the ElementValue child.
232       * @param node The new node to replace the ElementValue child.
233       * @apilevel high-level
234       */
235      public void setElementValue(ElementValue node) {
236        setChild(node, 0);
237      }
238      /**
239       * Retrieves the ElementValue child.
240       * @return The current node used as the ElementValue child.
241       * @apilevel high-level
242       */
243      @ASTNodeAnnotation.Child(name="ElementValue")
244      public ElementValue getElementValue() {
245        return (ElementValue) getChild(0);
246      }
247      /**
248       * Retrieves the ElementValue child.
249       * <p><em>This method does not invoke AST transformations.</em></p>
250       * @return The current node used as the ElementValue child.
251       * @apilevel low-level
252       */
253      public ElementValue getElementValueNoTransform() {
254        return (ElementValue) getChildNoTransform(0);
255      }
256      /**
257       * @apilevel internal
258       */
259      protected boolean type_computed = false;
260      /**
261       * @apilevel internal
262       */
263      protected TypeDecl type_value;
264      /**
265       * @apilevel internal
266       */
267      private void type_reset() {
268        type_computed = false;
269        type_value = null;
270      }
271      /**
272       * The return type of this method defines the element type of the element-value
273       * pair. An ElementValueArrayInitializer is similar to a normal array initializer
274       * (\ufffd10.6), except that annotations are permitted in place of expressions.
275       * @attribute syn
276       * @aspect Annotations
277       * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:532
278       */
279      @ASTNodeAnnotation.Attribute
280      public TypeDecl type() {
281        ASTNode$State state = state();
282        if (type_computed) {
283          return type_value;
284        }
285        boolean intermediate = state.INTERMEDIATE_VALUE;
286        state.INTERMEDIATE_VALUE = false;
287        int num = state.boundariesCrossed;
288        boolean isFinal = this.is$Final();
289        type_value = type_compute();
290        if (isFinal && num == state().boundariesCrossed) {
291          type_computed = true;
292        } else {
293        }
294        state.INTERMEDIATE_VALUE |= intermediate;
295    
296        return type_value;
297      }
298      /**
299       * @apilevel internal
300       */
301      private TypeDecl type_compute() {
302          Map<String,SimpleSet> methodMap = enclosingAnnotationDecl().localMethodsSignatureMap();
303          SimpleSet set = methodMap.get(getName() + "()");
304          if (set != null) {
305            return ((MethodDecl) set.iterator().next()).type();
306          } else {
307            return unknownType();
308          }
309        }
310      /**
311       * @attribute inh
312       * @aspect Annotations
313       * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:541
314       */
315      /**
316       * @attribute inh
317       * @aspect Annotations
318       * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:541
319       */
320      @ASTNodeAnnotation.Attribute
321      public TypeDecl unknownType() {
322        TypeDecl unknownType_value = getParent().Define_unknownType(this, null);
323    
324        return unknownType_value;
325      }
326      /**
327       * @attribute inh
328       * @aspect Annotations
329       * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:543
330       */
331      /**
332       * @attribute inh
333       * @aspect Annotations
334       * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:543
335       */
336      @ASTNodeAnnotation.Attribute
337      public TypeDecl enclosingAnnotationDecl() {
338        TypeDecl enclosingAnnotationDecl_value = getParent().Define_enclosingAnnotationDecl(this, null);
339    
340        return enclosingAnnotationDecl_value;
341      }
342      /**
343       * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:601
344       * @apilevel internal
345       */
346      public TypeDecl Define_declType(ASTNode caller, ASTNode child) {
347        int childIndex = this.getIndexOfChild(caller);
348        return type();
349      }
350      protected boolean canDefine_declType(ASTNode caller, ASTNode child) {
351        return true;
352      }
353      /**
354       * @apilevel internal
355       */
356      public ASTNode rewriteTo() {
357        // Declared at /home/jesper/git/extendj/java5/frontend/Annotations.jrag:624
358        if (type().isArrayDecl() && getElementValue() instanceof ElementConstantValue) {
359          return rewriteRule0();
360        }
361        return super.rewriteTo();
362      }
363      /**
364       * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:624
365       * @apilevel internal
366       */
367      private ElementValuePair rewriteRule0() {
368    {
369          setElementValue(new ElementArrayValue(new List().add(getElementValue())));
370          return this;
371        }  }
372    }