src/share/classes/com/sun/tools/javac/comp/Attr.java

Print this page




 964         for (Scope.Entry e = enumType.tsym.members().lookup(name);
 965              e.scope != null; e = e.next()) {
 966             if (e.sym.kind == VAR) {
 967                 Symbol s = ident.sym = e.sym;
 968                 ((VarSymbol)s).getConstValue(); // ensure initializer is evaluated
 969                 ident.type = s.type;
 970                 return ((s.flags_field & Flags.ENUM) == 0)
 971                     ? null : s;
 972             }
 973         }
 974         return null;
 975     }
 976 
 977     public void visitSynchronized(JCSynchronized tree) {
 978         chk.checkRefType(tree.pos(), attribExpr(tree.lock, env));
 979         attribStat(tree.body, env);
 980         result = null;
 981     }
 982 
 983     public void visitTry(JCTry tree) {



























 984         // Attribute body
 985         attribStat(tree.body, env.dup(tree, env.info.dup()));
 986 
 987         // Attribute catch clauses
 988         for (List<JCCatch> l = tree.catchers; l.nonEmpty(); l = l.tail) {
 989             JCCatch c = l.head;
 990             Env<AttrContext> catchEnv =
 991                 env.dup(c, env.info.dup(env.info.scope.dup()));
 992             Type ctype = attribStat(c.param, catchEnv);
 993             if (TreeInfo.isMultiCatch(c)) {
 994                 //check that multi-catch parameter is marked as final
 995                 if ((c.param.sym.flags() & FINAL) == 0) {
 996                     log.error(c.param.pos(), "multicatch.param.must.be.final", c.param.sym);
 997                 }
 998                 c.param.sym.flags_field = c.param.sym.flags() | DISJOINT;
 999             }
1000             if (c.param.type.tsym.kind == Kinds.VAR) {
1001                 c.param.sym.setData(ElementKind.EXCEPTION_PARAMETER);
1002             }
1003             chk.checkType(c.param.vartype.pos(),
1004                           chk.checkClassType(c.param.vartype.pos(), ctype),
1005                           syms.throwableType);
1006             attribStat(c.body, catchEnv);
1007             catchEnv.info.scope.leave();
1008         }
1009 
1010         // Attribute finalizer
1011         if (tree.finalizer != null) attribStat(tree.finalizer, env);


1012         result = null;
1013     }
1014 
1015     public void visitConditional(JCConditional tree) {
1016         attribExpr(tree.cond, env, syms.booleanType);
1017         attribExpr(tree.truepart, env);
1018         attribExpr(tree.falsepart, env);
1019         result = check(tree,
1020                        capture(condType(tree.pos(), tree.cond.type,
1021                                         tree.truepart.type, tree.falsepart.type)),
1022                        VAL, pkind, pt);
1023     }
1024     //where
1025         /** Compute the type of a conditional expression, after
1026          *  checking that it exists. See Spec 15.25.
1027          *
1028          *  @param pos      The source position to be used for
1029          *                  error diagnostics.
1030          *  @param condtype The type of the expression's condition.
1031          *  @param thentype The type of the expression's then-part.




 964         for (Scope.Entry e = enumType.tsym.members().lookup(name);
 965              e.scope != null; e = e.next()) {
 966             if (e.sym.kind == VAR) {
 967                 Symbol s = ident.sym = e.sym;
 968                 ((VarSymbol)s).getConstValue(); // ensure initializer is evaluated
 969                 ident.type = s.type;
 970                 return ((s.flags_field & Flags.ENUM) == 0)
 971                     ? null : s;
 972             }
 973         }
 974         return null;
 975     }
 976 
 977     public void visitSynchronized(JCSynchronized tree) {
 978         chk.checkRefType(tree.pos(), attribExpr(tree.lock, env));
 979         attribStat(tree.body, env);
 980         result = null;
 981     }
 982 
 983     public void visitTry(JCTry tree) {
 984         // Create a new local environment with a local scope.
 985         Env<AttrContext> localEnv = env.dup(tree, env.info.dup(env.info.scope.dup()));
 986         // Attribute resource declarations
 987         for (JCTree resource : tree.resources) {
 988             if (resource instanceof JCVariableDecl) {
 989                 JCVariableDecl var = (JCVariableDecl) resource;
 990                 Type resourceType = types.upperBound(attribStat(var, localEnv));
 991                 if (var.type.tsym.kind == Kinds.VAR) {
 992                     var.sym.setData(ElementKind.RESOURCE_VARIABLE);
 993                 }
 994                 if (types.asSuper(resourceType, syms.autoCloseableType.tsym) == null) {
 995                     log.error(var.pos(), "arm.not.applicable.to.type");
 996                     resourceType = types.createErrorType(resourceType);
 997                 }
 998                 chk.checkType(var.vartype.pos(), resourceType, var.sym.type);
 999             } else if (resource instanceof JCExpression) {
1000                 JCExpression expr = (JCExpression)resource;
1001                 Type resourceType = types.upperBound(attribExpr(expr, localEnv));
1002                 if (types.asSuper(resourceType, syms.autoCloseableType.tsym) == null) {
1003                     log.error(expr.pos(), "arm.not.applicable.to.type");
1004                     resourceType = types.createErrorType(resourceType);
1005                 }
1006             } else {
1007                 // Parser error.
1008                 throw new AssertionError(tree);
1009             }
1010         }
1011         // Attribute body
1012         attribStat(tree.body, localEnv.dup(tree, localEnv.info.dup()));
1013 
1014         // Attribute catch clauses
1015         for (List<JCCatch> l = tree.catchers; l.nonEmpty(); l = l.tail) {
1016             JCCatch c = l.head;
1017             Env<AttrContext> catchEnv =
1018                 localEnv.dup(c, localEnv.info.dup(localEnv.info.scope.dup()));
1019             Type ctype = attribStat(c.param, catchEnv);
1020             if (TreeInfo.isMultiCatch(c)) {
1021                 //check that multi-catch parameter is marked as final
1022                 if ((c.param.sym.flags() & FINAL) == 0) {
1023                     log.error(c.param.pos(), "multicatch.param.must.be.final", c.param.sym);
1024                 }
1025                 c.param.sym.flags_field = c.param.sym.flags() | DISJOINT;
1026             }
1027             if (c.param.type.tsym.kind == Kinds.VAR) {
1028                 c.param.sym.setData(ElementKind.EXCEPTION_PARAMETER);
1029             }
1030             chk.checkType(c.param.vartype.pos(),
1031                           chk.checkClassType(c.param.vartype.pos(), ctype),
1032                           syms.throwableType);
1033             attribStat(c.body, catchEnv);
1034             catchEnv.info.scope.leave();
1035         }
1036 
1037         // Attribute finalizer
1038         if (tree.finalizer != null) attribStat(tree.finalizer, localEnv);
1039 
1040         localEnv.info.scope.leave();
1041         result = null;
1042     }
1043 
1044     public void visitConditional(JCConditional tree) {
1045         attribExpr(tree.cond, env, syms.booleanType);
1046         attribExpr(tree.truepart, env);
1047         attribExpr(tree.falsepart, env);
1048         result = check(tree,
1049                        capture(condType(tree.pos(), tree.cond.type,
1050                                         tree.truepart.type, tree.falsepart.type)),
1051                        VAL, pkind, pt);
1052     }
1053     //where
1054         /** Compute the type of a conditional expression, after
1055          *  checking that it exists. See Spec 15.25.
1056          *
1057          *  @param pos      The source position to be used for
1058          *                  error diagnostics.
1059          *  @param condtype The type of the expression's condition.
1060          *  @param thentype The type of the expression's then-part.