45 public class JavacTypes implements javax.lang.model.util.Types { |
45 public class JavacTypes implements javax.lang.model.util.Types { |
46 |
46 |
47 private Symtab syms; |
47 private Symtab syms; |
48 private Types types; |
48 private Types types; |
49 |
49 |
50 private static final Context.Key<JavacTypes> KEY = |
|
51 new Context.Key<JavacTypes>(); |
|
52 |
|
53 public static JavacTypes instance(Context context) { |
50 public static JavacTypes instance(Context context) { |
54 JavacTypes instance = context.get(KEY); |
51 JavacTypes instance = context.get(JavacTypes.class); |
55 if (instance == null) { |
52 if (instance == null) |
56 instance = new JavacTypes(context); |
53 instance = new JavacTypes(context); |
57 context.put(KEY, instance); |
|
58 } |
|
59 return instance; |
54 return instance; |
60 } |
55 } |
61 |
56 |
62 /** |
57 /** |
63 * Public for use only by JavacProcessingEnvironment |
58 * Public for use only by JavacProcessingEnvironment |
64 */ |
59 */ |
65 // TODO JavacTypes constructor should be protected |
60 protected JavacTypes(Context context) { |
66 public JavacTypes(Context context) { |
|
67 setContext(context); |
61 setContext(context); |
68 } |
62 } |
69 |
63 |
70 /** |
64 /** |
71 * Use a new context. May be called from outside to update |
65 * Use a new context. May be called from outside to update |
72 * internal state for a new annotation-processing round. |
66 * internal state for a new annotation-processing round. |
73 * This instance is *not* then registered with the new context. |
|
74 */ |
67 */ |
75 public void setContext(Context context) { |
68 public void setContext(Context context) { |
|
69 context.put(JavacTypes.class, this); |
76 syms = Symtab.instance(context); |
70 syms = Symtab.instance(context); |
77 types = Types.instance(context); |
71 types = Types.instance(context); |
78 } |
72 } |
79 |
73 |
80 public Element asElement(TypeMirror t) { |
74 public Element asElement(TypeMirror t) { |