src/share/classes/com/sun/tools/javac/comp/AttrContext.java

Thu, 07 Jan 2016 08:45:19 +0000

author
sadayapalam
date
Thu, 07 Jan 2016 08:45:19 +0000
changeset 3005
0353cf89ea96
parent 2390
b06c2db45ddb
child 3295
859dc787b52b
permissions
-rw-r--r--

8145466: javac: No line numbers in compilation error
Summary: Compiler should not use the syntax tree from enclosing contexts in diagnostics even when the enclosing contexts are consulted for method lookup.
Reviewed-by: mcimadamore

duke@1 1 /*
vromero@2390 2 * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
ohair@554 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@554 9 * by Oracle in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
ohair@554 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 22 * or visit www.oracle.com if you need additional information or have any
ohair@554 23 * questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.tools.javac.comp;
duke@1 27
sadayapalam@3005 28 import com.sun.tools.javac.tree.JCTree;
duke@1 29 import com.sun.tools.javac.util.*;
duke@1 30 import com.sun.tools.javac.code.*;
duke@1 31
duke@1 32 /** Contains information specific to the attribute and enter
duke@1 33 * passes, to be used in place of the generic field in environments.
duke@1 34 *
jjg@581 35 * <p><b>This is NOT part of any supported API.
jjg@581 36 * If you write code that depends on this, you do so at your own risk.
duke@1 37 * This code and its internal interfaces are subject to change or
duke@1 38 * deletion without notice.</b>
duke@1 39 */
duke@1 40 public class AttrContext {
duke@1 41
duke@1 42 /** The scope of local symbols.
duke@1 43 */
duke@1 44 Scope scope = null;
duke@1 45
duke@1 46 /** The number of enclosing `static' modifiers.
duke@1 47 */
duke@1 48 int staticLevel = 0;
duke@1 49
duke@1 50 /** Is this an environment for a this(...) or super(...) call?
duke@1 51 */
duke@1 52 boolean isSelfCall = false;
duke@1 53
duke@1 54 /** Are we evaluating the selector of a `super' or type name?
duke@1 55 */
duke@1 56 boolean selectSuper = false;
duke@1 57
vromero@2390 58 /** Is the current target of lambda expression or method reference serializable?
vromero@2390 59 */
vromero@2390 60 boolean isSerializable = false;
vromero@2390 61
duke@1 62 /** Are arguments to current function applications boxed into an array for varargs?
duke@1 63 */
mcimadamore@1347 64 Resolve.MethodResolutionPhase pendingResolutionPhase = null;
duke@1 65
duke@1 66 /** A record of the lint/SuppressWarnings currently in effect
duke@1 67 */
duke@1 68 Lint lint;
duke@1 69
mcimadamore@94 70 /** The variable whose initializer is being attributed
mcimadamore@94 71 * useful for detecting self-references in variable initializers
mcimadamore@94 72 */
mcimadamore@94 73 Symbol enclVar = null;
mcimadamore@94 74
mcimadamore@1347 75 /** ResultInfo to be used for attributing 'return' statement expressions
mcimadamore@1347 76 * (set by Attr.visitMethod and Attr.visitLambda)
mcimadamore@1347 77 */
mcimadamore@1347 78 Attr.ResultInfo returnResult = null;
mcimadamore@1347 79
mcimadamore@1393 80 /** Symbol corresponding to the site of a qualified default super call
mcimadamore@1393 81 */
mcimadamore@1393 82 Type defaultSuperCallSite = null;
mcimadamore@1393 83
sadayapalam@3005 84 /** Tree that when non null, is to be preferentially used in diagnostics.
sadayapalam@3005 85 * Usually Env<AttrContext>.tree is the tree to be referred to in messages,
sadayapalam@3005 86 * but this may not be true during the window a method is looked up in enclosing
sadayapalam@3005 87 * contexts (JDK-8145466)
sadayapalam@3005 88 */
sadayapalam@3005 89 JCTree preferredTreeForDiagnostics;
sadayapalam@3005 90
duke@1 91 /** Duplicate this context, replacing scope field and copying all others.
duke@1 92 */
duke@1 93 AttrContext dup(Scope scope) {
duke@1 94 AttrContext info = new AttrContext();
duke@1 95 info.scope = scope;
duke@1 96 info.staticLevel = staticLevel;
duke@1 97 info.isSelfCall = isSelfCall;
duke@1 98 info.selectSuper = selectSuper;
mcimadamore@1347 99 info.pendingResolutionPhase = pendingResolutionPhase;
duke@1 100 info.lint = lint;
mcimadamore@94 101 info.enclVar = enclVar;
mcimadamore@1347 102 info.returnResult = returnResult;
mcimadamore@1393 103 info.defaultSuperCallSite = defaultSuperCallSite;
vromero@2390 104 info.isSerializable = isSerializable;
sadayapalam@3005 105 info.preferredTreeForDiagnostics = preferredTreeForDiagnostics;
duke@1 106 return info;
duke@1 107 }
duke@1 108
duke@1 109 /** Duplicate this context, copying all fields.
duke@1 110 */
duke@1 111 AttrContext dup() {
duke@1 112 return dup(scope);
duke@1 113 }
duke@1 114
duke@1 115 public Iterable<Symbol> getLocalElements() {
duke@1 116 if (scope == null)
duke@1 117 return List.nil();
duke@1 118 return scope.getElements();
duke@1 119 }
duke@1 120
mcimadamore@1347 121 boolean lastResolveVarargs() {
mcimadamore@1347 122 return pendingResolutionPhase != null &&
mcimadamore@1347 123 pendingResolutionPhase.isVarargsRequired();
mcimadamore@1347 124 }
mcimadamore@1347 125
jjg@1409 126 @Override
duke@1 127 public String toString() {
duke@1 128 return "AttrContext[" + scope.toString() + "]";
duke@1 129 }
duke@1 130 }

mercurial