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/java8/grammar/ConstructorReference.ast:5
027     * @production ConstructorReferenceAccess : {@link ClassInstanceExpr};
028    
029     */
030    public class ConstructorReferenceAccess extends ClassInstanceExpr implements Cloneable {
031      /**
032       * @aspect Synthetics
033       * @declaredat /home/jesper/git/extendj/java8/frontend/MethodReference.jrag:393
034       */
035      private FunctionDescriptor targetDescriptor;
036      /**
037       * @aspect Synthetics
038       * @declaredat /home/jesper/git/extendj/java8/frontend/MethodReference.jrag:394
039       */
040      public ConstructorReferenceAccess(Access access,
041          List<Expr> args, FunctionDescriptor f) {
042        super(access, args);
043        this.targetDescriptor = f;
044      }
045      /**
046       * @declaredat ASTNode:1
047       */
048      public ConstructorReferenceAccess() {
049        super();
050      }
051      /**
052       * Initializes the child array to the correct size.
053       * Initializes List and Opt nta children.
054       * @apilevel internal
055       * @ast method
056       * @declaredat ASTNode:10
057       */
058      public void init$Children() {
059        children = new ASTNode[3];
060        setChild(new List(), 1);
061        setChild(new Opt(), 2);
062      }
063      /**
064       * @declaredat ASTNode:15
065       */
066      public ConstructorReferenceAccess(Access p0, List<Expr> p1, Opt<TypeDecl> p2) {
067        setChild(p0, 0);
068        setChild(p1, 1);
069        setChild(p2, 2);
070      }
071      /**
072       * @apilevel low-level
073       * @declaredat ASTNode:23
074       */
075      protected int numChildren() {
076        return 3;
077      }
078      /**
079       * @apilevel internal
080       * @declaredat ASTNode:29
081       */
082      public boolean mayHaveRewrite() {
083        return false;
084      }
085      /**
086       * @apilevel internal
087       * @declaredat ASTNode:35
088       */
089      public void flushAttrCache() {
090        super.flushAttrCache();
091        targetType_reset();
092      }
093      /**
094       * @apilevel internal
095       * @declaredat ASTNode:42
096       */
097      public void flushCollectionCache() {
098        super.flushCollectionCache();
099      }
100      /**
101       * @apilevel internal
102       * @declaredat ASTNode:48
103       */
104      public void flushRewriteCache() {
105        super.flushRewriteCache();
106      }
107      /**
108       * @apilevel internal
109       * @declaredat ASTNode:54
110       */
111      public ConstructorReferenceAccess clone() throws CloneNotSupportedException {
112        ConstructorReferenceAccess node = (ConstructorReferenceAccess) super.clone();
113        return node;
114      }
115      /**
116       * @apilevel internal
117       * @declaredat ASTNode:61
118       */
119      public ConstructorReferenceAccess copy() {
120        try {
121          ConstructorReferenceAccess node = (ConstructorReferenceAccess) clone();
122          node.parent = null;
123          if (children != null) {
124            node.children = (ASTNode[]) children.clone();
125          }
126          return node;
127        } catch (CloneNotSupportedException e) {
128          throw new Error("Error: clone not supported for " + getClass().getName());
129        }
130      }
131      /**
132       * Create a deep copy of the AST subtree at this node.
133       * The copy is dangling, i.e. has no parent.
134       * @return dangling copy of the subtree at this node
135       * @apilevel low-level
136       * @deprecated Please use treeCopy or treeCopyNoTransform instead
137       * @declaredat ASTNode:80
138       */
139      @Deprecated
140      public ConstructorReferenceAccess fullCopy() {
141        return treeCopyNoTransform();
142      }
143      /**
144       * Create a deep copy of the AST subtree at this node.
145       * The copy is dangling, i.e. has no parent.
146       * @return dangling copy of the subtree at this node
147       * @apilevel low-level
148       * @declaredat ASTNode:90
149       */
150      public ConstructorReferenceAccess treeCopyNoTransform() {
151        ConstructorReferenceAccess tree = (ConstructorReferenceAccess) copy();
152        if (children != null) {
153          for (int i = 0; i < children.length; ++i) {
154            ASTNode child = (ASTNode) children[i];
155            if (child != null) {
156              child = child.treeCopyNoTransform();
157              tree.setChild(child, i);
158            }
159          }
160        }
161        return tree;
162      }
163      /**
164       * Create a deep copy of the AST subtree at this node.
165       * The subtree of this node is traversed to trigger rewrites before copy.
166       * The copy is dangling, i.e. has no parent.
167       * @return dangling copy of the subtree at this node
168       * @apilevel low-level
169       * @declaredat ASTNode:110
170       */
171      public ConstructorReferenceAccess treeCopy() {
172        doFullTraversal();
173        return treeCopyNoTransform();
174      }
175      /**
176       * @apilevel internal
177       * @declaredat ASTNode:117
178       */
179      protected boolean is$Equal(ASTNode node) {
180        return super.is$Equal(node);    
181      }
182      /**
183       * Replaces the Access child.
184       * @param node The new node to replace the Access child.
185       * @apilevel high-level
186       */
187      public void setAccess(Access node) {
188        setChild(node, 0);
189      }
190      /**
191       * Retrieves the Access child.
192       * @return The current node used as the Access child.
193       * @apilevel high-level
194       */
195      @ASTNodeAnnotation.Child(name="Access")
196      public Access getAccess() {
197        return (Access) getChild(0);
198      }
199      /**
200       * Retrieves the Access child.
201       * <p><em>This method does not invoke AST transformations.</em></p>
202       * @return The current node used as the Access child.
203       * @apilevel low-level
204       */
205      public Access getAccessNoTransform() {
206        return (Access) getChildNoTransform(0);
207      }
208      /**
209       * Replaces the Arg list.
210       * @param list The new list node to be used as the Arg list.
211       * @apilevel high-level
212       */
213      public void setArgList(List<Expr> list) {
214        setChild(list, 1);
215      }
216      /**
217       * Retrieves the number of children in the Arg list.
218       * @return Number of children in the Arg list.
219       * @apilevel high-level
220       */
221      public int getNumArg() {
222        return getArgList().getNumChild();
223      }
224      /**
225       * Retrieves the number of children in the Arg list.
226       * Calling this method will not trigger rewrites.
227       * @return Number of children in the Arg list.
228       * @apilevel low-level
229       */
230      public int getNumArgNoTransform() {
231        return getArgListNoTransform().getNumChildNoTransform();
232      }
233      /**
234       * Retrieves the element at index {@code i} in the Arg list.
235       * @param i Index of the element to return.
236       * @return The element at position {@code i} in the Arg list.
237       * @apilevel high-level
238       */
239      public Expr getArg(int i) {
240        return (Expr) getArgList().getChild(i);
241      }
242      /**
243       * Check whether the Arg list has any children.
244       * @return {@code true} if it has at least one child, {@code false} otherwise.
245       * @apilevel high-level
246       */
247      public boolean hasArg() {
248        return getArgList().getNumChild() != 0;
249      }
250      /**
251       * Append an element to the Arg list.
252       * @param node The element to append to the Arg list.
253       * @apilevel high-level
254       */
255      public void addArg(Expr node) {
256        List<Expr> list = (parent == null) ? getArgListNoTransform() : getArgList();
257        list.addChild(node);
258      }
259      /**
260       * @apilevel low-level
261       */
262      public void addArgNoTransform(Expr node) {
263        List<Expr> list = getArgListNoTransform();
264        list.addChild(node);
265      }
266      /**
267       * Replaces the Arg list element at index {@code i} with the new node {@code node}.
268       * @param node The new node to replace the old list element.
269       * @param i The list index of the node to be replaced.
270       * @apilevel high-level
271       */
272      public void setArg(Expr node, int i) {
273        List<Expr> list = getArgList();
274        list.setChild(node, i);
275      }
276      /**
277       * Retrieves the Arg list.
278       * @return The node representing the Arg list.
279       * @apilevel high-level
280       */
281      @ASTNodeAnnotation.ListChild(name="Arg")
282      public List<Expr> getArgList() {
283        List<Expr> list = (List<Expr>) getChild(1);
284        return list;
285      }
286      /**
287       * Retrieves the Arg list.
288       * <p><em>This method does not invoke AST transformations.</em></p>
289       * @return The node representing the Arg list.
290       * @apilevel low-level
291       */
292      public List<Expr> getArgListNoTransform() {
293        return (List<Expr>) getChildNoTransform(1);
294      }
295      /**
296       * Retrieves the Arg list.
297       * @return The node representing the Arg list.
298       * @apilevel high-level
299       */
300      public List<Expr> getArgs() {
301        return getArgList();
302      }
303      /**
304       * Retrieves the Arg list.
305       * <p><em>This method does not invoke AST transformations.</em></p>
306       * @return The node representing the Arg list.
307       * @apilevel low-level
308       */
309      public List<Expr> getArgsNoTransform() {
310        return getArgListNoTransform();
311      }
312      /**
313       * Replaces the optional node for the TypeDecl child. This is the <code>Opt</code>
314       * node containing the child TypeDecl, not the actual child!
315       * @param opt The new node to be used as the optional node for the TypeDecl child.
316       * @apilevel low-level
317       */
318      public void setTypeDeclOpt(Opt<TypeDecl> opt) {
319        setChild(opt, 2);
320      }
321      /**
322       * Replaces the (optional) TypeDecl child.
323       * @param node The new node to be used as the TypeDecl child.
324       * @apilevel high-level
325       */
326      public void setTypeDecl(TypeDecl node) {
327        getTypeDeclOpt().setChild(node, 0);
328      }
329      /**
330       * Check whether the optional TypeDecl child exists.
331       * @return {@code true} if the optional TypeDecl child exists, {@code false} if it does not.
332       * @apilevel high-level
333       */
334      public boolean hasTypeDecl() {
335        return getTypeDeclOpt().getNumChild() != 0;
336      }
337      /**
338       * Retrieves the (optional) TypeDecl child.
339       * @return The TypeDecl child, if it exists. Returns {@code null} otherwise.
340       * @apilevel low-level
341       */
342      public TypeDecl getTypeDecl() {
343        return (TypeDecl) getTypeDeclOpt().getChild(0);
344      }
345      /**
346       * Retrieves the optional node for the TypeDecl child. This is the <code>Opt</code> node containing the child TypeDecl, not the actual child!
347       * @return The optional node for child the TypeDecl child.
348       * @apilevel low-level
349       */
350      @ASTNodeAnnotation.OptChild(name="TypeDecl")
351      public Opt<TypeDecl> getTypeDeclOpt() {
352        return (Opt<TypeDecl>) getChild(2);
353      }
354      /**
355       * Retrieves the optional node for child TypeDecl. This is the <code>Opt</code> node containing the child TypeDecl, not the actual child!
356       * <p><em>This method does not invoke AST transformations.</em></p>
357       * @return The optional node for child TypeDecl.
358       * @apilevel low-level
359       */
360      public Opt<TypeDecl> getTypeDeclOptNoTransform() {
361        return (Opt<TypeDecl>) getChildNoTransform(2);
362      }
363      /**
364       * @apilevel internal
365       */
366      protected boolean targetType_computed = false;
367      /**
368       * @apilevel internal
369       */
370      protected TypeDecl targetType_value;
371      /**
372       * @apilevel internal
373       */
374      private void targetType_reset() {
375        targetType_computed = false;
376        targetType_value = null;
377      }
378      /**
379       * @attribute syn
380       * @aspect TargetType
381       * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:183
382       */
383      @ASTNodeAnnotation.Attribute
384      public TypeDecl targetType() {
385        ASTNode$State state = state();
386        if (targetType_computed) {
387          return targetType_value;
388        }
389        boolean intermediate = state.INTERMEDIATE_VALUE;
390        state.INTERMEDIATE_VALUE = false;
391        int num = state.boundariesCrossed;
392        boolean isFinal = this.is$Final();
393        targetType_value = targetDescriptor.method.type();
394        if (isFinal && num == state().boundariesCrossed) {
395          targetType_computed = true;
396        } else {
397        }
398        state.INTERMEDIATE_VALUE |= intermediate;
399    
400        return targetType_value;
401      }
402      /**
403       * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:30
404       * @apilevel internal
405       */
406      public TypeDecl Define_targetType(ASTNode caller, ASTNode child) {
407        if (caller == getAccessNoTransform()) {
408          // @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:189
409          return targetDescriptor.method.type();
410        }
411        else {
412          return super.Define_targetType(caller, child);
413        }
414      }
415      protected boolean canDefine_targetType(ASTNode caller, ASTNode child) {
416        return true;
417      }
418      /**
419       * @apilevel internal
420       */
421      public ASTNode rewriteTo() {
422        return super.rewriteTo();
423      }
424    }