254 abstract void visitSymbol(Symbol _sym);
255
256 /** If tree refers to a class instance creation expression
257 * add all free variables of the freshly created class.
258 */
259 public void visitNewClass(JCNewClass tree) {
260 ClassSymbol c = (ClassSymbol)tree.constructor.owner;
261 addFreeVars(c);
262 super.visitNewClass(tree);
263 }
264
265 /** If tree refers to a superclass constructor call,
266 * add all free variables of the superclass.
267 */
268 public void visitApply(JCMethodInvocation tree) {
269 if (TreeInfo.name(tree.meth) == names._super) {
270 addFreeVars((ClassSymbol) TreeInfo.symbol(tree.meth).owner);
271 }
272 super.visitApply(tree);
273 }
274 }
275
276 /**
277 * Lower-specific subclass of {@code BasicFreeVarCollector}.
278 */
279 class FreeVarCollector extends BasicFreeVarCollector {
280
281 /** The owner of the local class.
282 */
283 Symbol owner;
284
285 /** The local class.
286 */
287 ClassSymbol clazz;
288
289 /** The list of owner's variables accessed from within the local class,
290 * without any duplicates.
291 */
292 List<VarSymbol> fvs;
293
356 outerThisStack.head != null)
357 visitSymbol(outerThisStack.head);
358 super.visitSelect(tree);
359 }
360
361 /** If tree refers to a superclass constructor call,
362 * add all free variables of the superclass.
363 */
364 public void visitApply(JCMethodInvocation tree) {
365 if (TreeInfo.name(tree.meth) == names._super) {
366 Symbol constructor = TreeInfo.symbol(tree.meth);
367 ClassSymbol c = (ClassSymbol)constructor.owner;
368 if (c.hasOuterInstance() &&
369 !tree.meth.hasTag(SELECT) &&
370 outerThisStack.head != null)
371 visitSymbol(outerThisStack.head);
372 }
373 super.visitApply(tree);
374 }
375
376 @Override
377 public void visitBreak(JCBreak tree) {
378 if (tree.isValueBreak())
379 scan(tree.value);
380 }
381
382 }
383
384 ClassSymbol ownerToCopyFreeVarsFrom(ClassSymbol c) {
385 if (!c.isLocal()) {
386 return null;
387 }
388 Symbol currentOwner = c.owner;
389 while (currentOwner.owner.kind.matches(KindSelector.TYP) && currentOwner.isLocal()) {
390 currentOwner = currentOwner.owner;
391 }
392 if (currentOwner.owner.kind.matches(KindSelector.VAL_MTH) && c.isSubClass(currentOwner, types)) {
393 return (ClassSymbol)currentOwner;
394 }
395 return null;
396 }
397
398 /** Return the variables accessed from within a local class, which
399 * are declared in the local class' owner.
400 * (in reverse order of first access).
401 */
|
254 abstract void visitSymbol(Symbol _sym);
255
256 /** If tree refers to a class instance creation expression
257 * add all free variables of the freshly created class.
258 */
259 public void visitNewClass(JCNewClass tree) {
260 ClassSymbol c = (ClassSymbol)tree.constructor.owner;
261 addFreeVars(c);
262 super.visitNewClass(tree);
263 }
264
265 /** If tree refers to a superclass constructor call,
266 * add all free variables of the superclass.
267 */
268 public void visitApply(JCMethodInvocation tree) {
269 if (TreeInfo.name(tree.meth) == names._super) {
270 addFreeVars((ClassSymbol) TreeInfo.symbol(tree.meth).owner);
271 }
272 super.visitApply(tree);
273 }
274
275 @Override
276 public void visitBreak(JCBreak tree) {
277 if (tree.isValueBreak())
278 scan(tree.value);
279 }
280
281 }
282
283 /**
284 * Lower-specific subclass of {@code BasicFreeVarCollector}.
285 */
286 class FreeVarCollector extends BasicFreeVarCollector {
287
288 /** The owner of the local class.
289 */
290 Symbol owner;
291
292 /** The local class.
293 */
294 ClassSymbol clazz;
295
296 /** The list of owner's variables accessed from within the local class,
297 * without any duplicates.
298 */
299 List<VarSymbol> fvs;
300
363 outerThisStack.head != null)
364 visitSymbol(outerThisStack.head);
365 super.visitSelect(tree);
366 }
367
368 /** If tree refers to a superclass constructor call,
369 * add all free variables of the superclass.
370 */
371 public void visitApply(JCMethodInvocation tree) {
372 if (TreeInfo.name(tree.meth) == names._super) {
373 Symbol constructor = TreeInfo.symbol(tree.meth);
374 ClassSymbol c = (ClassSymbol)constructor.owner;
375 if (c.hasOuterInstance() &&
376 !tree.meth.hasTag(SELECT) &&
377 outerThisStack.head != null)
378 visitSymbol(outerThisStack.head);
379 }
380 super.visitApply(tree);
381 }
382
383 }
384
385 ClassSymbol ownerToCopyFreeVarsFrom(ClassSymbol c) {
386 if (!c.isLocal()) {
387 return null;
388 }
389 Symbol currentOwner = c.owner;
390 while (currentOwner.owner.kind.matches(KindSelector.TYP) && currentOwner.isLocal()) {
391 currentOwner = currentOwner.owner;
392 }
393 if (currentOwner.owner.kind.matches(KindSelector.VAL_MTH) && c.isSubClass(currentOwner, types)) {
394 return (ClassSymbol)currentOwner;
395 }
396 return null;
397 }
398
399 /** Return the variables accessed from within a local class, which
400 * are declared in the local class' owner.
401 * (in reverse order of first access).
402 */
|