< 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;

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













 447     private JCTree breakTree = null;
 448 
 449     private static class BreakAttr extends RuntimeException {
 450         static final long serialVersionUID = -6924771130405446405L;
 451         private transient Env<AttrContext> env;
 452         private BreakAttr(Env<AttrContext> env) {
 453             this.env = env;
 454         }
 455     }
 456 
 457     /**
 458      * Mode controlling behavior of Attr.Check
 459      */
 460     enum CheckMode {
 461 
 462         NORMAL,
 463 
 464         /**
 465          * Mode signalling 'fake check' - skip tree update. A side-effect of this mode is
 466          * 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;

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