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/Generics.ast:16
027     * @production ParTypeAccess : {@link Access} ::= <span class="component">TypeAccess:{@link Access}</span> <span class="component">TypeArgument:{@link Access}*</span>;
028    
029     */
030    public class ParTypeAccess extends Access implements Cloneable {
031      /**
032       * @aspect GenericsTypeAnalysis
033       * @declaredat /home/jesper/git/extendj/java5/frontend/Generics.jrag:415
034       */
035      public boolean isRaw() {
036        return false;
037      }
038      /**
039       * @aspect GenericsTypeCheck
040       * @declaredat /home/jesper/git/extendj/java5/frontend/Generics.jrag:668
041       */
042      public void typeCheck() {
043        super.typeCheck();
044        if (!genericDecl().isUnknown()) {
045          TypeDecl type = type();
046          if (!genericDecl().isGenericType()) {
047            errorf("%s is not a generic type but used as one in %s",
048                genericDecl().typeName(), this.prettyPrint());
049          } else if (!type.isRawType() && type.isNestedType() && type.enclosingType().isRawType()) {
050            error("Can not access a member type of a raw type as a parameterized type");
051          } else {
052            GenericTypeDecl decl = (GenericTypeDecl) genericDecl();
053            GenericTypeDecl original = (GenericTypeDecl) decl.original();
054            if (original.getNumTypeParameter() != getNumTypeArgument()) {
055              errorf("%s takes %d type parameters, not %d as used in %s",
056                  decl.typeName(), original.getNumTypeParameter(), getNumTypeArgument(),
057                  this.prettyPrint());
058            } else {
059              for (int i = 0; i < getNumTypeArgument(); i++) {
060                if (!getTypeArgument(i).type().withinBounds(original.getTypeParameter(i),
061                    (Parameterization) type())) {
062                  errorf("type argument %s is of type %s which is not within"
063                      + " the bounds of type parameter %s (%s)",
064                      i, getTypeArgument(i).type().typeName(), original.getTypeParameter(i).typeName(),
065                      original.getTypeParameter(i).prettyPrint());
066                }
067              }
068            }
069          }
070        }
071      }
072      /**
073       * @aspect Java5PrettyPrint
074       * @declaredat /home/jesper/git/extendj/java5/frontend/PrettyPrint.jadd:102
075       */
076      public void prettyPrint(PrettyPrinter out) {
077        out.print(getTypeAccess());
078        out.print("<");
079        out.join(getTypeArgumentList(), new PrettyPrinter.Joiner() {
080          @Override
081          public void printSeparator(PrettyPrinter out) {
082            out.print(", ");
083          }
084        });
085        out.print(">");
086      }
087      /**
088       * @aspect FunctionalInterface
089       * @declaredat /home/jesper/git/extendj/java8/frontend/FunctionalInterface.jrag:223
090       */
091      public boolean sameType(ParTypeAccess p) {
092        TypeAccess ta1 = (TypeAccess) getTypeAccess();
093        TypeAccess ta2 = (TypeAccess) p.getTypeAccess();
094        if (!ta1.sameType(ta2)) {
095          return false;
096        }
097    
098        if (getNumTypeArgument() != p.getNumTypeArgument()) {
099          return false;
100        }
101    
102        for (int i = 0; i < getNumTypeArgument(); i++) {
103          Access a1 = getTypeArgument(i);
104          Access a2 = p.getTypeArgument(i);
105          if (!a1.sameType(a2)) {
106            return false;
107          }
108        }
109    
110        return true;
111      }
112      /**
113       * @declaredat ASTNode:1
114       */
115      public ParTypeAccess() {
116        super();
117      }
118      /**
119       * Initializes the child array to the correct size.
120       * Initializes List and Opt nta children.
121       * @apilevel internal
122       * @ast method
123       * @declaredat ASTNode:10
124       */
125      public void init$Children() {
126        children = new ASTNode[2];
127        setChild(new List(), 1);
128      }
129      /**
130       * @declaredat ASTNode:14
131       */
132      public ParTypeAccess(Access p0, List<Access> p1) {
133        setChild(p0, 0);
134        setChild(p1, 1);
135      }
136      /**
137       * @apilevel low-level
138       * @declaredat ASTNode:21
139       */
140      protected int numChildren() {
141        return 2;
142      }
143      /**
144       * @apilevel internal
145       * @declaredat ASTNode:27
146       */
147      public boolean mayHaveRewrite() {
148        return false;
149      }
150      /**
151       * @apilevel internal
152       * @declaredat ASTNode:33
153       */
154      public void flushAttrCache() {
155        super.flushAttrCache();
156        type_reset();
157      }
158      /**
159       * @apilevel internal
160       * @declaredat ASTNode:40
161       */
162      public void flushCollectionCache() {
163        super.flushCollectionCache();
164      }
165      /**
166       * @apilevel internal
167       * @declaredat ASTNode:46
168       */
169      public void flushRewriteCache() {
170        super.flushRewriteCache();
171      }
172      /**
173       * @apilevel internal
174       * @declaredat ASTNode:52
175       */
176      public ParTypeAccess clone() throws CloneNotSupportedException {
177        ParTypeAccess node = (ParTypeAccess) super.clone();
178        return node;
179      }
180      /**
181       * @apilevel internal
182       * @declaredat ASTNode:59
183       */
184      public ParTypeAccess copy() {
185        try {
186          ParTypeAccess node = (ParTypeAccess) clone();
187          node.parent = null;
188          if (children != null) {
189            node.children = (ASTNode[]) children.clone();
190          }
191          return node;
192        } catch (CloneNotSupportedException e) {
193          throw new Error("Error: clone not supported for " + getClass().getName());
194        }
195      }
196      /**
197       * Create a deep copy of the AST subtree at this node.
198       * The copy is dangling, i.e. has no parent.
199       * @return dangling copy of the subtree at this node
200       * @apilevel low-level
201       * @deprecated Please use treeCopy or treeCopyNoTransform instead
202       * @declaredat ASTNode:78
203       */
204      @Deprecated
205      public ParTypeAccess fullCopy() {
206        return treeCopyNoTransform();
207      }
208      /**
209       * Create a deep copy of the AST subtree at this node.
210       * The copy is dangling, i.e. has no parent.
211       * @return dangling copy of the subtree at this node
212       * @apilevel low-level
213       * @declaredat ASTNode:88
214       */
215      public ParTypeAccess treeCopyNoTransform() {
216        ParTypeAccess tree = (ParTypeAccess) copy();
217        if (children != null) {
218          for (int i = 0; i < children.length; ++i) {
219            ASTNode child = (ASTNode) children[i];
220            if (child != null) {
221              child = child.treeCopyNoTransform();
222              tree.setChild(child, i);
223            }
224          }
225        }
226        return tree;
227      }
228      /**
229       * Create a deep copy of the AST subtree at this node.
230       * The subtree of this node is traversed to trigger rewrites before copy.
231       * The copy is dangling, i.e. has no parent.
232       * @return dangling copy of the subtree at this node
233       * @apilevel low-level
234       * @declaredat ASTNode:108
235       */
236      public ParTypeAccess treeCopy() {
237        doFullTraversal();
238        return treeCopyNoTransform();
239      }
240      /**
241       * @apilevel internal
242       * @declaredat ASTNode:115
243       */
244      protected boolean is$Equal(ASTNode node) {
245        return super.is$Equal(node);    
246      }
247      /**
248       * Replaces the TypeAccess child.
249       * @param node The new node to replace the TypeAccess child.
250       * @apilevel high-level
251       */
252      public void setTypeAccess(Access node) {
253        setChild(node, 0);
254      }
255      /**
256       * Retrieves the TypeAccess child.
257       * @return The current node used as the TypeAccess child.
258       * @apilevel high-level
259       */
260      @ASTNodeAnnotation.Child(name="TypeAccess")
261      public Access getTypeAccess() {
262        return (Access) getChild(0);
263      }
264      /**
265       * Retrieves the TypeAccess child.
266       * <p><em>This method does not invoke AST transformations.</em></p>
267       * @return The current node used as the TypeAccess child.
268       * @apilevel low-level
269       */
270      public Access getTypeAccessNoTransform() {
271        return (Access) getChildNoTransform(0);
272      }
273      /**
274       * Replaces the TypeArgument list.
275       * @param list The new list node to be used as the TypeArgument list.
276       * @apilevel high-level
277       */
278      public void setTypeArgumentList(List<Access> list) {
279        setChild(list, 1);
280      }
281      /**
282       * Retrieves the number of children in the TypeArgument list.
283       * @return Number of children in the TypeArgument list.
284       * @apilevel high-level
285       */
286      public int getNumTypeArgument() {
287        return getTypeArgumentList().getNumChild();
288      }
289      /**
290       * Retrieves the number of children in the TypeArgument list.
291       * Calling this method will not trigger rewrites.
292       * @return Number of children in the TypeArgument list.
293       * @apilevel low-level
294       */
295      public int getNumTypeArgumentNoTransform() {
296        return getTypeArgumentListNoTransform().getNumChildNoTransform();
297      }
298      /**
299       * Retrieves the element at index {@code i} in the TypeArgument list.
300       * @param i Index of the element to return.
301       * @return The element at position {@code i} in the TypeArgument list.
302       * @apilevel high-level
303       */
304      public Access getTypeArgument(int i) {
305        return (Access) getTypeArgumentList().getChild(i);
306      }
307      /**
308       * Check whether the TypeArgument list has any children.
309       * @return {@code true} if it has at least one child, {@code false} otherwise.
310       * @apilevel high-level
311       */
312      public boolean hasTypeArgument() {
313        return getTypeArgumentList().getNumChild() != 0;
314      }
315      /**
316       * Append an element to the TypeArgument list.
317       * @param node The element to append to the TypeArgument list.
318       * @apilevel high-level
319       */
320      public void addTypeArgument(Access node) {
321        List<Access> list = (parent == null) ? getTypeArgumentListNoTransform() : getTypeArgumentList();
322        list.addChild(node);
323      }
324      /**
325       * @apilevel low-level
326       */
327      public void addTypeArgumentNoTransform(Access node) {
328        List<Access> list = getTypeArgumentListNoTransform();
329        list.addChild(node);
330      }
331      /**
332       * Replaces the TypeArgument list element at index {@code i} with the new node {@code node}.
333       * @param node The new node to replace the old list element.
334       * @param i The list index of the node to be replaced.
335       * @apilevel high-level
336       */
337      public void setTypeArgument(Access node, int i) {
338        List<Access> list = getTypeArgumentList();
339        list.setChild(node, i);
340      }
341      /**
342       * Retrieves the TypeArgument list.
343       * @return The node representing the TypeArgument list.
344       * @apilevel high-level
345       */
346      @ASTNodeAnnotation.ListChild(name="TypeArgument")
347      public List<Access> getTypeArgumentList() {
348        List<Access> list = (List<Access>) getChild(1);
349        return list;
350      }
351      /**
352       * Retrieves the TypeArgument list.
353       * <p><em>This method does not invoke AST transformations.</em></p>
354       * @return The node representing the TypeArgument list.
355       * @apilevel low-level
356       */
357      public List<Access> getTypeArgumentListNoTransform() {
358        return (List<Access>) getChildNoTransform(1);
359      }
360      /**
361       * Retrieves the TypeArgument list.
362       * @return The node representing the TypeArgument list.
363       * @apilevel high-level
364       */
365      public List<Access> getTypeArguments() {
366        return getTypeArgumentList();
367      }
368      /**
369       * Retrieves the TypeArgument list.
370       * <p><em>This method does not invoke AST transformations.</em></p>
371       * @return The node representing the TypeArgument list.
372       * @apilevel low-level
373       */
374      public List<Access> getTypeArgumentsNoTransform() {
375        return getTypeArgumentListNoTransform();
376      }
377      /**
378       * @attribute syn
379       * @aspect LookupMethod
380       * @declaredat /home/jesper/git/extendj/java4/frontend/LookupMethod.jrag:39
381       */
382      @ASTNodeAnnotation.Attribute
383      public Expr unqualifiedScope() {
384        Expr unqualifiedScope_value = getParent() instanceof Access
385              ? ((Access) getParent()).unqualifiedScope()
386              : super.unqualifiedScope();
387    
388        return unqualifiedScope_value;
389      }
390      /**
391       * @apilevel internal
392       */
393      protected boolean type_computed = false;
394      /**
395       * @apilevel internal
396       */
397      protected TypeDecl type_value;
398      /**
399       * @apilevel internal
400       */
401      private void type_reset() {
402        type_computed = false;
403        type_value = null;
404      }
405      /**
406       * @attribute syn
407       * @aspect TypeAnalysis
408       * @declaredat /home/jesper/git/extendj/java4/frontend/TypeAnalysis.jrag:302
409       */
410      @ASTNodeAnnotation.Attribute
411      public TypeDecl type() {
412        ASTNode$State state = state();
413        if (type_computed) {
414          return type_value;
415        }
416        boolean intermediate = state.INTERMEDIATE_VALUE;
417        state.INTERMEDIATE_VALUE = false;
418        int num = state.boundariesCrossed;
419        boolean isFinal = this.is$Final();
420        type_value = type_compute();
421        if (isFinal && num == state().boundariesCrossed) {
422          type_computed = true;
423        } else {
424        }
425        state.INTERMEDIATE_VALUE |= intermediate;
426    
427        return type_value;
428      }
429      /**
430       * @apilevel internal
431       */
432      private TypeDecl type_compute() {
433          TypeDecl typeDecl = genericDecl();
434          if (typeDecl instanceof GenericTypeDecl) {
435            // Use signature in lookup for types that are used in extends and implements clauses.
436            if (unqualifiedScope().inExtendsOrImplements()) {
437              return ((GenericTypeDecl) typeDecl).lookupParTypeDecl(this);
438            }
439            ArrayList<TypeDecl> args = new ArrayList<TypeDecl>();
440            for (int i = 0; i < getNumTypeArgument(); i++) {
441              args.add(getTypeArgument(i).type());
442            }
443            return ((GenericTypeDecl) typeDecl).lookupParTypeDecl(args);
444          }
445          return typeDecl;
446        }
447      /**
448       * @attribute syn
449       * @aspect GenericsTypeAnalysis
450       * @declaredat /home/jesper/git/extendj/java5/frontend/Generics.jrag:356
451       */
452      @ASTNodeAnnotation.Attribute
453      public TypeDecl genericDecl() {
454        TypeDecl genericDecl_value = getTypeAccess().type();
455    
456        return genericDecl_value;
457      }
458      /**
459       * @attribute syn
460       * @aspect AccessTypes
461       * @declaredat /home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:35
462       */
463      @ASTNodeAnnotation.Attribute
464      public boolean isTypeAccess() {
465        boolean isTypeAccess_value = true;
466    
467        return isTypeAccess_value;
468      }
469      /**
470       * Builds a copy of this Access node where all occurrences
471       * of type variables in the original type parameter list have been replaced
472       * by the substitution type parameters.
473       * 
474       * @return the substituted Access node
475       * @attribute syn
476       * @aspect Diamond
477       * @declaredat /home/jesper/git/extendj/java7/frontend/Diamond.jrag:361
478       */
479      @ASTNodeAnnotation.Attribute
480      public Access substituted(Collection<TypeVariable> original, List<TypeVariable> substitution) {
481        {
482            List<Access> substArgs = new List<Access>();
483            for (Access arg : getTypeArgumentList()) {
484              substArgs.add(arg.substituted(original, substitution));
485            }
486            return new ParTypeAccess(getTypeAccess().substituted(original, substitution), substArgs);
487          }
488      }
489      /**
490       * @declaredat /home/jesper/git/extendj/java5/frontend/GenericMethods.jrag:197
491       * @apilevel internal
492       */
493      public SimpleSet Define_lookupType(ASTNode caller, ASTNode child, String name) {
494        if (caller == getTypeArgumentListNoTransform()) {
495          // @declaredat /home/jesper/git/extendj/java5/frontend/Generics.jrag:332
496          int childIndex = caller.getIndexOfChild(child);
497          return unqualifiedScope().lookupType(name);
498        }
499        else {
500          return getParent().Define_lookupType(this, caller, name);
501        }
502      }
503      protected boolean canDefine_lookupType(ASTNode caller, ASTNode child, String name) {
504        return true;
505      }
506      /**
507       * @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:36
508       * @apilevel internal
509       */
510      public NameType Define_nameType(ASTNode caller, ASTNode child) {
511        int childIndex = this.getIndexOfChild(caller);
512        return NameType.TYPE_NAME;
513      }
514      protected boolean canDefine_nameType(ASTNode caller, ASTNode child) {
515        return true;
516      }
517      /**
518       * @apilevel internal
519       */
520      public ASTNode rewriteTo() {
521        return super.rewriteTo();
522      }
523    }