001    /* This file was generated with JastAdd2 (http://jastadd.org) version 2.1.13-9-g0922917 */
002    package org.jastadd.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 org.jastadd.util.*;
013    import java.util.zip.*;
014    import java.io.*;
015    import org.jastadd.util.PrettyPrintable;
016    import org.jastadd.util.PrettyPrinter;
017    import java.io.FileNotFoundException;
018    import java.io.BufferedInputStream;
019    import java.io.DataInputStream;
020    /**
021     * @ast node
022     * @declaredat /home/jesper/git/extendj/java8/grammar/MethodReference.ast:3
023     * @production ExprMethodReference : {@link MethodReference} ::= <span class="component">{@link Expr}</span>;
024    
025     */
026    public class ExprMethodReference extends MethodReference implements Cloneable {
027      /**
028       * @aspect Java8NameCheck
029       * @declaredat /home/jesper/git/extendj/java8/frontend/NameCheck.jrag:521
030       */
031      public void nameCheck() {
032        super.nameCheck();
033        if (!getExpr().isSuperAccess()) {
034          if (!getExpr().type().isReferenceType()) {
035            error("Expression in a method reference must have reference type");
036          }
037        }
038      }
039      /**
040       * @aspect Java8PrettyPrint
041       * @declaredat /home/jesper/git/extendj/java8/frontend/PrettyPrint.jadd:88
042       */
043      public void prettyPrint(PrettyPrinter out) {
044        out.print(getExpr());
045        out.print("::");
046        if (hasTypeArgument()) {
047          out.print("<");
048          out.join(getTypeArguments(), new PrettyPrinter.Joiner() {
049            @Override
050            public void printSeparator(PrettyPrinter out) {
051              out.print(", ");
052            }
053          });
054          out.print(">");
055        }
056        out.print(name());
057      }
058      /**
059       * @aspect Java8CreateBCode
060       * @declaredat /home/jesper/git/extendj/java8/backend/CreateBCode.jrag:33
061       */
062      public void createBCode(CodeGeneration gen) {
063        toClass().createBCode(gen);
064      }
065      /**
066       * @aspect MethodReferenceToClass
067       * @declaredat /home/jesper/git/extendj/java8/backend/MethodReferenceToClass.jrag:30
068       */
069      private String syntheticFieldName() {
070        return "#1";
071      }
072      /**
073       * @aspect Transformations
074       * @declaredat /home/jesper/git/extendj/java8/backend/Transformations.jrag:33
075       */
076      public void transformation() {
077        toClass().transformation();
078      }
079      /**
080       * @declaredat ASTNode:1
081       */
082      public ExprMethodReference() {
083        super();
084      }
085      /**
086       * Initializes the child array to the correct size.
087       * Initializes List and Opt nta children.
088       * @apilevel internal
089       * @ast method
090       * @declaredat ASTNode:10
091       */
092      public void init$Children() {
093        children = new ASTNode[2];
094        setChild(new List(), 0);
095      }
096      /**
097       * @declaredat ASTNode:14
098       */
099      public ExprMethodReference(List<Access> p0, String p1, Expr p2) {
100        setChild(p0, 0);
101        setID(p1);
102        setChild(p2, 1);
103      }
104      /**
105       * @declaredat ASTNode:19
106       */
107      public ExprMethodReference(List<Access> p0, beaver.Symbol p1, Expr p2) {
108        setChild(p0, 0);
109        setID(p1);
110        setChild(p2, 1);
111      }
112      /**
113       * @apilevel low-level
114       * @declaredat ASTNode:27
115       */
116      protected int numChildren() {
117        return 2;
118      }
119      /**
120       * @apilevel internal
121       * @declaredat ASTNode:33
122       */
123      public boolean mayHaveRewrite() {
124        return false;
125      }
126      /**
127       * @apilevel internal
128       * @declaredat ASTNode:39
129       */
130      public void flushAttrCache() {
131        super.flushAttrCache();
132        targetMethod_FunctionDescriptor_reset();
133        syntheticAccess_FunctionDescriptor_reset();
134        syntheticMethodAccess_FunctionDescriptor_reset();
135        congruentTo_FunctionDescriptor_reset();
136        potentiallyApplicableMethods_FunctionDescriptor_reset();
137        exactCompileTimeDeclaration_reset();
138        potentiallyCompatible_TypeDecl_BodyDecl_reset();
139        toClass_reset();
140        toBlock_reset();
141      }
142      /**
143       * @apilevel internal
144       * @declaredat ASTNode:54
145       */
146      public void flushCollectionCache() {
147        super.flushCollectionCache();
148      }
149      /**
150       * @apilevel internal
151       * @declaredat ASTNode:60
152       */
153      public void flushRewriteCache() {
154        super.flushRewriteCache();
155      }
156      /**
157       * @apilevel internal
158       * @declaredat ASTNode:66
159       */
160      public ExprMethodReference clone() throws CloneNotSupportedException {
161        ExprMethodReference node = (ExprMethodReference) super.clone();
162        return node;
163      }
164      /**
165       * @apilevel internal
166       * @declaredat ASTNode:73
167       */
168      public ExprMethodReference copy() {
169        try {
170          ExprMethodReference node = (ExprMethodReference) clone();
171          node.parent = null;
172          if (children != null) {
173            node.children = (ASTNode[]) children.clone();
174          }
175          return node;
176        } catch (CloneNotSupportedException e) {
177          throw new Error("Error: clone not supported for " + getClass().getName());
178        }
179      }
180      /**
181       * Create a deep copy of the AST subtree at this node.
182       * The copy is dangling, i.e. has no parent.
183       * @return dangling copy of the subtree at this node
184       * @apilevel low-level
185       * @deprecated Please use treeCopy or treeCopyNoTransform instead
186       * @declaredat ASTNode:92
187       */
188      @Deprecated
189      public ExprMethodReference fullCopy() {
190        return treeCopyNoTransform();
191      }
192      /**
193       * Create a deep copy of the AST subtree at this node.
194       * The copy is dangling, i.e. has no parent.
195       * @return dangling copy of the subtree at this node
196       * @apilevel low-level
197       * @declaredat ASTNode:102
198       */
199      public ExprMethodReference treeCopyNoTransform() {
200        ExprMethodReference tree = (ExprMethodReference) copy();
201        if (children != null) {
202          for (int i = 0; i < children.length; ++i) {
203            ASTNode child = (ASTNode) children[i];
204            if (child != null) {
205              child = child.treeCopyNoTransform();
206              tree.setChild(child, i);
207            }
208          }
209        }
210        return tree;
211      }
212      /**
213       * Create a deep copy of the AST subtree at this node.
214       * The subtree of this node is traversed to trigger rewrites before copy.
215       * The copy is dangling, i.e. has no parent.
216       * @return dangling copy of the subtree at this node
217       * @apilevel low-level
218       * @declaredat ASTNode:122
219       */
220      public ExprMethodReference treeCopy() {
221        doFullTraversal();
222        return treeCopyNoTransform();
223      }
224      /**
225       * @apilevel internal
226       * @declaredat ASTNode:129
227       */
228      protected boolean is$Equal(ASTNode node) {
229        return super.is$Equal(node) && (tokenString_ID == ((ExprMethodReference)node).tokenString_ID);    
230      }
231      /**
232       * Replaces the TypeArgument list.
233       * @param list The new list node to be used as the TypeArgument list.
234       * @apilevel high-level
235       */
236      public void setTypeArgumentList(List<Access> list) {
237        setChild(list, 0);
238      }
239      /**
240       * Retrieves the number of children in the TypeArgument list.
241       * @return Number of children in the TypeArgument list.
242       * @apilevel high-level
243       */
244      public int getNumTypeArgument() {
245        return getTypeArgumentList().getNumChild();
246      }
247      /**
248       * Retrieves the number of children in the TypeArgument list.
249       * Calling this method will not trigger rewrites.
250       * @return Number of children in the TypeArgument list.
251       * @apilevel low-level
252       */
253      public int getNumTypeArgumentNoTransform() {
254        return getTypeArgumentListNoTransform().getNumChildNoTransform();
255      }
256      /**
257       * Retrieves the element at index {@code i} in the TypeArgument list.
258       * @param i Index of the element to return.
259       * @return The element at position {@code i} in the TypeArgument list.
260       * @apilevel high-level
261       */
262      public Access getTypeArgument(int i) {
263        return (Access) getTypeArgumentList().getChild(i);
264      }
265      /**
266       * Check whether the TypeArgument list has any children.
267       * @return {@code true} if it has at least one child, {@code false} otherwise.
268       * @apilevel high-level
269       */
270      public boolean hasTypeArgument() {
271        return getTypeArgumentList().getNumChild() != 0;
272      }
273      /**
274       * Append an element to the TypeArgument list.
275       * @param node The element to append to the TypeArgument list.
276       * @apilevel high-level
277       */
278      public void addTypeArgument(Access node) {
279        List<Access> list = (parent == null) ? getTypeArgumentListNoTransform() : getTypeArgumentList();
280        list.addChild(node);
281      }
282      /**
283       * @apilevel low-level
284       */
285      public void addTypeArgumentNoTransform(Access node) {
286        List<Access> list = getTypeArgumentListNoTransform();
287        list.addChild(node);
288      }
289      /**
290       * Replaces the TypeArgument list element at index {@code i} with the new node {@code node}.
291       * @param node The new node to replace the old list element.
292       * @param i The list index of the node to be replaced.
293       * @apilevel high-level
294       */
295      public void setTypeArgument(Access node, int i) {
296        List<Access> list = getTypeArgumentList();
297        list.setChild(node, i);
298      }
299      /**
300       * Retrieves the TypeArgument list.
301       * @return The node representing the TypeArgument list.
302       * @apilevel high-level
303       */
304      @ASTNodeAnnotation.ListChild(name="TypeArgument")
305      public List<Access> getTypeArgumentList() {
306        List<Access> list = (List<Access>) getChild(0);
307        return list;
308      }
309      /**
310       * Retrieves the TypeArgument list.
311       * <p><em>This method does not invoke AST transformations.</em></p>
312       * @return The node representing the TypeArgument list.
313       * @apilevel low-level
314       */
315      public List<Access> getTypeArgumentListNoTransform() {
316        return (List<Access>) getChildNoTransform(0);
317      }
318      /**
319       * Retrieves the TypeArgument list.
320       * @return The node representing the TypeArgument list.
321       * @apilevel high-level
322       */
323      public List<Access> getTypeArguments() {
324        return getTypeArgumentList();
325      }
326      /**
327       * Retrieves the TypeArgument list.
328       * <p><em>This method does not invoke AST transformations.</em></p>
329       * @return The node representing the TypeArgument list.
330       * @apilevel low-level
331       */
332      public List<Access> getTypeArgumentsNoTransform() {
333        return getTypeArgumentListNoTransform();
334      }
335      /**
336       * Replaces the lexeme ID.
337       * @param value The new value for the lexeme ID.
338       * @apilevel high-level
339       */
340      public void setID(String value) {
341        tokenString_ID = value;
342      }
343      /**
344       * JastAdd-internal setter for lexeme ID using the Beaver parser.
345       * @param symbol Symbol containing the new value for the lexeme ID
346       * @apilevel internal
347       */
348      public void setID(beaver.Symbol symbol) {
349        if (symbol.value != null && !(symbol.value instanceof String))
350        throw new UnsupportedOperationException("setID is only valid for String lexemes");
351        tokenString_ID = (String)symbol.value;
352        IDstart = symbol.getStart();
353        IDend = symbol.getEnd();
354      }
355      /**
356       * Retrieves the value for the lexeme ID.
357       * @return The value for the lexeme ID.
358       * @apilevel high-level
359       */
360      @ASTNodeAnnotation.Token(name="ID")
361      public String getID() {
362        return tokenString_ID != null ? tokenString_ID : "";
363      }
364      /**
365       * Replaces the Expr child.
366       * @param node The new node to replace the Expr child.
367       * @apilevel high-level
368       */
369      public void setExpr(Expr node) {
370        setChild(node, 1);
371      }
372      /**
373       * Retrieves the Expr child.
374       * @return The current node used as the Expr child.
375       * @apilevel high-level
376       */
377      @ASTNodeAnnotation.Child(name="Expr")
378      public Expr getExpr() {
379        return (Expr) getChild(1);
380      }
381      /**
382       * Retrieves the Expr child.
383       * <p><em>This method does not invoke AST transformations.</em></p>
384       * @return The current node used as the Expr child.
385       * @apilevel low-level
386       */
387      public Expr getExprNoTransform() {
388        return (Expr) getChildNoTransform(1);
389      }
390      /**
391       * @apilevel internal
392       */
393      protected java.util.Map targetMethod_FunctionDescriptor_values;
394      /**
395       * @apilevel internal
396       */
397      private void targetMethod_FunctionDescriptor_reset() {
398        targetMethod_FunctionDescriptor_values = null;
399      }
400      /**
401       * @attribute syn
402       * @aspect MethodReference
403       * @declaredat /home/jesper/git/extendj/java8/frontend/MethodReference.jrag:32
404       */
405      @ASTNodeAnnotation.Attribute
406      public MethodDecl targetMethod(FunctionDescriptor f) {
407        Object _parameters = f;
408        if (targetMethod_FunctionDescriptor_values == null) targetMethod_FunctionDescriptor_values = new org.jastadd.util.RobustMap(new java.util.HashMap());
409        ASTNode$State state = state();
410        if (targetMethod_FunctionDescriptor_values.containsKey(_parameters)) {
411          return (MethodDecl) targetMethod_FunctionDescriptor_values.get(_parameters);
412        }
413        boolean intermediate = state.INTERMEDIATE_VALUE;
414        state.INTERMEDIATE_VALUE = false;
415        int num = state.boundariesCrossed;
416        boolean isFinal = this.is$Final();
417        MethodDecl targetMethod_FunctionDescriptor_value = targetMethod_compute(f);
418        if (isFinal && num == state().boundariesCrossed) {
419          targetMethod_FunctionDescriptor_values.put(_parameters, targetMethod_FunctionDescriptor_value);
420        } else {
421        }
422        state.INTERMEDIATE_VALUE |= intermediate;
423    
424        return targetMethod_FunctionDescriptor_value;
425      }
426      /**
427       * @apilevel internal
428       */
429      private MethodDecl targetMethod_compute(FunctionDescriptor f) {
430          return syntheticMethodAccess(f).decl();
431        }
432      /**
433       * @apilevel internal
434       */
435      protected List syntheticAccess_FunctionDescriptor_list;
436      /**
437       * @apilevel internal
438       */
439      protected java.util.Map syntheticAccess_FunctionDescriptor_values;
440      /**
441       * @apilevel internal
442       */
443      private void syntheticAccess_FunctionDescriptor_reset() {
444        syntheticAccess_FunctionDescriptor_values = null;
445        syntheticAccess_FunctionDescriptor_list = null;
446      }
447      /**
448       * @attribute syn
449       * @aspect MethodReference
450       * @declaredat /home/jesper/git/extendj/java8/frontend/MethodReference.jrag:36
451       */
452      @ASTNodeAnnotation.Attribute
453      public Access syntheticAccess(FunctionDescriptor f) {
454        Object _parameters = f;
455        if (syntheticAccess_FunctionDescriptor_values == null) syntheticAccess_FunctionDescriptor_values = new org.jastadd.util.RobustMap(new java.util.HashMap());
456        ASTNode$State state = state();
457        if (syntheticAccess_FunctionDescriptor_values.containsKey(_parameters)) {
458          return (Access) syntheticAccess_FunctionDescriptor_values.get(_parameters);
459        }
460        boolean intermediate = state.INTERMEDIATE_VALUE;
461        state.INTERMEDIATE_VALUE = false;
462        int num = state.boundariesCrossed;
463        boolean isFinal = this.is$Final();
464        Access syntheticAccess_FunctionDescriptor_value = syntheticAccess_compute(f);
465        if (syntheticAccess_FunctionDescriptor_list == null) {
466          syntheticAccess_FunctionDescriptor_list = new List();
467          syntheticAccess_FunctionDescriptor_list.is$Final = true;
468          syntheticAccess_FunctionDescriptor_list.setParent(this);
469        }
470        syntheticAccess_FunctionDescriptor_list.add(syntheticAccess_FunctionDescriptor_value);
471        if (syntheticAccess_FunctionDescriptor_value != null) {
472          syntheticAccess_FunctionDescriptor_value = (Access) syntheticAccess_FunctionDescriptor_list.getChild(syntheticAccess_FunctionDescriptor_list.numChildren-1);
473          syntheticAccess_FunctionDescriptor_value.is$Final = true;
474        }
475        if (true) {
476          syntheticAccess_FunctionDescriptor_values.put(_parameters, syntheticAccess_FunctionDescriptor_value);
477        } else {
478        }
479        state.INTERMEDIATE_VALUE |= intermediate;
480    
481        return syntheticAccess_FunctionDescriptor_value;
482      }
483      /**
484       * @apilevel internal
485       */
486      private Access syntheticAccess_compute(FunctionDescriptor f) {
487          List<Expr> arguments = new List<Expr>();
488          for (int i = 0; i < f.method.getNumParameter(); i++) {
489            TypeDecl argumentType = f.method.getParameter(i).type();
490            arguments.add(new SyntheticTypeAccess(argumentType));
491          }
492      
493          if (!hasTypeArgument()) {
494            MethodReferenceAccess mAccess = new MethodReferenceAccess(name(), arguments, f);
495            return ((Expr) getExpr().treeCopyNoTransform()).qualifiesAccess(mAccess);
496          } else {
497            ParMethodReferenceAccess pmAccess = new ParMethodReferenceAccess(name(), arguments,
498                (List<Access>) getTypeArgumentList().treeCopyNoTransform(), f);
499            return ((Expr) getExpr().treeCopyNoTransform()).qualifiesAccess(pmAccess);
500          }
501        }
502      /**
503       * @apilevel internal
504       */
505      protected java.util.Map syntheticMethodAccess_FunctionDescriptor_values;
506      /**
507       * @apilevel internal
508       */
509      private void syntheticMethodAccess_FunctionDescriptor_reset() {
510        syntheticMethodAccess_FunctionDescriptor_values = null;
511      }
512      /**
513       * @attribute syn
514       * @aspect MethodReference
515       * @declaredat /home/jesper/git/extendj/java8/frontend/MethodReference.jrag:53
516       */
517      @ASTNodeAnnotation.Attribute
518      public MethodAccess syntheticMethodAccess(FunctionDescriptor f) {
519        Object _parameters = f;
520        if (syntheticMethodAccess_FunctionDescriptor_values == null) syntheticMethodAccess_FunctionDescriptor_values = new org.jastadd.util.RobustMap(new java.util.HashMap());
521        ASTNode$State state = state();
522        if (syntheticMethodAccess_FunctionDescriptor_values.containsKey(_parameters)) {
523          return (MethodAccess) syntheticMethodAccess_FunctionDescriptor_values.get(_parameters);
524        }
525        boolean intermediate = state.INTERMEDIATE_VALUE;
526        state.INTERMEDIATE_VALUE = false;
527        int num = state.boundariesCrossed;
528        boolean isFinal = this.is$Final();
529        MethodAccess syntheticMethodAccess_FunctionDescriptor_value = syntheticMethodAccess_compute(f);
530        if (isFinal && num == state().boundariesCrossed) {
531          syntheticMethodAccess_FunctionDescriptor_values.put(_parameters, syntheticMethodAccess_FunctionDescriptor_value);
532        } else {
533        }
534        state.INTERMEDIATE_VALUE |= intermediate;
535    
536        return syntheticMethodAccess_FunctionDescriptor_value;
537      }
538      /**
539       * @apilevel internal
540       */
541      private MethodAccess syntheticMethodAccess_compute(FunctionDescriptor f) {
542          Access synAccess = syntheticAccess(f);
543          return (MethodAccess) synAccess.lastAccess();
544        }
545      /**
546       * @apilevel internal
547       */
548      protected java.util.Map congruentTo_FunctionDescriptor_values;
549      /**
550       * @apilevel internal
551       */
552      private void congruentTo_FunctionDescriptor_reset() {
553        congruentTo_FunctionDescriptor_values = null;
554      }
555      /**
556       * @attribute syn
557       * @aspect MethodReference
558       * @declaredat /home/jesper/git/extendj/java8/frontend/MethodReference.jrag:212
559       */
560      @ASTNodeAnnotation.Attribute
561      public boolean congruentTo(FunctionDescriptor f) {
562        Object _parameters = f;
563        if (congruentTo_FunctionDescriptor_values == null) congruentTo_FunctionDescriptor_values = new org.jastadd.util.RobustMap(new java.util.HashMap());
564        ASTNode$State state = state();
565        if (congruentTo_FunctionDescriptor_values.containsKey(_parameters)) {
566          return (Boolean) congruentTo_FunctionDescriptor_values.get(_parameters);
567        }
568        boolean intermediate = state.INTERMEDIATE_VALUE;
569        state.INTERMEDIATE_VALUE = false;
570        int num = state.boundariesCrossed;
571        boolean isFinal = this.is$Final();
572        boolean congruentTo_FunctionDescriptor_value = congruentTo_compute(f);
573        if (isFinal && num == state().boundariesCrossed) {
574          congruentTo_FunctionDescriptor_values.put(_parameters, congruentTo_FunctionDescriptor_value);
575        } else {
576        }
577        state.INTERMEDIATE_VALUE |= intermediate;
578    
579        return congruentTo_FunctionDescriptor_value;
580      }
581      /**
582       * @apilevel internal
583       */
584      private boolean congruentTo_compute(FunctionDescriptor f) {
585          MethodDecl decl = targetMethod(f);
586          if (unknownMethod() == decl) {
587            return false;
588          }
589          if (f.method.type().isVoid()) {
590            return true;
591          }
592          if (decl.type().isVoid()) {
593            return false;
594          }
595          return decl.type().assignConversionTo(f.method.type(), null);
596        }
597      /**
598       * @apilevel internal
599       */
600      protected java.util.Map potentiallyApplicableMethods_FunctionDescriptor_values;
601      /**
602       * @apilevel internal
603       */
604      private void potentiallyApplicableMethods_FunctionDescriptor_reset() {
605        potentiallyApplicableMethods_FunctionDescriptor_values = null;
606      }
607      /**
608       * @attribute syn
609       * @aspect MethodReference
610       * @declaredat /home/jesper/git/extendj/java8/frontend/MethodReference.jrag:253
611       */
612      @ASTNodeAnnotation.Attribute
613      public ArrayList<MethodDecl> potentiallyApplicableMethods(FunctionDescriptor f) {
614        Object _parameters = f;
615        if (potentiallyApplicableMethods_FunctionDescriptor_values == null) potentiallyApplicableMethods_FunctionDescriptor_values = new org.jastadd.util.RobustMap(new java.util.HashMap());
616        ASTNode$State state = state();
617        if (potentiallyApplicableMethods_FunctionDescriptor_values.containsKey(_parameters)) {
618          return (ArrayList<MethodDecl>) potentiallyApplicableMethods_FunctionDescriptor_values.get(_parameters);
619        }
620        boolean intermediate = state.INTERMEDIATE_VALUE;
621        state.INTERMEDIATE_VALUE = false;
622        int num = state.boundariesCrossed;
623        boolean isFinal = this.is$Final();
624        ArrayList<MethodDecl> potentiallyApplicableMethods_FunctionDescriptor_value = potentiallyApplicableMethods_compute(f);
625        if (isFinal && num == state().boundariesCrossed) {
626          potentiallyApplicableMethods_FunctionDescriptor_values.put(_parameters, potentiallyApplicableMethods_FunctionDescriptor_value);
627        } else {
628        }
629        state.INTERMEDIATE_VALUE |= intermediate;
630    
631        return potentiallyApplicableMethods_FunctionDescriptor_value;
632      }
633      /**
634       * @apilevel internal
635       */
636      private ArrayList<MethodDecl> potentiallyApplicableMethods_compute(FunctionDescriptor f) {
637          Collection<MethodDecl> col = getExpr().type().memberMethods(name());
638          ArrayList<MethodDecl> applicable = new ArrayList<MethodDecl>();
639          for (MethodDecl decl : col) {
640            if (!decl.accessibleFrom(hostType())) {
641              continue;
642            }
643            if (!(decl.arity() == f.method.arity())) {
644              continue;
645            }
646            if (hasTypeArgument()) {
647              if (!decl.isGeneric()) {
648                continue;
649              }
650              GenericMethodDecl genDecl = decl.genericDecl();
651              if (!(getNumTypeArgument() == genDecl.getNumTypeParameter())) {
652              }
653                continue;
654            }
655            applicable.add(decl);
656          }
657          return applicable;
658        }
659      /**
660       * @apilevel internal
661       */
662      protected boolean exactCompileTimeDeclaration_computed = false;
663      /**
664       * @apilevel internal
665       */
666      protected MethodDecl exactCompileTimeDeclaration_value;
667      /**
668       * @apilevel internal
669       */
670      private void exactCompileTimeDeclaration_reset() {
671        exactCompileTimeDeclaration_computed = false;
672        exactCompileTimeDeclaration_value = null;
673      }
674      /**
675       * @attribute syn
676       * @aspect MethodReference
677       * @declaredat /home/jesper/git/extendj/java8/frontend/MethodReference.jrag:308
678       */
679      @ASTNodeAnnotation.Attribute
680      public MethodDecl exactCompileTimeDeclaration() {
681        ASTNode$State state = state();
682        if (exactCompileTimeDeclaration_computed) {
683          return exactCompileTimeDeclaration_value;
684        }
685        boolean intermediate = state.INTERMEDIATE_VALUE;
686        state.INTERMEDIATE_VALUE = false;
687        int num = state.boundariesCrossed;
688        boolean isFinal = this.is$Final();
689        exactCompileTimeDeclaration_value = exactCompileTimeDeclaration_compute();
690        if (isFinal && num == state().boundariesCrossed) {
691          exactCompileTimeDeclaration_computed = true;
692        } else {
693        }
694        state.INTERMEDIATE_VALUE |= intermediate;
695    
696        return exactCompileTimeDeclaration_value;
697      }
698      /**
699       * @apilevel internal
700       */
701      private MethodDecl exactCompileTimeDeclaration_compute() {
702          Collection<MethodDecl> col = getExpr().type().memberMethods(name());
703          int foundCompatible = 0;
704          MethodDecl latestDecl = null;
705          for (MethodDecl decl  : col) {
706            if (decl.accessibleFrom(hostType())) {
707              foundCompatible++;
708              latestDecl = decl;
709            }
710          }
711          if (foundCompatible != 1) {
712            return unknownMethod();
713          }
714          if (latestDecl.isVariableArity()) {
715            return unknownMethod();
716          }
717          if (latestDecl.isGeneric()) {
718            GenericMethodDecl genericDecl = latestDecl.genericDecl();
719            if (getNumTypeArgument() == genericDecl.getNumTypeParameter()) {
720              return latestDecl;
721            } else {
722              return unknownMethod();
723            }
724          }
725          return latestDecl;
726        }
727      /**
728       * @apilevel internal
729       */
730      protected java.util.Map potentiallyCompatible_TypeDecl_BodyDecl_values;
731      /**
732       * @apilevel internal
733       */
734      private void potentiallyCompatible_TypeDecl_BodyDecl_reset() {
735        potentiallyCompatible_TypeDecl_BodyDecl_values = null;
736      }
737      /**
738       * @attribute syn
739       * @aspect MethodSignature18
740       * @declaredat /home/jesper/git/extendj/java8/frontend/MethodSignature.jrag:466
741       */
742      @ASTNodeAnnotation.Attribute
743      public boolean potentiallyCompatible(TypeDecl type, BodyDecl candidateDecl) {
744        java.util.List _parameters = new java.util.ArrayList(2);
745        _parameters.add(type);
746        _parameters.add(candidateDecl);
747        if (potentiallyCompatible_TypeDecl_BodyDecl_values == null) potentiallyCompatible_TypeDecl_BodyDecl_values = new org.jastadd.util.RobustMap(new java.util.HashMap());
748        ASTNode$State state = state();
749        if (potentiallyCompatible_TypeDecl_BodyDecl_values.containsKey(_parameters)) {
750          return (Boolean) potentiallyCompatible_TypeDecl_BodyDecl_values.get(_parameters);
751        }
752        boolean intermediate = state.INTERMEDIATE_VALUE;
753        state.INTERMEDIATE_VALUE = false;
754        int num = state.boundariesCrossed;
755        boolean isFinal = this.is$Final();
756        boolean potentiallyCompatible_TypeDecl_BodyDecl_value = potentiallyCompatible_compute(type, candidateDecl);
757        if (isFinal && num == state().boundariesCrossed) {
758          potentiallyCompatible_TypeDecl_BodyDecl_values.put(_parameters, potentiallyCompatible_TypeDecl_BodyDecl_value);
759        } else {
760        }
761        state.INTERMEDIATE_VALUE |= intermediate;
762    
763        return potentiallyCompatible_TypeDecl_BodyDecl_value;
764      }
765      /**
766       * @apilevel internal
767       */
768      private boolean potentiallyCompatible_compute(TypeDecl type, BodyDecl candidateDecl) {
769          if (super.potentiallyCompatible(type, candidateDecl) && type.isTypeVariable()) {
770            return true;
771          } else if (!super.potentiallyCompatible(type, candidateDecl)) {
772            return false;
773          }
774      
775          InterfaceDecl iDecl = (InterfaceDecl) type;
776          FunctionDescriptor f = iDecl.functionDescriptor();
777      
778          boolean foundMethod = false;
779          for (MethodDecl decl : potentiallyApplicableMethods(f)) {
780            if (!decl.isStatic() && f.method.arity() == decl.arity()) {
781              foundMethod = true;
782              break;
783            }
784          }
785          return foundMethod;
786        }
787      /**
788       * @apilevel internal
789       */
790      protected boolean toClass_computed = false;
791      /**
792       * @apilevel internal
793       */
794      protected ClassInstanceExpr toClass_value;
795      /**
796       * @apilevel internal
797       */
798      private void toClass_reset() {
799        toClass_computed = false;
800        toClass_value = null;
801      }
802      /**
803       * @attribute syn
804       * @aspect MethodReferenceToClass
805       * @declaredat /home/jesper/git/extendj/java8/backend/MethodReferenceToClass.jrag:37
806       */
807      @ASTNodeAnnotation.Attribute
808      public ClassInstanceExpr toClass() {
809        ASTNode$State state = state();
810        if (toClass_computed) {
811          return toClass_value;
812        }
813        boolean intermediate = state.INTERMEDIATE_VALUE;
814        state.INTERMEDIATE_VALUE = false;
815        int num = state.boundariesCrossed;
816        boolean isFinal = this.is$Final();
817        toClass_value = toClass_compute();
818        toClass_value.setParent(this);
819        toClass_value.is$Final = true;
820        if (true) {
821          toClass_computed = true;
822        } else {
823        }
824        state.INTERMEDIATE_VALUE |= intermediate;
825    
826        return toClass_value;
827      }
828      /**
829       * @apilevel internal
830       */
831      private ClassInstanceExpr toClass_compute() {
832          List<Access> implementsList = new List<Access>();
833          InterfaceDecl iDecl = targetInterface();
834      
835          // First compute the interface implemented by the anonymous class
836          Access implementsInterface = iDecl.createQualifiedAccess();
837          implementsList.add(implementsInterface);
838      
839          // Next compute the BodyDecls for the anonymous class
840          List<BodyDecl> bodyDecls = new List<BodyDecl>();
841      
842          FieldDeclaration fieldDecl = null;
843          // If this reference uses a primary or expression name, must evaluate that part first
844          if (!(getExpr() instanceof Access) || !(((Access) getExpr()).lastAccess() instanceof SuperAccess)) {
845            fieldDecl = new FieldDeclaration(new Modifiers(),
846                getExpr().type().createQualifiedAccess(), syntheticFieldName(), (Expr) getExpr().treeCopyNoTransform());
847            bodyDecls.add(fieldDecl);
848          }
849      
850          // Then we must build the method overriding the abstract methods
851      
852          Modifiers methodModifiers = new Modifiers(new List<Modifier>().add(new Modifier("public")));
853          Access returnType = new SyntheticTypeAccess(iDecl.functionDescriptor().method.type());
854          List<ParameterDeclaration> methodParams = toParameterList();
855          List<Access> methodThrows = new List<Access>();
856          for (TypeDecl throwsType : iDecl.functionDescriptor().throwsList) {
857            methodThrows.add(new SyntheticTypeAccess(throwsType));
858          }
859          Opt<Block> methodBlock = new Opt<Block>(toBlock());
860          MethodDecl method = new MethodDecl(methodModifiers, returnType, iDecl.functionDescriptor().method.name(),
861                            methodParams, methodThrows, methodBlock);
862      
863          bodyDecls.add(method);
864      
865          /* Now the anonymous class can be built. Must use the type LambdaAnonymousDecl instead
866          of a normal AnonymousDecl in order for this and super keywords to get the type of the outer
867          scope. */
868          LambdaAnonymousDecl anonymousDecl = new LambdaAnonymousDecl(new Modifiers(), "MethodReference", bodyDecls);
869          for (Access impl: implementsList) {
870            anonymousDecl.addImplements(impl);
871          }
872      
873          return new ClassInstanceExpr((Access) implementsInterface.treeCopyNoTransform(), new List<Expr>(), new Opt<TypeDecl>(anonymousDecl));
874        }
875      /**
876       * @apilevel internal
877       */
878      protected boolean toBlock_computed = false;
879      /**
880       * @apilevel internal
881       */
882      protected Block toBlock_value;
883      /**
884       * @apilevel internal
885       */
886      private void toBlock_reset() {
887        toBlock_computed = false;
888        toBlock_value = null;
889      }
890      /**
891       * @attribute syn
892       * @aspect MethodReferenceToClass
893       * @declaredat /home/jesper/git/extendj/java8/backend/MethodReferenceToClass.jrag:93
894       */
895      @ASTNodeAnnotation.Attribute
896      public Block toBlock() {
897        ASTNode$State state = state();
898        if (toBlock_computed) {
899          return toBlock_value;
900        }
901        boolean intermediate = state.INTERMEDIATE_VALUE;
902        state.INTERMEDIATE_VALUE = false;
903        int num = state.boundariesCrossed;
904        boolean isFinal = this.is$Final();
905        toBlock_value = toBlock_compute();
906        if (isFinal && num == state().boundariesCrossed) {
907          toBlock_computed = true;
908        } else {
909        }
910        state.INTERMEDIATE_VALUE |= intermediate;
911    
912        return toBlock_value;
913      }
914      /**
915       * @apilevel internal
916       */
917      private Block toBlock_compute() {
918          Expr qualifier = null;
919          if (getExpr() instanceof Access && ((Access) getExpr()).lastAccess() instanceof SuperAccess) {
920            qualifier = (Expr) getExpr().treeCopyNoTransform();
921          } else {
922            qualifier = new VarAccess(syntheticFieldName());
923          }
924      
925          List<Expr> arguments = new List<Expr>();
926          for (int i = 0; i < targetInterface().functionDescriptor().method.getNumParameter(); i++) {
927            String paramName = targetInterface().functionDescriptor().method.getParameter(i).name();
928            arguments.add(new VarAccess(paramName));
929          }
930      
931          MethodAccess m = null;
932          if (!hasTypeArgument()) {
933            m = new MethodAccess(name(), arguments);
934          } else {
935            m = new ParMethodAccess(name(), arguments, (List<Access>)getTypeArgumentList().treeCopyNoTransform());
936          }
937          Access qualifiedMethod = qualifier.qualifiesAccess(m);
938          Stmt blockStmt = null;
939          if (targetInterface().functionDescriptor().method.type().isVoid()) {
940            blockStmt = new ExprStmt(qualifiedMethod);
941          } else {
942            blockStmt = new ReturnStmt(qualifiedMethod);
943          }
944          List<Stmt> stmtList = new List<Stmt>();
945          stmtList.add(blockStmt);
946          return new Block(stmtList);
947        }
948      /**
949       * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:196
950       * @apilevel internal
951       */
952      public boolean Define_assignmentContext(ASTNode caller, ASTNode child) {
953        if (caller == getExprNoTransform()) {
954          // @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:385
955          return false;
956        }
957        else {
958          return getParent().Define_assignmentContext(this, caller);
959        }
960      }
961      protected boolean canDefine_assignmentContext(ASTNode caller, ASTNode child) {
962        return true;
963      }
964      /**
965       * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:197
966       * @apilevel internal
967       */
968      public boolean Define_invocationContext(ASTNode caller, ASTNode child) {
969        if (caller == getExprNoTransform()) {
970          // @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:386
971          return false;
972        }
973        else {
974          return getParent().Define_invocationContext(this, caller);
975        }
976      }
977      protected boolean canDefine_invocationContext(ASTNode caller, ASTNode child) {
978        return true;
979      }
980      /**
981       * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:198
982       * @apilevel internal
983       */
984      public boolean Define_castContext(ASTNode caller, ASTNode child) {
985        if (caller == getExprNoTransform()) {
986          // @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:387
987          return false;
988        }
989        else {
990          return getParent().Define_castContext(this, caller);
991        }
992      }
993      protected boolean canDefine_castContext(ASTNode caller, ASTNode child) {
994        return true;
995      }
996      /**
997       * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:199
998       * @apilevel internal
999       */
1000      public boolean Define_stringContext(ASTNode caller, ASTNode child) {
1001        if (caller == getExprNoTransform()) {
1002          // @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:388
1003          return false;
1004        }
1005        else {
1006          return getParent().Define_stringContext(this, caller);
1007        }
1008      }
1009      protected boolean canDefine_stringContext(ASTNode caller, ASTNode child) {
1010        return true;
1011      }
1012      /**
1013       * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:200
1014       * @apilevel internal
1015       */
1016      public boolean Define_numericContext(ASTNode caller, ASTNode child) {
1017        if (caller == getExprNoTransform()) {
1018          // @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:389
1019          return false;
1020        }
1021        else {
1022          return getParent().Define_numericContext(this, caller);
1023        }
1024      }
1025      protected boolean canDefine_numericContext(ASTNode caller, ASTNode child) {
1026        return true;
1027      }
1028      /**
1029       * @declaredat /home/jesper/git/extendj/java5/frontend/GenericMethodsInference.jrag:58
1030       * @apilevel internal
1031       */
1032      public TypeDecl Define_assignConvertedType(ASTNode caller, ASTNode child) {
1033        if (caller == toClass_value) {
1034          // @declaredat /home/jesper/git/extendj/java8/backend/ToClassInherited.jrag:36
1035          {
1036              return targetInterface().functionDescriptor().method.type();
1037            }
1038        }
1039        else {
1040          return getParent().Define_assignConvertedType(this, caller);
1041        }
1042      }
1043      protected boolean canDefine_assignConvertedType(ASTNode caller, ASTNode child) {
1044        return true;
1045      }
1046      /**
1047       * @apilevel internal
1048       */
1049      public ASTNode rewriteTo() {
1050        return super.rewriteTo();
1051      }
1052    }