66 import java.util.function.Function; |
66 import java.util.function.Function; |
67 import java.util.function.Predicate; |
67 import java.util.function.Predicate; |
68 import java.util.stream.Stream; |
68 import java.util.stream.Stream; |
69 |
69 |
70 import javax.lang.model.element.ElementVisitor; |
70 import javax.lang.model.element.ElementVisitor; |
71 |
|
72 import com.sun.tools.javac.comp.Infer.InferenceException; |
|
73 |
71 |
74 import static com.sun.tools.javac.code.Flags.*; |
72 import static com.sun.tools.javac.code.Flags.*; |
75 import static com.sun.tools.javac.code.Flags.BLOCK; |
73 import static com.sun.tools.javac.code.Flags.BLOCK; |
76 import static com.sun.tools.javac.code.Flags.STATIC; |
74 import static com.sun.tools.javac.code.Flags.STATIC; |
77 import static com.sun.tools.javac.code.Kinds.*; |
75 import static com.sun.tools.javac.code.Kinds.*; |
816 args = args2; |
814 args = args2; |
817 } |
815 } |
818 String key = inferDiag ? diag.inferKey : diag.basicKey; |
816 String key = inferDiag ? diag.inferKey : diag.basicKey; |
819 throw inferDiag ? |
817 throw inferDiag ? |
820 infer.error(diags.create(DiagnosticType.FRAGMENT, log.currentSource(), pos, key, args)) : |
818 infer.error(diags.create(DiagnosticType.FRAGMENT, log.currentSource(), pos, key, args)) : |
821 new InapplicableMethodException(diags.create(DiagnosticType.FRAGMENT, log.currentSource(), pos, key, args)); |
819 methodCheckFailure.setMessage(diags.create(DiagnosticType.FRAGMENT, log.currentSource(), pos, key, args)); |
822 } |
820 } |
|
821 |
|
822 /** |
|
823 * To eliminate the overhead associated with allocating an exception object in such an |
|
824 * hot execution path, we use flyweight pattern - and share the same exception instance |
|
825 * across multiple method check failures. |
|
826 */ |
|
827 class SharedInapplicableMethodException extends InapplicableMethodException { |
|
828 private static final long serialVersionUID = 0; |
|
829 |
|
830 SharedInapplicableMethodException() { |
|
831 super(null); |
|
832 } |
|
833 |
|
834 SharedInapplicableMethodException setMessage(JCDiagnostic details) { |
|
835 this.diagnostic = details; |
|
836 return this; |
|
837 } |
|
838 } |
|
839 |
|
840 SharedInapplicableMethodException methodCheckFailure = new SharedInapplicableMethodException(); |
823 |
841 |
824 public MethodCheck mostSpecificCheck(List<Type> actuals) { |
842 public MethodCheck mostSpecificCheck(List<Type> actuals) { |
825 return nilMethodCheck; |
843 return nilMethodCheck; |
826 } |
844 } |
827 |
845 |