Search in sources :

Example 1 with CheckContext

use of org.eclipse.ceylon.langtools.tools.javac.comp.Check.CheckContext in project ceylon by eclipse.

the class Attr method visitTry.

public void visitTry(JCTry tree) {
    // Create a new local environment with a local
    Env<AttrContext> localEnv = env.dup(tree, env.info.dup(env.info.scope.dup()));
    try {
        boolean isTryWithResource = tree.resources.nonEmpty();
        // Create a nested environment for attributing the try block if needed
        Env<AttrContext> tryEnv = isTryWithResource ? env.dup(tree, localEnv.info.dup(localEnv.info.scope.dup())) : localEnv;
        try {
            // Attribute resource declarations
            for (JCTree resource : tree.resources) {
                CheckContext twrContext = new Check.NestedCheckContext(resultInfo.checkContext) {

                    @Override
                    public void report(DiagnosticPosition pos, JCDiagnostic details) {
                        chk.basicHandler.report(pos, diags.fragment("try.not.applicable.to.type", details));
                    }
                };
                ResultInfo twrResult = new ResultInfo(VAL, syms.autoCloseableType, twrContext);
                if (resource.hasTag(VARDEF)) {
                    attribStat(resource, tryEnv);
                    twrResult.check(resource, resource.type);
                    // check that resource type cannot throw InterruptedException
                    checkAutoCloseable(resource.pos(), localEnv, resource.type);
                    VarSymbol var = ((JCVariableDecl) resource).sym;
                    var.setData(ElementKind.RESOURCE_VARIABLE);
                } else {
                    attribTree(resource, tryEnv, twrResult);
                }
            }
            // Attribute body
            attribStat(tree.body, tryEnv);
        } finally {
            if (isTryWithResource)
                tryEnv.info.scope.leave();
        }
        // Attribute catch clauses
        for (List<JCCatch> l = tree.catchers; l.nonEmpty(); l = l.tail) {
            JCCatch c = l.head;
            Env<AttrContext> catchEnv = localEnv.dup(c, localEnv.info.dup(localEnv.info.scope.dup()));
            try {
                Type ctype = attribStat(c.param, catchEnv);
                if (TreeInfo.isMultiCatch(c)) {
                    // multi-catch parameter is implicitly marked as final
                    c.param.sym.flags_field |= FINAL | UNION;
                }
                if (c.param.sym.kind == Kinds.VAR) {
                    c.param.sym.setData(ElementKind.EXCEPTION_PARAMETER);
                }
                chk.checkType(c.param.vartype.pos(), chk.checkClassType(c.param.vartype.pos(), ctype), syms.throwableType);
                attribStat(c.body, catchEnv);
            } finally {
                catchEnv.info.scope.leave();
            }
        }
        // Attribute finalizer
        if (tree.finalizer != null)
            attribStat(tree.finalizer, localEnv);
        result = null;
    } finally {
        localEnv.info.scope.leave();
    }
}
Also used : CheckContext(org.eclipse.ceylon.langtools.tools.javac.comp.Check.CheckContext) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree) Type(org.eclipse.ceylon.langtools.tools.javac.code.Type) DiagnosticPosition(org.eclipse.ceylon.langtools.tools.javac.util.JCDiagnostic.DiagnosticPosition)

Aggregations

Type (org.eclipse.ceylon.langtools.tools.javac.code.Type)1 CheckContext (org.eclipse.ceylon.langtools.tools.javac.comp.Check.CheckContext)1 JCTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)1 DiagnosticPosition (org.eclipse.ceylon.langtools.tools.javac.util.JCDiagnostic.DiagnosticPosition)1