255 ListBuffer<Name> idents = new ListBuffer<>();
256 for (List<JCTree> defs = classDef.defs; defs.nonEmpty(); defs=defs.tail) {
257 if (defs.head.hasTag(VARDEF) &&
258 (((JCVariableDecl) defs.head).mods.flags & ENUM) != 0) {
259 JCVariableDecl var = (JCVariableDecl)defs.head;
260 idents.append(var.name);
261 }
262 }
263 return idents.toList();
264 }
265
266 /** A hash table mapping class symbols to lists of free variables.
267 * accessed by them. Only free variables of the method immediately containing
268 * a class are associated with that class.
269 */
270 Map<ClassSymbol,List<VarSymbol>> freevarCache;
271
272 /** A navigator class for collecting the free variables accessed
273 * from a local class.
274 */
275 class FreeVarCollector extends CaptureScanner {
276
277 FreeVarCollector(JCTree ownerTree) {
278 super(ownerTree);
279 }
280
281 void addFreeVars(ClassSymbol c) {
282 List<VarSymbol> fvs = freevarCache.get(c);
283 if (fvs != null) {
284 for (List<VarSymbol> l = fvs; l.nonEmpty(); l = l.tail) {
285 addFreeVar(l.head);
286 }
287 }
288 }
289
290 /** If tree refers to a class instance creation expression
291 * add all free variables of the freshly created class.
292 */
293 public void visitNewClass(JCNewClass tree) {
294 ClassSymbol c = (ClassSymbol)tree.constructor.owner;
295 addFreeVars(c);
296 super.visitNewClass(tree);
297 }
298
299 /** If tree refers to a superclass constructor call,
300 * add all free variables of the superclass.
301 */
|
255 ListBuffer<Name> idents = new ListBuffer<>();
256 for (List<JCTree> defs = classDef.defs; defs.nonEmpty(); defs=defs.tail) {
257 if (defs.head.hasTag(VARDEF) &&
258 (((JCVariableDecl) defs.head).mods.flags & ENUM) != 0) {
259 JCVariableDecl var = (JCVariableDecl)defs.head;
260 idents.append(var.name);
261 }
262 }
263 return idents.toList();
264 }
265
266 /** A hash table mapping class symbols to lists of free variables.
267 * accessed by them. Only free variables of the method immediately containing
268 * a class are associated with that class.
269 */
270 Map<ClassSymbol,List<VarSymbol>> freevarCache;
271
272 /** A navigator class for collecting the free variables accessed
273 * from a local class.
274 */
275 public class FreeVarCollector extends CaptureScanner {
276
277 protected FreeVarCollector(JCTree ownerTree) {
278 super(ownerTree);
279 }
280
281 protected void addFreeVars(ClassSymbol c) {
282 List<VarSymbol> fvs = freevarCache.get(c);
283 if (fvs != null) {
284 for (List<VarSymbol> l = fvs; l.nonEmpty(); l = l.tail) {
285 addFreeVar(l.head);
286 }
287 }
288 }
289
290 /** If tree refers to a class instance creation expression
291 * add all free variables of the freshly created class.
292 */
293 public void visitNewClass(JCNewClass tree) {
294 ClassSymbol c = (ClassSymbol)tree.constructor.owner;
295 addFreeVars(c);
296 super.visitNewClass(tree);
297 }
298
299 /** If tree refers to a superclass constructor call,
300 * add all free variables of the superclass.
301 */
|