456 List.<JCVariableDecl>nil(),
457 List.<JCExpression>nil(), // thrown
458 null, //make.Block(0, Tree.emptyList.prepend(make.Return(make.Ident(names._null)))),
459 null);
460 memberEnter(values, env);
461
462 // public static T valueOf(String name) { return ???; }
463 JCMethodDecl valueOf = make.
464 MethodDef(make.Modifiers(Flags.PUBLIC|Flags.STATIC),
465 names.valueOf,
466 make.Type(tree.sym.type),
467 List.<JCTypeParameter>nil(),
468 List.of(make.VarDef(make.Modifiers(Flags.PARAMETER |
469 Flags.MANDATED),
470 names.fromString("name"),
471 make.Type(syms.stringType), null)),
472 List.<JCExpression>nil(), // thrown
473 null, //make.Block(0, Tree.emptyList.prepend(make.Return(make.Ident(names._null)))),
474 null);
475 memberEnter(valueOf, env);
476
477 // the remaining members are for bootstrapping only
478 if (!target.compilerBootstrap(tree.sym)) return;
479
480 // public final int ordinal() { return ???; }
481 JCMethodDecl ordinal = make.at(tree.pos).
482 MethodDef(make.Modifiers(Flags.PUBLIC|Flags.FINAL),
483 names.ordinal,
484 make.Type(syms.intType),
485 List.<JCTypeParameter>nil(),
486 List.<JCVariableDecl>nil(),
487 List.<JCExpression>nil(),
488 null,
489 null);
490 memberEnter(ordinal, env);
491
492 // public final String name() { return ???; }
493 JCMethodDecl name = make.
494 MethodDef(make.Modifiers(Flags.PUBLIC|Flags.FINAL),
495 names._name,
496 make.Type(syms.stringType),
497 List.<JCTypeParameter>nil(),
498 List.<JCVariableDecl>nil(),
499 List.<JCExpression>nil(),
500 null,
501 null);
502 memberEnter(name, env);
503
504 // public int compareTo(E other) { return ???; }
505 MethodSymbol compareTo = new
506 MethodSymbol(Flags.PUBLIC,
507 names.compareTo,
508 new MethodType(List.of(tree.sym.type),
509 syms.intType,
510 List.<Type>nil(),
511 syms.methodClass),
512 tree.sym);
513 memberEnter(make.MethodDef(compareTo, null), env);
514 }
515
516 public void visitTopLevel(JCCompilationUnit tree) {
517 if (tree.starImportScope.elems != null) {
518 // we must have already processed this toplevel
519 return;
520 }
521
522 // check that no class exists with same fully qualified name as
523 // toplevel package
524 if (checkClash && tree.pid != null) {
525 Symbol p = tree.packge;
526 while (p.owner != syms.rootPackage) {
527 p.owner.complete(); // enter all class members of p
528 if (syms.classes.get(p.getQualifiedName()) != null) {
529 log.error(tree.pos,
530 "pkg.clashes.with.class.of.same.name",
531 p);
532 }
533 p = p.owner;
919 memberEnter(env.toplevel, env.enclosing(TOPLEVEL));
920 todo.append(env);
921 }
922
923 if (c.owner.kind == TYP)
924 c.owner.complete();
925
926 // create an environment for evaluating the base clauses
927 Env<AttrContext> baseEnv = baseEnv(tree, env);
928
929 if (tree.extending != null)
930 typeAnnotate(tree.extending, baseEnv, sym);
931 for (JCExpression impl : tree.implementing)
932 typeAnnotate(impl, baseEnv, sym);
933 annotate.flush();
934
935 // Determine supertype.
936 Type supertype =
937 (tree.extending != null)
938 ? attr.attribBase(tree.extending, baseEnv, true, false, true)
939 : ((tree.mods.flags & Flags.ENUM) != 0 && !target.compilerBootstrap(c))
940 ? attr.attribBase(enumBase(tree.pos, c), baseEnv,
941 true, false, false)
942 : (c.fullname == names.java_lang_Object)
943 ? Type.noType
944 : syms.objectType;
945 ct.supertype_field = modelMissingTypes(supertype, tree.extending, false);
946
947 // Determine interfaces.
948 ListBuffer<Type> interfaces = new ListBuffer<Type>();
949 ListBuffer<Type> all_interfaces = null; // lazy init
950 Set<Type> interfaceSet = new HashSet<Type>();
951 List<JCExpression> interfaceTrees = tree.implementing;
952 if ((tree.mods.flags & Flags.ENUM) != 0 && target.compilerBootstrap(c)) {
953 // add interface Comparable<T>
954 interfaceTrees =
955 interfaceTrees.prepend(make.Type(new ClassType(syms.comparableType.getEnclosingType(),
956 List.of(c.type),
957 syms.comparableType.tsym)));
958 // add interface Serializable
959 interfaceTrees =
960 interfaceTrees.prepend(make.Type(syms.serializableType));
961 }
962 for (JCExpression iface : interfaceTrees) {
963 Type i = attr.attribBase(iface, baseEnv, false, true, true);
964 if (i.hasTag(CLASS)) {
965 interfaces.append(i);
966 if (all_interfaces != null) all_interfaces.append(i);
967 chk.checkNotRepeated(iface.pos(), types.erasure(i), interfaceSet);
968 } else {
969 if (all_interfaces == null)
970 all_interfaces = new ListBuffer<Type>().appendList(interfaces);
971 all_interfaces.append(modelMissingTypes(i, iface, true));
972 }
973 }
974 if ((c.flags_field & ANNOTATION) != 0) {
975 ct.interfaces_field = List.of(syms.annotationType);
976 ct.all_interfaces_field = ct.interfaces_field;
977 } else {
978 ct.interfaces_field = interfaces.toList();
979 ct.all_interfaces_field = (all_interfaces == null)
980 ? ct.interfaces_field : all_interfaces.toList();
981 }
1384 * }
1385 *
1386 * @param make The tree factory.
1387 * @param c The class owning the default constructor.
1388 * @param argtypes The parameter types of the constructor.
1389 * @param thrown The thrown exceptions of the constructor.
1390 * @param based Is first parameter a this$n?
1391 */
1392 JCTree DefaultConstructor(TreeMaker make,
1393 ClassSymbol c,
1394 List<Type> typarams,
1395 List<Type> argtypes,
1396 List<Type> thrown,
1397 long flags,
1398 boolean based) {
1399 List<JCVariableDecl> params = make.Params(argtypes, syms.noSymbol);
1400 List<JCStatement> stats = List.nil();
1401 if (c.type != syms.objectType)
1402 stats = stats.prepend(SuperCall(make, typarams, params, based));
1403 if ((c.flags() & ENUM) != 0 &&
1404 (types.supertype(c.type).tsym == syms.enumSym ||
1405 target.compilerBootstrap(c))) {
1406 // constructors of true enums are private
1407 flags = (flags & ~AccessFlags) | PRIVATE | GENERATEDCONSTR;
1408 } else
1409 flags |= (c.flags() & AccessFlags) | GENERATEDCONSTR;
1410 if (c.name.isEmpty()) flags |= ANONCONSTR;
1411 JCTree result = make.MethodDef(
1412 make.Modifiers(flags),
1413 names.init,
1414 null,
1415 make.TypeParams(typarams),
1416 params,
1417 make.Types(thrown),
1418 make.Block(0, stats),
1419 null);
1420 return result;
1421 }
1422
1423 /** Generate call to superclass constructor. This is:
1424 *
1425 * super(id_0, ..., id_n)
|
456 List.<JCVariableDecl>nil(),
457 List.<JCExpression>nil(), // thrown
458 null, //make.Block(0, Tree.emptyList.prepend(make.Return(make.Ident(names._null)))),
459 null);
460 memberEnter(values, env);
461
462 // public static T valueOf(String name) { return ???; }
463 JCMethodDecl valueOf = make.
464 MethodDef(make.Modifiers(Flags.PUBLIC|Flags.STATIC),
465 names.valueOf,
466 make.Type(tree.sym.type),
467 List.<JCTypeParameter>nil(),
468 List.of(make.VarDef(make.Modifiers(Flags.PARAMETER |
469 Flags.MANDATED),
470 names.fromString("name"),
471 make.Type(syms.stringType), null)),
472 List.<JCExpression>nil(), // thrown
473 null, //make.Block(0, Tree.emptyList.prepend(make.Return(make.Ident(names._null)))),
474 null);
475 memberEnter(valueOf, env);
476 }
477
478 public void visitTopLevel(JCCompilationUnit tree) {
479 if (tree.starImportScope.elems != null) {
480 // we must have already processed this toplevel
481 return;
482 }
483
484 // check that no class exists with same fully qualified name as
485 // toplevel package
486 if (checkClash && tree.pid != null) {
487 Symbol p = tree.packge;
488 while (p.owner != syms.rootPackage) {
489 p.owner.complete(); // enter all class members of p
490 if (syms.classes.get(p.getQualifiedName()) != null) {
491 log.error(tree.pos,
492 "pkg.clashes.with.class.of.same.name",
493 p);
494 }
495 p = p.owner;
881 memberEnter(env.toplevel, env.enclosing(TOPLEVEL));
882 todo.append(env);
883 }
884
885 if (c.owner.kind == TYP)
886 c.owner.complete();
887
888 // create an environment for evaluating the base clauses
889 Env<AttrContext> baseEnv = baseEnv(tree, env);
890
891 if (tree.extending != null)
892 typeAnnotate(tree.extending, baseEnv, sym);
893 for (JCExpression impl : tree.implementing)
894 typeAnnotate(impl, baseEnv, sym);
895 annotate.flush();
896
897 // Determine supertype.
898 Type supertype =
899 (tree.extending != null)
900 ? attr.attribBase(tree.extending, baseEnv, true, false, true)
901 : ((tree.mods.flags & Flags.ENUM) != 0)
902 ? attr.attribBase(enumBase(tree.pos, c), baseEnv,
903 true, false, false)
904 : (c.fullname == names.java_lang_Object)
905 ? Type.noType
906 : syms.objectType;
907 ct.supertype_field = modelMissingTypes(supertype, tree.extending, false);
908
909 // Determine interfaces.
910 ListBuffer<Type> interfaces = new ListBuffer<Type>();
911 ListBuffer<Type> all_interfaces = null; // lazy init
912 Set<Type> interfaceSet = new HashSet<Type>();
913 List<JCExpression> interfaceTrees = tree.implementing;
914 for (JCExpression iface : interfaceTrees) {
915 Type i = attr.attribBase(iface, baseEnv, false, true, true);
916 if (i.hasTag(CLASS)) {
917 interfaces.append(i);
918 if (all_interfaces != null) all_interfaces.append(i);
919 chk.checkNotRepeated(iface.pos(), types.erasure(i), interfaceSet);
920 } else {
921 if (all_interfaces == null)
922 all_interfaces = new ListBuffer<Type>().appendList(interfaces);
923 all_interfaces.append(modelMissingTypes(i, iface, true));
924 }
925 }
926 if ((c.flags_field & ANNOTATION) != 0) {
927 ct.interfaces_field = List.of(syms.annotationType);
928 ct.all_interfaces_field = ct.interfaces_field;
929 } else {
930 ct.interfaces_field = interfaces.toList();
931 ct.all_interfaces_field = (all_interfaces == null)
932 ? ct.interfaces_field : all_interfaces.toList();
933 }
1336 * }
1337 *
1338 * @param make The tree factory.
1339 * @param c The class owning the default constructor.
1340 * @param argtypes The parameter types of the constructor.
1341 * @param thrown The thrown exceptions of the constructor.
1342 * @param based Is first parameter a this$n?
1343 */
1344 JCTree DefaultConstructor(TreeMaker make,
1345 ClassSymbol c,
1346 List<Type> typarams,
1347 List<Type> argtypes,
1348 List<Type> thrown,
1349 long flags,
1350 boolean based) {
1351 List<JCVariableDecl> params = make.Params(argtypes, syms.noSymbol);
1352 List<JCStatement> stats = List.nil();
1353 if (c.type != syms.objectType)
1354 stats = stats.prepend(SuperCall(make, typarams, params, based));
1355 if ((c.flags() & ENUM) != 0 &&
1356 (types.supertype(c.type).tsym == syms.enumSym)) {
1357 // constructors of true enums are private
1358 flags = (flags & ~AccessFlags) | PRIVATE | GENERATEDCONSTR;
1359 } else
1360 flags |= (c.flags() & AccessFlags) | GENERATEDCONSTR;
1361 if (c.name.isEmpty()) flags |= ANONCONSTR;
1362 JCTree result = make.MethodDef(
1363 make.Modifiers(flags),
1364 names.init,
1365 null,
1366 make.TypeParams(typarams),
1367 params,
1368 make.Types(thrown),
1369 make.Block(0, stats),
1370 null);
1371 return result;
1372 }
1373
1374 /** Generate call to superclass constructor. This is:
1375 *
1376 * super(id_0, ..., id_n)
|