AttrContext.java revision 2868:816bd88d33a8
166458Sdfr/* 266458Sdfr * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. 396912Smarcel * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 496912Smarcel * 566458Sdfr * This code is free software; you can redistribute it and/or modify it 666458Sdfr * under the terms of the GNU General Public License version 2 only, as 766458Sdfr * published by the Free Software Foundation. Oracle designates this 866458Sdfr * particular file as subject to the "Classpath" exception as provided 966458Sdfr * by Oracle in the LICENSE file that accompanied this code. 1066458Sdfr * 1166458Sdfr * This code is distributed in the hope that it will be useful, but WITHOUT 1266458Sdfr * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1366458Sdfr * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1466458Sdfr * version 2 for more details (a copy is included in the LICENSE file that 1566458Sdfr * accompanied this code). 1666458Sdfr * 1766458Sdfr * You should have received a copy of the GNU General Public License version 1866458Sdfr * 2 along with this work; if not, write to the Free Software Foundation, 1966458Sdfr * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2066458Sdfr * 2166458Sdfr * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2266458Sdfr * or visit www.oracle.com if you need additional information or have any 2366458Sdfr * questions. 2466458Sdfr */ 2566458Sdfr 2666458Sdfrpackage com.sun.tools.javac.comp; 2766458Sdfr 2866458Sdfrimport com.sun.tools.javac.util.*; 2966458Sdfrimport com.sun.tools.javac.code.*; 3066458Sdfrimport com.sun.tools.javac.code.Scope.WriteableScope; 3166458Sdfr 3266458Sdfr/** Contains information specific to the attribute and enter 3366458Sdfr * passes, to be used in place of the generic field in environments. 3466458Sdfr * 3566458Sdfr * <p><b>This is NOT part of any supported API. 3666458Sdfr * If you write code that depends on this, you do so at your own risk. 3766458Sdfr * This code and its internal interfaces are subject to change or 3866458Sdfr * deletion without notice.</b> 3966458Sdfr */ 4066458Sdfrpublic class AttrContext { 4166458Sdfr 4266458Sdfr /** The scope of local symbols. 4366458Sdfr */ 4466458Sdfr WriteableScope scope = null; 4566458Sdfr 4666458Sdfr /** The number of enclosing `static' modifiers. 4766458Sdfr */ 4896912Smarcel int staticLevel = 0; 4966458Sdfr 5066458Sdfr /** Is this an environment for a this(...) or super(...) call? 5166458Sdfr */ 5266458Sdfr boolean isSelfCall = false; 5366458Sdfr 5466458Sdfr /** Are we evaluating the selector of a `super' or type name? 5566458Sdfr */ 5666458Sdfr boolean selectSuper = false; 5766633Sdfr 5866458Sdfr /** Is the current target of lambda expression or method reference serializable? 5966458Sdfr */ 6066458Sdfr boolean isSerializable = false; 6166458Sdfr 6266458Sdfr /** Is this a speculative attribution environment? 6366458Sdfr */ 6466458Sdfr boolean isSpeculative = false; 6566458Sdfr 6666458Sdfr /** 6766458Sdfr * Is this an attribution environment for an anonymous class instantiated using <> ? 6866458Sdfr */ 6966458Sdfr boolean isAnonymousDiamond = false; 7066458Sdfr 7166458Sdfr /** Are arguments to current function applications boxed into an array for varargs? 7266458Sdfr */ 7366458Sdfr Resolve.MethodResolutionPhase pendingResolutionPhase = null; 7466458Sdfr 7592670Speter /** A record of the lint/SuppressWarnings currently in effect 7666458Sdfr */ 7766458Sdfr Lint lint; 7866458Sdfr 7966458Sdfr /** The variable whose initializer is being attributed 8066458Sdfr * useful for detecting self-references in variable initializers 8166458Sdfr */ 8266458Sdfr Symbol enclVar = null; 8366458Sdfr 8466458Sdfr /** ResultInfo to be used for attributing 'return' statement expressions 8566458Sdfr * (set by Attr.visitMethod and Attr.visitLambda) 8666458Sdfr */ 8766458Sdfr Attr.ResultInfo returnResult = null; 8866458Sdfr 8966458Sdfr /** Symbol corresponding to the site of a qualified default super call 9066458Sdfr */ 9166458Sdfr Type defaultSuperCallSite = null; 9266458Sdfr 9366458Sdfr /** Duplicate this context, replacing scope field and copying all others. 9466458Sdfr */ 9566458Sdfr AttrContext dup(WriteableScope scope) { 9666458Sdfr AttrContext info = new AttrContext(); 9766458Sdfr info.scope = scope; 9866458Sdfr info.staticLevel = staticLevel; 9966458Sdfr info.isSelfCall = isSelfCall; 10066458Sdfr info.selectSuper = selectSuper; 10166458Sdfr info.pendingResolutionPhase = pendingResolutionPhase; 10266458Sdfr info.lint = lint; 10366458Sdfr info.enclVar = enclVar; 10466458Sdfr info.returnResult = returnResult; 10566458Sdfr info.defaultSuperCallSite = defaultSuperCallSite; 10666458Sdfr info.isSerializable = isSerializable; 10766458Sdfr info.isSpeculative = isSpeculative; 10866458Sdfr info.isAnonymousDiamond = isAnonymousDiamond; 10966458Sdfr return info; 11066458Sdfr } 11166458Sdfr 11266458Sdfr /** Duplicate this context, copying all fields. 11366458Sdfr */ 11466458Sdfr AttrContext dup() { 11566458Sdfr return dup(scope); 11666458Sdfr } 11766458Sdfr 11866458Sdfr public Iterable<Symbol> getLocalElements() { 11966458Sdfr if (scope == null) 12066458Sdfr return List.nil(); 12166458Sdfr return scope.getSymbols(); 12266458Sdfr } 12366458Sdfr 12496912Smarcel boolean lastResolveVarargs() { 12596912Smarcel return pendingResolutionPhase != null && 12696912Smarcel pendingResolutionPhase.isVarargsRequired(); 12796912Smarcel } 12896912Smarcel 12996912Smarcel @Override 13096912Smarcel public String toString() { 13196912Smarcel return "AttrContext[" + scope.toString() + "]"; 13296912Smarcel } 13366458Sdfr} 13466458Sdfr