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/GenericMethods.ast:17
027     * @production ParConstructorAccess : {@link ConstructorAccess} ::= <span class="component">TypeArgument:{@link Access}*</span>;
028    
029     */
030    public class ParConstructorAccess extends ConstructorAccess implements Cloneable {
031      /**
032       * @aspect GenericMethodsPrettyPrint
033       * @declaredat /home/jesper/git/extendj/java5/frontend/GenericMethods.jrag:227
034       */
035      public void prettyPrint(PrettyPrinter out) {
036        out.print("<");
037        for (int i = 0; i < getNumTypeArgument(); i++) {
038          if (i != 0) {
039            out.print(", ");
040          }
041          out.print(getTypeArgument(i));
042        }
043        out.print(">");
044        super.prettyPrint(out);
045      }
046      /**
047       * @declaredat ASTNode:1
048       */
049      public ParConstructorAccess() {
050        super();
051      }
052      /**
053       * Initializes the child array to the correct size.
054       * Initializes List and Opt nta children.
055       * @apilevel internal
056       * @ast method
057       * @declaredat ASTNode:10
058       */
059      public void init$Children() {
060        children = new ASTNode[2];
061        setChild(new List(), 0);
062        setChild(new List(), 1);
063      }
064      /**
065       * @declaredat ASTNode:15
066       */
067      public ParConstructorAccess(String p0, List<Expr> p1, List<Access> p2) {
068        setID(p0);
069        setChild(p1, 0);
070        setChild(p2, 1);
071      }
072      /**
073       * @declaredat ASTNode:20
074       */
075      public ParConstructorAccess(beaver.Symbol p0, List<Expr> p1, List<Access> p2) {
076        setID(p0);
077        setChild(p1, 0);
078        setChild(p2, 1);
079      }
080      /**
081       * @apilevel low-level
082       * @declaredat ASTNode:28
083       */
084      protected int numChildren() {
085        return 2;
086      }
087      /**
088       * @apilevel internal
089       * @declaredat ASTNode:34
090       */
091      public boolean mayHaveRewrite() {
092        return false;
093      }
094      /**
095       * @apilevel internal
096       * @declaredat ASTNode:40
097       */
098      public void flushAttrCache() {
099        super.flushAttrCache();
100        inferTypeArguments_TypeDecl_List_ParameterDeclaration__List_Expr__List_TypeVariable__reset();
101      }
102      /**
103       * @apilevel internal
104       * @declaredat ASTNode:47
105       */
106      public void flushCollectionCache() {
107        super.flushCollectionCache();
108      }
109      /**
110       * @apilevel internal
111       * @declaredat ASTNode:53
112       */
113      public void flushRewriteCache() {
114        super.flushRewriteCache();
115      }
116      /**
117       * @apilevel internal
118       * @declaredat ASTNode:59
119       */
120      public ParConstructorAccess clone() throws CloneNotSupportedException {
121        ParConstructorAccess node = (ParConstructorAccess) super.clone();
122        return node;
123      }
124      /**
125       * @apilevel internal
126       * @declaredat ASTNode:66
127       */
128      public ParConstructorAccess copy() {
129        try {
130          ParConstructorAccess node = (ParConstructorAccess) 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:85
147       */
148      @Deprecated
149      public ParConstructorAccess 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:95
158       */
159      public ParConstructorAccess treeCopyNoTransform() {
160        ParConstructorAccess tree = (ParConstructorAccess) 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:115
179       */
180      public ParConstructorAccess treeCopy() {
181        doFullTraversal();
182        return treeCopyNoTransform();
183      }
184      /**
185       * @apilevel internal
186       * @declaredat ASTNode:122
187       */
188      protected boolean is$Equal(ASTNode node) {
189        return super.is$Equal(node) && (tokenString_ID == ((ParConstructorAccess)node).tokenString_ID);    
190      }
191      /**
192       * Replaces the lexeme ID.
193       * @param value The new value for the lexeme ID.
194       * @apilevel high-level
195       */
196      public void setID(String value) {
197        tokenString_ID = value;
198      }
199      /**
200       * JastAdd-internal setter for lexeme ID using the Beaver parser.
201       * @param symbol Symbol containing the new value for the lexeme ID
202       * @apilevel internal
203       */
204      public void setID(beaver.Symbol symbol) {
205        if (symbol.value != null && !(symbol.value instanceof String))
206        throw new UnsupportedOperationException("setID is only valid for String lexemes");
207        tokenString_ID = (String)symbol.value;
208        IDstart = symbol.getStart();
209        IDend = symbol.getEnd();
210      }
211      /**
212       * Retrieves the value for the lexeme ID.
213       * @return The value for the lexeme ID.
214       * @apilevel high-level
215       */
216      @ASTNodeAnnotation.Token(name="ID")
217      public String getID() {
218        return tokenString_ID != null ? tokenString_ID : "";
219      }
220      /**
221       * Replaces the Arg list.
222       * @param list The new list node to be used as the Arg list.
223       * @apilevel high-level
224       */
225      public void setArgList(List<Expr> list) {
226        setChild(list, 0);
227      }
228      /**
229       * Retrieves the number of children in the Arg list.
230       * @return Number of children in the Arg list.
231       * @apilevel high-level
232       */
233      public int getNumArg() {
234        return getArgList().getNumChild();
235      }
236      /**
237       * Retrieves the number of children in the Arg list.
238       * Calling this method will not trigger rewrites.
239       * @return Number of children in the Arg list.
240       * @apilevel low-level
241       */
242      public int getNumArgNoTransform() {
243        return getArgListNoTransform().getNumChildNoTransform();
244      }
245      /**
246       * Retrieves the element at index {@code i} in the Arg list.
247       * @param i Index of the element to return.
248       * @return The element at position {@code i} in the Arg list.
249       * @apilevel high-level
250       */
251      public Expr getArg(int i) {
252        return (Expr) getArgList().getChild(i);
253      }
254      /**
255       * Check whether the Arg list has any children.
256       * @return {@code true} if it has at least one child, {@code false} otherwise.
257       * @apilevel high-level
258       */
259      public boolean hasArg() {
260        return getArgList().getNumChild() != 0;
261      }
262      /**
263       * Append an element to the Arg list.
264       * @param node The element to append to the Arg list.
265       * @apilevel high-level
266       */
267      public void addArg(Expr node) {
268        List<Expr> list = (parent == null) ? getArgListNoTransform() : getArgList();
269        list.addChild(node);
270      }
271      /**
272       * @apilevel low-level
273       */
274      public void addArgNoTransform(Expr node) {
275        List<Expr> list = getArgListNoTransform();
276        list.addChild(node);
277      }
278      /**
279       * Replaces the Arg list element at index {@code i} with the new node {@code node}.
280       * @param node The new node to replace the old list element.
281       * @param i The list index of the node to be replaced.
282       * @apilevel high-level
283       */
284      public void setArg(Expr node, int i) {
285        List<Expr> list = getArgList();
286        list.setChild(node, i);
287      }
288      /**
289       * Retrieves the Arg list.
290       * @return The node representing the Arg list.
291       * @apilevel high-level
292       */
293      @ASTNodeAnnotation.ListChild(name="Arg")
294      public List<Expr> getArgList() {
295        List<Expr> list = (List<Expr>) getChild(0);
296        return list;
297      }
298      /**
299       * Retrieves the Arg list.
300       * <p><em>This method does not invoke AST transformations.</em></p>
301       * @return The node representing the Arg list.
302       * @apilevel low-level
303       */
304      public List<Expr> getArgListNoTransform() {
305        return (List<Expr>) getChildNoTransform(0);
306      }
307      /**
308       * Retrieves the Arg list.
309       * @return The node representing the Arg list.
310       * @apilevel high-level
311       */
312      public List<Expr> getArgs() {
313        return getArgList();
314      }
315      /**
316       * Retrieves the Arg list.
317       * <p><em>This method does not invoke AST transformations.</em></p>
318       * @return The node representing the Arg list.
319       * @apilevel low-level
320       */
321      public List<Expr> getArgsNoTransform() {
322        return getArgListNoTransform();
323      }
324      /**
325       * Replaces the TypeArgument list.
326       * @param list The new list node to be used as the TypeArgument list.
327       * @apilevel high-level
328       */
329      public void setTypeArgumentList(List<Access> list) {
330        setChild(list, 1);
331      }
332      /**
333       * Retrieves the number of children in the TypeArgument list.
334       * @return Number of children in the TypeArgument list.
335       * @apilevel high-level
336       */
337      public int getNumTypeArgument() {
338        return getTypeArgumentList().getNumChild();
339      }
340      /**
341       * Retrieves the number of children in the TypeArgument list.
342       * Calling this method will not trigger rewrites.
343       * @return Number of children in the TypeArgument list.
344       * @apilevel low-level
345       */
346      public int getNumTypeArgumentNoTransform() {
347        return getTypeArgumentListNoTransform().getNumChildNoTransform();
348      }
349      /**
350       * Retrieves the element at index {@code i} in the TypeArgument list.
351       * @param i Index of the element to return.
352       * @return The element at position {@code i} in the TypeArgument list.
353       * @apilevel high-level
354       */
355      public Access getTypeArgument(int i) {
356        return (Access) getTypeArgumentList().getChild(i);
357      }
358      /**
359       * Check whether the TypeArgument list has any children.
360       * @return {@code true} if it has at least one child, {@code false} otherwise.
361       * @apilevel high-level
362       */
363      public boolean hasTypeArgument() {
364        return getTypeArgumentList().getNumChild() != 0;
365      }
366      /**
367       * Append an element to the TypeArgument list.
368       * @param node The element to append to the TypeArgument list.
369       * @apilevel high-level
370       */
371      public void addTypeArgument(Access node) {
372        List<Access> list = (parent == null) ? getTypeArgumentListNoTransform() : getTypeArgumentList();
373        list.addChild(node);
374      }
375      /**
376       * @apilevel low-level
377       */
378      public void addTypeArgumentNoTransform(Access node) {
379        List<Access> list = getTypeArgumentListNoTransform();
380        list.addChild(node);
381      }
382      /**
383       * Replaces the TypeArgument list element at index {@code i} with the new node {@code node}.
384       * @param node The new node to replace the old list element.
385       * @param i The list index of the node to be replaced.
386       * @apilevel high-level
387       */
388      public void setTypeArgument(Access node, int i) {
389        List<Access> list = getTypeArgumentList();
390        list.setChild(node, i);
391      }
392      /**
393       * Retrieves the TypeArgument list.
394       * @return The node representing the TypeArgument list.
395       * @apilevel high-level
396       */
397      @ASTNodeAnnotation.ListChild(name="TypeArgument")
398      public List<Access> getTypeArgumentList() {
399        List<Access> list = (List<Access>) getChild(1);
400        return list;
401      }
402      /**
403       * Retrieves the TypeArgument list.
404       * <p><em>This method does not invoke AST transformations.</em></p>
405       * @return The node representing the TypeArgument list.
406       * @apilevel low-level
407       */
408      public List<Access> getTypeArgumentListNoTransform() {
409        return (List<Access>) getChildNoTransform(1);
410      }
411      /**
412       * Retrieves the TypeArgument list.
413       * @return The node representing the TypeArgument list.
414       * @apilevel high-level
415       */
416      public List<Access> getTypeArguments() {
417        return getTypeArgumentList();
418      }
419      /**
420       * Retrieves the TypeArgument list.
421       * <p><em>This method does not invoke AST transformations.</em></p>
422       * @return The node representing the TypeArgument list.
423       * @apilevel low-level
424       */
425      public List<Access> getTypeArgumentsNoTransform() {
426        return getTypeArgumentListNoTransform();
427      }
428      /**
429       * @apilevel internal
430       */
431      protected java.util.Map inferTypeArguments_TypeDecl_List_ParameterDeclaration__List_Expr__List_TypeVariable__values;
432      /**
433       * @apilevel internal
434       */
435      private void inferTypeArguments_TypeDecl_List_ParameterDeclaration__List_Expr__List_TypeVariable__reset() {
436        inferTypeArguments_TypeDecl_List_ParameterDeclaration__List_Expr__List_TypeVariable__values = null;
437      }
438      /**
439       * Infers type arguments for this method invocation.
440       * @attribute syn
441       * @aspect MethodSignature15
442       * @declaredat /home/jesper/git/extendj/java5/frontend/MethodSignature.jrag:479
443       */
444      @ASTNodeAnnotation.Attribute
445      public ArrayList<TypeDecl> inferTypeArguments(TypeDecl resultType, List<ParameterDeclaration> params, List<Expr> args, List<TypeVariable> typeParams) {
446        java.util.List _parameters = new java.util.ArrayList(4);
447        _parameters.add(resultType);
448        _parameters.add(params);
449        _parameters.add(args);
450        _parameters.add(typeParams);
451        if (inferTypeArguments_TypeDecl_List_ParameterDeclaration__List_Expr__List_TypeVariable__values == null) inferTypeArguments_TypeDecl_List_ParameterDeclaration__List_Expr__List_TypeVariable__values = new org.jastadd.util.RobustMap(new java.util.HashMap());
452        ASTNode$State state = state();
453        if (inferTypeArguments_TypeDecl_List_ParameterDeclaration__List_Expr__List_TypeVariable__values.containsKey(_parameters)) {
454          return (ArrayList<TypeDecl>) inferTypeArguments_TypeDecl_List_ParameterDeclaration__List_Expr__List_TypeVariable__values.get(_parameters);
455        }
456        boolean intermediate = state.INTERMEDIATE_VALUE;
457        state.INTERMEDIATE_VALUE = false;
458        int num = state.boundariesCrossed;
459        boolean isFinal = this.is$Final();
460        ArrayList<TypeDecl> inferTypeArguments_TypeDecl_List_ParameterDeclaration__List_Expr__List_TypeVariable__value = inferTypeArguments_compute(resultType, params, args, typeParams);
461        if (isFinal && num == state().boundariesCrossed) {
462          inferTypeArguments_TypeDecl_List_ParameterDeclaration__List_Expr__List_TypeVariable__values.put(_parameters, inferTypeArguments_TypeDecl_List_ParameterDeclaration__List_Expr__List_TypeVariable__value);
463        } else {
464        }
465        state.INTERMEDIATE_VALUE |= intermediate;
466    
467        return inferTypeArguments_TypeDecl_List_ParameterDeclaration__List_Expr__List_TypeVariable__value;
468      }
469      /**
470       * @apilevel internal
471       */
472      private ArrayList<TypeDecl> inferTypeArguments_compute(TypeDecl resultType, List<ParameterDeclaration> params, List<Expr> args, List<TypeVariable> typeParams) {
473          ArrayList<TypeDecl> typeArguments = new ArrayList<TypeDecl>();
474          for (Access typeArgument : getTypeArgumentList()) {
475            typeArguments.add(typeArgument.type());
476          }
477          return typeArguments;
478        }
479      /**
480       * @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:36
481       * @apilevel internal
482       */
483      public NameType Define_nameType(ASTNode caller, ASTNode child) {
484        if (caller == getTypeArgumentListNoTransform()) {
485          // @declaredat /home/jesper/git/extendj/java5/frontend/GenericMethods.jrag:191
486          int childIndex = caller.getIndexOfChild(child);
487          return NameType.TYPE_NAME;
488        }
489        else {
490          return super.Define_nameType(caller, child);
491        }
492      }
493      protected boolean canDefine_nameType(ASTNode caller, ASTNode child) {
494        return true;
495      }
496      /**
497       * @declaredat /home/jesper/git/extendj/java5/frontend/GenericMethods.jrag:197
498       * @apilevel internal
499       */
500      public SimpleSet Define_lookupType(ASTNode caller, ASTNode child, String name) {
501        if (caller == getTypeArgumentListNoTransform()) {
502          // @declaredat /home/jesper/git/extendj/java5/frontend/GenericMethods.jrag:192
503          int childIndex = caller.getIndexOfChild(child);
504          return unqualifiedScope().lookupType(name);
505        }
506        else {
507          return super.Define_lookupType(caller, child, name);
508        }
509      }
510      protected boolean canDefine_lookupType(ASTNode caller, ASTNode child, String name) {
511        return true;
512      }
513      /**
514       * @apilevel internal
515       */
516      public ASTNode rewriteTo() {
517        return super.rewriteTo();
518      }
519    }