src/share/classes/com/sun/tools/javac/main/JavaCompiler.java

changeset 2166
31fe30e2deac
parent 2088
3e3c321710be
child 2386
f8e84de96252
equal deleted inserted replaced
2165:864dafc5ab7a 2166:31fe30e2deac
269 269
270 /** The type eraser. 270 /** The type eraser.
271 */ 271 */
272 protected TransTypes transTypes; 272 protected TransTypes transTypes;
273 273
274 /** The lambda translator.
275 */
276 protected LambdaToMethod lambdaToMethod;
277
278 /** The syntactic sugar desweetener. 274 /** The syntactic sugar desweetener.
279 */ 275 */
280 protected Lower lower; 276 protected Lower lower;
281 277
282 /** The annotation annotator. 278 /** The annotation annotator.
385 taskListener = MultiTaskListener.instance(context); 381 taskListener = MultiTaskListener.instance(context);
386 382
387 reader.sourceCompleter = thisCompleter; 383 reader.sourceCompleter = thisCompleter;
388 384
389 options = Options.instance(context); 385 options = Options.instance(context);
390
391 lambdaToMethod = LambdaToMethod.instance(context);
392 386
393 verbose = options.isSet(VERBOSE); 387 verbose = options.isSet(VERBOSE);
394 sourceOutput = options.isSet(PRINTSOURCE); // used to be -s 388 sourceOutput = options.isSet(PRINTSOURCE); // used to be -s
395 stubOutput = options.isSet("-stubs"); 389 stubOutput = options.isSet("-stubs");
396 relax = options.isSet("-relax"); 390 relax = options.isSet("-relax");
1391 * out during lowering require that all synthetic fields/methods have 1385 * out during lowering require that all synthetic fields/methods have
1392 * already been added to C and its superclasses. 1386 * already been added to C and its superclasses.
1393 */ 1387 */
1394 class ScanNested extends TreeScanner { 1388 class ScanNested extends TreeScanner {
1395 Set<Env<AttrContext>> dependencies = new LinkedHashSet<Env<AttrContext>>(); 1389 Set<Env<AttrContext>> dependencies = new LinkedHashSet<Env<AttrContext>>();
1390 protected boolean hasLambdas;
1396 @Override 1391 @Override
1397 public void visitClassDef(JCClassDecl node) { 1392 public void visitClassDef(JCClassDecl node) {
1398 Type st = types.supertype(node.sym.type); 1393 Type st = types.supertype(node.sym.type);
1399 boolean envForSuperTypeFound = false; 1394 boolean envForSuperTypeFound = false;
1400 while (!envForSuperTypeFound && st.hasTag(CLASS)) { 1395 while (!envForSuperTypeFound && st.hasTag(CLASS)) {
1401 ClassSymbol c = st.tsym.outermostClass(); 1396 ClassSymbol c = st.tsym.outermostClass();
1402 Env<AttrContext> stEnv = enter.getEnv(c); 1397 Env<AttrContext> stEnv = enter.getEnv(c);
1403 if (stEnv != null && env != stEnv) { 1398 if (stEnv != null && env != stEnv) {
1404 if (dependencies.add(stEnv)) { 1399 if (dependencies.add(stEnv)) {
1405 scan(stEnv.tree); 1400 boolean prevHasLambdas = hasLambdas;
1401 try {
1402 scan(stEnv.tree);
1403 } finally {
1404 /*
1405 * ignore any updates to hasLambdas made during
1406 * the nested scan, this ensures an initalized
1407 * LambdaToMethod is available only to those
1408 * classes that contain lambdas
1409 */
1410 hasLambdas = prevHasLambdas;
1411 }
1406 } 1412 }
1407 envForSuperTypeFound = true; 1413 envForSuperTypeFound = true;
1408 } 1414 }
1409 st = types.supertype(st); 1415 st = types.supertype(st);
1410 } 1416 }
1411 super.visitClassDef(node); 1417 super.visitClassDef(node);
1418 }
1419 @Override
1420 public void visitLambda(JCLambda tree) {
1421 hasLambdas = true;
1422 super.visitLambda(tree);
1423 }
1424 @Override
1425 public void visitReference(JCMemberReference tree) {
1426 hasLambdas = true;
1427 super.visitReference(tree);
1412 } 1428 }
1413 } 1429 }
1414 ScanNested scanner = new ScanNested(); 1430 ScanNested scanner = new ScanNested();
1415 scanner.scan(env.tree); 1431 scanner.scan(env.tree);
1416 for (Env<AttrContext> dep: scanner.dependencies) { 1432 for (Env<AttrContext> dep: scanner.dependencies) {
1466 return; 1482 return;
1467 1483
1468 env.tree = transTypes.translateTopLevelClass(env.tree, localMake); 1484 env.tree = transTypes.translateTopLevelClass(env.tree, localMake);
1469 compileStates.put(env, CompileState.TRANSTYPES); 1485 compileStates.put(env, CompileState.TRANSTYPES);
1470 1486
1471 if (source.allowLambda()) { 1487 if (source.allowLambda() && scanner.hasLambdas) {
1472 if (shouldStop(CompileState.UNLAMBDA)) 1488 if (shouldStop(CompileState.UNLAMBDA))
1473 return; 1489 return;
1474 1490
1475 env.tree = lambdaToMethod.translateTopLevelClass(env, env.tree, localMake); 1491 env.tree = LambdaToMethod.instance(context).translateTopLevelClass(env, env.tree, localMake);
1476 compileStates.put(env, CompileState.UNLAMBDA); 1492 compileStates.put(env, CompileState.UNLAMBDA);
1477 } 1493 }
1478 1494
1479 if (shouldStop(CompileState.LOWER)) 1495 if (shouldStop(CompileState.LOWER))
1480 return; 1496 return;

mercurial