1095
1096 VarSymbol var = (VarSymbol)TreeInfo.symbolFor(resource);
1097 var.setData(ElementKind.RESOURCE_VARIABLE);
1098 } else {
1099 attribExpr(resource, tryEnv, syms.autoCloseableType, "try.not.applicable.to.type");
1100 }
1101 }
1102 // Attribute body
1103 attribStat(tree.body, tryEnv);
1104 if (isTryWithResource)
1105 tryEnv.info.scope.leave();
1106
1107 // Attribute catch clauses
1108 for (List<JCCatch> l = tree.catchers; l.nonEmpty(); l = l.tail) {
1109 JCCatch c = l.head;
1110 Env<AttrContext> catchEnv =
1111 localEnv.dup(c, localEnv.info.dup(localEnv.info.scope.dup()));
1112 Type ctype = attribStat(c.param, catchEnv);
1113 if (TreeInfo.isMultiCatch(c)) {
1114 //multi-catch parameter is implicitly marked as final
1115 c.param.sym.flags_field |= FINAL | DISJUNCTION;
1116 }
1117 if (c.param.sym.kind == Kinds.VAR) {
1118 c.param.sym.setData(ElementKind.EXCEPTION_PARAMETER);
1119 }
1120 chk.checkType(c.param.vartype.pos(),
1121 chk.checkClassType(c.param.vartype.pos(), ctype),
1122 syms.throwableType);
1123 attribStat(c.body, catchEnv);
1124 catchEnv.info.scope.leave();
1125 }
1126
1127 // Attribute finalizer
1128 if (tree.finalizer != null) attribStat(tree.finalizer, localEnv);
1129
1130 localEnv.info.scope.leave();
1131 result = null;
1132 }
1133
1134 void checkAutoCloseable(DiagnosticPosition pos, Env<AttrContext> env, Type resource) {
1135 if (!resource.isErroneous() &&
2890 site = types.asOuterSuper(site, clazzOuter.tsym);
2891 if (site == null)
2892 site = types.erasure(clazzOuter);
2893 clazzOuter = site;
2894 }
2895 }
2896 owntype = new ClassType(clazzOuter, actuals, clazztype.tsym);
2897 } else {
2898 if (formals.length() != 0) {
2899 log.error(tree.pos(), "wrong.number.type.args",
2900 Integer.toString(formals.length()));
2901 } else {
2902 log.error(tree.pos(), "type.doesnt.take.params", clazztype.tsym);
2903 }
2904 owntype = types.createErrorType(tree.type);
2905 }
2906 }
2907 result = check(tree, owntype, TYP, pkind, pt);
2908 }
2909
2910 public void visitTypeDisjunction(JCTypeDisjunction tree) {
2911 ListBuffer<Type> multicatchTypes = ListBuffer.lb();
2912 for (JCExpression typeTree : tree.alternatives) {
2913 Type ctype = attribType(typeTree, env);
2914 ctype = chk.checkType(typeTree.pos(),
2915 chk.checkClassType(typeTree.pos(), ctype),
2916 syms.throwableType);
2917 if (!ctype.isErroneous()) {
2918 //check that alternatives of a disjunctive type are pairwise
2919 //unrelated w.r.t. subtyping
2920 if (chk.intersects(ctype, multicatchTypes.toList())) {
2921 for (Type t : multicatchTypes) {
2922 boolean sub = types.isSubtype(ctype, t);
2923 boolean sup = types.isSubtype(t, ctype);
2924 if (sub || sup) {
2925 //assume 'a' <: 'b'
2926 Type a = sub ? ctype : t;
2927 Type b = sub ? t : ctype;
2928 log.error(typeTree.pos(), "multicatch.types.must.be.disjoint", a, b);
2929 }
2930 }
2931 }
2932 multicatchTypes.append(ctype);
2933 }
2934 }
2935 tree.type = result = check(tree, types.lub(multicatchTypes.toList()), TYP, pkind, pt);
2936 }
2937
2938 public void visitTypeParameter(JCTypeParameter tree) {
|
1095
1096 VarSymbol var = (VarSymbol)TreeInfo.symbolFor(resource);
1097 var.setData(ElementKind.RESOURCE_VARIABLE);
1098 } else {
1099 attribExpr(resource, tryEnv, syms.autoCloseableType, "try.not.applicable.to.type");
1100 }
1101 }
1102 // Attribute body
1103 attribStat(tree.body, tryEnv);
1104 if (isTryWithResource)
1105 tryEnv.info.scope.leave();
1106
1107 // Attribute catch clauses
1108 for (List<JCCatch> l = tree.catchers; l.nonEmpty(); l = l.tail) {
1109 JCCatch c = l.head;
1110 Env<AttrContext> catchEnv =
1111 localEnv.dup(c, localEnv.info.dup(localEnv.info.scope.dup()));
1112 Type ctype = attribStat(c.param, catchEnv);
1113 if (TreeInfo.isMultiCatch(c)) {
1114 //multi-catch parameter is implicitly marked as final
1115 c.param.sym.flags_field |= FINAL | UNION;
1116 }
1117 if (c.param.sym.kind == Kinds.VAR) {
1118 c.param.sym.setData(ElementKind.EXCEPTION_PARAMETER);
1119 }
1120 chk.checkType(c.param.vartype.pos(),
1121 chk.checkClassType(c.param.vartype.pos(), ctype),
1122 syms.throwableType);
1123 attribStat(c.body, catchEnv);
1124 catchEnv.info.scope.leave();
1125 }
1126
1127 // Attribute finalizer
1128 if (tree.finalizer != null) attribStat(tree.finalizer, localEnv);
1129
1130 localEnv.info.scope.leave();
1131 result = null;
1132 }
1133
1134 void checkAutoCloseable(DiagnosticPosition pos, Env<AttrContext> env, Type resource) {
1135 if (!resource.isErroneous() &&
2890 site = types.asOuterSuper(site, clazzOuter.tsym);
2891 if (site == null)
2892 site = types.erasure(clazzOuter);
2893 clazzOuter = site;
2894 }
2895 }
2896 owntype = new ClassType(clazzOuter, actuals, clazztype.tsym);
2897 } else {
2898 if (formals.length() != 0) {
2899 log.error(tree.pos(), "wrong.number.type.args",
2900 Integer.toString(formals.length()));
2901 } else {
2902 log.error(tree.pos(), "type.doesnt.take.params", clazztype.tsym);
2903 }
2904 owntype = types.createErrorType(tree.type);
2905 }
2906 }
2907 result = check(tree, owntype, TYP, pkind, pt);
2908 }
2909
2910 public void visitTypeUnion(JCTypeUnion tree) {
2911 ListBuffer<Type> multicatchTypes = ListBuffer.lb();
2912 for (JCExpression typeTree : tree.alternatives) {
2913 Type ctype = attribType(typeTree, env);
2914 ctype = chk.checkType(typeTree.pos(),
2915 chk.checkClassType(typeTree.pos(), ctype),
2916 syms.throwableType);
2917 if (!ctype.isErroneous()) {
2918 //check that alternatives of a union type are pairwise
2919 //unrelated w.r.t. subtyping
2920 if (chk.intersects(ctype, multicatchTypes.toList())) {
2921 for (Type t : multicatchTypes) {
2922 boolean sub = types.isSubtype(ctype, t);
2923 boolean sup = types.isSubtype(t, ctype);
2924 if (sub || sup) {
2925 //assume 'a' <: 'b'
2926 Type a = sub ? ctype : t;
2927 Type b = sub ? t : ctype;
2928 log.error(typeTree.pos(), "multicatch.types.must.be.disjoint", a, b);
2929 }
2930 }
2931 }
2932 multicatchTypes.append(ctype);
2933 }
2934 }
2935 tree.type = result = check(tree, types.lub(multicatchTypes.toList()), TYP, pkind, pt);
2936 }
2937
2938 public void visitTypeParameter(JCTypeParameter tree) {
|