< prev index next >

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

Print this page

  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.javac.comp;
  27 
  28 import java.util.*;
  29 import java.util.function.BiConsumer;
  30 import java.util.function.Consumer;

  31 import java.util.stream.Stream;
  32 
  33 import javax.lang.model.element.ElementKind;
  34 import javax.tools.JavaFileObject;
  35 
  36 import com.sun.source.tree.CaseTree;
  37 import com.sun.source.tree.IdentifierTree;
  38 import com.sun.source.tree.MemberReferenceTree.ReferenceMode;
  39 import com.sun.source.tree.MemberSelectTree;
  40 import com.sun.source.tree.TreeVisitor;
  41 import com.sun.source.util.SimpleTreeVisitor;
  42 import com.sun.tools.javac.code.*;
  43 import com.sun.tools.javac.code.Lint.LintCategory;
  44 import com.sun.tools.javac.code.LintMapper;
  45 import com.sun.tools.javac.code.Scope.WriteableScope;
  46 import com.sun.tools.javac.code.Source.Feature;
  47 import com.sun.tools.javac.code.Symbol.*;
  48 import com.sun.tools.javac.code.Type.*;
  49 import com.sun.tools.javac.code.Types.FunctionDescriptorLookupError;
  50 import com.sun.tools.javac.comp.ArgumentAttr.LocalCacheContext;

 429         try {
 430             deferredAttr.attribSpeculative(root, env, resultInfo,
 431                     null, DeferredAttr.AttributionMode.ATTRIB_TO_TREE,
 432                     argumentAttr.withLocalCacheContext());
 433             attrRecover.doRecovery();
 434         } catch (BreakAttr b) {
 435             return b.env;
 436         } catch (AssertionError ae) {
 437             if (ae.getCause() instanceof BreakAttr breakAttr) {
 438                 return breakAttr.env;
 439             } else {
 440                 throw ae;
 441             }
 442         } finally {
 443             breakTree = null;
 444             log.useSource(prev);
 445         }
 446         return env;
 447     }
 448 















 449     private JCTree breakTree = null;
 450 
 451     private static class BreakAttr extends RuntimeException {
 452         static final long serialVersionUID = -6924771130405446405L;
 453         private transient Env<AttrContext> env;
 454         private BreakAttr(Env<AttrContext> env) {
 455             this.env = env;
 456         }
 457     }
 458 
 459     /**
 460      * Mode controlling behavior of Attr.Check
 461      */
 462     enum CheckMode {
 463 
 464         NORMAL,
 465 
 466         /**
 467          * Mode signalling 'fake check' - skip tree update. A side-effect of this mode is
 468          * that the captured var cache in {@code InferenceContext} will be used in read-only

  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.javac.comp;
  27 
  28 import java.util.*;
  29 import java.util.function.BiConsumer;
  30 import java.util.function.Consumer;
  31 import java.util.function.Function;
  32 import java.util.stream.Stream;
  33 
  34 import javax.lang.model.element.ElementKind;
  35 import javax.tools.JavaFileObject;
  36 
  37 import com.sun.source.tree.CaseTree;
  38 import com.sun.source.tree.IdentifierTree;
  39 import com.sun.source.tree.MemberReferenceTree.ReferenceMode;
  40 import com.sun.source.tree.MemberSelectTree;
  41 import com.sun.source.tree.TreeVisitor;
  42 import com.sun.source.util.SimpleTreeVisitor;
  43 import com.sun.tools.javac.code.*;
  44 import com.sun.tools.javac.code.Lint.LintCategory;
  45 import com.sun.tools.javac.code.LintMapper;
  46 import com.sun.tools.javac.code.Scope.WriteableScope;
  47 import com.sun.tools.javac.code.Source.Feature;
  48 import com.sun.tools.javac.code.Symbol.*;
  49 import com.sun.tools.javac.code.Type.*;
  50 import com.sun.tools.javac.code.Types.FunctionDescriptorLookupError;
  51 import com.sun.tools.javac.comp.ArgumentAttr.LocalCacheContext;

 430         try {
 431             deferredAttr.attribSpeculative(root, env, resultInfo,
 432                     null, DeferredAttr.AttributionMode.ATTRIB_TO_TREE,
 433                     argumentAttr.withLocalCacheContext());
 434             attrRecover.doRecovery();
 435         } catch (BreakAttr b) {
 436             return b.env;
 437         } catch (AssertionError ae) {
 438             if (ae.getCause() instanceof BreakAttr breakAttr) {
 439                 return breakAttr.env;
 440             } else {
 441                 throw ae;
 442             }
 443         } finally {
 444             breakTree = null;
 445             log.useSource(prev);
 446         }
 447         return env;
 448     }
 449 
 450     public <R> R runWithAttributedMethod(Env<AttrContext> env, JCMethodDecl tree, Function<JCBlock, R> attributedAction) {
 451         JavaFileObject prevSource = log.useSource(env.toplevel.sourcefile);
 452         try {
 453             annotate.queueScanTreeAndTypeAnnotate(tree.body, env, tree.sym);
 454             annotate.flush();
 455             JCBlock dupTree = (JCBlock)deferredAttr.attribSpeculative(tree.body, env, statInfo,
 456                     null, DeferredAttr.AttributionMode.ATTRIB_TO_TREE,
 457                     argumentAttr.withLocalCacheContext());
 458             return attributedAction.apply(dupTree);
 459         } finally {
 460             attrRecover.doRecovery();
 461             log.useSource(prevSource);
 462         }
 463     }
 464 
 465     private JCTree breakTree = null;
 466 
 467     private static class BreakAttr extends RuntimeException {
 468         static final long serialVersionUID = -6924771130405446405L;
 469         private transient Env<AttrContext> env;
 470         private BreakAttr(Env<AttrContext> env) {
 471             this.env = env;
 472         }
 473     }
 474 
 475     /**
 476      * Mode controlling behavior of Attr.Check
 477      */
 478     enum CheckMode {
 479 
 480         NORMAL,
 481 
 482         /**
 483          * Mode signalling 'fake check' - skip tree update. A side-effect of this mode is
 484          * that the captured var cache in {@code InferenceContext} will be used in read-only
< prev index next >