27 |
27 |
28 import com.sun.tools.javac.util.*; |
28 import com.sun.tools.javac.util.*; |
29 import com.sun.tools.javac.util.List; |
29 import com.sun.tools.javac.util.List; |
30 import com.sun.tools.javac.code.*; |
30 import com.sun.tools.javac.code.*; |
31 import com.sun.tools.javac.code.Type.*; |
31 import com.sun.tools.javac.code.Type.*; |
|
32 import com.sun.tools.javac.util.JCDiagnostic; |
32 |
33 |
33 import static com.sun.tools.javac.code.Flags.*; |
34 import static com.sun.tools.javac.code.Flags.*; |
34 import static com.sun.tools.javac.code.Kinds.*; |
35 import static com.sun.tools.javac.code.Kinds.*; |
35 import static com.sun.tools.javac.code.TypeTags.*; |
36 import static com.sun.tools.javac.code.TypeTags.*; |
36 |
37 |
60 |
62 |
61 protected Infer(Context context) { |
63 protected Infer(Context context) { |
62 context.put(inferKey, this); |
64 context.put(inferKey, this); |
63 syms = Symtab.instance(context); |
65 syms = Symtab.instance(context); |
64 types = Types.instance(context); |
66 types = Types.instance(context); |
|
67 diags = JCDiagnostic.Factory.instance(context); |
|
68 ambiguousNoInstanceException = |
|
69 new NoInstanceException(true, diags); |
|
70 unambiguousNoInstanceException = |
|
71 new NoInstanceException(false, diags); |
65 } |
72 } |
66 |
73 |
67 public static class NoInstanceException extends RuntimeException { |
74 public static class NoInstanceException extends RuntimeException { |
68 private static final long serialVersionUID = 0; |
75 private static final long serialVersionUID = 0; |
69 |
76 |
70 boolean isAmbiguous; // exist several incomparable best instances? |
77 boolean isAmbiguous; // exist several incomparable best instances? |
71 |
78 |
72 JCDiagnostic diagnostic; |
79 JCDiagnostic diagnostic; |
73 |
80 JCDiagnostic.Factory diags; |
74 NoInstanceException(boolean isAmbiguous) { |
81 |
|
82 NoInstanceException(boolean isAmbiguous, JCDiagnostic.Factory diags) { |
75 this.diagnostic = null; |
83 this.diagnostic = null; |
76 this.isAmbiguous = isAmbiguous; |
84 this.isAmbiguous = isAmbiguous; |
|
85 this.diags = diags; |
77 } |
86 } |
78 NoInstanceException setMessage(String key) { |
87 NoInstanceException setMessage(String key) { |
79 this.diagnostic = JCDiagnostic.fragment(key); |
88 this.diagnostic = diags.fragment(key); |
80 return this; |
89 return this; |
81 } |
90 } |
82 NoInstanceException setMessage(String key, Object arg1) { |
91 NoInstanceException setMessage(String key, Object arg1) { |
83 this.diagnostic = JCDiagnostic.fragment(key, arg1); |
92 this.diagnostic = diags.fragment(key, arg1); |
84 return this; |
93 return this; |
85 } |
94 } |
86 NoInstanceException setMessage(String key, Object arg1, Object arg2) { |
95 NoInstanceException setMessage(String key, Object arg1, Object arg2) { |
87 this.diagnostic = JCDiagnostic.fragment(key, arg1, arg2); |
96 this.diagnostic = diags.fragment(key, arg1, arg2); |
88 return this; |
97 return this; |
89 } |
98 } |
90 NoInstanceException setMessage(String key, Object arg1, Object arg2, Object arg3) { |
99 NoInstanceException setMessage(String key, Object arg1, Object arg2, Object arg3) { |
91 this.diagnostic = JCDiagnostic.fragment(key, arg1, arg2, arg3); |
100 this.diagnostic = diags.fragment(key, arg1, arg2, arg3); |
92 return this; |
101 return this; |
93 } |
102 } |
94 public JCDiagnostic getDiagnostic() { |
103 public JCDiagnostic getDiagnostic() { |
95 return diagnostic; |
104 return diagnostic; |
96 } |
105 } |
97 } |
106 } |
98 private final NoInstanceException ambiguousNoInstanceException = |
107 private final NoInstanceException ambiguousNoInstanceException; |
99 new NoInstanceException(true); |
108 private final NoInstanceException unambiguousNoInstanceException; |
100 private final NoInstanceException unambiguousNoInstanceException = |
|
101 new NoInstanceException(false); |
|
102 |
109 |
103 /*************************************************************************** |
110 /*************************************************************************** |
104 * Auxiliary type values and classes |
111 * Auxiliary type values and classes |
105 ***************************************************************************/ |
112 ***************************************************************************/ |
106 |
113 |