AttrContext.java revision 3993:ce416299fd2d
18705Sjkh/* 28705Sjkh * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved. 38705Sjkh * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 48705Sjkh * 58705Sjkh * This code is free software; you can redistribute it and/or modify it 68705Sjkh * under the terms of the GNU General Public License version 2 only, as 750479Speter * published by the Free Software Foundation. Oracle designates this 88705Sjkh * particular file as subject to the "Classpath" exception as provided 98705Sjkh * by Oracle in the LICENSE file that accompanied this code. 108705Sjkh * 118705Sjkh * This code is distributed in the hope that it will be useful, but WITHOUT 128705Sjkh * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 138705Sjkh * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 148705Sjkh * version 2 for more details (a copy is included in the LICENSE file that 158705Sjkh * accompanied this code). 168881Srgrimes * 178881Srgrimes * You should have received a copy of the GNU General Public License version 188705Sjkh * 2 along with this work; if not, write to the Free Software Foundation, 198705Sjkh * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 208705Sjkh * 218705Sjkh * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 228705Sjkh * or visit www.oracle.com if you need additional information or have any 238705Sjkh * questions. 248705Sjkh */ 258705Sjkh 268705Sjkhpackage com.sun.tools.javac.comp; 278705Sjkh 288705Sjkhimport com.sun.tools.javac.tree.JCTree; 298705Sjkhimport com.sun.tools.javac.util.*; 308705Sjkhimport com.sun.tools.javac.code.*; 318705Sjkhimport com.sun.tools.javac.code.Scope.WriteableScope; 328705Sjkh 338705Sjkh/** Contains information specific to the attribute and enter 348705Sjkh * passes, to be used in place of the generic field in environments. 358705Sjkh * 368705Sjkh * <p><b>This is NOT part of any supported API. 378705Sjkh * If you write code that depends on this, you do so at your own risk. 388705Sjkh * This code and its internal interfaces are subject to change or 398768Sjkh * deletion without notice.</b> 4015417Sjkh */ 4115417Sjkhpublic class AttrContext { 4215417Sjkh 4315417Sjkh /** The scope of local symbols. 4415417Sjkh */ 4515417Sjkh WriteableScope scope = null; 4615417Sjkh 478705Sjkh /** The number of enclosing `static' modifiers. 488705Sjkh */ 498705Sjkh int staticLevel = 0; 5020484Sjkh 518705Sjkh /** Is this an environment for a this(...) or super(...) call? 528705Sjkh */ 538705Sjkh boolean isSelfCall = false; 5412661Speter 558705Sjkh /** Are we evaluating the selector of a `super' or type name? 5612661Speter */ 578705Sjkh boolean selectSuper = false; 5812661Speter 5912661Speter /** Is the current target of lambda expression or method reference serializable or is this a 6012661Speter * serializable class? 6112661Speter */ 6214793Sjoerg boolean isSerializable = false; 6312661Speter 6414793Sjoerg /** Is this a lambda environment? 6512661Speter */ 6614793Sjoerg boolean isLambda = false; 678705Sjkh 688705Sjkh /** Is this a speculative attribution environment? 6914793Sjoerg */ 708705Sjkh boolean isSpeculative = false; 718705Sjkh 7212661Speter /** 7312661Speter * Is this an attribution environment for an anonymous class instantiated using <> ? 7412661Speter */ 7512661Speter boolean isAnonymousDiamond = false; 7612661Speter 7712661Speter /** 7812661Speter * Is this an attribution environment for an instance creation expression? 7912661Speter */ 8012661Speter boolean isNewClass = false; 8112661Speter 8212661Speter /** Indicate if the type being visited is a service implementation 8312661Speter */ 8412661Speter boolean visitingServiceImplementation = false; 8512661Speter 8612661Speter /** Are arguments to current function applications boxed into an array for varargs? 8712661Speter */ 8812661Speter Resolve.MethodResolutionPhase pendingResolutionPhase = null; 8920484Sjkh 9020484Sjkh /** A record of the lint/SuppressWarnings currently in effect 9120484Sjkh */ 9220484Sjkh Lint lint; 9320484Sjkh 9420484Sjkh /** The variable whose initializer is being attributed 9520484Sjkh * useful for detecting self-references in variable initializers 9620484Sjkh */ 9720484Sjkh Symbol enclVar = null; 9820484Sjkh 9920484Sjkh /** ResultInfo to be used for attributing 'return' statement expressions 10020484Sjkh * (set by Attr.visitMethod and Attr.visitLambda) 10120484Sjkh */ 10220484Sjkh Attr.ResultInfo returnResult = null; 10320484Sjkh 1048705Sjkh /** Symbol corresponding to the site of a qualified default super call 10512661Speter */ 1068751Sjkh Type defaultSuperCallSite = null; 10734394Sjkh 1088751Sjkh /** Tree that when non null, is to be preferentially used in diagnostics. 1098751Sjkh * Usually Env<AttrContext>.tree is the tree to be referred to in messages, 1108751Sjkh * but this may not be true during the window a method is looked up in enclosing 1118705Sjkh * contexts (JDK-8145466) 1128705Sjkh */ 1139202Srgrimes JCTree preferredTreeForDiagnostics; 1149202Srgrimes 1159202Srgrimes /** Duplicate this context, replacing scope field and copying all others. 11614793Sjoerg */ 1178705Sjkh AttrContext dup(WriteableScope scope) { 1188705Sjkh AttrContext info = new AttrContext(); 1198705Sjkh info.scope = scope; 1208705Sjkh info.staticLevel = staticLevel; 1218705Sjkh info.isSelfCall = isSelfCall; 1228705Sjkh info.selectSuper = selectSuper; 1238756Sjkh info.pendingResolutionPhase = pendingResolutionPhase; 1248705Sjkh info.lint = lint; 1258705Sjkh info.enclVar = enclVar; 1268705Sjkh info.returnResult = returnResult; 1278705Sjkh info.defaultSuperCallSite = defaultSuperCallSite; 1288705Sjkh info.isSerializable = isSerializable; 1298705Sjkh info.isLambda = isLambda; 1308705Sjkh info.isSpeculative = isSpeculative; 1319202Srgrimes info.isAnonymousDiamond = isAnonymousDiamond; 1328705Sjkh info.isNewClass = isNewClass; 1338705Sjkh info.preferredTreeForDiagnostics = preferredTreeForDiagnostics; 1348705Sjkh info.visitingServiceImplementation = visitingServiceImplementation; 1358705Sjkh return info; 1368705Sjkh } 1378705Sjkh 13820484Sjkh /** Duplicate this context, copying all fields. 13920484Sjkh */ 14020484Sjkh AttrContext dup() { 14120484Sjkh return dup(scope); 14220484Sjkh } 14320484Sjkh 1448705Sjkh public Iterable<Symbol> getLocalElements() { 1458705Sjkh if (scope == null) 1468705Sjkh return List.nil(); 14720484Sjkh return scope.getSymbols(); 14820484Sjkh } 14920484Sjkh 15020484Sjkh boolean lastResolveVarargs() { 15120484Sjkh return pendingResolutionPhase != null && 15220484Sjkh pendingResolutionPhase.isVarargsRequired(); 1538705Sjkh } 1548705Sjkh 1558705Sjkh @Override 1568705Sjkh public String toString() { 1578705Sjkh return "AttrContext[" + scope.toString() + "]"; 1588705Sjkh } 15920484Sjkh} 16020484Sjkh