2362N/A * Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * This class defines a member of a Java class: 0N/A * a variable, a method, or an inner class. 0N/A * WARNING: The contents of this source file are not part of any 0N/A * supported API. Code that depends on them does so at its own risk: 0N/A * they are subject to change or removal without notice. 0N/A * Constructor for an inner class. 0N/A * Inner classes are represented as fields right along with 0N/A * variables and methods for simplicity of data structure, 0N/A * and to reflect properly the textual declaration order. 0N/A * This constructor calls the generic constructor for this 0N/A * class, extracting all necessary values from the innerClass. 0N/A * A cache of previously created proxy members. Used to ensure 0N/A * uniqueness of proxy objects. See the makeProxyMember method 0N/A * Create a member which is externally the same as `field' but 0N/A * is defined in class `classDef'. This is used by code 0N/A * in sun.tools.tree.(MethodExpression,FieldExpression) as 0N/A * part of the fix for bug 4135692. 0N/A * Proxy members should not be added, ala addMember(), to classes. 0N/A * They are merely "stand-ins" to produce modified MethodRef 0N/A * constant pool entries during code generation. 0N/A * We keep a cache of previously created proxy members not to 0N/A * save time or space, but to ensure uniqueness of the proxy 0N/A * member for any (field,classDef) pair. If these are not made 0N/A * unique then we can end up generating duplicate MethodRef 0N/A * constant pool entries during code generation. 0N/A // System.out.println("Key is : " + key); 0N/A * Get the position in the input 0N/A * Get the class declaration 0N/A * A stub. Subclasses can do more checking. 0N/A * Get the class declaration in which the field is actually defined 0N/A * Get the class definition 0N/A * Get the field's top-level enclosing class 0N/A * Get the field's modifiers 0N/A * Get the field's type 0N/A * Get the field's name 0N/A * Get arguments (a vector of LocalMember) 0N/A * Get the exceptions that are thrown by this method. 0N/A // we should have translated this already! 0N/A * Get an inner class. 0N/A * Is this a synthetic field which holds a copy of, 0N/A * or reference to, a local variable or enclosing instance? 0N/A // This no longer works, because access methods 0N/A // for constructors do not use the standard naming 0N/A // return isSynthetic() && isMethod() 0N/A // && name.toString().startsWith(prefixAccess); 0N/A // Assume that a method is an access method if it has 0N/A // an access peer. NOTE: An access method will not be 0N/A // recognized as such until 'setAccessMethodTarget' has 0N/A // been called on it. 0N/A * Is this a synthetic method which provides access to a 0N/A * visible private member? 0N/A // perhaps skip over another access for the same field 0N/A /*-------------------* 0N/A if (!isAccessMethod() || accessPeer != null || 0N/A target.accessPeer != null) { 0N/A throw new CompilerError("accessPeer"); 0N/A *-------------------*/ 0N/A * If this method is a getter for a private field, return the setter. 0N/A * Is this an access method for a field selection or method call 0N/A * of the form '...super.foo' or '...super.foo()'? 0N/A * Mark this member as an access method for a field selection 0N/A * or method call via the 'super' keyword. 0N/A * Tell if this is a final variable without an initializer. 0N/A * Such variables are subject to definite single assignment. 0N/A // loc$x and this$C are never null 0N/A * Get the field's final value (may return null) 0N/A * Get the next field or the next match 0N/A * Get the field's documentation 0N/A * Request a check of the field definition. 0N/A * Really check the field definition. 0N/A * Tells whether to report a deprecation error for this field. 0N/A * Check if a field can reach another field (only considers 0N/A * forward references, not the access modifiers). 0N/A // They are located in the same class, and are either both 0N/A // static or both non-static. Check the initialization order. 0N/A //----------------------------------------------------------------- 0N/A // The code in this section is intended to test certain kinds of 0N/A // compatibility between methods. There are two kinds of compatibility 0N/A // that the compiler may need to test. The first is whether one 0N/A // method can legally override another. The second is whether two 0N/A // method definitions can legally coexist. We use the word `meet' 0N/A // to mean the intersection of two legally coexisting methods. 0N/A // For more information on these kinds of compatibility, see the 0N/A * Constants used by getAccessLevel() to represent the access 0N/A * modifiers as numbers. 0N/A * Return the access modifier of this member as a number. The idea 0N/A * is that this number may be used to check properties like "the 0N/A * access modifier of x is more restrictive than the access 0N/A * modifier of y" with a simple inequality test: 0N/A * "x.getAccessLevel() > y.getAccessLevel. 0N/A * This is an internal utility method. 0N/A // Could just compute this once instead of recomputing. 0N/A // Check to see if this is worth it. 0N/A * Munge our error message to report whether the override conflict 0N/A * came from an inherited method or a declared method. 0N/A // "Instance method BLAH inherited from CLASSBLAH1 cannot be 0N/A // overridden by the static method declared in CLASSBLAH2." 0N/A // "In CLASSBLAH1, instance method BLAH inherited from CLASSBLAH2 0N/A // cannot be overridden by the static method inherited from 0N/A //"inherit." + errorString, 0N/A * Convenience method to see if two methods return the same type 0N/A // Make sure both are methods. 0N/A * responsible for verifying that `method' has the same signature 0N/A * as `this'. Caller is also responsible for verifying that 0N/A * `method' is visible to the class where this override is occurring. 0N/A * This method is called for the case when class B extends A and both 0N/A * A and B define some method. 0N/A * A - void foo() throws e1 0N/A * B - void foo() throws e2 0N/A * Checks whether `this' can override `method'. It `clazz' is 0N/A * null, it reports the errors in the class where `this' is 0N/A * declared. If `clazz' is not null, it reports the error in `clazz'. 0N/A // This section of code is largely based on section 8.4.6.3 0N/A // Suppress checks for synthetic methods, as the compiler presumably 0N/A // knows what it is doing, e.g., access methods. 0N/A // Sanity check: We generally do not intend for one synthetic 0N/A // method to override another, though hiding of static members 0N/A // is expected. This check may need to be changed if new uses 0N/A // of synthetic methods are devised. 0N/A // Query: this code was copied from elsewhere. What 0N/A // exactly is the role of the !isStatic() in the test? 0N/A //////////////////////////////////////////////////////////// 0N/A // NMG 2003-01-28 removed the following test because it is 0N/A // invalidated by bridge methods inserted by the "generic" 0N/A // (1.5) Java compiler. In 1.5, this code is used, 0N/A // indirectly, by rmic 0N/A //////////////////////////////////////////////////////////// 0N/A // throw new CompilerError("checkOverride() synthetic"); 0N/A //////////////////////////////////////////////////////////// 0N/A // We trust the compiler. (Ha!) We're done checking. 0N/A // Our caller should have verified that the method had the 0N/A // It is forbidden to `override' a static method with an instance 0N/A // It is forbidden to `hide' an instance method with a static 0N/A // We cannot override a final method. 0N/A // Give a warning when we override a deprecated method with 0N/A // a non-deprecated one. 0N/A // We bend over backwards to suppress this warning if 0N/A // the `method' has not been already compiled or 0N/A // `this' has been already compiled. 0N/A // Visibility may not be more restrictive 0N/A // Return type equality 0N/A //////////////////////////////////////////////////////////// 0N/A // PCJ 2003-07-30 removed the following error because it is 0N/A // invalidated by the covariant return type feature of the 0N/A // 1.5 compiler. The resulting check is now much looser 0N/A // than the actual 1.5 language spec, but that should be OK 0N/A // because this code is only still used by rmic. See 4892308. 0N/A //////////////////////////////////////////////////////////// 0N/A //////////////////////////////////////////////////////////// 0N/A // Exception agreeement 0N/A * Check to see if two method definitions are compatible, that is 0N/A * do they have a `meet'. The meet of two methods is essentially 0N/A * and `intersection' of 0N/A * two methods. This method is called when some class C inherits 0N/A * declarations for some method foo from two parents (superclass, 0N/A * interfaces) but it does not, itself, have a declaration of foo. 0N/A * Caller is responsible for making sure that both methods are 0N/A * indeed visible in clazz. 0N/A * A - void foo() throws e1 0N/A * \ B void foo() throws e2 0N/A // This section of code is largely based on Section 8.4.6 0N/A // and 9.4.1 of the JLS. 0N/A // Check for both non-abstract. 0N/A // If either method is non-abstract, then we need to check that 0N/A // the abstract method can be properly overridden. We call 0N/A // the checkOverride method to check this and generate any errors. 0N/A // This test must follow the previous test. 0N/A // Both methods are abstract. 0N/A // Our caller should have verified that the method has the 0N/A // Check for return type equality 0N/A // We don't have to check visibility -- there always 0N/A // potentially exists a meet. Similarly with exceptions. 0N/A // There does exist a meet. 0N/A * This method is meant to be used to determine if one of two inherited 0N/A * methods could override the other. Unlike checkOverride(), failure 0N/A * is not an error. This method is only meant to be called after 0N/A * checkMeet() has succeeded on the two methods. 0N/A * If you call couldOverride() without doing a checkMeet() first, then 0N/A * you are on your own. 0N/A // couldOverride() is only called with `this' and `method' both 0N/A // being inherited methods. Neither of them is defined in the 0N/A // class which we are currently working on. Even though an 0N/A // abstract method defined *in* a class can override a non-abstract 0N/A // method defined in a superclass, an abstract method inherited 0N/A // from an interface *never* can override a non-abstract method. 0N/A // This comment may sound odd, but that's the way inheritance is. 0N/A // The following check makes sure we aren't trying to override 0N/A // an inherited non-abstract definition with an abstract definition 0N/A // from an interface. 0N/A // Visibility should be less restrictive 0N/A // Potentially some deprecation warnings could be given here 0N/A // when we merge two abstract methods, one of which is deprecated. 0N/A // This is not currently reported. 0N/A * Check to see if the exceptions of `this' fit within the 0N/A * exceptions of `method'. 0N/A // This code is taken nearly verbatim from the old implementation 0N/A // of checkOverride() in SourceClass. 0N/A // the throws was neither something declared by a parent, 0N/A // nor one of the ignorables. 0N/A // We were unable to find one of the exceptions. 0N/A // All of the exceptions `fit'. 0N/A //----------------------------------------------------------------- 0N/A * Check if constant: Will it inline away to a constant? 0N/A // If an infinite regress requeries this name, 0N/A // deny that it is a constant. 0N/A * Print for debugging 0N/A // will never be inlined 0N/A cost +
" expression cost units remain]");