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