/* * Copyright 1999-2009 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, * CA 95054 USA or visit www.sun.com if you need additional information or * have any questions. */ //todo: one might eliminate uninits.andSets when monotonic package com.sun.tools.javac.comp; import com.sun.tools.javac.code.Symtab; import com.sun.tools.javac.code.Type; import com.sun.tools.javac.code.Types; import com.sun.tools.javac.tree.TreeScanner; import com.sun.tools.javac.tree.JCTree.JCBlock; import com.sun.tools.javac.tree.JCTree.JCReturn; import com.sun.tools.javac.util.Context; public class LambdaFlow extends TreeScanner { protected static final Context.Key lambdaFlowKey = new Context.Key(); private final Types types; private final Symtab syms; private Type lub; public static LambdaFlow instance(Context context) { LambdaFlow instance = context.get(lambdaFlowKey); if (instance == null) instance = new LambdaFlow(context); return instance; } protected LambdaFlow(Context context) { context.put(lambdaFlowKey, this); types = Types.instance(context); syms = Symtab.instance(context); } public Type inferReturnType(JCBlock lambdaBody) { lub = null; try { scan(lambdaBody); return (lub == null)?syms.voidType:lub; } finally { lub = null; } } @Override public void visitReturn(JCReturn tree) { Type type = tree.type; if (lub == null) lub = type; else lub = types.lub(lub, type); } }