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/java4/grammar/Java.ast:27
027     * @production SuperAccess : {@link Access} ::= <span class="component">&lt;ID:String&gt;</span>;
028    
029     */
030    public class SuperAccess extends Access implements Cloneable {
031      /**
032       * @aspect Java4PrettyPrint
033       * @declaredat /home/jesper/git/extendj/java4/frontend/PrettyPrint.jadd:162
034       */
035      public void prettyPrint(PrettyPrinter out) {
036        out.print("super");
037      }
038      /**
039       * @declaredat ASTNode:1
040       */
041      public SuperAccess() {
042        super();
043      }
044      /**
045       * Initializes the child array to the correct size.
046       * Initializes List and Opt nta children.
047       * @apilevel internal
048       * @ast method
049       * @declaredat ASTNode:10
050       */
051      public void init$Children() {
052      }
053      /**
054       * @declaredat ASTNode:12
055       */
056      public SuperAccess(String p0) {
057        setID(p0);
058      }
059      /**
060       * @declaredat ASTNode:15
061       */
062      public SuperAccess(beaver.Symbol p0) {
063        setID(p0);
064      }
065      /**
066       * @apilevel low-level
067       * @declaredat ASTNode:21
068       */
069      protected int numChildren() {
070        return 0;
071      }
072      /**
073       * @apilevel internal
074       * @declaredat ASTNode:27
075       */
076      public boolean mayHaveRewrite() {
077        return false;
078      }
079      /**
080       * @apilevel internal
081       * @declaredat ASTNode:33
082       */
083      public void flushAttrCache() {
084        super.flushAttrCache();
085        decl_reset();
086        type_reset();
087      }
088      /**
089       * @apilevel internal
090       * @declaredat ASTNode:41
091       */
092      public void flushCollectionCache() {
093        super.flushCollectionCache();
094      }
095      /**
096       * @apilevel internal
097       * @declaredat ASTNode:47
098       */
099      public void flushRewriteCache() {
100        super.flushRewriteCache();
101      }
102      /**
103       * @apilevel internal
104       * @declaredat ASTNode:53
105       */
106      public SuperAccess clone() throws CloneNotSupportedException {
107        SuperAccess node = (SuperAccess) super.clone();
108        return node;
109      }
110      /**
111       * @apilevel internal
112       * @declaredat ASTNode:60
113       */
114      public SuperAccess copy() {
115        try {
116          SuperAccess node = (SuperAccess) clone();
117          node.parent = null;
118          if (children != null) {
119            node.children = (ASTNode[]) children.clone();
120          }
121          return node;
122        } catch (CloneNotSupportedException e) {
123          throw new Error("Error: clone not supported for " + getClass().getName());
124        }
125      }
126      /**
127       * Create a deep copy of the AST subtree at this node.
128       * The copy is dangling, i.e. has no parent.
129       * @return dangling copy of the subtree at this node
130       * @apilevel low-level
131       * @deprecated Please use treeCopy or treeCopyNoTransform instead
132       * @declaredat ASTNode:79
133       */
134      @Deprecated
135      public SuperAccess fullCopy() {
136        return treeCopyNoTransform();
137      }
138      /**
139       * Create a deep copy of the AST subtree at this node.
140       * The copy is dangling, i.e. has no parent.
141       * @return dangling copy of the subtree at this node
142       * @apilevel low-level
143       * @declaredat ASTNode:89
144       */
145      public SuperAccess treeCopyNoTransform() {
146        SuperAccess tree = (SuperAccess) copy();
147        if (children != null) {
148          for (int i = 0; i < children.length; ++i) {
149            ASTNode child = (ASTNode) children[i];
150            if (child != null) {
151              child = child.treeCopyNoTransform();
152              tree.setChild(child, i);
153            }
154          }
155        }
156        return tree;
157      }
158      /**
159       * Create a deep copy of the AST subtree at this node.
160       * The subtree of this node is traversed to trigger rewrites before copy.
161       * The copy is dangling, i.e. has no parent.
162       * @return dangling copy of the subtree at this node
163       * @apilevel low-level
164       * @declaredat ASTNode:109
165       */
166      public SuperAccess treeCopy() {
167        doFullTraversal();
168        return treeCopyNoTransform();
169      }
170      /**
171       * @apilevel internal
172       * @declaredat ASTNode:116
173       */
174      protected boolean is$Equal(ASTNode node) {
175        return super.is$Equal(node) && (tokenString_ID == ((SuperAccess)node).tokenString_ID);    
176      }
177      /**
178       * Replaces the lexeme ID.
179       * @param value The new value for the lexeme ID.
180       * @apilevel high-level
181       */
182      public void setID(String value) {
183        tokenString_ID = value;
184      }
185      /**
186       * @apilevel internal
187       */
188      protected String tokenString_ID;
189      /**
190       */
191      public int IDstart;
192      /**
193       */
194      public int IDend;
195      /**
196       * JastAdd-internal setter for lexeme ID using the Beaver parser.
197       * @param symbol Symbol containing the new value for the lexeme ID
198       * @apilevel internal
199       */
200      public void setID(beaver.Symbol symbol) {
201        if (symbol.value != null && !(symbol.value instanceof String))
202        throw new UnsupportedOperationException("setID is only valid for String lexemes");
203        tokenString_ID = (String)symbol.value;
204        IDstart = symbol.getStart();
205        IDend = symbol.getEnd();
206      }
207      /**
208       * Retrieves the value for the lexeme ID.
209       * @return The value for the lexeme ID.
210       * @apilevel high-level
211       */
212      @ASTNodeAnnotation.Token(name="ID")
213      public String getID() {
214        return tokenString_ID != null ? tokenString_ID : "";
215      }
216      /**
217       * @aspect Java8NameCheck
218       * @declaredat /home/jesper/git/extendj/java8/frontend/NameCheck.jrag:371
219       */
220       
221      public void nameCheck() {
222        if (isQualified()) {
223          if (decl().isInterfaceDecl()) {
224            InterfaceDecl decl = (InterfaceDecl) decl();
225            if (hostType().isClassDecl()) {
226              ClassDecl hostDecl = (ClassDecl) hostType();
227              InterfaceDecl found = null;
228              for (int i = 0; i < hostDecl.getNumImplements(); i++) {
229                if (hostDecl.getImplements(i).type() == decl) {
230                  found = (InterfaceDecl) hostDecl.getImplements(i).type();
231                  break;
232                }
233              }
234              if (found == null) {
235                // 15.12.1 - fourth bullet
236                errorf("Type %s is not a direct superinterface of %s",
237                    decl().typeName(), hostType().typeName());
238                return;
239              }
240              InterfaceDecl foundRedundant = null;
241              for (int i = 0; i < hostDecl.getNumImplements(); i++) {
242                if (hostDecl.getImplements(i).type() != found && hostDecl.getImplements(i).type().strictSubtype(found)) {
243                  foundRedundant = (InterfaceDecl) hostDecl.getImplements(i).type();
244                  break;
245                }
246              }
247              if (foundRedundant != null) {
248                // 15.12.1 - fourth bullet
249                errorf("Type %s cannot be used as qualifier, it is extended by implemented interface %s and is redundant",
250                    decl().typeName(), foundRedundant.typeName());
251                return;
252              }
253              if (hasNextAccess() && nextAccess() instanceof MethodAccess) {
254                MethodAccess methodAccess = (MethodAccess) nextAccess();
255                if (hostDecl.hasOverridingMethodInSuper(methodAccess.decl())) {
256                  errorf("Cannot make a super reference to method %s,"
257                      + " there is a more specific override",
258                      methodAccess.decl().fullSignature());
259                }
260              }
261            } else if (hostType().isInterfaceDecl()) {
262              InterfaceDecl hostDecl = (InterfaceDecl) hostType();
263              InterfaceDecl found = null;
264              for (int i = 0; i < hostDecl.getNumSuperInterface(); i++) {
265                if (hostDecl.getSuperInterface(i).type() == decl) {
266                  found = (InterfaceDecl) hostDecl.getSuperInterface(i).type();
267                  break;
268                }
269              }
270              if (found == null) {
271                // 15.12.1 - fourth bullet
272                errorf("Type %s is not a direct superinterface of %s",
273                    decl().typeName(), hostType().typeName());
274                return;
275              }
276              InterfaceDecl foundRedundant = null;
277              for (int i = 0; i < hostDecl.getNumSuperInterface(); i++) {
278                if (hostDecl.getSuperInterface(i).type() != found && hostDecl.getSuperInterface(i).type().strictSubtype(found)) {
279                  foundRedundant = (InterfaceDecl) hostDecl.getSuperInterface(i).type();
280                  break;
281                }
282              }
283              if (foundRedundant != null) {
284                // 15.12.1 - fourth bullet
285                errorf("Type %s cannot be used as qualifier, it is extended by"
286                    + " implemented interface %s and is redundant",
287                    decl().typeName(), foundRedundant.typeName());
288                return;
289              }
290              if (hasNextAccess() && nextAccess() instanceof MethodAccess) {
291                MethodAccess methodAccess = (MethodAccess) nextAccess();
292                if (hostDecl.hasOverridingMethodInSuper(methodAccess.decl())) {
293                  errorf("Cannot make a super reference to method %s,"
294                      + " there is a more specific override",
295                      methodAccess.decl().fullSignature());
296                }
297              }
298            } else {
299              error("Illegal context for super access");
300            }
301    
302            if (nextAccess() instanceof MethodAccess) {
303              if (((MethodAccess) nextAccess()).decl().isStatic()) {
304                error("Cannot reference static interface methods with super");
305              }
306            }
307    
308            if (!hostType().strictSubtype(decl())) {
309              errorf("Type %s is not a superinterface for %s",
310                  decl().typeName(), hostType().typeName());
311            }
312          } else if (!hostType().isInnerTypeOf(decl()) && hostType() != decl()) {
313            error("qualified super must name an enclosing type");
314          }
315          if (inStaticContext()) {
316            error("*** Qualified super may not occur in static context");
317          }
318        }
319        // 8.8.5.1
320        // JLSv7 8.8.7.1
321        TypeDecl constructorHostType = enclosingExplicitConstructorHostType();
322        if (constructorHostType != null && (constructorHostType == decl())) {
323          error("super may not be accessed in an explicit constructor invocation");
324        }
325        // 8.4.3.2
326        if (inStaticContext()) {
327          error("super may not be accessed in a static context");
328        }
329      }
330      /**
331       * @aspect Java8CreateBCode
332       * @declaredat /home/jesper/git/extendj/java8/backend/CreateBCode.jrag:45
333       */
334       
335      public void createBCode(CodeGeneration gen) {
336        if (decl().isInterfaceDecl()) {
337          emitThis(gen, hostType());
338        } else {
339          emitThis(gen, decl());
340        }
341      }
342      /**
343       * @aspect TypeScopePropagation
344       * @declaredat /home/jesper/git/extendj/java4/frontend/LookupType.jrag:328
345       */
346      private TypeDecl refined_TypeScopePropagation_SuperAccess_decl()
347    { return isQualified() ? qualifier().type() : hostType(); }
348      /**
349       * @attribute syn
350       * @aspect TypeScopePropagation
351       * @declaredat /home/jesper/git/extendj/java4/frontend/LookupType.jrag:318
352       */
353      @ASTNodeAnnotation.Attribute
354      public SimpleSet decls() {
355        SimpleSet decls_value = SimpleSet.emptySet;
356    
357        return decls_value;
358      }
359      /**
360       * @apilevel internal
361       */
362      protected boolean decl_computed = false;
363      /**
364       * @apilevel internal
365       */
366      protected TypeDecl decl_value;
367      /**
368       * @apilevel internal
369       */
370      private void decl_reset() {
371        decl_computed = false;
372        decl_value = null;
373      }
374      /**
375       * @return the type whose supertype this super access references
376       * @attribute syn
377       * @aspect TypeScopePropagation
378       * @declaredat /home/jesper/git/extendj/java4/frontend/LookupType.jrag:328
379       */
380      @ASTNodeAnnotation.Attribute
381      public TypeDecl decl() {
382        ASTNode$State state = state();
383        if (decl_computed) {
384          return decl_value;
385        }
386        boolean intermediate = state.INTERMEDIATE_VALUE;
387        state.INTERMEDIATE_VALUE = false;
388        int num = state.boundariesCrossed;
389        boolean isFinal = this.is$Final();
390        decl_value = decl_compute();
391        if (isFinal && num == state().boundariesCrossed) {
392          decl_computed = true;
393        } else {
394        }
395        state.INTERMEDIATE_VALUE |= intermediate;
396    
397        return decl_value;
398      }
399      /**
400       * @apilevel internal
401       */
402      private TypeDecl decl_compute() {
403          TypeDecl typeDecl;
404          if (isQualified()) {
405            typeDecl = qualifier().type();
406          } else {
407            typeDecl = hostType();
408            while (typeDecl instanceof LambdaAnonymousDecl) {
409              typeDecl = typeDecl.enclosingType();
410            }
411          }
412      
413          if (typeDecl instanceof ParTypeDecl) {
414            typeDecl = ((ParTypeDecl) typeDecl).genericDecl();
415          }
416          return typeDecl;
417        }
418      /**
419       * @attribute syn
420       * @aspect AccessTypes
421       * @declaredat /home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:47
422       */
423      @ASTNodeAnnotation.Attribute
424      public boolean isSuperAccess() {
425        boolean isSuperAccess_value = true;
426    
427        return isSuperAccess_value;
428      }
429      /**
430       * Defines the expected kind of name for the left hand side in a qualified
431       * expression.
432       * @attribute syn
433       * @aspect SyntacticClassification
434       * @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:58
435       */
436      @ASTNodeAnnotation.Attribute
437      public NameType predNameType() {
438        NameType predNameType_value = NameType.TYPE_NAME;
439    
440        return predNameType_value;
441      }
442      /**
443       * @apilevel internal
444       */
445      protected boolean type_computed = false;
446      /**
447       * @apilevel internal
448       */
449      protected TypeDecl type_value;
450      /**
451       * @apilevel internal
452       */
453      private void type_reset() {
454        type_computed = false;
455        type_value = null;
456      }
457      /**
458       * @attribute syn
459       * @aspect TypeAnalysis
460       * @declaredat /home/jesper/git/extendj/java4/frontend/TypeAnalysis.jrag:302
461       */
462      @ASTNodeAnnotation.Attribute
463      public TypeDecl type() {
464        ASTNode$State state = state();
465        if (type_computed) {
466          return type_value;
467        }
468        boolean intermediate = state.INTERMEDIATE_VALUE;
469        state.INTERMEDIATE_VALUE = false;
470        int num = state.boundariesCrossed;
471        boolean isFinal = this.is$Final();
472        type_value = type_compute();
473        if (isFinal && num == state().boundariesCrossed) {
474          type_computed = true;
475        } else {
476        }
477        state.INTERMEDIATE_VALUE |= intermediate;
478    
479        return type_value;
480      }
481      /**
482       * @apilevel internal
483       */
484      private TypeDecl type_compute() {
485          TypeDecl typeDecl = decl();
486          if (typeDecl.isInterfaceDecl()) {
487            if (isQualified() && qualifier().type() == typeDecl) {
488              return typeDecl;
489            }
490          }
491          if (!typeDecl.isClassDecl()) {
492            return unknownType();
493          }
494          ClassDecl classDecl = (ClassDecl) typeDecl;
495          if (!classDecl.hasSuperclass()) {
496            return unknownType();
497          }
498          return classDecl.superclass();
499        }
500      /**
501       * @attribute inh
502       * @aspect TypeHierarchyCheck
503       * @declaredat /home/jesper/git/extendj/java4/frontend/TypeHierarchyCheck.jrag:162
504       */
505      /**
506       * @attribute inh
507       * @aspect TypeHierarchyCheck
508       * @declaredat /home/jesper/git/extendj/java4/frontend/TypeHierarchyCheck.jrag:162
509       */
510      @ASTNodeAnnotation.Attribute
511      public boolean inExplicitConstructorInvocation() {
512        boolean inExplicitConstructorInvocation_value = getParent().Define_inExplicitConstructorInvocation(this, null);
513    
514        return inExplicitConstructorInvocation_value;
515      }
516      /**
517       * @attribute inh
518       * @aspect TypeHierarchyCheck
519       * @declaredat /home/jesper/git/extendj/java4/frontend/TypeHierarchyCheck.jrag:173
520       */
521      /**
522       * @attribute inh
523       * @aspect TypeHierarchyCheck
524       * @declaredat /home/jesper/git/extendj/java4/frontend/TypeHierarchyCheck.jrag:173
525       */
526      @ASTNodeAnnotation.Attribute
527      public TypeDecl enclosingExplicitConstructorHostType() {
528        TypeDecl enclosingExplicitConstructorHostType_value = getParent().Define_enclosingExplicitConstructorHostType(this, null);
529    
530        return enclosingExplicitConstructorHostType_value;
531      }
532      /**
533       * @apilevel internal
534       */
535      public ASTNode rewriteTo() {
536        return super.rewriteTo();
537      }
538    }