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