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