private Context contextForNextRound(Context context, boolean shareNames)
        throws IOException
    {
        Context next = new Context();

        Options options = Options.instance(context);
        assert options != null;
        next.put(Options.optionsKey, options);

        PrintWriter out = context.get(Log.outKey);
        assert out != null;
        next.put(Log.outKey, out);

        if (shareNames) {
            Name.Table names = Name.Table.instance(context);
            assert names != null;
            next.put(Name.Table.namesKey, names);
        }

        DiagnosticListener dl = context.get(DiagnosticListener.class);
        if (dl != null)
            next.put(DiagnosticListener.class, dl);

        TaskListener tl = context.get(TaskListener.class);
        if (tl != null)
            next.put(TaskListener.class, tl);

        JavaFileManager jfm = context.get(JavaFileManager.class);
        assert jfm != null;
        next.put(JavaFileManager.class, jfm);
        if (jfm instanceof JavacFileManager) {
            ((JavacFileManager)jfm).setContext(next);
        }

        Name.Table names = Name.Table.instance(context);
        assert names != null;
        next.put(Name.Table.namesKey, names);

        Keywords keywords = Keywords.instance(context);
        assert(keywords != null);
        next.put(Keywords.keywordsKey, keywords);

        JavaCompiler oldCompiler = JavaCompiler.instance(context);
        JavaCompiler nextCompiler = JavaCompiler.instance(next);
        nextCompiler.initRound(oldCompiler);

        JavacTaskImpl task = context.get(JavacTaskImpl.class);
        if (task != null) {
            next.put(JavacTaskImpl.class, task);
            task.updateContext(next);
        }

        context.clear();
        return next;
    }