64 private Symtab syms; |
64 private Symtab syms; |
65 private Names names; |
65 private Names names; |
66 private Types types; |
66 private Types types; |
67 private Enter enter; |
67 private Enter enter; |
68 |
68 |
69 private static final Context.Key<JavacElements> KEY = |
|
70 new Context.Key<JavacElements>(); |
|
71 |
|
72 public static JavacElements instance(Context context) { |
69 public static JavacElements instance(Context context) { |
73 JavacElements instance = context.get(KEY); |
70 JavacElements instance = context.get(JavacElements.class); |
74 if (instance == null) { |
71 if (instance == null) |
75 instance = new JavacElements(context); |
72 instance = new JavacElements(context); |
76 context.put(KEY, instance); |
|
77 } |
|
78 return instance; |
73 return instance; |
79 } |
74 } |
80 |
75 |
81 /** |
76 /** |
82 * Public for use only by JavacProcessingEnvironment |
77 * Public for use only by JavacProcessingEnvironment |
83 */ |
78 */ |
84 // TODO JavacElements constructor should be protected |
79 protected JavacElements(Context context) { |
85 public JavacElements(Context context) { |
|
86 setContext(context); |
80 setContext(context); |
87 } |
81 } |
88 |
82 |
89 /** |
83 /** |
90 * Use a new context. May be called from outside to update |
84 * Use a new context. May be called from outside to update |
91 * internal state for a new annotation-processing round. |
85 * internal state for a new annotation-processing round. |
92 * This instance is *not* then registered with the new context. |
|
93 */ |
86 */ |
94 public void setContext(Context context) { |
87 public void setContext(Context context) { |
|
88 context.put(JavacElements.class, this); |
95 javaCompiler = JavaCompiler.instance(context); |
89 javaCompiler = JavaCompiler.instance(context); |
96 syms = Symtab.instance(context); |
90 syms = Symtab.instance(context); |
97 names = Names.instance(context); |
91 names = Names.instance(context); |
98 types = Types.instance(context); |
92 types = Types.instance(context); |
99 enter = Enter.instance(context); |
93 enter = Enter.instance(context); |