27 import com.sun.tools.javac.code.Types; |
27 import com.sun.tools.javac.code.Types; |
28 import com.sun.tools.javac.code.Symtab; |
28 import com.sun.tools.javac.code.Symtab; |
29 import com.sun.tools.javac.code.Type; |
29 import com.sun.tools.javac.code.Type; |
30 import com.sun.tools.javac.code.Type.*; |
30 import com.sun.tools.javac.code.Type.*; |
31 import com.sun.tools.javac.code.Symbol.*; |
31 import com.sun.tools.javac.code.Symbol.*; |
|
32 import com.sun.tools.javac.comp.Check; |
32 import com.sun.tools.javac.util.List; |
33 import com.sun.tools.javac.util.List; |
33 import com.sun.tools.javac.util.ListBuffer; |
34 import com.sun.tools.javac.util.ListBuffer; |
34 import com.sun.tools.javac.util.Name; |
35 import com.sun.tools.javac.util.Name; |
35 import com.sun.tools.javac.util.Names; |
36 import com.sun.tools.javac.util.Names; |
36 import com.sun.tools.javac.file.JavacFileManager; |
37 import com.sun.tools.javac.file.JavacFileManager; |
66 * @author mcimadamore |
67 * @author mcimadamore |
67 */ |
68 */ |
68 public class TypeHarness { |
69 public class TypeHarness { |
69 |
70 |
70 protected Types types; |
71 protected Types types; |
|
72 protected Check chk; |
71 protected Symtab predef; |
73 protected Symtab predef; |
72 protected Names names; |
74 protected Names names; |
73 protected Factory fac; |
75 protected Factory fac; |
74 |
76 |
75 protected TypeHarness() { |
77 protected TypeHarness() { |
76 Context ctx = new Context(); |
78 Context ctx = new Context(); |
77 JavacFileManager.preRegister(ctx); |
79 JavacFileManager.preRegister(ctx); |
78 types = Types.instance(ctx); |
80 types = Types.instance(ctx); |
|
81 chk = Check.instance(ctx); |
79 predef = Symtab.instance(ctx); |
82 predef = Symtab.instance(ctx); |
80 names = Names.instance(ctx); |
83 names = Names.instance(ctx); |
81 fac = new Factory(); |
84 fac = new Factory(); |
82 } |
85 } |
83 |
86 |
153 if (types.isAssignable(s, t) != expected) { |
156 if (types.isAssignable(s, t) != expected) { |
154 String msg = expected ? |
157 String msg = expected ? |
155 " is not assignable to " : |
158 " is not assignable to " : |
156 " is assignable to "; |
159 " is assignable to "; |
157 error(s + msg + t); |
160 error(s + msg + t); |
|
161 } |
|
162 } |
|
163 |
|
164 /** assert that generic type 't' is well-formed */ |
|
165 public void assertValidGenericType(Type t) { |
|
166 assertValidGenericType(t, true); |
|
167 } |
|
168 |
|
169 /** assert that 's' is/is not assignable to 't' */ |
|
170 public void assertValidGenericType(Type t, boolean expected) { |
|
171 if (chk.checkValidGenericType(t) != expected) { |
|
172 String msg = expected ? |
|
173 " is not a valid generic type" : |
|
174 " is a valid generic type"; |
|
175 error(t + msg + " " + t.tsym.type); |
158 } |
176 } |
159 } |
177 } |
160 // </editor-fold> |
178 // </editor-fold> |
161 |
179 |
162 private void error(String msg) { |
180 private void error(String msg) { |